- Contents
- Developing
- Commands
- Getting Bumbag set up on your machine
- Guide to developing a new component
- Pushing your changes and creating a pull request
Before you start developing, ensure that you have installed the package's dependencies:
yarn
After everything has installed, you can run the docs on a development server which will listen for changes made in the components:
yarn docs
yarn build
- Compile the components, type definitions, and proxy packages.yarn type-check
- Check that all the types are validyarn lint
- Runs the linteryarn lint:fix
- Fixes lint issuesyarn test-packages
- Runs type-check, linter & testsyarn docs
- Runs component documentation on a local development server.yarn develop
- Compile components & listen for changes (only use this for testing Bumbag consumer apps)
To get Bumbag up and running on your machine, follow these steps:
- Fork this repository
Click on 'Fork' in the top right hand corner.
- Clone your newly created forked Bumbag repository onto your machine
Run
git clone git@github.com:<your-username>/bumbag.git
(SSH) orgit clone https://github.com/<your-username>/bumbag.git
(HTTPS) in your terminal
- Go to the
bumbag
folder and install the dependencies
Run
yarn
- Now you can start developing!
Run
yarn docs
to get the component documentation up and running.
-
Create a new branch for your component
git checkout -b add-my-component
The Bumbag repository is set up as a "monorepo" consisting of two main packages: the Bumbag library (packages/bumbag
) and the website (packages/website
). When creating or updating a component, you will have to make changes in both these packages.
The list below is a guide (or checklist) to creating a new Bumbag component. You can reference this list as well as referencing existing components.
-
A component folder (e.g.
packages/bumbag/src/MyComponent/
) which consists of:- The component's
.tsx
file (e.g.MyComponent.tsx
). - A
index.ts
file that exports the component and it's child components (if it has any). - A
styles.ts
file that manages the component's styling (CSS-in-JS via emotion). - A
__tests__
folder, consisting of the component's tests.
- The component's
-
The component itself (
MyComponent.tsx
):Ensure local TypeScript prop types are exported:
Local prop types consists of props which locally belong to the component.
export type LocalComponentProps = { // A required prop name: string; // An optional prop (as denoted with ?) foo?: boolean; };
Ensure TypeScript prop types are exported:
The difference between this, and local prop types is that it extends the local prop types to provide HTML/style based props that can belong on the component. Generally, you want to extend the type which the component inherits (if the component inherits the
<Button>
component, then you extend offButtonProps
- in the "realistic example" above,<Button>
extends offBoxProps
).export type ComponentProps = ButtonProps & LocalComponentProps;
Ensure the component has a
useProps
function to get it's HTML props.Ensure the component is created with the
createComponent
utility.- and the component returns an element via
createElement
, - and the
useProps
hook & appropriatedefaultProps
are attached to the component, - and the component has a
themeKey
.
- and the component returns an element via
-
The component's
styles.ts
All of the component styles are kept in
styles.ts
files.Ensure that theme variables are used when neccessary:
padding: ${space(4)}rem;
Ensure that the component is themeable:
Every component has a
root
in it's theme config. It's nice to add theme keys (e.g.MyComponent.styles.hover
) to stuff you think would be themeable inside the styled component.export const MyComponent = styleProps => cssClass` &:hover { ${theme('MyComponent.styles.hover')(styleProps)}; } & { ${theme('MyComponent.styles.base')(styleProps)}; } `
-
The component is tested
Ensure that component snapshot tests are added in the
__tests__
folderHere are some things you may want to test:
- Prop variants
- User interaction
- Overrides
- Theming
- Default props (via theme)
-
The component is accessible
Ensure that the component is WAI-ARIA compliant.
A good reference is the WAI-ARIA Authoring Practices Doc as well as Using ARIA: Roles, States and Properties
Ensure that the component is tested via the WAVE accessibility plugin
-
Component is exported in
src/index.ts
-
Component's theme config is added to
src/types/theme.ts
- The component's documentation page (e.g.
packages/website/pages/components/MyComponent.mdx
) contains:- Import instructions
- Basic usage of the component
- Variants of the component
- Prop types
- Theming docs
Once you are happy with your new component, create a pull request by doing the following:
- Push all your changes to your branch
git push origin add-my-component
- Head to the Bumbag repository, and open a pull request
Or enter this in your address bar:
https://github.com/bumbagui/bumbag/compare/master...<your-username>:<branch>