List
Three composable patches for navigation and display lists. Apply list to the <ul> container, listItem to non-interactive <li> rows, and listItemButton to interactive <button> or <a> elements inside each row. Set aria-selected="true" or aria-current="page" to highlight the active item.
list
| Prop | Type | Default |
|---|---|---|
color | ThemeColor | "neutral" |
listItem
| Prop | Type | Default |
|---|---|---|
dense | boolean | false |
listItemButton
| Prop | Type | Default |
|---|---|---|
color | ValueOrState<ThemeColor> | "neutral" |
accentColor | ThemeColor | "primary" |
dense | boolean | false |
Customization
Must see the source of patch at the bottom of each patch page to understand the structure then code it still code as html native element.
There are four levels of customization, in increasing order of effort:
- Patch props. Each patch exposes a small, stable set of props—typically fewer than five. Lowest friction.
- Context attributes. Use
dataTone,dataSize, anddataDensityon a container to shift tone, size, or density for an entire subtree without touching individual elements. - Inline override. Native-wins merge strategy: any property set directly on the element overrides the patch value.
- Create a variant. Clone a similar patch and edit it. Use this only when you need a reusable custom version.
Formulas
Unit - U = fontSize / 4 - convert final values with themeSpacing(n).
Size - n = intrinsic text lines, w = wrapping level, d = density factor:
height = (n * 6 + 2 * d * w) * U
paddingBlock = d * w * U
paddingInline = ceil(3 / w) * d * w * U
radius = d * w * U
Base density d = 1.5:
| U | w=0 | w=1 | w=2 | w=3 |
|---|---|---|---|---|
height (n = 1) | 6 | 9 | 12 | 15 |
| paddingBlock | 0 | 1.5 | 3 | 4.5 |
| paddingInline | 3 | 4.5 | 6 | 4.5 |
| radius | 0 | 1.5 | 3 | 4.5 |
Tone - K = N / 2 where N is the palette length. For N = 18, K = 9.
| Role | Shift | n=0 |
|---|---|---|
| Background | parent +/- n | 0 |
| Text | bg + K | 6 |
| Border | bg + K/2 | 3 |
| Hover | bg + 2K/3 | 4 |
| Selected / Focus | above +/- K/3 | 2-4 |
State shift range: K/3 <= delta <= 2K/3.
import { type PartialElement, toState, type ValueOrState } from "@domphy/core";
import {
type ThemeColor,
themeColor,
themeDensity,
themeSize,
themeSpacing,
} from "@domphy/theme";
/**
* Styles a navigation/display list container. Sets `list-style: none` and
* zero padding; pairs with `listItem` and `listItemButton`. Apply to `<ul>`.
*
* @hostTag ul
* @param props.color - Surface color tone. Optional `ThemeColor`, defaults to `"neutral"`.
* @example { ul: [...], $: [list()] }
*/
function list(props: { color?: ThemeColor } = {}): PartialElement {
const { color = "neutral" } = props;
return {
_context: { list: { color } },
style: {
listStyle: "none",
margin: 0,
padding: 0,
display: "flex",
flexDirection: "column",
},
};
}
/**
* A non-interactive list row. Typically wraps an icon + text. Apply to `<li>`.
*
* @hostTag li
* @param props.dense - Reduce vertical padding. Optional `boolean`, defaults to `false`.
* @example { li: "Item", $: [listItem()] }
*/
function listItem(props: { dense?: boolean } = {}): PartialElement {
const { dense = false } = props;
return {
style: {
display: "flex",
alignItems: "center",
gap: (listener) => themeSpacing(themeDensity(listener) * 2),
paddingBlock: (listener) =>
themeSpacing(dense ? 1 : themeDensity(listener) * 2),
paddingInline: (listener) => themeSpacing(themeDensity(listener) * 3),
fontSize: (listener) => themeSize(listener, "inherit"),
},
};
}
/**
* An interactive (clickable) list row with hover/focus-visible states. Apply
* to `<button>` or `<a>` inside an `<li>`.
*
* @param props.color - Color tone. Optional `ValueOrState<ThemeColor>`, defaults to `"neutral"`.
* @param props.accentColor - Focus/active accent. Optional `ThemeColor`, defaults to `"primary"`.
* @param props.dense - Reduce vertical padding. Optional `boolean`, defaults to `false`.
* @example { button: "Action", $: [listItemButton()] }
*/
function listItemButton(
props: {
color?: ValueOrState<ThemeColor>;
accentColor?: ThemeColor;
dense?: boolean;
} = {},
): PartialElement {
const color = toState(props.color ?? "neutral", "color");
const accentColor = props.accentColor ?? "primary";
const { dense = false } = props;
return {
cursor: "pointer",
style: {
appearance: "none",
border: "none",
background: "transparent",
textDecoration: "none",
textAlign: "left",
display: "flex",
alignItems: "center",
width: "100%",
gap: (listener) => themeSpacing(themeDensity(listener) * 2),
paddingBlock: (listener) =>
themeSpacing(dense ? 1 : themeDensity(listener) * 2),
paddingInline: (listener) => themeSpacing(themeDensity(listener) * 3),
fontSize: (listener) => themeSize(listener, "inherit"),
color: (listener) => themeColor(listener, "shift-9", color.get(listener)),
borderRadius: (listener) => themeSpacing(themeDensity(listener) * 1),
transition: "background-color 150ms ease",
"&:hover:not([disabled])": {
backgroundColor: (listener) =>
themeColor(listener, "shift-2", color.get(listener)),
},
"&[aria-current=page], &[aria-selected=true]": {
backgroundColor: (listener) =>
themeColor(listener, "shift-3", accentColor),
color: (listener) => themeColor(listener, "shift-12", accentColor),
},
"&:focus-visible": {
outline: (listener) =>
`2px solid ${themeColor(listener, "shift-6", accentColor)}`,
outlineOffset: "-2px",
},
"&[disabled]": { opacity: 0.5, cursor: "not-allowed" },
},
};
}
export { list, listItem, listItemButton };