# Color Dot

> A small mark in a project's, label's or calendar's color.

Page: https://uicontext.com/docs/components/color-dot

Group: Primitives.

## When to use

A small mark in a project's, label's or calendar's color. Use [Glyphs](https://uicontext.com/docs/components/glyphs.md) instead when the mark says status or priority, not a color someone chose.

## Usage

```ts
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

Each example is a complete file. Its imports point where the CLI installs the source.

### Projects by color

The example the page opens with: Color Dot in “Projects by color”.

```ts title="src/demo.ts" source="www/src/examples/color-dot/demo.ts"
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 included
const 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)),
			)),
	)
```

### Shown and hidden

`square` for a calendar that shows, `ring` once it's hidden.

```ts title="src/calendars.ts" source="www/src/examples/color-dot/calendars.ts"
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 hidden
export 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 |
| --- | --- | --- |
| `color` (required) | `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

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/color-dot
```

With npm: `npx shadcn@latest add checkfu/uicontext/color-dot`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/color-dot`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/color-dot`.

It writes these files:

- `src/ui/uicontext/components/ColorDot.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/ColorDot.ts](https://github.com/checkfu/uicontext/blob/main/src/ColorDot.ts)

## Related

- [Button](https://uicontext.com/docs/components/button.md) (`button`): A button, and a link that looks like one, in every tone and three sizes.
- [Toggle](https://uicontext.com/docs/components/toggle.md) (`toggle`): A button that stays pressed, such as Bold or Pin.
- [Toggle Group](https://uicontext.com/docs/components/toggle-group.md) (`toggle-group`): Buttons that stay pressed and share one value, such as text styles.
- [Input](https://uicontext.com/docs/components/input.md) (`input`): Text inputs, selects and textareas in a labeled field with a hint and an error, and their styles for controls you lay out yourself.
- [Status](https://uicontext.com/docs/components/status.md) (`status`): Status badges and tags for runs and records.
- [Glyphs](https://uicontext.com/docs/components/glyphs.md) (`glyphs`): Small marks for status, priority, color and people.
