A small mark in a project's, label's or calendar's color.
- 0.6 kB JS 2.3 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 9 tests
- Mobile app41
- Billing migration18
- Design system7
- Onboarding23
- Infrastructure and on-call rotation5
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { ColorDot } from "./ui/uicontext/components/ColorDot.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ list: { display: "grid", gap: space.sm, inlineSize: "min(100%, 18rem)", margin: 0, padding: 0, listStyle: "none" }, row: { display: "flex", alignItems: "center", gap: space.sm, fontSize: font.sm, color: color.fg }, name: { flexGrow: 1, minInlineSize: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, count: { color: color.muted, fontVariantNumeric: "tabular-nums" },})// projects in an issue tracker's sidebar, each in the color its team picked, pale ones includedconst projects = [ { id: "mob", name: "Mobile app", color: "#7c3aed", open: 41 }, { id: "bil", name: "Billing migration", color: "#ea580c", open: 18 }, { id: "dsn", name: "Design system", color: "#0891b2", open: 7 }, { id: "onb", name: "Onboarding", color: "#fde68a", open: 23 }, { id: "inf", name: "Infrastructure and on-call rotation", color: "#e5e7eb", open: 5 },]export const ProjectList = <M>(h: Html.H<M>) => h.ul.attrs({ "aria-label": "Projects", ...sx(styles.list) }).children( projects.map((p) => h.li.key(p.id).attrs(sx(styles.row)).children( ColorDot(h, { color: p.color }), h.span.attrs({ dir: "auto", ...sx(styles.name) }).children(p.name), h.span.attrs(sx(styles.count)).children(String(p.open)), )), )When to use
A small mark in a project's, label's or calendar's color. Use Glyphs instead when the mark says status or priority, not a color someone chose.
Usage
import { ColorDot } from "./ui/uicontext/components/ColorDot.ts"export const ProjectName = <M>(h: Html.H<M>) => h.span.children(ColorDot(h, { color: "#7c3aed" }), " Mobile app")Examples
Shown and hidden
square for a calendar that shows, ring once it's hidden.
import { UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { ColorDot } from "./ui/uicontext/components/ColorDot.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, corner, density, font, motion, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ list: { display: "grid", gap: 2, inlineSize: "min(100%, 16rem)", margin: 0, padding: 0, listStyle: "none" }, toggle: { display: "flex", alignItems: "center", gap: space.sm, inlineSize: "100%", minBlockSize: density.control, paddingInline: space.sm, borderWidth: 0, borderRadius: corner.control, backgroundColor: { default: "transparent", ":hover": { default: null, "@media (hover: hover) and (pointer: fine)": color.hover } }, color: color.fg, fontFamily: "inherit", fontSize: font.sm, textAlign: "start", cursor: "pointer", outline: { default: "none", ":focus-visible": `2px solid ${color.focusRing}` }, transitionProperty: "background-color, color", transitionDuration: motion.fast, }, off: { color: color.muted },})const calendars = [ { id: "work", name: "Work", color: "#2563eb" }, { id: "family", name: "Family", color: "#16a34a" }, { id: "holidays", name: "Holidays in Portugal", color: "#dc2626" }, { id: "gym", name: "Gym", color: "#d97706" },]const Message = UiSchema.TaggedEnum({ Toggled: { id: Schema.String } })// a calendar app's list: a square in the calendar's color while it shows, an outline once hiddenexport const CalendarList = Html.component({ name: "CalendarList", model: Schema.Struct({ hidden: Schema.Array(Schema.String) }), message: Message,}).make({ init: () => ({ hidden: ["holidays"] }), update: { Toggled: ($, { id }) => $.evolve({ hidden: (list) => (list.includes(id) ? list.filter((x) => x !== id) : [...list, id]) }) }, view: (h, model) => h.ul.attrs({ "aria-label": "Calendars", ...sx(styles.list) }).children( calendars.map((c) => { const shown = !model.hidden.includes(c.id) return h.li.key(c.id).children( h.button.attrs({ type: "button", "aria-pressed": shown ? "true" : "false", ...sx(styles.toggle, !shown && styles.off) }).on("click", Message.Toggled({ id: c.id })).children( ColorDot(h, { color: c.color, shape: shown ? "square" : "ring", size: "md" }), h.span.attrs({ dir: "auto" }).children(c.name), ), ) }), ),})API reference
Options
| Name | Type | Description |
|---|---|---|
colorrequired | string | Any CSS color: "#7c3aed", "oklch(62% 0.2 300)", a theme variable. |
shape | "dot" | "square" | "ring" | dot (the default), square for labels and calendars, ring for one that's off or hidden. |
size | keyof typeof sizes | 8px (sm) by default. |
label | string | What the color means, when nothing beside it says: "Work calendar". |
style | Style | — |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/color-dot