vhx / quartz-react

Quartz components using React
2 stars 1 forks source link

React Components for VHX Quartz

https://vhx.github.io/quartz-react/

Installation

npm install @vhx/quartz-react

Usage

First include quartz.css, components.css, quartz-icons.css, and the css files from dist/ for any components you intend to use.

Then import the components:

import { Button, Tag, util } from '@vhx/quartz-react';

const MyComponent = () => (
  <div>
    <Button>Hello</Button>
  </div>
);

For demos and code examples, run npm start and open up localhost:3000 in your browser. Or visit https://vhx.github.io/quartz-react/

NPM Scripts

Folder Hierarchy

build/
  build-css.js                  # Copies css from /docs/css to /dist and prepends version & hash
  rollup.config.js              # Configuration for the bundler to output js to dist/
  rollup.demo-config.js         # Same as above, but for the demo site (/docs/js)
components/
  [Component]/                  # At minimum contains the following files, but can be extended as necessary
    index.js                    # This just exports your [Component].jsx
    [Component].jsx             # The main component file
    [Component].test.jsx        # Unit tests for the component
  util/                         # Utility functions shared by components
demo/
  sections/                     # Sections of the demo page with code and examples
  ui/                           # Components specific to the demo page that are not included in quartz-react
  index.jsx                     # The demo page itself (ie. what is seen on localhost:3000)
docs/                           # The github pages website. `demo/index.jsx` gets compiled into here.
index.js                        # Every component that is exported in quartz-react

How to Create a New Component

Checklist:

Documenting Components

In addition to the documentation in demo site, components should be self-documenting. Using propTypes and defaultProps help with this effort. A third, non-standard property called propDescriptions may additionally be used to document props. If any of these statics are defined on your component, use a <PropTypeTable />. For example:

// in components/MyComponent/MyComponent.jsx
// ---------------------------------------------
const MyComponent = ({ title }) => <h1>{title.slice(0, 50)}</h1>;

MyComponent.propTypes = {
  title: PropTypes.string,
};

MyComponent.defaultProps = {
  title: 'Hello World',
};

MyComponent.propDescriptions = {
  title: 'A brief title, truncated at 50 characters',
};

// in demo/sections/MyComponent.jsx
// ---------------------------------------------
const MyComponentDemo = () => (
  <div>
    <DemoRow>
      <Title>MyComponent</Title>
      <Details>Some documentation for your component goes here...</Details>
    </DemoRow>
    <DemoRow code='<MyComponent />'>
      <Subtitle>Section heading goes here</Subtitle>
      <MyComponent />
    </DemoRow>
    <DemoRow>
      <PropTypeTable component={MyComponent} />
    </DemoRow>
  </div>
);

You must also write tests for your component. This not only helps prevent regressions, but serves as an additional source of documentation.

Demo UI Components

Component demo files (demo/sections/*.jsx) should export a component containing <DemoRow>s. These accept an optional code prop that's a string of code to display on the right side of the page.

Available UI componennts for use in demos include:

Follow the example from the Text component's demo for the simplest example setup.