1.0.3 • Published 4 years ago
@djamel_soualmi/components v1.0.3
Components
This library provide sharable components for web applications, either :
- as CommonJS components
- as a minified library
Goal
- Edit a component once, share it across all our platforms
-Provide a documentation referencing every component with its
- available states (disabled, selected)
- skinable properties
- Provide the smallest lib
Development
Seeing the components on Storybook
yarn
npm run startThen open http://localhost:3004.
Analyse your component
The props is the contract your app should fill in order to use the component.
If the props are not properly set, it is not the role of you component to change them in order to render somehow.
The propTypes are the representation of this contract.
Keep this workflow in mind:
props -> propTypes -> fixtures -> componentThen your app will just have to read propTypes to know which props to provide to render a view.
Adding a component
- choose your atomic folder depending your component:
template,organism,molecule,atom - add a folder having your component name: for example, for
buttonyou should have this tree:
atom
└── button
├── index.js
├── style.css
└── test
└── fixtures
└── default.js
└── disabled.js
└── hovered.jsindex.jscontains the React code + jsx, and exports your componentstyle.csscontains the css module style for your componenttest/fixtures/*.jsare files representing all the possible states for your component, thus export props accordingly
note that whenever you add new component or new fixtures you have to generate the storybook index:
npm run generatewhich is also launched automatically whenever you run npm start
Adding a locale
- You need to add your locale in en/global.json file
- Be sure to have
translate: Provider.childContextTypes.translatein the contextTypes object of your component
example:
....
const YourComponent = (props, context) => {
const {translate} = context;
return <p>{translate('your new locale')}</p>
}
YourComponent.contextTypes = {
translate: Provider.childContextTypes.translate
};
...