|
| 1 | +# plop generator react atomic component |
| 2 | + |
| 3 | +_An opinionated [`plop`][plop] generator for [`typescript`][typescript] [`atomic`][atomic] [`react`][react] components._ |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +This package is hosted on [`npm`][npm]. |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install --save-dev @a9g/plop-generator-react-atomic-component |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +First, create two interfaces to include classnames or styles (depending on if you are using react-native or not) to include them into your props. |
| 16 | + |
| 17 | +```typescript |
| 18 | +import { StyleProp, ViewStyle } from "react-native"; |
| 19 | + |
| 20 | +export interface PropsWithClassName { |
| 21 | + className?: string; |
| 22 | +} |
| 23 | + |
| 24 | +export interface PropsWithStyle { |
| 25 | + style?: StyleProp<ViewStyle>; |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +Afterwards, be sure you have [`plop`][plop] installed. Then, add the following lines to your `plopfile.js`. |
| 30 | + |
| 31 | +```javascript |
| 32 | +const atomicGenerator = |
| 33 | + require("@a9g/plop-generator-react-atomic-component").default; |
| 34 | + |
| 35 | +const defaultConfig = { |
| 36 | + createIndex: true, |
| 37 | + functional: true, |
| 38 | + basePath: "src/ui/components", |
| 39 | + withClassnameInterfaceImportPath: "/framework/ui", //make sure to configure this path |
| 40 | + withStyleInterfaceImportPath: "/framework/ui", |
| 41 | + tests: true, |
| 42 | + stories: true, |
| 43 | + styledComponents: true, |
| 44 | + useNative: false, // native and macro can't be used together |
| 45 | + useMacro: false |
| 46 | +}; |
| 47 | + |
| 48 | +atomicGenerator(plop, defaultConfig); |
| 49 | +``` |
| 50 | + |
| 51 | +Now you'll have access to the `atomic-component` generator as shown below. |
| 52 | + |
| 53 | +```bash |
| 54 | +plop atomic-component |
| 55 | +``` |
| 56 | + |
| 57 | +```text |
| 58 | +src |
| 59 | +└── ui |
| 60 | + └── components |
| 61 | + └── $Type |
| 62 | + └── $ComponentName |
| 63 | + ├── $ComponentName.tsx |
| 64 | + ├── $ComponentName.test.tsx (optional) |
| 65 | + ├── $ComponentName.stories.tsx (optional) |
| 66 | + ├── $ComponentName.styles.tsx (optional) |
| 67 | + └── index.tsx (optional) |
| 68 | +``` |
| 69 | + |
| 70 | +## Questions |
| 71 | + |
| 72 | +Report bugs or provide feedback by filing [issues][issues] |
| 73 | + |
| 74 | +## License |
| 75 | + |
| 76 | +MIT see [license.md](license.md) |
| 77 | + |
| 78 | +[npm]: https://www.npmjs.com/package/@a9g/plop-generator-react-atomic-component |
| 79 | +[issues]: https://github.com/ahoendgen/plop-generator-react-atomic-component/issues |
| 80 | +[plop]: https://plopjs.com |
| 81 | +[react]: https://reactjs.org |
| 82 | +[typescript]: https://typescriptlang.org |
| 83 | +[atomic]: https://atomicdesign.bradfrost.com/ |
0 commit comments