Every documented component follows the same rules for its props, so a prop means the same thing on every component. Read this page before you add or change a prop.

#Before you open the PR

yarn designsystem:check:props reports each violation with its rule ID and a link to the section below.

Rule IDCheckSection
is-prefixNo boolean prop starts with isBooleans
bool-default-trueNo optional boolean defaults to trueBooleans
managed-componentNo separate ManagedX componentState
camel-ariaNo ariaLabel-style props, use aria-*ARIA
enum-caseString-literal values are one lowercase word or kebab-caseVariant and interaction
size-scalesize uses xxsmall … xlargeSizes and alignment
loading-booleanloading is a booleanLoading
slot-wordNo ReactNode prop named after a position (trailing, leading, meta, extra, info, content, slot)Slots
divider-wordA divider is called divider, not line, border or separatorDividers
dollar-propNo public prop starts with $Styled components
props-type-nameThe props type is exactly <Component>Props and exported from the barrelTypes
exported-i-typeNo exported type starts with I followed by an uppercase letterTypes

#How CI enforces this

yarn designsystem:check:props reads every component referenced by a <PropTable component={…}> on a design-system page and checks its props against the rules above. CI fails on any violation.

#DOM first

If React DOM or ARIA already has a name for it, use that name. Engineers know the DOM names, and the props pass through to the element without mapping. disabled, checked, open, aria-*, and onChange for the DOM event.

Exceptions:

  • loading on <img> becomes loadingStrategy. loading means busy on every component, see Loading.
  • Framework props are not DOM names. next/link's scroll follows the boolean rules and becomes noScroll, see Booleans.

Do

Use the DOM name

<Button disabled>Save</Button>

Don't

Invent a second name for a DOM attribute

<Link isDisabled href="/cart">
  Cart
</Link>

#Booleans

  • Bare adjectives: selected, not isSelected.
  • has* only for possession: hasChildren.
  • Optional booleans default to false. Absent means off.
  • Put the polarity in the name: hide*, show*, no*. A prop that turns off a default behaviour is noScroll, not scroll defaulting to true.
  • No required booleans, except controlled state such as open.

Do

Bare name, off by default

<SelectorButton selected />
<NextLink href="/cart" noScroll />

Don't

is prefix, or a boolean you have to set to false

<SelectorButton isSelected />
<NextLink href="/cart" scroll={false} />

#State

One component per state concept, controlled or uncontrolled:

  • x for controlled, defaultX for uncontrolled, onXChange(value) for changes.
  • defaultX without x is read once on mount, like defaultValue on an <input>. Never initialX.
  • No separate ManagedX component.
  • Open state uses open, defaultOpen, onOpen and onClose.

Do

One component, controlled or uncontrolled

<Accordion defaultOpen onOpen={track}>

Don't

A second component for the managed case

<ManagedAccordion initialOpen onToggle={track}>

#Events

  • on<Thing>Change(value) for value changes, called with the value.
  • onChange only for the DOM event, called with the event.
  • Events of a sub-part get the part as prefix: onMenuOpen.

Do

Name the thing that changed

<Carousel onSlideChange={(index) => track(index)} />

Don't

onChange called with a value instead of the DOM event

<SearchField onChange={(searchTerm) => search(searchTerm)} />

#Variant and interaction

  • variant is appearance. It has a default only when the default is the neutral look.
  • interaction is how the component can be interacted with: <Chip interaction="radio">. Not type, which reads as an HTML or TypeScript type at the call site. type only passes through to the native attribute.
  • Enum values are one lowercase word or kebab-case: "primary", "text-only", never "textOnly".

Do

Lowercase values, appearance in variant

<Button variant="primary" type="submit" />

Don't

camelCase values

<Button variant="textOnly" />

#Sizes and alignment

ConceptProp and values
Sizesize: xxsmall … xlarge
Alignmentalign: start, center, end
Inline position<part>Position: before, after
Floating elementplacement
Scroll targetscrollAlignment

Don't use left and right, they break in right-to-left layouts. Don't use s, m, l or small/big/huge mixes.

#ARIA

  • Native aria-* props on the root element.
  • Sub-parts get <part>AriaLabel: closeButtonAriaLabel, or <part>AriaLabelledBy to reference a visible label by ID.
  • The component derives ARIA state (aria-expanded, aria-selected) from its own props. Don't make the caller pass it.

Do

Native attribute on the root

<Carousel aria-label="Similar products" />

Don't

A camelCase copy of an ARIA attribute

<Carousel ariaLabel="Similar products" />

#Text

  • heading is visible heading text.
  • title is only the HTML title attribute.
  • <part>Label names a sub-part's visible text: confirmLabel.

Do

heading for the visible heading

<DataTable heading="Delivery times" />

Don't

title for rendered text

<DataTable title="Delivery times" />

#Icons

icon: ReactNode plus iconPosition: "before" | "after". The caller renders the icon, so it controls size and colour.

Do

Pass an element

<Button icon={<ArrowRight />} iconPosition="after" />

Don't

Pass a component type

<Alert icon={InfoIcon} />

#Slots

  • Name a slot after the role of its content: actions, collapsedSummary.
  • No position words: trailing, leading, meta, extra, info, content, slot.
  • Render props are render<Role>. Element overrides are <part>As.

Do

Name the role

<Accordion heading="Specifications" collapsedSummary="4 items">

Don't

Name the position or the mechanism

<Accordion heading="Specifications" metaInfoSlot="4 items">

#Loading

loading means the component is busy and shows it. The browser's image loading attribute is loadingStrategy. This is an exception to DOM first: one name can't mean both busy and lazy.

Do

loading for busy, loadingStrategy for images

<LoadingButton loading />
<Avatar loadingStrategy="lazy" />

Don't

isLoading, or loading for the image strategy

<LoadingButton isLoading />
<Avatar loading="lazy" />

#Dividers

A line between parts is a divider: divider, hideDivider, showDivider. Not line, border or separator.

  • One edge: <show|hide><Top|Bottom>Divider. The prefix turns the default off into absent: LineSeparator hideBottomDivider (shown by default), DataTable showTopDivider (hidden by default).
  • Depends on state: keepDividerWhen<State>, e.g. Accordion keepDividerWhenExpanded.

#Styled components

$ props are private styling props. They never appear in a component's public props. A component whose styles depend on a public prop is a function component that takes the public name and applies only the prop-dependent styles with the css prop. The static styles stay in a styled() around it, which is the export, so consumers can extend it with styled(Skeleton) and target it with ${Skeleton} selectors.

The css prop's styles come first in the stylesheet. Where one overrides a static style of the same component, raise its specificity with &&.

/** @jsxImportSource @yak/react */
import { css, styled } from "@yak/react";
import type { ComponentProps } from "react";

const SkeletonBase = ({
  disableAnimation,
  ...props
}: ComponentProps<"div"> & SkeletonProps) => (
  <div
    {...props}
    css={
      disableAnimation &&
      css`
        && {
          animation: none;
        }
      `
    }
  />
);

export const Skeleton = styled(SkeletonBase)`
  …
`;

#Types

  • The props type is named exactly <Component>Props and exported from the package barrel.
  • No exported type starts with an I prefix.
  • Test ids use data-testid.

Do

<Component>Props

export type SkeletonProps = { … };

Don't

I prefix or a different name

export type ISkeletonProps = { … };