Components for Stellar Development Foundation’s design system
npm install @stellar/design-systemThis document highlights the overall file structure of the Stellar Design System
project, along with some guidelines for creating components and naming to keep
everything as consistent as possible.
``javascript`
root/@stellar/design-system
|-- build/
|-- docs/
|-- src/
|-- assets/
|-- icons/
|-- logos/
|-- components/
|-- Component/
|-- index.tsx
|-- styles.scss
|-- utils
|-- Component/
|-- index.tsx
|-- styles.scss
|-- index.ts
|-- helpers/
|-- types/
|-- entry.ts
|-- global.scss
|-- icons.ts
|-- index.ts
|-- logos.ts
|-- normalize.scss
|-- theme.scss
|-- utils.scss
|-- ...config files and docs
Optimized, production ready output of the design system.
Generated documentation from TypeDoc comments.
Assets used in the project.
SVG files of icons we use. Make sure SVG files don’t have color on them because
it should be set in CSS. They need to be imported in /icons.ts.
The file name should be in lowercase and words separated with dashes
(info-bubble.svg). Do not prefix the file name with icon-.
SVG files of logos we use. If possible, remove the color from the SVG files so
that it can be set in CSS. They need to be imported in /logos.ts.
The file name should be in lowercase and words separated with dashes
(stellar-quest.svg). Do not prefix the file name with logo-.
All components have their own folder named after the component
(components/Input). Inside the folder there are index.tsx and styles.scss
files.
The contents of the index.tsx file should be in the following order.
#### Imports
`javascript`
import React from "react";
import "./styles.scss";
#### Types
Interface named [Component]Props (InputProps). Use TypeScript string union"primary" | "secondary"
type to define values for props with multiple options
().
`javascript`
interface InputProps extends React.InputHTMLAttributes
id: string;
fieldSize: "md" | "sm" | "xs";
label?: string;
...
}
#### React component
- Export component directly (do not use export default).
- Use BEM naming convention (except, capitalize block element, which should
match the component name):
- block: the same as the component name (Input),__element
- element: (Input__container),--modifier
- modifier: (Input__element--right).data-
- Use only classes for styling (do not use IDs or attributes).label
- Do not add a class to an HTML element if it can be styled without it (for
example, , p should have default styling but can be changed for thiserror
component as needed).
- Use global classes (, success) instead of creating a modifier.
` {rightElement && ( {error && javascript`
{label && }
{rightElement}
)}
{error}}
{note && {note}}
#### Comments for documentation
Add comments to the component file using the JsDoc convention.
##### Props
- Component props interface must be named [ComponenName]Props and must be
exported (otherwise, they are not generated in the docs).
- Export only the props we want to display. If extending another interface, make
a local (not exported) interface to use with the component.
- There must be an empty /* / comment above the interface declaration.
Without it, the props are not added to the docs.
- This comment displays text below the props table on the website. It can be
used to add notes.
Use Button as an example.
##### Component
Add a comment above the component definition.
- Root element is the component class.
`scss`
.Input {
/ all component styles go here /
}
- Use Sass parent selector & to name child classes and other selectors.
`scss
.Input {
width: 100%;
/ Turns into .Input__container /
&__container {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
}
}
`
- Always use colors defined in theme.scss (to make sure themes will always
look good), and other variables as much as possible.
- For consistency, use __container for the outermost container, and__wrapper
for anything that is inside of it. The analogy would be a candy
box is a container, and every candy has a wrapper.
- Use as few wrapping elements as possible (use CSS selectors, flex, grid, etc.
to achieve the same result).
Helper components, which are not part of the Design System. The component
structure should be the same as the main components.
All components are listed in this file.
`javascript`
export * from "./Button";
export * from "./Checkbox";
...
Helper methods go here.
Global types go here.
Main project file used to generate distribution files in Rollup (we generate
separate ESM build/index.esm.js and CJS build/index.js modules to supportindex.ts
server-side rendering). It is separated from file because we don’tentry.ts
want to validate or compile (it can include external files).
`javascript
import "./normalize.scss";
import "./global.scss";
import "./theme.scss";
export * from "./index";
`
Main CSS file that has all the global styles shared among all components.
All SVG icon files are listed here. The exported icon components should be named
Icon[Filename] (IconCalendar).
`javascript`
export { ReactComponent as IconCalendar } from "./assets/icons/calendar.svg";
Exports all React components, including icons and logos.
`javascript`
export * from "./components";
export * from "./icons";
export * from "./logos";
All SVG logo files are listed here. The exported logo components should be named
Logo[Filename] (LogoStellar).
`javascript`
export { ReactComponent as LogoStellar } from "./assets/logos/stellar.svg";
Normalize CSS to make UI more consistent in all browsers.
Color variables for light and dark theme.
Sass helper functions.