fragments-ui
Fragments UI Best Practices
Reference guide for building with @fragments-sdk/ui. This skill loads automatically when working with Fragments UI components.
Core principles
- Use the design system first. Always check if a Fragments component exists before building custom UI. Use
fragments_discoverwith auseCasequery to find the right component. - Use design tokens, not raw values. Never hardcode colors, spacing, font sizes, or radii. Use CSS custom properties from the token system (
--fui-*). - Compose, don't customize. Build complex UI by composing smaller components. Don't override internal component styles -- use the provided props and slots.
- Accessibility is not optional. Every interactive element needs keyboard support, focus management, and ARIA attributes. Fragments components handle this -- don't break it with custom wrappers.
Component discovery workflow
When building new UI, follow this order:
-
Check for an existing component: Use
fragments_discoverwithuseCaseto find matching components. Usefragments_discoverwithcompact: truefor a quick overview of everything available. -
Check for composition blocks: Use
fragments_blockswithsearchto find pre-built patterns (e.g., "login form", "settings page", "data table"). -
Get implementation details: Use
fragments_inspecton the chosen component to see full props, guidelines, and code examples. Usefragments_implementfor a one-shot bundle of components + tokens + blocks for a use case. -
Only build custom if no component or block covers the use case.
Token usage
Use fragments_tokens to find the right token. Key categories:
Colors
- Text:
--fui-text-primary,--fui-text-secondary,--fui-text-tertiary,--fui-text-muted - Surfaces:
--fui-bg-primary,--fui-bg-secondary,--fui-bg-tertiary,--fui-color-surface-raised - Borders:
--fui-border-default,--fui-border-subtle - Semantic:
--fui-color-accent,--fui-color-success,--fui-color-danger,--fui-color-warning
Spacing
- Use the spacing scale:
--fui-space-1through--fui-space-8 - Component gaps: prefer
gapwith spacing tokens over margin hacks
Typography
- Sizes:
--fui-font-size-xsthrough--fui-font-size-xl - Weights via the
Textcomponentweightprop:regular,medium,semibold,bold - Mono:
--fui-font-monofor code/technical content
Radii
--fui-radius-sm,--fui-radius-md,--fui-radius-lg,--fui-radius-full
Common patterns
Layout
- Use
Stackfor vertical layouts with consistentgap - Use flexbox with
gapfor horizontal layouts - Use
Cardwithvariant="outlined"orvariant="filled"for content containers - Use
Skeletonfor loading states -- match the shape of the content it replaces
Forms
- Always use
Inputwith alabelprop -- never a detached label - Use
Selectfor enumerated choices, not custom dropdowns - Use
Buttonvariants intentionally:defaultfor primary actions,outlinefor secondary,ghostfor tertiary - Show validation errors inline using
Textwithcolor="danger"
Data display
- Use
CodeBlockfor code snippets withlanguageandtitleprops - Use
Avatarwithnamefallback for user/org images - Use
Badgefor status indicators - Use
Textwith semanticcolorprops (tertiary,muted) -- not inline color styles
Icons
- Import from
@phosphor-icons/react - Use
weight="bold"for interactive elements (buttons, links) - Use
weight="duotone"for decorative/illustrative contexts - Size icons to match text: 12px for
xs, 14px forsm, 16px formd
Accessibility checklist
- Interactive elements: use
Button, not<div onClick> - Images: always pass
alttoAvatarvia thenameprop - Dynamic content: use
aria-liveregions for toast/notification areas - Focus: never set
tabIndexon non-interactive elements - Color: never rely on color alone to convey meaning -- pair with text or icons
Performance
Use fragments_perf to check component bundle sizes before adding heavy components. Prefer:
Textover custom styled spansStackover nested divs with marginIconwrapper over raw SVG imports (enables tree-shaking)
Use fragments_graph with mode: "impact" to understand the blast radius before modifying shared components.
Anti-patterns -- avoid these
- Wrapping Fragments components in custom styled-components -- use props and tokens instead
- Using
!importantto override component styles - Hardcoding
pxvalues for spacing (use tokens) - Creating one-off button/input components when
Button/Inputvariants exist - Using
<a>tags for actions that don't navigate -- useButtonwithvariant="ghost" - Nesting
CardinsideCard-- flatten the hierarchy