npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@stellar/design-system

v2.0.0-beta.17

Published

Components for Stellar Development Foundation’s design system

Downloads

971

Readme

Stellar Design System Guide

This 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.

File structure overview

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

build/

Optimized, production ready output of the design system.

docs/

Generated documentation from TypeDoc comments.

assets/

Assets used in the project.

icons/

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-.

logos/

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-.

components/

All components have their own folder named after the component (components/Input). Inside the folder there are index.tsx and styles.scss files.

Component’s index.tsx structure

The contents of the index.tsx file should be in the following order.

Imports

import React from "react";
import "./styles.scss";

Types

Interface named [Component]Props (InputProps). Use TypeScript string union type to define values for props with multiple options ("primary" | "secondary").

interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
  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).
  • Use only classes for styling (do not use IDs or data- attributes).
  • Do not add a class to an HTML element if it can be styled without it (for example, label, p should have default styling but can be changed for this component as needed).
  • Use global classes (error, success) instead of creating a modifier.
<div className="Input">
  {label && <label htmlFor={id}>{label}</label>}

  <div className="Input__container">
    <div className="Input__wrapper" data-disabled={props.disabled}>
      <input id={id} aria-invalid={!!error} {...props} />
    </div>

    {rightElement && (
      <div className="Input__element--right">{rightElement}</div>
    )}
  </div>

  {error && <div className="Input__note error">{error}</div>}
  {note && <div className="Input__note">{note}</div>}
</div>

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.

Component’s styles.scss structure

  • Root element is the component class.
.Input {
  /* all component styles go here */
}
  • Use Sass parent selector & to name child classes and other selectors.
.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).

/components/utils/

Helper components, which are not part of the Design System. The component structure should be the same as the main components.

/components/index.ts

All components are listed in this file.

export * from "./Button";
export * from "./Checkbox";
...

/helpers

Helper methods go here.

/types

Global types go here.

entry.ts

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 support server-side rendering). It is separated from index.ts file because we don’t want to validate or compile entry.ts (it can include external files).

import "./normalize.scss";
import "./global.scss";
import "./theme.scss";

export * from "./index";

global.scss

Main CSS file that has all the global styles shared among all components.

icons.ts

All SVG icon files are listed here. The exported icon components should be named Icon[Filename] (IconCalendar).

export { ReactComponent as IconCalendar } from "./assets/icons/calendar.svg";

index.ts

Exports all React components, including icons and logos.

export * from "./components";
export * from "./icons";
export * from "./logos";

logos.ts

All SVG logo files are listed here. The exported logo components should be named Logo[Filename] (LogoStellar).

export { ReactComponent as LogoStellar } from "./assets/logos/stellar.svg";

normalize.scss

Normalize CSS to make UI more consistent in all browsers.

theme.scss

Color variables for light and dark theme.

utils.scss

Sass helper functions.