Skip to content

Latest commit

 

History

History
253 lines (175 loc) · 12.1 KB

CONTRIBUTING.md

File metadata and controls

253 lines (175 loc) · 12.1 KB

Contribution guidelines

  1. Roadmap
  2. Developing Components
  3. Writing documentation
  4. Creating a pull request
  5. Deploying & publishing
  6. Troubleshooting
  7. Glossary

Roadmap

If you're looking for something to work on, a great place to start is our issues labeled up for grabs! If you've got a feature that you'd like to implement, be sure to check out our Primer Components Roadmap to make sure it hasn't already been started on.

Developing components

We primarily use our documentation site as a workspace to develop new components or make changes to existing components (stay tuned for a better development environment coming soon!).

To get the documentation site running locally run the following in your terminal:

yarn start

Navigate to http://localhost:8000/ to see the site in your browser ✨

Tools we use

  1. We use styled-components to style our components.
  2. We use style functions from styled-system whenever possible, and styled-systems' style() function to create new ones.

Component patterns

With a couple of exceptions, all components should be created with the styled function from [styled-components] and should have the appropriate groups of system props attached.

Default values for system props can be set in Component.defaultProps.

Prop Types from system props such as COMMON or TYPOGRAPHY as well as styled-system functions can be spread in the component's prop types declaration (see example below).

⚠️ Make sure to always set the default theme prop to our theme! This allows consumers of our components to access our theme values without a ThemeProvider.

Here's an example of a basic component written in the style of Primer Components:

import {TYPOGRAPHY, COMMON} from './constants'
import theme from './theme'

const Component = styled.div`
  ${TYPOGRAPHY};
  ${COMMON};
  // additional styles here
`

Component.defaultProps = {
  theme, // make sure to always set the default theme!
  m: 0,
  fontSize: 5,
}

Component.propTypes = {
  ...COMMON.propTypes,
  ...TYPOGRAPHY.propTypes
}

export default Component

Adding default theme

Each component needs access to our default Primer Theme, so that users of the component can access theme values easily in their consuming applications.

To add the default theme to a component, import the theme and assign it to the component's defaultProps object:

import theme from './theme'

Component.defaultProps = {
  theme, // make sure to always set the default theme!
}

Adding system props

Each component should have access to the appropriate system props. Every component has access to COMMON. For most components added, you'll only need to give the component to COMMON. If you are unsure, ping a DS team member on your PR.

Categories of system props are exported from src/constants.js:

  • COMMON includes color and spacing (margin and padding) props
  • TYPOGRAPHY includes font family, font weight, and line-height props
  • POSITION includes positioning props
  • FLEX_CONTAINER includes flexbox props for containers
  • FLEX_ITEM includes flexbox props for items in a flex container

To give the component access to a group of system props, import the system prop function from ./constants and include the system prop function in your styled-component like so:

import {COMMON} from './constants'

const Component = styled.div`
  ${COMMON};
  // additional styles here
`

// don't forget to also add it to your prop type declaration!

Component.propTypes = {
   ...COMMON.propTypes
}

Linting

We use the React configuration from GitHub's eslint plugin to lint our JavaScript. To check your work before pushing, run:

yarn run lint

Or, you can use npx to run eslint on one or more specific files:

# lint the component and the tests in src/__tests__
npx eslint src/**/MyComponent.js

Protip: The eslint --fix flag can automatically fix most linting errors, such as those involving whitespace or incorrect ordering of object keys and imports. You can fix those issues across the entire project with:

yarn run lint -- --fix

Protip: yarn run lint -- --quiet (or npx eslint --quiet ...) will suppress warnings so that you can focus on fixing errors.

Testing

We test our components with Jest and react-test-renderer. You can run the tests locally with yarn test. To run the tests as you work, run Jest in watch mode with:

yarn test -- --watch

See src/__tests__/example.js for examples of ways that we test our components.

TypeScript support

Several of the projects that consume Primer Components are written in TypeScript. Though Primer Components is not currently written in TS, we do export type definitions in order to make Primer Components compatible with other TS projects.

Whenever adding new components or modifying the props of an existing component, please make sure to update the type definition in index.d.ts! This is super important to make sure we don't break compatibility :)

Additional resources

Writing documentation

We use Doctocat to power our documentation site at https://primer.style/components.

To add a new component to our documentation site, create a new file with the .md extension for your component in docs/content (e.g. docs/content/Button.md).

Creating a pull request

When creating a new pull request, please follow the guidelines in the auto-populated pull request template. Be sure to add screenshots of any relevant work and a thoughtful description.

What to expect after opening a pull request

After opening a pull request, a member of the design systems team will add the appropriate labels (major, minor, patch release labels) and update the base branch to the correct release branch. Usually, you'll receive a response from the design systems team within a day or two. The design systems team member will review the pull request keeping the following items in mind:

What we look for in reviews

  • If it's a new component, does the component make sense to add to Primer Components? (Ideally this is discussed before the pull request stage, please reach out to a DS member if you aren't sure if a component should be added to Primer Componets!)
  • Does the component follow our Primer Components code style?
  • Does the component use theme values for most CSS values?
  • Does the component have access to the default theme?
  • Does the component have the correct system props implemented?
  • Is the component API intuitive?
  • Does the component have the appropriate type definitions in index.d.ts?
  • Is the component documented accurately?
  • Does the component have appropriate tests?
  • Does the pull request increase the bundle size significantly?

If everything looks great, the design systems team member will approve the pull request and merge when appropriate. Minor and patch changes are released frequently, and we try to bundle up breaking changes and avoid shipping major versions too often. If your pull request is time-senstive, please let a design systems team member know. You do not need to worry about merging pull requests on your own, we'll take care of that for you :)

Deploying and publishing

Deploying

All of our documentation sites use the Now integration to deploy documentation changes whenever code is merged into master. The integration also creates a preview site every time you commit code to a branch. To view the preview site, navigate to the PR and find the comment from the now bot. This will include a link to the preview site for your branch.

Once you merge your branch into master, any changes to the docs will automatically deploy. No further action is necessary.

Path aliasing

This site is served as a subdirectory of primer.style using a path alias configured in that repo's rules.json. If you change the production deployment URL for this app, you will also need to change it there and re-deploy that app; otherwise, Now will automatically route requests from primer.style/components to the new deployment whenever you alias this one to primer-components.now.sh.

Publishing

We use a custom GitHub Actions to handle all of our processes relating to publishing to NPM. This includes release candidates, canary releases, and publishing the final release.

The publish GitHub Action will automatically publish a canary release for each commit to a branch. If the branch is prefixed with release- it will publish a release candidate. To find the canary release or release candidtate, navigate to the PR and find the publish check in the merge box. Clicking on the details link for the check will navigate you to the unpkg page for that canary release/release candidate. For more documentation on our publish GitHub Action and workflows, please refer to the @primer/publish repo.

Troubleshooting

yarn start fails with an error like gatsby: command not found

Make sure to run yarn from inside the docs/ subfolder as well as the root folder.

** yarn start fails with a different error**

Ensure you are using the latest minor of Node.js for the major version specified in the .nvmrc file. For example, if .nvmrc contains 8, make sure you're using the latest version of Node.js with the major version of 8.

Glossary

System props

System props are style functions that provide one or more props, and can be passed directly the return value of [styled-components]'s styled() function:

import {styled} from 'styled-components'
import {space} from 'styled-system'
const SpaceDiv = styled.div`
  ${space}
`

System props come with propTypes that can be mixed into your own with ES6 spread syntax:

SpaceDiv.propTypes = {
  stellar: PropTypes.bool,
  ...space.propTypes
}