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 ID | Check | Section |
|---|---|---|
is-prefix | No boolean prop starts with is | Booleans |
bool-default-true | No optional boolean defaults to true | Booleans |
managed-component | No separate ManagedX component | State |
camel-aria | No ariaLabel-style props, use aria-* | ARIA |
enum-case | String-literal values are one lowercase word or kebab-case | Variant and interaction |
size-scale | size uses xxsmall … xlarge | Sizes and alignment |
loading-boolean | loading is a boolean | Loading |
slot-word | No ReactNode prop named after a position (trailing, leading, meta, extra, info, content, slot) | Slots |
divider-word | A divider is called divider, not line, border or separator | Dividers |
dollar-prop | No public prop starts with $ | Styled components |
props-type-name | The props type is exactly <Component>Props and exported from the barrel | Types |
exported-i-type | No exported type starts with I followed by an uppercase letter | Types |
#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:
loadingon<img>becomesloadingStrategy.loadingmeans busy on every component, see Loading.- Framework props are not DOM names.
next/link'sscrollfollows the boolean rules and becomesnoScroll, 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, notisSelected. 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 isnoScroll, notscrolldefaulting totrue. - 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:
xfor controlled,defaultXfor uncontrolled,onXChange(value)for changes.defaultXwithoutxis read once on mount, likedefaultValueon an<input>. NeverinitialX.- No separate
ManagedXcomponent. - Open state uses
open,defaultOpen,onOpenandonClose.
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.onChangeonly 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
variantis appearance. It has a default only when the default is the neutral look.interactionis how the component can be interacted with:<Chip interaction="radio">. Nottype, which reads as an HTML or TypeScript type at the call site.typeonly 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
| Concept | Prop and values |
|---|---|
| Size | size: xxsmall … xlarge |
| Alignment | align: start, center, end |
| Inline position | <part>Position: before, after |
| Floating element | placement |
| Scroll target | scrollAlignment |
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>AriaLabelledByto 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
headingis visible heading text.titleis only the HTMLtitleattribute.<part>Labelnames 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. AccordionkeepDividerWhenExpanded.
#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>Propsand exported from the package barrel. - No exported type starts with an
Iprefix. - Test ids use
data-testid.
Do
<Component>Props
export type SkeletonProps = { … };
Don't
I prefix or a different name
export type ISkeletonProps = { … };