An open API service indexing awesome lists of open source software.

https://github.com/springload/react-patterns

A pattern library designed to be easier to maintain
https://github.com/springload/react-patterns

Last synced: 10 months ago
JSON representation

A pattern library designed to be easier to maintain

Awesome Lists containing this project

README

          


React Patterns

A pattern library system designed to be easier to maintain

# Install

npm install react-patterns

yarn add react-patterns

# What is a Pattern Library?

A pattern library (part of a Style Guide or a Design System), is a way of documenting usage of components and how they're made with HTML, CSS, and other assets.

Having this documented can help siloed teams or different vendors coordinate to achieve design consistency.

## What is React-Patterns?

A component that autodetects the HTML and CSS of your components, and provides a download cart.

## How can I make a pattern library with React-Patterns?

One of the advantages of react-patterns is that it detects the CSS Rules being applied, so you can put your production site's CSS files on the page and write HTML that uses them and react-patterns will only display the relevant CSS. This means that a lot less effort to repurpose your existing CSS as a pattern library.

Usage:

```javascript
import React from "react";
import Pattern from "react-patterns";
import "h6.css"; // contains h6 { color: red; }

export default () => (

My Heading 6


);
```

Will render as


My Heading 6
HTML<h6>My Heading 6</h6>CSSh6 { color: red; }

### Syntax Highlighting

Use `react-patterns/theme/solarize.css`.

## Demo

[LIC Pattern Library](https://springload.github.io/lic-pattern-library/)

## This is a pattern library so where's the dev webserver?

Great question.

`react-patterns` doesn't include a dev server because other projects do it better.

So instead just use Create-React-App or, add `` tags to a new route in your existing app, or use whatever boilerplate you like.

## How does react-patterns organise the page of patterns... with headings, accordions, tabs, or what?

Here's a hypothetical... if your pattern library had 5 components then it probably should be organised quite differently to another library with 1000 components, so this software is intentionally unopinionated about the presentation of your components. react-patterns just tries to do one thing well -- rendering the component preview. Decide for yourself how to organise them (do try `react-accessible-accordion` though!).

## Features


  • [x] Minimal

  • [x] React

  • [x] CSS Rule Autodetection, so there's no need to manually associate CSS with a component

  • [x] ZIP download of particular components

  • [x] HTML beautifier

  • [x] CSS beautifier

  • [x] CSS rule whitelist and blacklist. Pass in 'blacklist' prop with value of 'stylesheet' to string match against attributes of `<link>` or `<style>`, 'stylesheets' to pass in an array of those, or 'rule' to match against selectors, or rules for an array of those.

  • [x] CSS Rule whitelist (probably only useful to opt-in specific stylesheets while ignoring others)

  • [x] Render prop overrides for HTML and CSS

## Props

The only requirement is a wrapped `children` node. All other props are optional.

noCartDisable cart
filenameChoose the cart ZIP filename for the HTML
blacklistA blacklist of types of CSS to include. An Object or an array of Objects like { stylesheet: 'substring', rule: 'substring', media: 'substring' }. Use this to exclude certain CSS.
whitelistA whitelist of types of CSS to include. An Object or an array of Objects like { stylesheet: 'substring', rule: 'substring', media: 'substring' }. Use this to include certain CSS.
Render props
renderChildrenA render prop to wrap `children` prop
renderHTMLA render prop to wrap autodetected HTML.
renderCSSA render prop to wrap autodetected CSS.

## Roadmap


  • [ ] ...and show prop types, somehow? (`prop-types` or Flow/TS?). Sadly I'm not sure how we could support FlowType/TypeScript types because those are removed at compile-time.

  • [ ] Detect basic JSX React Components... this is almost working

  • [ ] Make it support interactive components (eg accumulating CSS across these multiple states).

  • [ ] Parse SourceMaps to derive Sass (etc) if possible.