1.0.0 • Published 4 years ago

react-cview v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

react-cview

react-cview allows user to create documentation for their components and view them directly with custom configurations.

Get started

react-cview is not published to npm yet, run the following commands to test it in your local project:

git clone https://github.com/NielXu/react-cview.git
cd react-cview
npm install
npm run build
npm link

cd /path/to/your/local/project
npm link react-cview

Then you can import react-cview in your index.js and start using it

import React from 'react';
import ReactDOM from 'react-dom';
import CView from 'react-cview';

const CONFIG = {...}

ReactDOM.render(
  <React.StrictMode>
    <CView config={CONFIG}>
      <App />
    </CView>
  </React.StrictMode>,
  document.getElementById('root')
);

To develop at local simply do npm run build after you modify the files under src folder, then the component will be updated automatically.

Props

Namerequiredtypedefaultdescription
configtrueobjectThe config that controls the components and documentation
urlfalsestring'cview'The url that will be used to browse the components

Config

The documentation will be rendered based on the configuration provided, here are the fields that can be configured.

Namerequiredtypedefaultdescription
componentstruearrayA list of components with configuration

components

Namerequiredtypedefaultdescription
componenttruefunction | classThe component that will be rendered
namefalsestringThe given component's nameThe name of the component
descriptionfalsestring'No description'The description of the component
propsfalsearray[]A list of props that will be applied to the component with documentation

props

Namerequiredtypedefaultdescription
nametruestringThe name of the prop
valuetruestringThe value of the prop
requiredfalsebooleanfalseWhether this prop is required by the component or not
defaultfalseanyThe default value of the prop
typefalsestring'any'The type of the prop
docfalsestring''The documentation of this prop

Example

An example of a valid config

const CONFIG = {
  components: [
    {
      name: "Select",
      component: Select,
      description: "A well styled select component from react-select",
      props: [
        {
          name: "options",
          value: [{value: "foo", label: "FOO"},{value: "bar", label: "BAR"}],
          type: "array",
          required: true,
          doc: "Options that can be selected"
        },
      ],
    },
    {
      name: "CSelect",
      component: CSelect,
      description: "Custom selection",
      props: [
        {
          name: "className",
          value: "custom-className",
          type: "array",
          doc: "Options that can be selected"
        }
      ]
    },
    {
      name: "Input"
      component: Input,
    }
  ],
}

To run examples use npm start and go to http://localhost:8080 in your browser, see examples folder for more information

TODO

v1.0.0
  • Add example
  • ~Improve add config using functions~ (Push to v1.1.0)
  • Change all bootstrap elements to React Bootstrap
  • Implement the search feature of the sidebar
  • Proper warning and error display
  • ~Figure out a way when user deleted required props and error is thrown~ (This only happens in react development mode)