Tip
Providing a label prop for an input field is often better than requiring users to manually add a <label> element.
Change the appearance of the site to suit your preferences
This section will cover how to develop new and maintain components in the design system. When creating a new component it is important for them to be consistent, accessible, and align with the design tokens.
At Spor, everyone contributes! If your team needs a new component, it’s your responsibility to make it happen. This guide will walk you through the process.
All components are located in packages/spor-react/src.
Our folder structure closely mirrors the Figma component file, so you should easily find the correct location for your component.
Button.tsx).<div> or <span>. Instead, use Chakra components to ensure design token compatibility.Decide whether to:
Providing a label prop for an input field is often better than requiring users to manually add a <label> element.
When using Chakra, be intentional about including rest props (...rest). Instead of automatically spreading all props onto the component, consider whether each prop should be exposed to users.
✔ Prevents unwanted props from affecting styling or behavior.
✔ Allows for better control over component API and defaults.
✔ Reduces inconsistencies by limiting excessive customization.
✅ If the component should allow additional props, include {...rest} in a controlled manner.
✅ If not, explicitly define accepted props to keep the API clean.
Example:
const Button = ({ children, variant = "primary", ...rest }: ButtonProps) => {return <ChakraButton colorScheme={variant} {...rest}>{children}</ChakraButton>;};
rest), but control the variant prop.❌ Avoid blindly spreading props unless necessary, as it can expose the component to unintended behaviors.
Spor provides typed and exported design tokens for colors, spacing, sizing, and more. Always use these tokens instead of static values to ensure consistency across components.
For colors, always use semantic tokens rather than aliases or raw color values. Semantic tokens automatically handle both light and dark mode, ensuring proper contrast and accessibility in different themes.
✅ Good:
<Box backgroundColor="core.surface" />
❌ Avoid:
<Box backgroundColor="darkTeal" />
type over interface.isDisabled, use disabled instead.Building accessible components benefits everyone, not just users with disabilities. Spor is committed to universal design, and you should be too!
Whenever possible, use native HTML elements instead of divs and spans. This ensures built-in accessibility without extra effort.
✅ Good:
<Button onClick={handleClick}>Button is semantic</Button>
❌ Avoid:
<div onClick={handleClick} role="button" tabindex="0">Click me</div>
Semantic elements come with correct roles, keyboard support, and screen reader behavior by default—saving you time and effort!
ARIA attributes (like aria-label, aria-labelledby, or aria-hidden) can enhance accessibility but should not replace semantic elements. Use them only when necessary.
✅ Use aria-label when no visible label exists:
<IconButton aria-label="Close modal" icon={<CloseIcon />} onClick={closeModal} />
❌ Don’t overuse ARIA when native elements work:
<div role="button" aria-label="Submit">Submit</div>
Instead, just use a <Button>.
tabindex when necessary).onKeyDown handlers where applicable (e.g., Enter for button-like elements).outline styles—users rely on them for navigation!By following these best practices, you'll create components that are usable by everyone—no extra work later to fix accessibility issues! 🚀
Mdn docsEkstern lenke contains a lot of tips for semantics and how your component should act when using keyboard navigation.
Every folder should have an index.ts file.
index.ts to ensure it’s available in the package.If you add or modify a slot in a slot recipe, you must run:
npm run typegen
For live updates while developing, use:
npm run typegen:watch
If you upload new icons or modify design tokens, run:
npm run build
This ensures your changes appear locally.
✔️ Place your component in the correct folder.
✔️ Follow best practices for modular and reusable code.
✔️ Decide between using props or composite components.
✔️ Use Chakra components instead of raw HTML elements.
✔️ Include documentation and comments on props.
✔️ Follow proper type definitions (type over interface).
✔️ Always use semantic tokens.
✔️ Prioritise accessibility
✔️ Export your component in index.ts.
✔️ Update Sanity documentation.
✔️ Run npm run typegen if you've changed a recipe.
✔️ Run npm run build if you modified icons or design tokens.