Git Product home page Git Product logo

mrmartineau / react-design-system-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
47.0 4.0 7.0 498 KB

At the moment this project is out-of-date and unmaintained. I hope to revisit it soon though... This is a boilerplate for you to create your own design system in React. It has everything setup to allow you to focus on what it is you care about: creating awesome, reusable components.

JavaScript 34.83% TypeScript 65.17%
react playroom storybook boilerplate design-system preconstruct theme-ui reusable-components

react-design-system-boilerplate's Introduction

๐ŸŽจ
React Design System Boilerplate

This is a boilerplate for you to create your own design system in React. It has everything setup to allow you to focus on what it is you care about: creating awesome, reusable components.


Docs TODO:

  • examples for how to create new entrypoints

How To Use

To clone and run this application, you'll need Git and Node.js (which comes with npm) installed on your computer. From your command line:

# Clone this repository
$ git clone https://github.com/mrmartineau/react-design-system-starter.git

# Go into the repository
$ cd react-design-system-starter

# Install dependencies
$ yarn install

# That's it, now create your own design system ๐ŸŽ‰

Core tools and technologies

Overview of your design system

Understanding Theme UI

Theme UI provides a constraint-based approach to component creation and themeing. This allows you and your team to create a design system that supports the widest

To fully understand Theme UI and all that it provides, please read and understand the documentation at https://theme-ui.com/getting-started.

Create your theme

Create a theme object to include custom color, typography, and layout values. Read more about this in the Theme UI docs.

// example themeUiTheme.js
export const theme = {
  fonts: {
    body: 'system-ui, sans-serif',
    heading: '"Avenir Next", sans-serif',
    monospace: 'Menlo, monospace',
  },
  colors: {
    text: '#000',
    background: '#fff',
    primary: '#33e',
  },
}

Add the theme to your application with the ThemeProvider, passing in the theme object as a prop.

// basic usage
import React from 'react'
import { ThemeProvider } from 'theme-ui'
import { theme } from 'your-design-system/tokens'
export default props => (
  <ThemeProvider theme={theme}>{props.children}</ThemeProvider>
)

Style your UI

This is an example of how a new component could be created without using Emotion's styled.div syntax. Read more about this method in the Theme UI docs

/** @jsx jsx */
import { jsx } from 'theme-ui'
export default props => (
  <h1
    sx={{
      color: 'primary',
      fontFamily: 'heading',
    }}
  >
    Hello
  </h1>
)

Theme UI components

The optional @theme-ui/components package includes pre-built UI components to make styling a page with Theme UI quicker. This package includes components for layouts, grids, buttons, form elements, and more. The main highlight, in my opinion, is the Box component that so flexible I predict you will use it almost everywhere.

import { Box } from '@theme-ui/components'

export const SomeComponent = (
  <Box p={4} color="white" bg="primary">
    Beep
  </Box>
)

Find out more in the Theme UI component docs.

Design tokens and theming

Design tokens are an important part of any design system, so this repo has been setup with 2 ways for your components to make use of these tokens: design-system-utils ๐Ÿ‘ฉโ€๐ŸŽจ and Theme UI.

Theme UI takes care of tokens using it's theme object and is the basis for your components and applications consuming your components.

design-system-utils is used when you need access to specific values from your tokens from anywhere in, or indeed outside, your application. It makes it really easy to store your design tokens in an organised way and reference them in your components.

All tokens-related files can be found in the src/tokens directory.

.
โ”œโ”€โ”€ colorPalette.ts
โ”œโ”€โ”€ index.ts
โ”œโ”€โ”€ themeUiTheme.ts
โ”œโ”€โ”€ tokens.models.ts
โ”œโ”€โ”€ tokens.stories.ts
โ””โ”€โ”€ tokens.ts

Using design-system-utils

design-system-utils ๐Ÿ‘ฉโ€๐ŸŽจ has already setup with this design system.

src/tokens/tokens.ts is the entry point used with design-system-utils. Please read the design-system-utils docs to find out all about this very useful library, or see below for a few simple examples:

tokens.get('radii')

Code

This is a basic view of the project's directory. All React components are located in the src/components directory. Your design tokens, which are managed by design-system-utils.

.
โ”œโ”€โ”€ build // the directory for compiled files
โ”œโ”€โ”€ jest.config.js
โ”œโ”€โ”€ playroom.config.js
โ”œโ”€โ”€ src
โ”‚ย ย  โ”œโ”€โ”€ buttons.ts // an example entry file for a subset of
โ”‚ย ย  โ”œโ”€โ”€ components
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Button
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Button.stories.tsx
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Button.test.tsx
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ Button.ts
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ index.ts
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ index.ts
โ”‚ย ย  โ”œโ”€โ”€ index.ts // this is the main project entry file
โ”‚ย ย  โ”œโ”€โ”€ intro.story.mdx
โ”‚ย ย  โ””โ”€โ”€ tokens
โ”‚ย ย      โ”œโ”€โ”€ colorPalette.ts
โ”‚ย ย      โ”œโ”€โ”€ index.ts
โ”‚ย ย      โ”œโ”€โ”€ themeUiTheme.ts
โ”‚ย ย      โ”œโ”€โ”€ tokens.models.ts
โ”‚ย ย      โ”œโ”€โ”€ tokens.stories.ts
โ”‚ย ย      โ””โ”€โ”€ tokens.ts
โ”œโ”€โ”€ types
โ””โ”€โ”€ yarn.lock

Test files use *.test.ts(x) or *.spec.ts(x)

Any file with *.story.tsx or *.stories.tsx, or *.story.mdx or *.stories.mdx can be used by Storybook. The *.mdx extensions are used for documentation.

Anatomy of a component directory

E.g. a Button found in the /src/components directory.

.
โ”œโ”€โ”€ Button.tsx // < component code
โ”œโ”€โ”€ README.md // < component documentation
โ”œโ”€โ”€ Button.story.tsx // < component story
โ”œโ”€โ”€ Button.test.tsx // < component tests
โ”œโ”€โ”€ __snapshots__
โ”‚   โ””โ”€โ”€ Button.test.tsx.snap // < auto-generated snapshot code
โ””โ”€โ”€ index.ts // < component entry file

Build and compilation

  • Simple, one file bundle
  • grouped files

Build scripts and commands

  • yarn build: Compile a production build with Rollup
  • yarn watch: Compile/watch with Rollup. This is useful in conjunction with yarn link.
  • yarn storybook: Run Storybook development environment
  • yarn playroom: Run Playroom
  • yarn format: Format all JS with Prettier
  • yarn lint: Lint JS and CSS-in-JS
  • yarn lint:js: Lint JS with ESLint
  • yarn lint:css: Lint CSS-in-JS with Stylelint
  • yarn size: Test the file size of the build
  • yarn size:why: Analyse the the build
  • yarn test: Run all tests
  • yarn test:js: Run all JS tests with Jest
  • yarn test:coverage: Run a code coverage test with Jest
  • yarn test:watch: Run test suite while watching for changes

Tooling

The boilerplate uses various tools to ensure better code quality. Defaults have been set for linting and code style, but can easily be overridden according to your needs.

  • Prettier
  • Eslint
  • Stylelint
  • Husky
  • lint-staged

Publishing your package to npm

There is a pre-build script that is be run by npm when you publish (npm run prebuild)

License

MIT

Made by Zander โšก

react-design-system-boilerplate's People

Contributors

mrmartineau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.