feat(ui): add flat input surfaces and compact sizing (#60598)

This commit is contained in:
usrnk1 2026-10-30 17:09:26 +01:00 • committed by GitHub
parent da87c475a7
commit c65bb26ca4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 263 additions and 38 deletions

View file

@ -0,0 +1,110 @@
import { expect, story } from "../../stories/playwright/story"
for (const control of ["text-input", "textarea"]) {
story(`${control} supports its surfaces with inset feedback and stable geometry`, async ({ mount, page }) => {
const root = await mount(`ui-${control}--surfaces`)
const fields = root.locator(`[data-component="${control}-v2"]`)
await page.addStyleTag({
content: `[data-component="${control}-v2"] {
--v2-background-bg-base: rgb(20, 30, 40);
--v2-background-bg-layer-01: rgb(50, 60, 70);
--v2-overlay-simple-overlay-hover: rgba(10, 20, 30, 0.1);
--v2-elevation-input: 0px 0px 0px 3px rgb(1, 2, 3);
--v2-elevation-button-neutral: 0px 0px 0px 7px rgb(4, 5, 6);
}`,
})
await expect(fields.nth(0)).toHaveCSS("background-color", "rgb(20, 30, 40)")
await expect(fields.nth(1)).toHaveCSS("background-color", "rgb(50, 60, 70)")
await expect(fields.nth(0)).toHaveCSS("box-shadow", "rgb(1, 2, 3) 0px 0px 0px 3px")
await expect(fields.nth(1)).toHaveCSS("box-shadow", "rgb(1, 2, 3) 0px 0px 0px 3px")
for (const field of await fields.all()) {
await expect(field).toHaveCSS("background-image", "none")
}
const base = fields.nth(0)
const geometry = await base.getByRole("textbox").boundingBox()
await base.hover()
await expect
.poll(() => base.evaluate((element) => getComputedStyle(element).boxShadow))
.toContain("rgb(1, 2, 3) 0px 0px 0px 3px")
await base.getByRole("textbox").fill("Still editable")
await expect(base.getByRole("textbox")).toHaveValue("Still editable")
await expect(base).toHaveCSS("outline-width", "1px")
await expect(base).toHaveCSS("outline-offset", "-1px")
await expect(base).not.toHaveCSS("outline-color", "rgba(0, 0, 0, 0)")
expect(await base.getByRole("textbox").boundingBox()).toEqual(geometry)
const invalid = root.locator("[data-invalid]")
const disabled = root.locator("[data-disabled]")
await expect(invalid).toHaveCSS("outline-width", "1px")
await expect(invalid).toHaveCSS("outline-offset", "-1px")
await expect(invalid).not.toHaveCSS("outline-color", "rgba(0, 0, 0, 0)")
await expect(invalid.getByRole("textbox")).toHaveAttribute("aria-invalid", "true")
await expect(disabled.getByRole("textbox")).toBeDisabled()
if (control === "textarea") return
const invisible = root.locator('[data-surface="invisible"]').first()
await base.getByRole("textbox").blur()
await expect(invisible).toHaveCSS("background-color", "rgba(0, 0, 0, 0)")
await invisible.hover()
await expect(invisible).toHaveCSS("background-color", "rgba(10, 20, 30, 0.1)")
await expect(invisible).toHaveCSS("box-shadow", "none")
await invisible.getByRole("textbox").focus()
await expect(invisible).toHaveCSS("background-color", "rgba(0, 0, 0, 0)")
await expect(invisible).toHaveCSS("outline-offset", "-1px")
await expect(invisible).not.toHaveCSS("outline-color", "rgba(0, 0, 0, 0)")
await expect(invalid).toHaveCSS("background-color", "rgba(0, 0, 0, 0)")
await expect(disabled).toHaveCSS("background-color", "rgba(0, 0, 0, 0)")
await expect(disabled).toHaveCSS("box-shadow", "none")
})
}
story(
"text inputs keep clear and copy actions equally sized and inset across sizes and directions",
async ({ mount, page }) => {
const root = await mount("ui-text-input--appearances")
const fields = root.locator('[data-component="text-input-v2"]')
for (const [index, height] of [24, 28, 32, 32, 24, 28, 32].entries()) {
await expect(fields.nth(index)).toHaveCSS("height", `${height}px`)
}
for (const direction of ["ltr", "rtl"]) {
await page.evaluate((dir) => (document.documentElement.dir = dir), direction)
for (const field of await fields.filter({ has: page.getByRole("button") }).all()) {
const button = field.getByRole("button")
await expect(button).toHaveCSS("width", "20px")
await expect(button).toHaveCSS("height", "20px")
await expect(button).toHaveCSS("padding", "2px")
await expect(button).toHaveCSS("border-radius", "4px")
expect(
await field.evaluate((element) => {
const bounds = element.getBoundingClientRect()
const action = element.querySelector("button")!.getBoundingClientRect()
return {
inset:
getComputedStyle(element).direction === "rtl" ? action.left - bounds.left : bounds.right - action.right,
center: action.y + action.height / 2 - bounds.y - bounds.height / 2,
}
}),
).toEqual({ inset: 8, center: 0 })
}
}
},
)

View file

@ -15,10 +15,9 @@
border: 0;
border-radius: 6px;
outline: 1px solid transparent;
outline-offset: 0;
background:
linear-gradient(180deg, var(--v2-alpha-light-6) 0%, var(--v2-alpha-light-2) 100%), var(--v2-background-bg-base);
box-shadow: var(--v2-elevation-button-neutral);
outline-offset: -1px;
background: var(--v2-background-bg-base);
box-shadow: var(--v2-elevation-input);
flex: none;
align-self: stretch;
transition:
@ -27,14 +26,37 @@
box-shadow 85ms ease-out;
}
[data-component="text-input-v2"][data-appearance="small"] {
height: 24px;
}
[data-component="text-input-v2"][data-appearance="large"] {
height: 32px;
}
[data-component="text-input-v2"]:where(:hover):not([data-disabled], [data-invalid]):not(:focus-within) {
background:
linear-gradient(0deg, var(--v2-overlay-simple-overlay-hover), var(--v2-overlay-simple-overlay-hover)),
linear-gradient(180deg, var(--v2-alpha-light-6) 0%, var(--v2-alpha-light-2) 100%), var(--v2-background-bg-base);
[data-component="text-input-v2"][data-surface="layer-1"] {
background: var(--v2-background-bg-layer-01);
}
[data-component="text-input-v2"][data-surface="invisible"] {
background: transparent;
box-shadow: none;
}
@media (hover: hover) {
[data-component="text-input-v2"]:where(:hover):not([data-disabled], [data-invalid], [data-surface="invisible"]):not(
:focus-within
) {
box-shadow:
inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover),
var(--v2-elevation-input);
}
[data-component="text-input-v2"][data-surface="invisible"]:where(:hover):not([data-disabled], [data-invalid]):not(
:focus-within
) {
background: var(--v2-overlay-simple-overlay-hover);
}
}
[data-component="text-input-v2"]:where(:focus-within):not([data-disabled], [data-invalid]) {
@ -166,14 +188,6 @@
color: currentColor;
}
[data-component="text-input-v2"] [data-slot="text-input-v2-icon-button"][data-variant="clear"] {
width: 28px;
height: 28px;
padding: 0;
border-radius: 6px;
margin-inline-end: -8px;
}
/* Pulls the buttons' padding out so their glyphs sit at the same inset as the leading icon. */
[data-component="text-input-v2"] [data-slot="text-input-v2-trailing"] {
display: flex;

View file

@ -12,14 +12,15 @@ Compact single-line text field with neutral elevation, optional trailing copy ac
- \`copyLabel\`: Accessible name for the copy button (default: "Copy").
- \`onCopyClick\`: Handler for the copy button.
- \`invalid\`: Error outline and danger text color.
- \`appearance\`: \`"base"\` (28px) or \`"large"\` (32px).
- \`appearance\`: \`"small"\` (24px), \`"base"\` (28px), or \`"large"\` (32px).
- \`surface\`: \`"base"\` (default) or \`"layer-1"\` for a flat fill; \`"invisible"\` is unfilled at rest, with hover fill and inset focus/error outlines.
### States
- **Hover**: neutral overlay on the raised surface.
- **Focus** (\`:focus-within\`): focus border, elevation removed.
- **Invalid**: danger border and text.
- **Disabled**: 50% opacity.
- Uses \`data-component="text-input-v2"\` with \`--v2-background-bg-base\`, \`--v2-elevation-button-neutral\`, \`--v2-text-text-faint\` (placeholder), and \`--v2-icon-icon-muted\` (copy icon).
- Uses \`data-component="text-input-v2"\` with \`--v2-background-bg-base\`, \`--v2-elevation-input\`, \`--v2-text-text-faint\` (placeholder), and \`--v2-icon-icon-muted\` (copy icon).
### Field
Compose with \`Field\` for label, helper prefix/suffix, and tooltip — see the **Field** story.
@ -45,11 +46,16 @@ export default {
disabled: false,
invalid: false,
appearance: "base",
surface: "base",
},
argTypes: {
surface: {
control: "select",
options: ["base", "layer-1", "invisible"],
},
appearance: {
control: "select",
options: ["base", "large"],
options: ["small", "base", "large"],
},
showCopyButton: {
control: "boolean",
@ -68,6 +74,18 @@ export default {
export const Playground = {}
export const Surfaces = {
render: () => (
<div style={{ display: "grid", gap: "20px", width: "280px" }}>
<TextInput placeholder="Base (default)" />
<TextInput surface="layer-1" placeholder="Layer 1" />
<TextInput surface="invisible" placeholder="Invisible" />
<TextInput surface="invisible" placeholder="Invisible, invalid" invalid />
<TextInput surface="invisible" placeholder="Invisible, disabled" disabled />
</div>
),
}
export const WithCopyButton = {
args: {
placeholder: "api.example.com/v1",
@ -101,9 +119,13 @@ export const Controlled = {
export const Appearances = {
render: () => (
<div style={{ display: "grid", gap: "20px", width: "280px" }}>
<TextInput appearance="small" placeholder="Small (24px)" />
<TextInput appearance="base" placeholder="Base (28px)" defaultValue="Base" />
<TextInput appearance="large" placeholder="Large (32px)" defaultValue="Large" />
<TextInput appearance="large" placeholder="Large with copy" defaultValue="copy-me" showCopyButton />
<TextInput appearance="small" placeholder="Small with clear" showClearButton />
<TextInput appearance="base" placeholder="Base with clear" showClearButton />
<TextInput appearance="large" placeholder="Large with clear" showClearButton />
</div>
),
}

View file

@ -24,8 +24,10 @@ export interface TextInputProps extends Omit<ComponentProps<"input">, "type"> {
numeric?: boolean
/** Error styling for the field and value text. */
invalid?: boolean
/** `base` is 28px tall; `large` is 32px tall. */
appearance?: "base" | "large"
/** `small` is 24px tall; `base` is 28px tall; `large` is 32px tall. */
appearance?: "small" | "base" | "large"
/** Background surface; invisible gains a fill on hover. */
surface?: "base" | "layer-1" | "invisible"
type?: ComponentProps<"input">["type"]
}
@ -47,6 +49,7 @@ export function TextInput(props: TextInputProps) {
"numeric",
"invalid",
"appearance",
"surface",
"disabled",
])
@ -57,6 +60,7 @@ export function TextInput(props: TextInputProps) {
data-invalid={local.invalid ? "" : undefined}
data-numeric={local.numeric ? "" : undefined}
data-appearance={local.appearance ?? "base"}
data-surface={local.surface ?? "base"}
data-leading-icon={local.leadingIcon ? "" : undefined}
classList={{
...local.classList,

View file

@ -9,10 +9,9 @@
border: 0;
border-radius: 6px;
outline: 1px solid transparent;
outline-offset: 0;
background:
linear-gradient(180deg, var(--v2-alpha-light-2) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-base);
box-shadow: var(--v2-elevation-button-neutral);
outline-offset: -1px;
background: var(--v2-background-bg-base);
box-shadow: var(--v2-elevation-input);
flex: none;
align-self: stretch;
transition:
@ -21,10 +20,16 @@
box-shadow 85ms ease-out;
}
[data-component="textarea-v2"]:where(:hover):not([data-disabled], [data-invalid]):not(:focus-within) {
background:
linear-gradient(0deg, var(--v2-overlay-simple-overlay-hover), var(--v2-overlay-simple-overlay-hover)),
linear-gradient(180deg, var(--v2-alpha-light-2) 0%, var(--v2-alpha-light-0) 100%), var(--v2-background-bg-base);
[data-component="textarea-v2"][data-surface="layer-1"] {
background: var(--v2-background-bg-layer-01);
}
@media (hover: hover) {
[data-component="textarea-v2"]:where(:hover):not([data-disabled], [data-invalid]):not(:focus-within) {
box-shadow:
inset 0 0 0 100vmax var(--v2-overlay-simple-overlay-hover),
var(--v2-elevation-input);
}
}
[data-component="textarea-v2"]:where(:focus-within):not([data-disabled], [data-invalid]) {

View file

@ -9,6 +9,7 @@ Multiline text field with the same neutral elevation, states, and tokens as Text
### API
- Forwards native \`textarea\` props (\`value\`, \`defaultValue\`, \`placeholder\`, \`disabled\`, \`name\`, \`rows\`, etc.).
- \`invalid\`: Error outline and danger text color.
- \`surface\`: \`"base"\` (default) or \`"layer-1"\` for a flat fill.
### States
- **Hover**: neutral overlay on the raised surface.
@ -39,8 +40,13 @@ export default {
disabled: false,
invalid: false,
rows: 3,
surface: "base",
},
argTypes: {
surface: {
control: "select",
options: ["base", "layer-1"],
},
disabled: {
control: "boolean",
},
@ -58,6 +64,18 @@ export default {
export const Playground = {}
export const Surfaces = {
parameters: { frameHeight: "700px" },
render: () => (
<div style={{ display: "grid", gap: "20px", width: "280px" }}>
<Textarea placeholder="Base (default)" />
<Textarea surface="layer-1" placeholder="Layer 1" />
<Textarea surface="layer-1" placeholder="Layer 1, invalid" invalid />
<Textarea surface="layer-1" placeholder="Layer 1, disabled" disabled />
</div>
),
}
export const Controlled = {
render: () => {
const [value, setValue] = createSignal("Controlled value")

View file

@ -4,14 +4,16 @@ import "./textarea.css"
export interface TextareaProps extends ComponentProps<"textarea"> {
/** Error styling for the field and value text. */
invalid?: boolean
surface?: "base" | "layer-1"
}
export function Textarea(props: TextareaProps) {
const [local, textareaProps] = splitProps(props, ["class", "classList", "invalid", "disabled", "rows"])
const [local, textareaProps] = splitProps(props, ["class", "classList", "invalid", "disabled", "rows", "surface"])
return (
<div
data-component="textarea-v2"
data-surface={local.surface ?? "base"}
data-disabled={local.disabled ? "" : undefined}
data-invalid={local.invalid ? "" : undefined}
classList={{

View file

@ -112,6 +112,9 @@
--v2-elevation-overlay:
0px 16px 32px 0px var(--v2-alpha-dark-4), 0px 8px 16px 0px var(--v2-alpha-dark-8),
0px 0px 0px 0.5px var(--v2-alpha-dark-12), 0px 0px 0px 0px var(--v2-alpha-dark-0);
--v2-elevation-input:
0px 1px 1.5px 0px var(--v2-alpha-dark-10), 0px 0px 0px 0.5px var(--v2-alpha-dark-14),
0px 0px 0px 0px var(--v2-alpha-dark-0);
--v2-elevation-button-neutral:
0px 1px 1.5px 0px var(--v2-alpha-dark-10), 0px 0px 0px 0.5px var(--v2-alpha-dark-14),
0px 0px 0px 0px var(--v2-alpha-dark-0);
@ -229,6 +232,10 @@
0px 8px 16px 0px var(--v2-alpha-dark-30),
0px 0px 0px 0.5px var(--v2-alpha-light-16),
0px -0.5px 0px 0px var(--v2-alpha-light-6);
--v2-elevation-input:
0px 1px 2px 0px var(--v2-alpha-dark-0),
0px 0px 0px 0.5px var(--v2-alpha-light-16),
0px -0.5px 0px 0px var(--v2-alpha-light-6);
--v2-elevation-button-neutral:
0px 1px 2px 0px var(--v2-alpha-dark-40),
0px 0px 0px 0.5px var(--v2-alpha-light-20),
@ -342,6 +349,9 @@
--v2-elevation-overlay:
0px 16px 32px 0px var(--v2-alpha-dark-4), 0px 8px 16px 0px var(--v2-alpha-dark-8),
0px 0px 0px 0.5px var(--v2-alpha-dark-12), 0px 0px 0px 0px var(--v2-alpha-dark-0);
--v2-elevation-input:
0px 1px 1.5px 0px var(--v2-alpha-dark-10), 0px 0px 0px 0.5px var(--v2-alpha-dark-14),
0px 0px 0px 0px var(--v2-alpha-dark-0);
--v2-elevation-button-neutral:
0px 1px 1.5px 0px var(--v2-alpha-dark-10), 0px 0px 0px 0.5px var(--v2-alpha-dark-14),
0px 0px 0px 0px var(--v2-alpha-dark-0);
@ -488,6 +498,9 @@
--v2-elevation-overlay:
0px 16px 32px 0px var(--v2-alpha-dark-30), 0px 8px 16px 0px var(--v2-alpha-dark-30),
0px 0px 0px 0.5px var(--v2-alpha-light-16), 0px -0.5px 0px 0px var(--v2-alpha-light-6);
--v2-elevation-input:
0px 1px 2px 0px var(--v2-alpha-dark-0), 0px 0px 0px 0.5px var(--v2-alpha-light-16),
0px -0.5px 0px 0px var(--v2-alpha-light-6);
--v2-elevation-button-neutral:
0px 1px 2px 0px var(--v2-alpha-dark-40), 0px 0px 0px 0.5px var(--v2-alpha-light-20),
0px -0.5px 0px 0px var(--v2-alpha-light-10);

View file

@ -243,6 +243,7 @@
"v2-elevation-raised": "0px 2px 4px 0px var(--v2-alpha-dark-4), 0px 1px 2px -1px var(--v2-alpha-dark-8), 0px 0px 0px 0.5px var(--v2-alpha-dark-12), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
"v2-elevation-floating": "0px 8px 16px 0px var(--v2-alpha-dark-4), 0px 4px 8px 0px var(--v2-alpha-dark-8), 0px 0px 0px 0.5px var(--v2-alpha-dark-12), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
"v2-elevation-overlay": "0px 16px 32px 0px var(--v2-alpha-dark-4), 0px 8px 16px 0px var(--v2-alpha-dark-8), 0px 0px 0px 0.5px var(--v2-alpha-dark-12), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
"v2-elevation-input": "0px 1px 1.5px 0px var(--v2-alpha-dark-10), 0px 0px 0px 0.5px var(--v2-alpha-dark-14), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
"v2-elevation-button-neutral": "0px 1px 1.5px 0px var(--v2-alpha-dark-10), 0px 0px 0px 0.5px var(--v2-alpha-dark-14), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
"v2-elevation-button-contrast": "0px 1px 1.5px 0px var(--v2-alpha-dark-20), 0px 0px 0px 0.5px var(--v2-grey-800), inset 0px 1px 2px 0px var(--v2-alpha-light-14), inset 0px -1px 2px 0px var(--v2-alpha-dark-6), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
"v2-elevation-elements": "0px 0.5px 0.5px 0px var(--v2-alpha-dark-40)",
@ -494,6 +495,7 @@
"v2-elevation-raised": "0px 2px 4px 0px var(--v2-alpha-dark-30), 0px 1px 2px 0px var(--v2-alpha-dark-30), 0px 0px 0px 0.5px var(--v2-alpha-light-16), 0px -0.5px 0px 0px var(--v2-alpha-light-6)",
"v2-elevation-floating": "0px 8px 16px 0px var(--v2-alpha-dark-30), 0px 4px 8px 0px var(--v2-alpha-dark-30), 0px 0px 0px 0.5px var(--v2-alpha-light-16), 0px -0.5px 0px 0px var(--v2-alpha-light-6)",
"v2-elevation-overlay": "0px 16px 32px 0px var(--v2-alpha-dark-30), 0px 8px 16px 0px var(--v2-alpha-dark-30), 0px 0px 0px 0.5px var(--v2-alpha-light-16), 0px -0.5px 0px 0px var(--v2-alpha-light-6)",
"v2-elevation-input": "0px 1px 2px 0px var(--v2-alpha-dark-0), 0px 0px 0px 0.5px var(--v2-alpha-light-16), 0px -0.5px 0px 0px var(--v2-alpha-light-6)",
"v2-elevation-button-neutral": "0px 1px 2px 0px var(--v2-alpha-dark-40), 0px 0px 0px 0.5px var(--v2-alpha-light-20), 0px -0.5px 0px 0px var(--v2-alpha-light-10)",
"v2-elevation-button-contrast": "0px 1px 2px 0px var(--v2-alpha-dark-40), 0px 0px 0px 0.5px var(--v2-alpha-light-40), inset 0px 0px 0px 0px var(--v2-alpha-light-0), inset 0px 0px 0px 0px var(--v2-alpha-light-0), 0px -0.5px 0px 0px var(--v2-alpha-light-30)",
"v2-elevation-elements": "0px 0.5px 0.5px 0px var(--v2-alpha-dark-40)",

View file

@ -3,7 +3,7 @@ import { V2_AVATAR_DARK, V2_AVATAR_LIGHT } from "./avatar"
const ref = (name: string): V2ColorValue => `var(--${name})`
const lightAgentTokens: Record<string, V2ColorValue> = {
const lightAgentTokens = {
"v2-agent-plan-solid": ref("v2-pink-800"),
"v2-agent-plan-border": "rgba(200, 61, 139, 0.20)",
"v2-agent-plan-background": "rgba(253, 236, 243, 0.10)",
@ -15,9 +15,9 @@ const lightAgentTokens: Record<string, V2ColorValue> = {
"v2-agent-explore-background": "rgba(254, 250, 236, 0.1)",
"v2-agent-review-solid": ref("v2-green-800"),
"v2-agent-writer-solid": ref("v2-purple-700"),
}
} satisfies Record<string, V2ColorValue>
const darkAgentTokens: Record<string, V2ColorValue> = {
const darkAgentTokens = {
"v2-agent-plan-solid": ref("v2-pink-400"),
"v2-agent-plan-border": "rgba(247, 153, 198, 0.20)",
"v2-agent-plan-background": "rgba(170, 53, 118, 0.05)",
@ -29,9 +29,9 @@ const darkAgentTokens: Record<string, V2ColorValue> = {
"v2-agent-explore-background": "rgba(172, 136, 51, 0.05)",
"v2-agent-review-solid": ref("v2-green-300"),
"v2-agent-writer-solid": ref("v2-purple-400"),
}
} satisfies Record<string, V2ColorValue>
const light: Record<string, V2ColorValue> = {
const light = {
"v2-background-bg-base": ref("v2-grey-100"),
"v2-background-bg-deep": ref("v2-grey-200"),
"v2-background-bg-layer-01": ref("v2-grey-300"),
@ -85,6 +85,8 @@ const light: Record<string, V2ColorValue> = {
"0px 8px 16px 0px var(--v2-alpha-dark-4), 0px 4px 8px 0px var(--v2-alpha-dark-8), 0px 0px 0px 0.5px var(--v2-alpha-dark-12), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
"v2-elevation-overlay":
"0px 16px 32px 0px var(--v2-alpha-dark-4), 0px 8px 16px 0px var(--v2-alpha-dark-8), 0px 0px 0px 0.5px var(--v2-alpha-dark-12), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
"v2-elevation-input":
"0px 1px 1.5px 0px var(--v2-alpha-dark-10), 0px 0px 0px 0.5px var(--v2-alpha-dark-14), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
"v2-elevation-button-neutral":
"0px 1px 1.5px 0px var(--v2-alpha-dark-10), 0px 0px 0px 0.5px var(--v2-alpha-dark-14), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
"v2-elevation-button-contrast":
@ -97,9 +99,9 @@ const light: Record<string, V2ColorValue> = {
"v2-illustration-illustration-layer-01": ref("v2-grey-300"),
"v2-illustration-illustration-layer-02": ref("v2-grey-400"),
"v2-illustration-illustration-layer-03": ref("v2-grey-500"),
}
} satisfies Record<string, V2ColorValue>
const dark: Record<string, V2ColorValue> = {
const dark = {
"v2-background-bg-base": ref("v2-grey-1000"),
"v2-background-bg-deep": ref("v2-grey-1100"),
"v2-background-bg-layer-01": ref("v2-grey-800"),
@ -153,6 +155,8 @@ const dark: Record<string, V2ColorValue> = {
"0px 8px 16px 0px var(--v2-alpha-dark-30), 0px 4px 8px 0px var(--v2-alpha-dark-30), 0px 0px 0px 0.5px var(--v2-alpha-light-16), 0px -0.5px 0px 0px var(--v2-alpha-light-6)",
"v2-elevation-overlay":
"0px 16px 32px 0px var(--v2-alpha-dark-30), 0px 8px 16px 0px var(--v2-alpha-dark-30), 0px 0px 0px 0.5px var(--v2-alpha-light-16), 0px -0.5px 0px 0px var(--v2-alpha-light-6)",
"v2-elevation-input":
"0px 1px 2px 0px var(--v2-alpha-dark-0), 0px 0px 0px 0.5px var(--v2-alpha-light-16), 0px -0.5px 0px 0px var(--v2-alpha-light-6)",
"v2-elevation-button-neutral":
"0px 1px 2px 0px var(--v2-alpha-dark-40), 0px 0px 0px 0.5px var(--v2-alpha-light-20), 0px -0.5px 0px 0px var(--v2-alpha-light-10)",
"v2-elevation-button-contrast":
@ -165,7 +169,7 @@ const dark: Record<string, V2ColorValue> = {
"v2-illustration-illustration-layer-01": ref("v2-grey-900"),
"v2-illustration-illustration-layer-02": ref("v2-grey-800"),
"v2-illustration-illustration-layer-03": ref("v2-grey-700"),
}
} satisfies Record<string, V2ColorValue>
export function mapV2Semantics(isDark: boolean): Record<string, V2ColorValue> {
return isDark ? dark : light

View file

@ -57,7 +57,38 @@ describe("contrast icon-button tokens", () => {
})
})
describe("input elevation", () => {
test.each([
{
mode: "light",
input:
"0px 1px 1.5px 0px var(--v2-alpha-dark-10), 0px 0px 0px 0.5px var(--v2-alpha-dark-14), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
button:
"0px 1px 1.5px 0px var(--v2-alpha-dark-10), 0px 0px 0px 0.5px var(--v2-alpha-dark-14), 0px 0px 0px 0px var(--v2-alpha-dark-0)",
},
{
mode: "dark",
input:
"0px 1px 2px 0px var(--v2-alpha-dark-0), 0px 0px 0px 0.5px var(--v2-alpha-light-16), 0px -0.5px 0px 0px var(--v2-alpha-light-6)",
button:
"0px 1px 2px 0px var(--v2-alpha-dark-40), 0px 0px 0px 0.5px var(--v2-alpha-light-20), 0px -0.5px 0px 0px var(--v2-alpha-light-10)",
},
] as const)(
"$mode matches Figma in OC-2 and custom-theme fallbacks without changing buttons",
({ mode, input, button }) => {
for (const tokens of [
resolveThemeV2(theme)[mode],
resolveThemeVariantV2({ ...theme[mode], v2Overrides: undefined }, mode === "dark"),
]) {
expect(tokens["v2-elevation-input"]).toBe(input)
expect(tokens["v2-elevation-button-neutral"]).toBe(button)
}
},
)
})
function expectIconEmphasis(tokens: ResolvedV2Theme) {
// SAFETY: these resolved background/icon color tokens are hex colors or references to other hex color tokens.
const resolve = (value: string): HexColor =>
value.startsWith("var(--") ? resolve(tokens[value.slice(6, -1)]) : (value as HexColor)