This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Diamond UI is a lightweight design system built with Lit web components, design tokens, and CSS. Components use minimal JavaScript and follow the "CSS web components" methodology (see https://etch.co/blog/css-web-components). The library is framework-agnostic and can be installed in any web project.
Component naming convention: All components are prefixed with dmd- (abbreviated from "diamond"). For example: dmd-grid, dmd-card, dmd-button.
npm start # Start Vite dev server
npm run storybook # Start Storybook on port 6006npm run build # Build components and styles with Rollup
npm run build-storybook # Build Storybook static sitenpm run lint:css # Lint CSS files with Stylelint
npm run lint:js # Lint JS with eslintNote: There are no test scripts configured yet (npm test will fail).
Components are organized into four categories under components/:
- canvas/ - Layout containers (e.g.,
Card,Section) - composition/ - Layout and structural components (e.g.,
Grid,FormGroup,Dialog,Hidden) - content/ - Content display components (e.g.,
Icon,Text,List,LoadingButton) - control/ - Interactive form components (e.g.,
Button,Input,RadioCheckbox,Link)
Diamond UI uses two component approaches:
- Lit Components - JavaScript web components built with Lit
- Located in
.tsfiles - Use
@customElementdecorator - Extend
LitElement - Example:
Icon,LoadingButton
- CSS Web Components - Pure CSS components with only TypeScript interfaces
- Have a
.tsfile that ONLY exports TypeScript types/interfaces (no implementation) - All styling and behaviour in corresponding
.cssfile - Example:
Card,Button,Grid
Each component follows this structure:
components/[category]/[ComponentName]/
├── ComponentName.ts # Lit component OR type definitions only
├── ComponentName.css # Component styles (always present)
└── ComponentName.stories.ts # Storybook stories
Key files:
ComponentName.tsexports an interface[ComponentName]Attributesdefining the component's props- All components declare global types for both vanilla HTML and React JSX usage
- React type declarations use
JSXCustomElement<T>helper type fromtypes/jsx-custom-element.ts
Example interface pattern:
export interface CardAttributes {
border?: string | boolean;
padding?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'none';
}
declare global {
interface HTMLElementTagNameMap {
'dmd-card': CardAttributes;
}
}
declare module 'react' {
namespace JSX {
interface IntrinsicElements {
'dmd-card': JSXCustomElement<CardAttributes>;
}
}
}All design tokens are defined as CSS custom properties in styles/tokens/:
border.css- Border stylesbutton.css- Button-specific tokenscolor.css- Color palettefont.css- Typographyicon.css- Icon sizinginput.css- Form input stylesradius.css- Border radius valuesshadow.css- Box shadowsspacing.css- Spacing scaletheme.css- Theme variablestransition.css- Animation timingswrap.css- Container widths
Tokens can be overridden by defining CSS custom properties on :root.
Rollup is configured to output three bundles:
- JavaScript components - All
.tsfiles fromcomponents/(excluding.stories.ts) - Type definitions - Generated
.d.tsfiles - Styles -
diamond-ui.cssbundle that includes all component styles via PostCSS glob imports
The build:
- Uses
@rollup/plugin-typescriptfor TypeScript compilation - Uses
rollup-plugin-postcsswithpostcss-import-ext-globto bundle CSS - Maintains directory structure in
dist/ - Copies individual token files to
dist/styles/for granular imports
Reusable code in lib/:
pulse.ts- Lit CSS for loading/skeleton animationsbreakpoints.ts- Responsive breakpoint definitionscss-map.ts- Utility for mapping props to CSS classes
When custom elements need to be interactive (clickable/tappable), wrap them in semantic HTML elements (<a>, <button>, or <label>).
The base CSS (styles/base/interactive.css) hides the styling of these wrappers when they contain:
dmd-cardcomponents- Elements with
data-interactiveattribute
This preserves accessibility while allowing visual customization.
Diamond supports custom theming via CSS custom properties. No production themes are included by default. Theme styles are defined in styles/themes.css.
Theme variables follow the pattern --dmd-theme-[property] and can be scoped to specific components or containers.