This package contains the most powerful components using react.
- Usage
- Requirements
- Run the project
- Folders Architecture
- Components Structure
- Available Scripts
- Useful vscode plugins
- How to write your code
- Make updates
In order to use this components you should add the following line to your App.js or your index.css
import 'c3-ui/assets/c3-ui.css'
Which styles all the components used here.
You can import all the components throught its corresponding group
import { DangerButton } from 'elements/Buttons'
Are you developing the
Yarn:
$ yarn
$ yarn run start
Npm:
$ npm install
$ npm run start
c3-ui
├── lib
└── generics
└── elements
└── components
└── styles
├── base
├── components
├── elements
├── fonts
├── generics
├── vendor
└── index.scss
├── node_modules
├── test-config
├── coverage
├── jest
├── file-mock.js
├── jest-setup.js
├── polyfills.js
└── style-mock.js
├── stories
└── .storybook
└── all-stories
├── .babelrc
├── .eslint
├── .eslintignore
├── .gitignore
├── .nvmrc
├── .prettierignore
├── .prettierrc.json
├── jsconfig.json
├── .env
└── README.md
You can preview all the components in the storybook after you run the project in the following url:
http://localhost:6006
-
- Placed in src/library/Generics
layer: (UI/CSS)
Here you can create generic Generics that will be useful in the next layer.
Rules:
-
You're able to make CSS changes through classes
- colors
- border
- shadows
- padding
- margin
- ...etc
-
Implement BEM methodology
-
Import the sass file of the component in app.scss
-
You will regularly use HTML Generics
-
Not Semantic Generics
-
Only imports of the same level are allowed
-
Import any of this component through due to babel-module-resolver, its config is placed in .babelrc
import { Button, IconButton } from 'generics/Buttons'
Examples:
Input.js
class Input extends Component { static propTypes = { onChange: PropTypes.func, value: PropTypes.any, type: PropTypes.string } state = { value: '' } onChange = event => { const { onChange } = this.props if (onChange) { this.props.onChange(event.target.value) } else { this.setState({ value: event.target.value }) } } render() { const { value: parentValue } = this.props return ( <input className="input" type={this.props.type || 'text'} {...this.props} onChange={this.onChange} value={parentValue ? parentValue : this.state.value} /> ) } }
-
- Placed in src/library/Elements
layer: (UI/CSS)
Rules:
- You're able to make CSS changes through classes
- colors
- border
- shadows
- padding
- margin
- ...etc
- Implement BEM methodology
- Import the sass file of the component in app.scss
- Semantic Generics
Examples:
TextInput.js
import { Input } from 'generics/FormInputs/Inputs' const TextInput = props => { return <Input type="text" {...props} /> } export default TextInput
-
- Placed in src/library/components
layer: (UX/Int)
Rules:
-
You are able to use any element created
-
You're able to change styles in css of the following attributes changes through classes
- padding
- margin
- position
- use of the breakpoints
As you can see only attributes according to layout style
-
Semantic Components
-
You can put some logic that is only for that specific component
Examples:
MainMenuLinks.js contains:
<Frame className="main-menu-links" justify> <FrameItem className="main-menu-links__item"> { children.map(child)=>( child ) } </FrameItem> </Frame>
OpenQuestion.js which is composed of some Elements as: Frame, TextInput, Label, Title
<Frame> <FrameItem><Title>Pregunta 1</Title> </FrameItem> <FrameItem small={2}> <Label>Responde con lo que quieras.</Label> </FrameItem> <FrameItem small={8}> <TextInput/> </FrameItem> </Frame>
In the project directory, you can run:
Checks the current version published on npmjs.org
Autoprefixes the css styles to be available on most browsers.
Watches for changes in .scss.
Files must be inside src/ folder
Compiles the .js files for development stage
Runs the storybook alone without compiling .scss files
Remember to have an **index.css** because it is imported in **app.js**
Starts the test runner called jest and executes it on watch mode.
Compiles de scss files and autoprefixes the result file. Furthermore giving you the css compiled file, it will compile js files and run the storybook.
Generates a test file which is a helper for jest addon placed on storybook.
Runs the storybook and the .scss files are compiled.
Note:
If you want tests to be on watch mode you should execute `npm run dev:test`
Creates the compiled index.css file for production
Compiles the .js files for production stage
Compiles the .scss files and .js files for production
The generated files will be available through npm package
Compiles the .scss files and .js files for production in `dist` folder
Formats all the code with a line of coding defined in **.prettierrc.json**
In case you do not have the plugin installed (Prettier Code Formatter) you can run this command and this will watch for all your changes.
Checks for any errors in your code according to rules defined in **.eslintrc.json**
Generates a test file with results. This file is a helper to be used on storybook(Shows the results in a section)
Make sure you have [Watchman installed](https://facebook.github.io/watchman/docs/install.html)
Runs test suites (all files with .test.js)
Executes `dev:generate-test` before storybook is built.
Regenerates the tests result file to be used on storybook.
- ES7 React/Redux/Graph ... - Dsznajder
- Docker - microsoft
- DotEnv - mikestead
- ESLint - Dirk Baeumer
- IntelliSense for Css - Zigng
- Jest Snippets - andys8
- Material Icon Theme - Philipp WebKitFileEntry
- Path Intellisense - Christian Kohler
- Prettier Code Formatter - Esben Petersen
- Scss Intellisense - Mrmlnc
-
-
Example:
import { Frame } from 'generics/Frames'
You are able to import the following that poinst to:
From Points to generics ./lib/generics elements ./lib/elements components ./lib/components styles ./lib/styles stories ./stories/all-stories -
-
-
-
Use modules imports
-
Use library imports
- Generics First
- Elements Secondly
- Components Lastly
-
-
- Make sure to use a breakline after each variety of library
Example:
import React from 'react' import PropTypes from 'prop-types' import { Frame } from 'generics/Frames' import { ImageButton, SubmitButton } from 'elements/Buttons'
-
-
Do not use style attribute on elements, but if the layer of the component allows you to add a class, go forward.
<Frame
style={{color: 'red'}}className="contact-news"
/>
-
You should be able to get the props according to the input Type due to the prefixed value.
getInputProps = () => { const { componentType } = this.props switch (componentType) { case 'CT': return { onChange: this.onChangeCT } case 'RF': return { ...input, onChange: this.onChangeRF } } }
In order to add a new input type, you should be aware of the two prefixes.
Prefix | Description |
---|---|
CT | Controlled |
RF | Controlled |
Remember to use the following commands if you have made changes and you want to make it available $ npm run build
$ npm version patch
$ npm publish
-
In case you have made a patch version
$ npm version patch
-
In case you have made a minor version
$ npm version minor
-
In case you have made a major version
$ npm version major
Remember to use a tag when publishing if you think it is not necesary to update it.
Useful ENV variables:
- STORYBOOK_GOOGLE_MAP_KEY
ALWAYS Remember to patch your version with npm version patch
so it can pass the publish package stage correctly on CI/CD.
- Pass axios instance when required a fetch function required.