-
Notifications
You must be signed in to change notification settings - Fork 6
Anatomy of a Component
All Reservoir DS components are in the src/components/
directory. Alongside the DS component are Storybook documentation and other components that include AccessibilityGuide
, Chakra
, ComponentWrapper
, DevelopmentGuide
, and StyleGuide
. Generally, a DS component folder consists of the following:
-
A
__snapshots__
folder: Snapshot tests created automatically by Jest through the--updateSnapshot
flag. For example, if they need to be updated, runnpm test -- --updateSnapshot
. -
A
.mdx
file: This is the main file for a component's Storybook documentation page. The documentation includes the component version table, the table of contents, and other sections that describe the component and its features. The convention is to include little or no React code in this file besides the Storybook block components. -
A
.stories.tsx
file: This is the main file for the React code for a component, its variants, and working examples. The convention is to create ameta
object to describe the component and its props, and various high-levelStory
components to render in the.mdx
file described above. -
A
.test.tsx
file: This file contains Jest unit tests for the component. -
A
.tsx
file: This is the main React component. -
A
[name]ChangelogData.ts
file: This contains all the changes per release for the component. -
A
.scss
file: Only true for components that need SCSS overrides for third-party component styles.
For the purposes of this documentation, we'll be walking through the Checkbox
component. Please note that what's in development
may differ from the examples here.
Checkbox.mdx |
Description |
---|---|
|
MDX Story files outline the DS component documentation page in the Storybook viewer. Without this file, they don't appear in a way where other engineers can understand what they look like and how they function to a user. This file uses the Storybook has great documentation if you've never used it before. Check out their documentation here. We use Controls to show off component functionality. When you're designing the Storybook experience for a component, ask yourself the following questions:
Full Checkbox.mdx example |
Checkbox.stories.tsx |
Description |
---|---|
|
This file must contain the base `meta` object to define the component, its type, and the props. Once created, individual `Story`-typed components objects are created and exported so they can be declared in the `.mdx` file either through the `Canvas` or `ArgTypes` components. Full Checkbox.stories.tsx example |
Checkbox.test.tsx |
Description |
---|---|
|
Unit tests describe how a component should act in different situations. We use Jest> and React Testing Library to do this. Here are some good things to try and test for:
Full Checkbox.test.tsx example |
Checkbox.tsx |
Description |
---|---|
|
Typescript is a superset of JavaScript—it's like writing JavaScript as you're used to, but with stricter rules. We use it in the Design System to enforce type safety. Components should define the props they can receive. Here, we both define the props and their types, such as Like with testing, this is a good place to think about a few things such as:
Full Checkbox.tsx example |
checkboxChangelogData.ts |
Description |
---|---|
|
This file contains an array of changelog data objects. Each object describes the type of changes per version for the component. Full checkboxChangelogData.ts example |
Still have questions? Want to improve this documentation? We're available on the #design-system slack channel.