Coder Social home page Coder Social logo

react-toolchain's Introduction



Toolchain to help build React components with Primer

 

Requirements

  • webpack 5+

 

Setup

npm install @primer/react-toolchain --save-dev

Storybook

Step 1. Add this script to your package.json:

{
  scripts: {
    "start": "webpack",
    "test": "jest",
+   "storybook": "toolchain storybook",
+   "storybook:build": "toolchain storybook:build"
  }
}

Step 2. Create a ComponentName.stories.tsx file

We recommend putting this file next to the component.

import { DatePicker } from './date-picker';

export default {
  title: 'Common components/Datepicker'
};

export const SimpleDatePicker = () => {
  return <DatePicker variant="single" value={new Date()} />;
};

Learn more about stories from the Storybook docs

 

You're good to go! Run npm run storybook.

Customise storybook

If you need to customize your storybook config, create .storybook directory in the root of your repository with the following files:

  1. main.js

    const defaultConfig = require('@primer/react-toolchain/storybook/main');
    const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
    
    module.exports = {
      // extend default config
      ...defaultConfig,
    
      // remember to include default properties while extending
      addons: [...defaultConfig.addons, 'storybook-addon-performance/register'],
    
      // need to customise webpack config because we use custom resolvers for helpers/util
      webpackFinal: (webpackConfig) => {
        webpackConfig.resolve.plugins = [new TsconfigPathsPlugin({ baseUrl: './src/client' })];
        return config;
      }
    };
  2. preview.js

    // step 1: export defaults
    export * from '@primer/react-toolchain/storybook/preview';
    
    // (optional) step 2: customise and overwrite
    import { decorators } from '@primer/react-toolchain/storybook/preview';
    import { withPerformance } from 'storybook-addon-performance';
    
    decorators.push(withPerformance);
    export { decorators };

react-toolchain's People

Contributors

github-actions[bot] avatar siddharthkp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-toolchain's Issues

running list

features:

  • default viewports from primer
  • primer theme switcher
  • set storyStoreV7: true
  • include .mdx by default
  • prc generate to scaffold a component structure based on file structure ADR

customistation

  • customisable preview.js

dx

  • should we just use .storybook if it exists?
  • is the name and bin commands good?
  • automatically scope down to story files to make it fast
  • detect missing .storybook/preview if .storybook/main exists and add it
  • "customise" command to scaffold .storybook with defaults

misc

  • pass cli flags through
  • test with primer/react
  • test with react-shared

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.