Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/components/onboarding/onboarding-frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function OnboardingFrame({
// Pills on a phone, as onboarding's buttons were; from `lg` the button's own corner, as on every
// other screen.
const shape =
"h-[52px] w-full rounded-full px-5 text-sm font-semibold lg:h-10 lg:w-auto lg:min-w-32 lg:rounded-md";
"h-[52px] w-full rounded-full px-5 lg:h-10 lg:w-auto lg:min-w-32 lg:rounded-md";
return (
<div
className="grid min-h-svh w-full min-w-0 grid-cols-[minmax(0,1fr)] grid-rows-[auto_auto_auto_1fr_auto] bg-background text-foreground lg:h-svh lg:grid-cols-[minmax(28rem,35rem)_minmax(0,1fr)] lg:grid-rows-[auto_auto_1fr_auto] lg:bg-sidebar lg:p-2"
Expand Down Expand Up @@ -208,7 +208,7 @@ export function OnboardingFrame({
<button
className={cn(
buttonVariants({ variant: "ghost", size: "lg" }),
"text-sm hidden font-semibold lg:order-first lg:inline-flex",
"hidden lg:order-first lg:inline-flex",
)}
data-onboarding-back="desktop"
onClick={onBack}
Expand Down
24 changes: 17 additions & 7 deletions app/src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/utils";

/*
* A button has a control's corner, `rounded-md`, which follows `--radius` as every control does,
* at every size. A call site squares one side off only to join two buttons into one control
* (`rounded-r-none` beside `rounded-l-none`), and no size puts the corner back. Its label is
* semibold.
*
* KEYBOARD FOCUS IS A SOLID RING, the same on every variant: the border turns `ring` and 3px more
* of it are drawn outside, 4px in all. Outside, it is measured against what the button stands on,
* which tokens/tests/contrast.test.ts holds at 3:1. Half strength (`ring-ring/50`) was 1.75:1 on the
* page in light, and a ring drawn inside would sit on the fill, 2.3:1 on the dark theme's primary.
*/
const buttonVariants = cva(
"group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-[color,background-color,border-color,box-shadow,scale,opacity] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:scale-[0.97] motion-reduce:active:not-aria-[haspopup]:scale-none disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
"group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-semibold whitespace-nowrap transition-[color,background-color,border-color,box-shadow,scale,opacity] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring active:not-aria-[haspopup]:scale-[0.97] motion-reduce:active:not-aria-[haspopup]:scale-none disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
{
variants: {
variant: {
Expand All @@ -16,19 +27,18 @@ const buttonVariants = cva(
ghost:
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground",
destructive:
"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20",
"bg-destructive/10 text-destructive hover:bg-destructive/20",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default:
"h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
xs: "h-6 gap-1 px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
sm: "h-7 gap-1 px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
xs: "h-6 gap-1 px-2 text-xs has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
sm: "h-7 gap-1 px-2.5 text-[0.8rem] has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
icon: "size-8",
"icon-xs":
"size-6 in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
"icon-sm": "size-7 in-data-[slot=button-group]:rounded-md",
"icon-xs": "size-6 [&_svg:not([class*='size-'])]:size-3",
"icon-sm": "size-7",
"icon-lg": "size-9",
},
},
Expand Down
27 changes: 27 additions & 0 deletions app/tests/ui-primitives-look.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { classes, offences, type Rule } from "./ui-look-rules";
* something floats, as Linear draws them: none in the page, `shadow-xs` on a control pressed on a
* surface, `shadow-lg` and a border on what opens beside its trigger, `shadow-2xl` and a border on
* what sits over the app. Corners come from `--radius`: controls md, cards lg, menus and dialogs xl.
* A button's label is semibold, and its keyboard focus a solid ring.
*/

const UI = join(import.meta.dir, "../src/components/ui");
Expand Down Expand Up @@ -100,6 +101,32 @@ describe("the primitives keep the look", () => {
expect(lg).toEqual([]);
});

test("a button has one corner at every size, so a split button keeps its squared sides", () => {
const corners = classes(source("button.tsx")).filter((name) =>
/(^|:)rounded(-|$)/.test(name),
);
expect(corners).toEqual(["rounded-md"]);
});

test("a button's label is semibold", () => {
const weights = classes(source("button.tsx")).filter((name) =>
/(^|:)font-(?!mono|sans|serif)/.test(name),
);
expect(weights).toEqual(["font-semibold"]);
});

test("a button's keyboard focus is a solid ring in --ring, whatever the variant", () => {
const focus = classes(source("button.tsx")).filter((name) =>
name.startsWith("focus-visible:"),
);
expect(focus).toContain("focus-visible:ring-ring");
expect(focus).toContain("focus-visible:border-ring");
// Half strength is under the 3:1 a focus ring needs, and a variant's own color is weaker still.
expect(
focus.filter((name) => /:(ring|border)-(?!ring$|3$)/.test(name)),
).toEqual([]);
});

test("a pressed control on a surface is raised: shadow-xs", () => {
const outline =
/outline:\s*"([^"]*)"/.exec(source("button.tsx"))?.[1] ?? "";
Expand Down
6 changes: 3 additions & 3 deletions docs/app-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ changes, for every screen at once, in a change agreed first.
1. **Colors.** Only the scheme's tokens, as above.
2. **Type.** Figtree on Tailwind's own type scale, in whole pixels: `text-xs` is 12px, `text-sm`
14px, `text-base` 16px and a page title's `text-2xl` 24px. Controls, rows and navigation are
`text-sm`; labels, times and counts are `text-xs`. The line under a row's name
(`ItemDescription`) is `text-sm` too, in `muted-foreground`: the name's weight and color set it
apart. No text size written by hand (`text-[13px]`).
`text-sm`; labels, times and counts are `text-xs`. A button's label is semibold. The line under
a row's name (`ItemDescription`) is `text-sm` too, in `muted-foreground`: the name's weight and
color set it apart. No text size written by hand (`text-[13px]`).
3. **Corners.** All from `--radius`, 10px, the design's radius base. Controls are `rounded-md`
(8px), cards and the page's panel `rounded-lg` (10px), menus, dialogs and the message box
`rounded-xl` (14px), round things `rounded-full`. `rounded-none` squares a part off. No other
Expand Down
15 changes: 9 additions & 6 deletions docs/design-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ changed in `tokens/src/scheme.ts` and written out with `bun run tokens:generate`
`--spacing-menu-item-x`, not `--radius-card`. A stock shadcn theme doesn't set them, so they stay
at our values while everything else changes, and the theme is broken. A state is made from the
tokens there are, as shadcn does it: hover is `hover:bg-primary/80` or `hover:bg-muted`, disabled
is `disabled:opacity-50`, focus is `ring-ring/50`, invalid is `destructive`.
is `disabled:opacity-50`, focus is a ring in `ring` (a button's is solid: see
[Primitives](#primitives)), invalid is `destructive`.
- **A token is a token wherever it is declared.** `:root`, `.dark`, `@theme` or a component's own
stylesheet: the rules above hold for all of them. The test reads only `:root` and `.dark`; the
rule is wider than the test.
Expand All @@ -118,11 +119,13 @@ changed in `tokens/src/scheme.ts` and written out with `bun run tokens:generate`
`data-slot` on each part, `cn` for the classes. Check shadcn first: badge, radio group, kbd and
the like are already there.
- **A variant or a size keeps its meaning.** `default`, `secondary`, `outline`, `ghost`,
`destructive` and `link`, and `xs`, `sm`, `default` and `lg`, look and measure as they do today
and as a shadcn user expects. Moving `sm` by 4px, or making every button a pill, redraws every
screen at once. A new look is a new variant, agreed first. A size of our own goes beside
shadcn's, never in place of one: `SidebarMenuButton`'s `page` (36px) is for a page's own menu,
Settings and Admin, and the app's main sidebar keeps `default` (32px).
`destructive` and `link`, and `xs`, `sm`, `default` and `lg`, measure as they do today and as a
shadcn user expects, and keep their colors and corners. Moving `sm` by 4px, or making every
button a pill, redraws every screen at once. A new look is a new variant, agreed first. A size
of our own goes beside shadcn's, never in place of one: `SidebarMenuButton`'s `page` (36px) is
for a page's own menu, Settings and Admin, and the app's main sidebar keeps `default` (32px).
- **A button's label is semibold,** and its keyboard focus is a solid ring in `ring`, drawn
outside it, the same on every variant. Its corner is a control's, `rounded-md`, from `--radius`.
- **One system.** No second kit beside the first, no "legacy" mode, no variant that switches
between two looks. A skin keeps its own layout and wears the scheme's colors: it sets none of
them under `:root[data-skin]`, and each color role of its own reads the scheme's token that means
Expand Down
3 changes: 3 additions & 0 deletions tokens/tests/contrast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const PAIRS: [Token, Token[], number][] = [
["sidebar-accent-foreground", ["sidebar-accent", "sidebar"], TEXT],
["ring", ["background"], NON_TEXT],
["ring", ["card"], NON_TEXT],
// A button's ring is drawn outside it, on whatever it stands on: a dialog, a muted row.
["ring", ["popover"], NON_TEXT],
["ring", ["muted"], NON_TEXT],
["sidebar-ring", ["sidebar"], NON_TEXT],
];

Expand Down