Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-custom-ratings

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-custom-ratings - npm Package Compare versions

Comparing version 0.1.72 to 0.1.73

3

dist/react-custom-ratings.cjs.development.js

@@ -186,3 +186,3 @@ 'use strict';

function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {

@@ -200,2 +200,3 @@ var source = arguments[i];

};
return _extends.apply(this, arguments);

@@ -202,0 +203,0 @@ }

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n,e=(n=require("react"))&&"object"==typeof n&&"default"in n?n.default:n,t=require("react-icons/ai");function a(n,e){void 0===e&&(e={});var t=e.insertAt;if(n&&"undefined"!=typeof document){var a=document.head||document.getElementsByTagName("head")[0],l=document.createElement("style");l.type="text/css","top"===t&&a.firstChild?a.insertBefore(l,a.firstChild):a.appendChild(l),l.styleSheet?l.styleSheet.cssText=n:l.appendChild(document.createTextNode(n))}}a(".filled {\n font-size: 3rem;\n position: absolute;\n top: 0;\n left: 0;\n white-space: nowrap;\n overflow: hidden;\n width: 0;\n /* overflow: hidden; */\n}\nspan {\n font-size: 3rem;\n /* overflow: hidden; */\n}\n.star {\n font-size: 3rem;\n /* overflow: hidden; */\n}\n");var l=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return e.filter(Boolean).map((function(n){return n.trim()})).join(" ")};function r(n){var t=n.filledColor,a=void 0===t?"":t,r=n.ratingIconClassname,i=void 0===r?"":r,o=n.FilledRatingIcon,c=n.width,s=Math.max.apply(Math,n.data.map((function(n){return n.rating})));return e.createElement("div",{className:"filled",style:{width:c}},[].concat(new Array(s).fill("_")).map((function(n,t){return e.createElement("span",{key:"unfilled-star custom icon "+t,className:l("star",i),style:{color:a||"#ffa41c"}},o)})))}a(".unfilled {\n position: relative;\n display: inline-block;\n}\n.unfilled span {\n font-size: 3rem;\n padding: 0.1rem;\n}\n\n.unfilled .filled {\n position: absolute;\n top: 0;\n left: 0;\n white-space: nowrap;\n overflow: hidden;\n width: 0;\n}\n");var i=function(n){var t=n.data,a=n.filledColor,i=n.unfilledColor,o=n.ratingIconClassname,c=void 0===o?"":o,s=n.FilledRatingIcon,d=n.UnfilledRatingIcon,u=n.width,f=Math.max.apply(Math,t.map((function(n){return n.rating})));return console.log({numberOfRating:f}),e.createElement("div",{className:"unfilled"},[].concat(new Array(f).fill("_")).map((function(n,t){return e.createElement("span",{key:"unfilled-star custom icon "+t,className:l("star",c),style:{color:i||"#ffa41c"}},i?s:d)})),e.createElement(r,{data:t,filledColor:a,ratingIconClassname:c,FilledRatingIcon:s,width:u}))};function o(n){var a=n.data,r=n.options,o=void 0===r?{}:r,c=o.filledColor,s=o.unfilledColor,d=o.ratingIconClassname,u=o.show,f=void 0===u||u,p=o.className,m=void 0===p?"":p,g=o.FilledRatingIcon,v=void 0===g?e.createElement(t.AiFillStar,null):g,h=o.UnfilledRatingIcon,x=void 0===h?e.createElement(t.AiOutlineStar,null):h,y=o.headerText,C=Math.max.apply(Math,a.map((function(n){return n.rating}))),w=a.reduce((function(n,e){return n+e.count}),0),b={},E=0;for(var N in a.forEach((function(n){b[""+n.rating]=n.count/w})),b)E+=Number(N)*b[N];var I=Number(E.toFixed(2))/C*100;return e.createElement(e.Fragment,null,f&&e.createElement("div",{className:"starRating"},e.createElement(i,{data:a,filledColor:c,unfilledColor:s,ratingIconClassname:d,FilledRatingIcon:v,UnfilledRatingIcon:x,width:I+"%"}),(null==y?void 0:y(E))||e.createElement("p",{className:l("rating",m)},E.toFixed(2)," out of ",C)))}function c(){return(c=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(n[a]=t[a])}return n}).apply(this,arguments)}function s(n){return e.createElement("div",{className:"progress_bar",style:{backgroundColor:n.unfilledColor||"#f0f2f2"},role:"progressbar","aria-valuenow":40,"aria-valuemax":20,"aria-valuemin":0},e.createElement("div",{className:"filled_bar",style:{width:n.percentage+"%",backgroundColor:n.filledColor||"#ffa41c"}}))}function d(n){var t=n.data,a=void 0===t?[]:t,r=n.options,i=void 0===r?{}:r,o=i.className,d=void 0===o?"":o,u=i.filledColor,f=i.unfilledColor,p=i.onClick,m=a.reduce((function(n,e){var t,a;return c({},n,n[e.rating]?((t={})[e.rating]=n[e.rating]+e.count,t):((a={})[e.rating]=e.count,a))}),{}),g=Math.max.apply(Math,a.map((function(n){return n.rating}))),v=[].concat(new Array(g).fill("_")).map((function(n,e){return e+1})).reduce((function(n,e){var t,a;return c({},n,m[e]?((t={})[e]=m[e],t):((a={})[e]=0,a))}),{}),h=Object.entries(v).map((function(n){return{count:n[1],rating:Number(n[0])}})),x=h.reduce((function(n,e){return n+e.count}),0);return console.log({combinedData:h}),e.createElement("div",{className:"container"},h.map((function(n,t){var a=n.count,r=n.rating,o=100*a/x||0;return e.createElement("div",{key:t+a,className:l("inner_container",d),onClick:function(){return p&&p(n)}},null!=i&&i.progressBarText?i.progressBarText(n):e.createElement("span",{className:"subtext"},r," stars"),e.createElement(s,{rating:r,value:a,total:x,percentage:o,filledColor:u,unfilledColor:f}),e.createElement("div",null,null!=i&&i.percentage?e.createElement(e.Fragment,null,i.percentage(o,n)," "):e.createElement("span",{className:"percent_text"},Math.ceil(o)," %")))})))}a(".starRating {\n display: flex;\n justify-content: center;\n}\n.starRating .rating {\n font-size: 14px;\n white-space: nowrap;\n margin-left: 1rem;\n}\n"),a(".ratings_container {\n display: flex;\n flex-direction: column;\n align-items: center;\n width: 100%;\n justify-content: center;\n background-color: #fff;\n}\n"),a(".progress_bar {\n display: flex;\n flex: 1;\n align-self: stretch;\n border-radius: 4px;\n}\n\n.filled_bar {\n border-radius: 4px 0 0 4px;\n height: 100%;\n}\n"),a(".container {\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n gap: 1.2rem;\n box-sizing: border-box;\n padding: 10px;\n}\n\n.inner_container {\n width: 100%;\n height: 1.2rem;\n display: flex;\n flex-direction: row;\n align-items: center;\n gap: 0.8rem;\n}\n\n.subtext {\n font-size: 14px;\n white-space: nowrap;\n display: flex;\n}\n\n.percent_text {\n font-size: 14px;\n white-space: nowrap;\n display: flex;\n width: 35px;\n justify-content: flex-end;\n}\n"),exports.ProgressBar=d,exports.Rating=o,exports.Ratings=function(n){var t=n.data,a=n.options,l=void 0===a?{progressBar:{},rating:{}}:a,r=l.progressBar,i=l.rating;return e.createElement("div",{className:"ratings_container"},e.createElement(o,{data:t,options:{show:null==i?void 0:i.show,filledColor:null==i?void 0:i.filledColor,unfilledColor:null==i?void 0:i.unfilledColor,ratingIconClassname:null==i?void 0:i.className,className:null==i?void 0:i.className,FilledRatingIcon:null==i?void 0:i.FilledRatingIcon,UnfilledRatingIcon:null==i?void 0:i.UnfilledRatingIcon,headerText:null==i?void 0:i.headerText}}),e.createElement(d,{data:t,options:{filledColor:null==r?void 0:r.filledColor,unfilledColor:null==r?void 0:r.unfilledColor,className:null==r?void 0:r.className,percentage:null==r?void 0:r.percentage,progressBarText:null==r?void 0:r.progressBarText,onClick:null==r?void 0:r.onClick}}))};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n,e=(n=require("react"))&&"object"==typeof n&&"default"in n?n.default:n,t=require("react-icons/ai");function a(n,e){void 0===e&&(e={});var t=e.insertAt;if(n&&"undefined"!=typeof document){var a=document.head||document.getElementsByTagName("head")[0],l=document.createElement("style");l.type="text/css","top"===t&&a.firstChild?a.insertBefore(l,a.firstChild):a.appendChild(l),l.styleSheet?l.styleSheet.cssText=n:l.appendChild(document.createTextNode(n))}}a(".filled {\n font-size: 3rem;\n position: absolute;\n top: 0;\n left: 0;\n white-space: nowrap;\n overflow: hidden;\n width: 0;\n /* overflow: hidden; */\n}\nspan {\n font-size: 3rem;\n /* overflow: hidden; */\n}\n.star {\n font-size: 3rem;\n /* overflow: hidden; */\n}\n");var l=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return e.filter(Boolean).map((function(n){return n.trim()})).join(" ")};function r(n){var t=n.filledColor,a=void 0===t?"":t,r=n.ratingIconClassname,i=void 0===r?"":r,o=n.FilledRatingIcon,c=n.width,s=Math.max.apply(Math,n.data.map((function(n){return n.rating})));return e.createElement("div",{className:"filled",style:{width:c}},[].concat(new Array(s).fill("_")).map((function(n,t){return e.createElement("span",{key:"unfilled-star custom icon "+t,className:l("star",i),style:{color:a||"#ffa41c"}},o)})))}a(".unfilled {\n position: relative;\n display: inline-block;\n}\n.unfilled span {\n font-size: 3rem;\n padding: 0.1rem;\n}\n\n.unfilled .filled {\n position: absolute;\n top: 0;\n left: 0;\n white-space: nowrap;\n overflow: hidden;\n width: 0;\n}\n");var i=function(n){var t=n.data,a=n.filledColor,i=n.unfilledColor,o=n.ratingIconClassname,c=void 0===o?"":o,s=n.FilledRatingIcon,d=n.UnfilledRatingIcon,u=n.width,f=Math.max.apply(Math,t.map((function(n){return n.rating})));return console.log({numberOfRating:f}),e.createElement("div",{className:"unfilled"},[].concat(new Array(f).fill("_")).map((function(n,t){return e.createElement("span",{key:"unfilled-star custom icon "+t,className:l("star",c),style:{color:i||"#ffa41c"}},i?s:d)})),e.createElement(r,{data:t,filledColor:a,ratingIconClassname:c,FilledRatingIcon:s,width:u}))};function o(n){var a=n.data,r=n.options,o=void 0===r?{}:r,c=o.filledColor,s=o.unfilledColor,d=o.ratingIconClassname,u=o.show,f=void 0===u||u,p=o.className,m=void 0===p?"":p,g=o.FilledRatingIcon,v=void 0===g?e.createElement(t.AiFillStar,null):g,h=o.UnfilledRatingIcon,x=void 0===h?e.createElement(t.AiOutlineStar,null):h,y=o.headerText,C=Math.max.apply(Math,a.map((function(n){return n.rating}))),w=a.reduce((function(n,e){return n+e.count}),0),b={},E=0;for(var N in a.forEach((function(n){b[""+n.rating]=n.count/w})),b)E+=Number(N)*b[N];var I=Number(E.toFixed(2))/C*100;return e.createElement(e.Fragment,null,f&&e.createElement("div",{className:"starRating"},e.createElement(i,{data:a,filledColor:c,unfilledColor:s,ratingIconClassname:d,FilledRatingIcon:v,UnfilledRatingIcon:x,width:I+"%"}),(null==y?void 0:y(E))||e.createElement("p",{className:l("rating",m)},E.toFixed(2)," out of ",C)))}function c(){return(c=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(n[a]=t[a])}return n}).apply(this,arguments)}function s(n){return e.createElement("div",{className:"progress_bar",style:{backgroundColor:n.unfilledColor||"#f0f2f2"},role:"progressbar","aria-valuenow":40,"aria-valuemax":20,"aria-valuemin":0},e.createElement("div",{className:"filled_bar",style:{width:n.percentage+"%",backgroundColor:n.filledColor||"#ffa41c"}}))}function d(n){var t=n.data,a=void 0===t?[]:t,r=n.options,i=void 0===r?{}:r,o=i.className,d=void 0===o?"":o,u=i.filledColor,f=i.unfilledColor,p=i.onClick,m=a.reduce((function(n,e){var t,a;return c({},n,n[e.rating]?((t={})[e.rating]=n[e.rating]+e.count,t):((a={})[e.rating]=e.count,a))}),{}),g=Math.max.apply(Math,a.map((function(n){return n.rating}))),v=[].concat(new Array(g).fill("_")).map((function(n,e){return e+1})).reduce((function(n,e){var t,a;return c({},n,m[e]?((t={})[e]=m[e],t):((a={})[e]=0,a))}),{}),h=Object.entries(v).map((function(n){return{count:n[1],rating:Number(n[0])}})),x=h.reduce((function(n,e){return n+e.count}),0);return console.log({combinedData:h}),e.createElement("div",{className:"container"},h.map((function(n,t){var a=n.count,r=n.rating,o=100*a/x||0;return e.createElement("div",{key:t+a,className:l("inner_container",d),onClick:function(){return p&&p(n)}},null!=i&&i.progressBarText?i.progressBarText(n):e.createElement("span",{className:"subtext"},r," stars"),e.createElement(s,{rating:r,value:a,total:x,percentage:o,filledColor:u,unfilledColor:f}),e.createElement("div",null,null!=i&&i.percentage?e.createElement(e.Fragment,null,i.percentage(o,n)," "):e.createElement("span",{className:"percent_text"},Math.ceil(o)," %")))})))}a(".starRating {\n display: flex;\n justify-content: center;\n}\n.starRating .rating {\n font-size: 14px;\n white-space: nowrap;\n margin-left: 1rem;\n}\n"),a(".ratings_container {\n display: flex;\n flex-direction: column;\n align-items: center;\n width: 100%;\n justify-content: center;\n background-color: #fff;\n}\n"),a(".progress_bar {\n display: flex;\n flex: 1;\n align-self: stretch;\n border-radius: 4px;\n}\n\n.filled_bar {\n border-radius: 4px 0 0 4px;\n height: 100%;\n}\n"),a(".container {\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n gap: 1.2rem;\n box-sizing: border-box;\n padding: 10px;\n}\n\n.inner_container {\n width: 100%;\n height: 1.2rem;\n display: flex;\n flex-direction: row;\n align-items: center;\n gap: 0.8rem;\n}\n\n.subtext {\n font-size: 14px;\n white-space: nowrap;\n display: flex;\n}\n\n.percent_text {\n font-size: 14px;\n white-space: nowrap;\n display: flex;\n width: 35px;\n justify-content: flex-end;\n}\n"),exports.ProgressBar=d,exports.Rating=o,exports.Ratings=function(n){var t=n.data,a=n.options,l=void 0===a?{progressBar:{},rating:{}}:a,r=l.progressBar,i=l.rating;return e.createElement("div",{className:"ratings_container"},e.createElement(o,{data:t,options:{show:null==i?void 0:i.show,filledColor:null==i?void 0:i.filledColor,unfilledColor:null==i?void 0:i.unfilledColor,ratingIconClassname:null==i?void 0:i.className,className:null==i?void 0:i.className,FilledRatingIcon:null==i?void 0:i.FilledRatingIcon,UnfilledRatingIcon:null==i?void 0:i.UnfilledRatingIcon,headerText:null==i?void 0:i.headerText}}),e.createElement(d,{data:t,options:{filledColor:null==r?void 0:r.filledColor,unfilledColor:null==r?void 0:r.unfilledColor,className:null==r?void 0:r.className,percentage:null==r?void 0:r.percentage,progressBarText:null==r?void 0:r.progressBarText,onClick:null==r?void 0:r.onClick}}))};
//# sourceMappingURL=react-custom-ratings.cjs.production.min.js.map

