The project is broken down into separate components for each component inside of the components/
folder.
Components are released on npm as @spectrum-css/$COMPONENT
, where $COMPONENT
corresponds to the folder name in this repository.
Each component has the following files:
index.css
- The scale-specific styles for the component: dimensions, layout, etc (these change between scales)metadata/*.yml
- The markup examples and documentation for the component; also makes additional examples possible that appear separately in the site navigation.themes/*.css
- The theme-specific styles for the component.stories/*.stories.js
andstories/template.js
- The storybook assets for rendering components in the Storybook tool and eventually to be used for visual regression testing.
- Run
gulp dev
in the root of the project to begin developing. - Edit
components/$COMPONENT/index.css
with dimensions and color properties. The documentation will live reload with your changes. - Edit the markup examples within
components/$COMPONENT/metadata/*.yml
. The documentation will live reload with your changes.
- Generate a new component using the
yarn new component
command. The generator will prompt you to answer questions about your component. - Edit the
dependencies
within thepackage.json
file to use only the dependencies your component needs. All components rely on@spectrum-css/tokens
and@spectrum-css/component-builder-simple
, and most rely on@spectrum-css/icon
. Note: If you are working on a legacy component, it will dependend on@spectrum-css/vars
and@spectrum-css/component-builder
instead. This is expected. - Once your folder has been generated, you can run
yarn dev
in the root of the project to begin developing. - The
index.css
file is where most of your styles will be added. - Inside the
stories
directory you will find atemplate.js
and an*.stories.js
file.- In the
*.stories.js
file, define the available knobs and properties for your component, as well as any standard variations you want to surface in Storybook. - Update the
template.js
file with the markup, using lit-html syntax to adjust results based on the provided settings from the Storybook knobs.
- In the
- Edit your
metadata/*.yml
to add markup examples for each of the variants of your component.
Because we use scoped packages, before it can be published with Lerna, you must manually publish the new component as public:
cd components/newcomponent
npm publish --access=public
- If your component requires another component in order to render, it should be declared in both
devDependencies
andpeerDependencies
.- The version range included in
peerDependencies
must satisfy the version included indevDependencies
. - If a component appears in
peerDependencies
, it must also appear indevDependencies
. - This goes for every class used to render the component; even if the class comes from a component that's a dependency of another component you already have a dependency on.
- For instance, if your component requires a button with an icon inside of it, you must explicitly include both
icon
andbutton
in bothdevDependencies
andpeerDependencies
.
- The version range included in
- If your component has an example that uses another component, but the component isn't required to render your component, it should be declared in
devDependencies
only.- For instance, if your component is commonly used with a table and includes an example where it is used with a table, but doesn't require table to render itself, you should declare
table
indevDependencies
only.
- For instance, if your component is commonly used with a table and includes an example where it is used with a table, but doesn't require table to render itself, you should declare
For example, actionbar
gets its tokens from vars
, and requires button
, checkbox
, icon
, and popover
to render, but also has an example where the component is used with a table
. Its dependencies should be declared as follows:
{
"name": "@spectrum-css/actionbar",
"peerDependencies": {
"@spectrum-css/button": ">=12,
"@spectrum-css/checkbox": ">=8",
"@spectrum-css/icon": ">=6",
"@spectrum-css/popover": ">=6",
"@spectrum-css/tokens": ">=13"
}
}
The release will error out if:
- A package is specified in
peerDependencies
that does not appear indevDependencies
- The version of a package is specified in
devDependencies
satisfy the range defined for that package inpeerDependencies
Any change to a component or a component's dependencies will require a release of that component and all components that depend upon it. Component releases cannot be done ala carte and must be done from the top-level.
See Releasing for more information.