npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@a9g/plop-generator-react-atomic-component

v0.0.5

Published

plop generator react atomic component

Downloads

979

Readme

plop generator react atomic component

An opinionated plop generator for typescript atomic react components.

Installation

This package is hosted on npm.

npm install --save-dev @a9g/plop-generator-react-atomic-component

Usage

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. h

import { StyleProp, ViewStyle } from "react-native";

export interface PropsWithClassName {
  className?: string;
}

export interface PropsWithStyle {
  style?: StyleProp<ViewStyle>;
}

Afterwards, be sure you have plop installed. Then, add the following lines to your plopfile.js.

const atomicGenerator =
  require("@a9g/plop-generator-react-atomic-component").default;

const defaultConfig = {
  createIndex: true,
  functional: true,
  basePath: "src/ui/components",
  withClassnameInterfaceImportPath: "/framework/ui", //make sure to configure this path
  withStyleInterfaceImportPath: "/framework/ui",
  tests: true,
  stories: true,
  styledComponents: true,
  useNative: false, // native and macro can't be used together
  useMacro: false,
  typeFormatter: "pascaleCase",
  fileNameFormatter: "pascaleCase",
  dirNameFormatter: "pascaleCase"
};

atomicGenerator(plop, defaultConfig);

so your plopfile.js could look e.g. like this

const atomicGenerator =
  require("@a9g/plop-generator-react-atomic-component").default;

const defaultConfig = {
  createIndex: true,
  functional: true,
  basePath: "src/ui/components",
  withClassnameInterfaceImportPath: "/framework/ui", //make sure to configure this path
  withStyleInterfaceImportPath: "/framework/ui",
  tests: true,
  stories: true,
  styledComponents: true,
  useNative: false,
  useMacro: false,
  typeFormatter: "pascaleCase",
  fileNameFormatter: "pascaleCase",
  dirNameFormatter: "pascaleCase"
};

const config = plop => {
  atomicGenerator(plop, defaultConfig);
};

module.exports = config;

Now you'll have access to the atomic-component generator as shown below.

plop atomic-component
src
└── ui
   └── components
      └── $Type
         └── $ComponentName
            ├── $ComponentName.tsx
            ├── $ComponentName.test.tsx (optional)
            ├── $ComponentName.stories.tsx (optional)
            ├── $ComponentName.styles.tsx (optional)
            └── index.tsx (optional)

Configuration

export interface GeneratorConfig {
  createIndex: boolean; //create an index file
  functional: boolean; //should the template be functional or class based?
  basePath: string; //where do you want to store the generated files
  withClassnameInterfaceImportPath: string; //from where can we import the classname interface
  withStyleInterfaceImportPath: string; //from where can we import the styles interface
  tests: boolean; //create test files
  stories: boolean; //create story files
  styledComponents: boolean; //use styled components
  useNative: boolean; //use react native
  useMacro: boolean; // use styled components macro import. native and macro can't be used together
  templateIndex?: string; //path to the corresponding files, need to be an absolute path
  templateStory?: string;
  templateStyles?: string;
  templateTest?: string;
  templateComponentFunctional?: string;
  templateComponentClassBased?: string;
  typeFormatter?: FileNameFormatters;
  fileNameFormatter?: FileNameFormatters;
  dirNameFormatter?: FileNameFormatters;
}

FileNameFormatters

export enum FileNameFormatters {
  "pascalCase" = "pascalCase",
  "camelCase" = "camelCase",
  "kebabCase" = "kebabCase",
  "snakeCase" = "snakeCase",
  "lowerCase" = "lowerCase"
}

Questions

Report bugs or provide feedback by filing issues

License

MIT see license.md