In order to create more isolated core components we will focus this workshop on creating our very own core library. We will do so with the help of Storybook. We want to focus on building isolated components with good and consistent props.
We will create the following components
- Avatar component - Is a graphical representation of a person through a profile picture, image, icon, or set of initials.
- Loader component - Circular loader indicates to user waiting state.
- Toggle component - Allow users to turn an single option on or off. They are usually used to activate or deactivate a specific setting.
- Accordion component - Accordion is a vertically stacked list of items. Each item can be "expanded" or "collapsed" to reveal the content within with that item.
This repo is based on the default React Create App and the default storybook configuration for that app.
- default react create app setup.
- Button story for reference.
In order to run & start developing in your own storybook environment do the following
npm i
once the npm
installation finishes please run
npm run storybbok
You should get this tab to open on chrome
You need to implement
- Avatar and Loader component
- stories according to the figma design (see each component section for a more detailed explenation on which story to implement)
Bonus: Implement either Toggle or Accordion
- Take your time going over the figma
- Try to use the same naming convention in your prop - i.e
size
vssizes
ordisabled
vsisDisabled
- Before implementing your own component, play around with the example and storybook (especially the controls tab).
Avatar - Figma Design
The avatar component ss a graphical representation of a person through a profile picture, image, icon, or set of initials.
The required stories are:
Shapes - the Avatar has two shapes, pay attention to the details
Sizes - The Avatar has three different sizes, pay attention to inner paddings
Content - The Avatar can show three different content types
- Pictures - think about what sort of prop you should pass
- Letters - think about how would you like the user to pass the information, maybe think about future improvements that might be needed
- Icon - Think about how you want to present this icon, and is it really different from the other types
Disabled - The Avatar component can be in a disabled mode
Loader - Figma Design
The Circular loader indicates to user waiting state.
Use this Loader example - as a reference, notice that this is a pure html/css implementation to the loader, so some React tweaks.
The require stories are:
Sizes - The loader has 4 different sizes.
States - The loader has 4 different states - the stroke color.
Variant - It has two different mode - with background and without background.
Toggle (Bonus) - Figma Design
Allow users to turn an single option on or off. They are usually used to activate or deactivate a specific setting.
The toggle is based on <input type="checkbox" />
element. Use this codepen as a reference
.
Pay attention to the HTML
structure - it is very important.
Think about the props which are given ti the component and how do we want to "inform" the consumer that the state has changed.
The required stories are:
States - on/off states.
Disable - a disabled mode.
Accordion (Bonus) - Figma Design
Accordion is a vertically stacked list of items. Each item can be "expanded" or "collapsed" to reveal the content within with that item.
This is the most complex component of the workshop, the component can be controlled via the props but it must keep a local state, think about how do you want to design your API, what is mandatory to pass in order for the component to function as intended
The required stories are:
Single Active - In this story, one and only one item can be expanded, the story should reflect this situation (it should be the default situation)
Multi Active - In this story and number of items can be extended.
Header Title - In this story you want to show the consumer how they can change the header content
You've been given our monday.com color palette, in order to use them in your code you should do something like the following example for using primary text color
.my-classname {
color: var(--primary-text-color);
}
you can see usage example in Button.css
- Create a folder for each component
- Create the relevant files for each component, for example (Avatar component):
- Directory called
Avatar
under theComponents
folder. - Create another folder called
__stories__
under theAvatar
folder. - Create the component file called
Avatar.jsx
. - Create a
css
file calledAvatar.css
. - Create a story file
Avatar.stories.jsx
.
- Directory called
- Create an initial story for you component in your stories file (see
Button.stories.jsx
for reference).
- Go to the relevant component Figma link (in the component description).
- Play around with it, click on the element and see in right pane the details - take your time
- Think about the default component, how the component behaviours when no props is being pass
- Create your component
- See the quick feedback loop in the storybook
Example for a generic component structure:
import PropTypes from "prop-types";
function MyComponent({ prop1 = true, prop2 = "some string", children }) {
return <div>
<h1>My Awesome Component</h1>
{children}
</div>
}
MyComponent.propTypes = {
prop1: PropTypes.bool,
prop2: PropTypes.string,
children: PropTypes.element
}
- Add additional logic for each component
- Add a unique story for each component behaviour
- Go back to figma and look at the relevant styling
- Try to make your component as close as possible to the Figma
- You can be creative with coloring but try to keep as close to possible with the design
Q: I can't see my story.
A: Make sure that the title is unique:
export default {
title: 'Example/Button', // => this should be unique
component: Button
};
Q: The storybook doesn't update when i update my code.
A: Make sure that you've start it (npm run storybook
) and you don't have errors there.