Skip to content

attributes.ts

~/ui/attributes.ts exports WithAttributes<ClassObject, UiAttributes> type utility for Ui component props, and transforms semantic Aria/HTML props with the toHtml<ElementName> utility.

The file is auto-generated every time you run vite or build the frontend guide locally with yarn dev:docs.

WithAttributes

As a component author, se this utility to fine-tune the allowed class combinations for your component. We follow the precedent set by Tailwind:

Always use complete class names

Example: "Component with any solid background color"

ts
defineProps < WithAttributes<{
  class: {
    color?: Extract<Color, `${string}-solid`>
  }
}>()

The class attribute for this component is now narrowed to any color class that ends in -solid.

Note that WithAttributes enforces alphabetically sorted class strings so that the same combination of classes always results in the same string.