@@ -180,3 +180,3 @@ import React from 'react';

function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {

@@ -194,2 +194,3 @@ var source = arguments[i];

};
return _extends.apply(this, arguments);

@@ -196,0 +197,0 @@ }

{
"version": "0.1.72",
"version": "0.1.73",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -1,160 +0,63 @@

# TSDX React User Guide
**react-custom-ratings**
react-custom-ratings is a react rating component which supports custom icons and styles and also provides progress bar which shows detailed information on ratings.
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
> This TSDX setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you’re looking to build a React-based app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`.
> If you’re new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/)
## Commands
TSDX scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`.
The recommended workflow is to run TSDX in one terminal:
```bash
npm start # or yarn start
**Installation**
```
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
Then run the example inside another:
```bash
cd example
npm i # or yarn to install dependencies
npm start # or yarn start
npm install react-custom-ratings
```
The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**, we use [Parcel's aliasing](https://parceljs.org/module_resolution.html#aliases).
**Usage**
```
import {Ratings, Rating, ProgressBar} from 'react-custom-ratings'
const Demo=()=>{
return(
<!-- Use Ratings component to display both ratings and progress bar -->
<Ratings data={[{count:10,rating:5},{count:13,rating:4},{count:10,rating:3},{count:8,rating:2},{count:4,rating:1}]}/>
<!-- Use Rating component to display ratings -->
<Rating data={[{count:10,rating:5},{count:13,rating:4},{count:10,rating:3},{count:8,rating:2},{count:4,rating:1}]}/>
<!-- Use ProgresBar component to display ProgressBar -->
<ProgressBar data={[{count:10,rating:5},{count:13,rating:4},{count:10,rating:3},{count:8,rating:2},{count:4,rating:1}]}/>
)};
```
**API**
To do a one-off build, use `npm run build` or `yarn build`.
This a list of props that you can pass down to the Ratings component:
| Property | Description | Default Value|Type|
| ----------- | ----------- | ------------ |----|
|data|Data for Ratings|NA|array|
| options | **Props applied to the Rating and ProgressBar elements.**|{ratings:{},progressBar:{}}|object
To run tests, use `npm test` or `yarn test`.
## Configuration
List of props that you can pass down to the Rating Component:
Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
| Property | Description | Default Value|Type|
| ----------- | ----------- | ------------ |----|
|show|If it is true the rating component is visible |true|boolean|
|filledColor|Filled rating icon color|'#ffa41c'|string|
|unfilledColor|Empty rating icon color|'#ffa41c'|string|
|ratingIconClassname|Classname for rating Icon|'star'|string|
|className|classname for rating header text|'rating'|string|
|FilledRatingIcon|Custom react element for filled rating icon|<AiFillStar/> from react-icons|React element|
|UnfilledRatingIcon|Custom react element for unfilled rating icon|<AiOutlineStar /> from react-icons|React element|
|headerText|headerText is function which takes 'percent' type of number as parameter and returns react element|NA|(percent: number) => React.ReactElement;
### Jest
List of props that you can pass down to the ProgressBar Component:
| Property | Description | Default Value|Type|
| ----------- | ----------- | ------------ |----|
|filledColor|Filled start rating color|'#ffa41c'|string|
|unfilledColor|Empty star rating color|'#ffa41c'|string|
|className|classname for rating header text|'rating'|string|
|progressBarText|To display custom text on left side of progress bar use progressBarText function.progressBarText takes function with parameter 'data' which should return react element|(data) => React.ReactElement;|React Element|
|percentage|To display custom percentage of ratings on rigt side of progress bar use percentage function.perecentage takes fucntion with two parameters 'data and 'percent' which should return react element|(percent: number, data) => React.ReactElement;|React Element|
|onClick|onClick is event handler function which gets executed when clicked on any of the progress bar,first parameter for onClick function is data of the progress bar clicked on. |(data) => void;|Function
**Help improve the component**
Build on your machine:
# Clone the repo
git clone https://github.com/Roxiler/react-ratings.git
Jest tests are set up to run with `npm test` or `yarn test`.
### Bundle analysis
Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`.
#### Setup Files
This is the folder structure we set up for you:
```txt
/example
index.html
index.tsx # test your component here in a demo app
package.json
tsconfig.json
/src
index.tsx # EDIT THIS
/test
blah.test.tsx # EDIT THIS
.gitignore
package.json
README.md # EDIT THIS
tsconfig.json
```
#### React Testing Library
We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.
### Rollup
TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
### TypeScript
`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
## Continuous Integration
### GitHub Actions
Two actions are added by default:
- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
- `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit)
## Optimizations
Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
```js
// ./types/index.d.ts
declare var __DEV__: boolean;
// inside your code...
if (__DEV__) {
console.log('foo');
}
```
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
## Module Formats
CJS, ESModules, and UMD module formats are supported.
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
## Deploying the Example Playground
The Playground is just a simple [Parcel](https://parceljs.org) app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for **manually** deploying with the Netlify CLI (`npm i -g netlify-cli`):
```bash
cd example # if not already in the example folder
npm run build # builds to dist
netlify deploy # deploy the dist folder
```
Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify:
```bash
netlify init
# build command: yarn build && cd example && yarn && yarn build
# directory to deploy: example/dist
# pick yes for netlify.toml
```
## Named Exports
Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
## Including Styles
There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
## Publishing to NPM
We recommend using [np](https://github.com/sindresorhus/np).
## Usage with Lerna
When creating a new package with TSDX within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_.
The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project.
Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below.
```diff
"alias": {
- "react": "../node_modules/react",
- "react-dom": "../node_modules/react-dom"
+ "react": "../../../node_modules/react",
+ "react-dom": "../../../node_modules/react-dom"
},
```
An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. [However, that might cause other problems.](https://github.com/palmerhq/tsdx/issues/64)
# Install dependancies
npm install

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc