Hi 👋 Thanks for considering contributing! The aim of this doc is to guide you throughout the process of contributing to and help you better understand the Style Guide project.
- Run this project locally (described below)
- Make your changes (including tests and documentation updates)
- Make sure all tests and linters are happy with your changes
- Open a PR
- Get your PR accepted by two of the maintainers
- Clone this repository.
- Run
yarn install
. - Run
yarn build
. - Run
yarn storybook
. - You should be able to access the docs in your browser by navigating to
localhost:6006
.
Remember that docs are an essential part of this project. Don't forget to update them whenever you change, add, or delete any components. Docs for each component are written in components/COMPONENT_NAME/*.stories.mdx|jsx
files.
We use the BEM naming convetion.
We have a standardized set of words you should use when adding modifiers to blocks.
-
If your component changes only in one dimension:
- width:
xnarrow
narrow
wide
xwide
full-width
- height:
xshort
short
tall
xtall
full-height
- width:
-
If it changes in both dimensions:
xsmall
small
large
xlarge
-
Behavior changes:
non-responsive
obscured
vsstandout
disabled
active
vsinactive
-
Combinations of behaviors:
padding-wide
padding-tall
padding-large
All components are responsive by default, so there is no need for modifiers specific to responsiveness (exception: non-responsive
).
Each component/container should have its own file. Components are dumb and should be written in pure function form. Each file should export the default module like so:
export default ComponentName;
Component and container files should be located next to .scss
files in src/components
directory.
Documentation pages for components should be located in same directory with name {component-name}.stories.mdx
.
Each component should be tested. We are using jest as a test runner/framework.
Test files should be located next to component/container file with extension .spec.js
There is also Chromatic visual regression tool which uses storybook stories to run tests. It is integrated with Github and being run on pull requests.
If you already have storybook stories, you can use them also for Chromatic. Run script:
$ node ./scripts/generate-chromatic-stories.js /path-to-your-storybook-file
It will generate script for Chromatic. That script just use existing component storybook stories, but you can modify it to omit or add some extra stories. Run storybook locally to check stories seen by Chromatic:
$ yarn storybook-chromatic
Then commit file and check Github PR to see Chromatic check status.
You can find more details how to work with Chromatic Confluence(INTERNAL)
When importing dependencies, we are using global imports instead of relative ones.
Bad:
import Button, {variants as buttonVariants} from '../../buttons/Button';
Good:
import Button, {BUTTON_VARIANT} from 'components/buttons/Button';
or just:
import Button from 'components/buttons/Button';
<Button variant="solid">Button</Button>
Component options should be stored in a const
object.
Options should have singular form ("alignment" not "alignments") and capitalized names like:
const ALIGNMENT = {START: 'start', END: 'end'};
Each component should export its configuration options (if it have some).
export {DIRECTION, ALIGNMENT};
Go to these links to find documentation about the Flexbox component and documentation regarding SASS mixins.
- Your svg file has to be exported with a
viewBox="0 0 512 512"
. - Clean up the file: keep only
xmlns
andviewBox
attributes onsvg
tag and remove the rest (eventually you can usedata-fixedcolors
attribute onsvg
icon which has to have fixed colors for some reason). There is no need to optimize a<path>
since it will be optimized during build process with svgo.
Now, your file should look like:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path ... />
</svg>
- Add svg file to
src/images/icons
(in case of a basic icon), or relevant folder fromsrc/images
directory. Usesnake_case
as a naming convention. - Define a new icon type in Icon.jsx. Add icon to a particular icon group in get-icon-group.js
- Run
yarn build
to re-generate icons. - Run
yarn storybook
and go to icons section at http://localhost:6006/?path=/story/foundation-%E2%9C%A8-icons--page and find your newly added icon. - Follow standard process of introducing changes to the style-guide.
- After releasing your changes, to use a new icon in your project you need to update the
src
of the icons in<script>
you include on your page. Thissrc
is avaialble on the main page of docs (https://styleguide.brainly.com
).
example:
<script src="https://styleguide.brainly.com/images/icons-0c5f18cafc.js"></script>
- Add new logo svg file to
src/images/logos
- Update typings with new logo type using filename(without extension)
- Use new logo type as prop
type
inLogo
component
Bumping the Release Version - this part is for maintainers
This project uses semver versioning. We follow SemVer:
- Bump first number - If your release breaks public API in any way - e.g. removed method, renamed class, different default parameters for method, new required parameters, removing components.
- Bump second number - If your release only extends public API and improves support, add new components, improves CSS.
- Bump the last number - Finally, if your release only fixes a bug w/o any API changes or introducing new features bump the last number.
To simplify version bumping you can use yarn version
. It will patch package.json
, create a corresponding commit, create a tag, and push those to git changes.
To bump the version correctly you should follow these steps:
- Merge approved, pending PR's into master.
- Create a branch with a bumped version according to the rules above, create tag and merge it (get approvals of course).
- Create proper, specific and detailed release note, with all the changes included in the release.
- Publish your newly prepared version of style-guide to NPM registry with
npm publish
command (do it from a fresh master branch containing commits with your changes and bumped version). - Remember to let know contributors (before merge their PR, just mention in the comment that we are releasing a new version of the library) and Brainly engineers (slack channel would be a perfect place for that), that new version was released and it's ready to use.
Release notes title format contains tag and date: [TAG] (Date)
. For example v198.3.0 (4 Nov 2021)
Following headlines should be used in release notes:
- Breaking Changes
- Features
- Bug Fixes
- Maintenance
- Dependency Updates
- Documentation
Although we strictly adhere to Semver's rules, the style guide is built on many different levels, where certain changes may affect some parts of the consumer application. Please use the following labels to highlight these changes:
-
Change: Accessibility
Marking release change containing accessibility related modification and improvements - these types of changes can affect the testing tools we use, such as react testing library. These tools often look at the accessibility tree, which changes are not covered by semantic versioning. -
Change: Visual
Marking release change containing visual changes e.g colors or size - means changing the color, size, positioning, etc. of a component. These changes are also not considered breaking changes, but they can affect the visual harmony of a design. -
Change: Internal Layout
Marking release change containing modifications inside internal layout or dom tree - this type of change is also not a breaking change in the sense of JS API, but CSS is often tricky and we should know when such modification occurred. For example, when we change the way things are displayed or restructure the internal component DOM tree.
Above tags should help testers and developers scan the release notes faster for possible regression points.
Style guide supports beta channel you can use to test your changes in prod like environment. To prepare pre release:
- Push a git branch with your feature
- Create a draft PR and label it with appropriate keyword (
alpha
/beta
etc.) - Once you're ready to deploy beta release, bump version and create git tag:
- run
yarn version
and type specific pre release version (follow the same principles as you would preparing standard release but put additional suffix to the version). e.gyarn version 220.6.0-beta.0
. This command will bump your package version and create git tag. If you need another beta version in the same branch use subsequent integer-beta.1, beta.2
etc.
- run
- Push your changes (make sure you add
--follow-tags
option if not enabled globally) - Publish to npm with:
npm publish --tag beta
(or--tag alpha
) command. Otherwise your release will be marked aslatest
- Deployed changes should be available in npm and on style guide dev cdn: https://styleguide-dev.brainly.com/X.X.X-beta.X/docs eg. https://styleguide-dev.brainly.com/220.3.0-beta.2/docs
- After initial testing of alpha/beta, you can close your PR or conitnue working on it and merge to the master branch as an official feature
npm publish
throwsPUT https://registry.npmjs.org/brainly-style-guide - Not found
- runnpm login
and try again
All linter settings are based on our standarized frontend tools configs.
To run the linters (and tests) you should use yarn test
.