From 5bdcc4e4316849b0422fdbcd8a9cca15a59cc72e Mon Sep 17 00:00:00 2001 From: Zakk Date: Sun, 4 Oct 2026 00:44:32 +1000 Subject: [PATCH] refactor(styles): move design tokens to foundations and split segmented The :root tokens, their direction, pointer, phone and dark overrides move from motion.css to the top of foundations.css, and the Segmented control rules move to segmented.css, imported right after motion.css. Rules move verbatim; the control size test follows the rules to their new file. --- changes/refactor-foundations-segmented.md | 3 + src/ui/styles/controlSize.test.ts | 12 +- src/ui/styles/foundations.css | 162 +++++++++++++ src/ui/styles/motion.css | 267 ---------------------- src/ui/styles/segmented.css | 105 +++++++++ src/ui/theme.css | 1 + 6 files changed, 277 insertions(+), 273 deletions(-) create mode 100644 changes/refactor-foundations-segmented.md create mode 100644 src/ui/styles/segmented.css diff --git a/changes/refactor-foundations-segmented.md b/changes/refactor-foundations-segmented.md new file mode 100644 index 00000000..da5c88fb --- /dev/null +++ b/changes/refactor-foundations-segmented.md @@ -0,0 +1,3 @@ +Internal + +- The design tokens live in foundations.css and the Segmented control styles in their own segmented.css, moved verbatim from motion.css. diff --git a/src/ui/styles/controlSize.test.ts b/src/ui/styles/controlSize.test.ts index 2a9574cb..7340bc67 100644 --- a/src/ui/styles/controlSize.test.ts +++ b/src/ui/styles/controlSize.test.ts @@ -4,7 +4,7 @@ import {transform, type Selector} from 'lightningcss'; import {expect, it} from 'vitest'; import {ControlSizeContext} from '../controlSize'; import {Segmented} from '../Segmented'; -import motion from './motion.css?raw'; +import segmentedCss from './segmented.css?raw'; const owners: Record = { 'rp-btn': 'buttons-menus.css', @@ -12,8 +12,8 @@ const owners: Record = { 'rp-input': 'dialogs-search.css', 'rp-selectbtn': 'fields.css', 'rp-switch': 'fields.css', - 'rp-seg': 'motion.css', - 'rp-segpick': 'motion.css', + 'rp-seg': 'segmented.css', + 'rp-segpick': 'segmented.css', 'rp-tab': 'tabs-panels.css', 'rp-tabbar': 'tabs-panels.css', 'rp-tablist': 'tabs-panels.css' @@ -48,7 +48,7 @@ function violations(css: string, filename: string): string[] { if (!(property in dimensions) || !controls.length) continue; const prefix = selector.slice(0, lastCombinator); const segmentedButton = - filename === 'motion.css' && + filename === 'segmented.css' && prefix[0]?.type === 'class' && prefix[0].name === 'rp-seg' && prefix.every(part => (part.type === 'class' && part.name === 'rp-seg') || part.type === 'attribute'); @@ -99,7 +99,7 @@ it('rejects page, one-off and literal control sizing, including logical sizes an function segmentedHeights(css: string): string[] { const values: string[] = []; transform({ - filename: 'motion.css', + filename: 'segmented.css', code: new TextEncoder().encode(css), visitor: { Rule: { @@ -118,7 +118,7 @@ function segmentedHeights(css: string): string[] { } it('sizes every segmented control at L only', () => { - const heights = segmentedHeights(motion); + const heights = segmentedHeights(segmentedCss); expect(heights.length).toBeGreaterThan(0); expect(heights.filter(value => !value.includes('"--rp-control-lg"'))).toEqual([]); const items: Array<[string, string]> = [ diff --git a/src/ui/styles/foundations.css b/src/ui/styles/foundations.css index 76d59b24..ac8933ff 100644 --- a/src/ui/styles/foundations.css +++ b/src/ui/styles/foundations.css @@ -1,3 +1,165 @@ +:root { + /* Touch browsers draw a square tap box over the pressed element; every control has its own rounded pressed state. */ + -webkit-tap-highlight-color: transparent; + color-scheme: light; + --rp-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12); + --rp-underlay: rgba(0, 0, 0, 0.32); + --rp-elevated: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04), 0 0 2px rgba(0, 0, 0, 0.12); + --rp-popover-border: transparent; + --rp-on-accent: var(--rp-surface); + /* Text on a success or error fill, such as a toast, or on a notice fill, such as a warning badge. Where the on-accent + colour is under 4.5:1 on that tone, the palette points these at another of its own colours. */ + --rp-on-positive: var(--rp-on-accent); + --rp-on-negative: var(--rp-on-accent); + --rp-on-notice: var(--rp-on-accent); + --rp-on-text: var(--rp-surface); + --rp-accent: var(--rp-pine); + /* The accent as text. Where a palette's accent is under 4.5:1 on its base or surface, the palette sets body text. */ + --rp-accent-text: var(--rp-accent); + --rp-negative: var(--rp-love); + --rp-positive: var(--rp-foam); + --rp-notice: var(--rp-gold); + --rp-info: var(--rp-pine); + /* The status tones as text, set by a palette to body text where the tone is under 4.5:1 in the same way. */ + --rp-negative-text: var(--rp-negative); + --rp-notice-text: var(--rp-notice); + --rp-positive-text: var(--rp-positive); + --rp-info-text: var(--rp-info); + /* The same roles on a tile, plain or selected, where a palette sets body text for a tone under 4.5:1 there. Page text + is judged on the base and the surface only, so a tone that passes there keeps its colour outside tiles. */ + --rp-accent-tile-text: var(--rp-accent-text); + --rp-negative-tile-text: var(--rp-negative-text); + --rp-notice-tile-text: var(--rp-notice-text); + --rp-positive-tile-text: var(--rp-positive-text); + --rp-info-tile-text: var(--rp-info-text); + /* Secondary text on a tile, plain or selected. Where a palette's subtle is under 4.5:1 there, the palette sets body + text; page-level secondary text keeps reading --rp-subtle. */ + --rp-subtle-text: var(--rp-subtle); + /* Dividers and quiet fills (hover, empty cells, tracks) drawn on a card. A palette whose highlight low is its + surface points both at a step that shows; the contrast spec holds them to 1.1:1 on the surface. */ + --rp-line: var(--rp-hl-low); + --rp-fill: var(--rp-hl-low); + --rp-ease: cubic-bezier(0.45, 0, 0.4, 1); + --rp-ease-in: cubic-bezier(0.5, 0, 1, 1); + --rp-ease-out: cubic-bezier(0, 0, 0.4, 1); + --rp-space-1: 4px; + --rp-space-2: calc(var(--rp-space-1) * 2); + --rp-space-6: calc(var(--rp-space-1) * 6); + --rp-r-xs: 3px; + --rp-r-sm: 6px; + --rp-r-md: 8px; + --rp-r-lg: 10px; + --rp-r-xl: 16px; + --rp-r-2xl: 20px; + --rp-r-pill: 999px; + /* The type scale stays in px, like the icons set beside it. */ + --rp-text-2xs: 11px; + --rp-text-xs: 12px; + --rp-text-sm: 13px; + --rp-text-md: 14px; + --rp-text-lg: 16px; + --rp-text-xl: 18px; + --rp-text-2xl: 20px; + --rp-text-3xl: 22px; + --rp-text-4xl: 24px; + --rp-text-5xl: 28px; + /* A tile value's line: its 3xl type, and the row a stacked tile keeps for it. */ + --rp-value-line: 28px; + --rp-space-half: 2px; + --rp-space-1: 4px; + --rp-space-1h: 6px; + --rp-space-2: 8px; + --rp-space-2h: 10px; + --rp-space-3: 12px; + --rp-space-3h: 14px; + --rp-space-4: 16px; + --rp-space-5: 20px; + --rp-space-6: 24px; + --rp-space-8: 32px; + --rp-space-10: 40px; + --rp-space-12: 48px; + --rp-space-16: 64px; + --rp-font-mono: + 'Twemoji Country Flags', ui-monospace, 'SF Mono', Menlo, Consolas, 'JetBrains Mono', 'Fira Code', 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono', + monospace; + --rp-line-body: 20px; + --rp-line-caption: 16px; + --rp-focus-width: 2px; + --rp-focus-color: var(--rp-accent); + --rp-focus-offset: var(--rp-space-half); + --rp-control-inset: var(--rp-space-half); + /* Segment items fill the track's height at every size, so a selected segment is as tall as the button beside it. */ + --rp-control-block-inset: 0px; + /* Global stacking, low to high: the floating panel, then modals and tooltips (tooltips are portaled after the modal + they sit on), then toasts. */ + --rp-z-panel: 9; + --rp-z-modal: 10; + --rp-z-tooltip: 10; + --rp-z-toast: 20; + --rp-sidebar-width: 240px; + --rp-sidebar-padding: 16px; + /* The overlay scroll classes draw a scrollbar this thick. */ + --rp-scrollbar: 6px; + --rp-control: 32px; + --rp-control-lg: 40px; + /* L's inline padding; phones take M's (below), so a row of L controls fits as a row of M controls does. L's text is M's text size at every width. */ + --rp-lg-inset-btn: calc(var(--rp-control-lg) / 2); + --rp-lg-inset-field: calc(var(--rp-control-lg) * 3 / 8); + --rp-lg-inset-compact: calc(var(--rp-control-lg) * 3 / 8); + --rp-lg-text: var(--rp-text-md); + --rp-lg-text-compact: var(--rp-text-lg); + --rp-control-xs: 24px; + --rp-duration: 150ms; + --rp-duration-panel: 200ms; + --rp-duration-modal-in: 250ms; + --rp-duration-modal-out: 130ms; + --rp-duration-toast: 400ms; + --rp-duration-slow: 400ms; + --rp-duration-tab: 120ms; + --rp-delay-tab: 100ms; + --rp-delay-dialog: 160ms; + --rp-duration-hop: 360ms; + --rp-duration-pop: 240ms; + --rp-duration-view: 300ms; + --rp-duration-spin: 800ms; + /* One turn of the refresh and reload arrows, as long as one turn of S2's indeterminate ProgressCircle. */ + --rp-duration-refresh: 1000ms; + --rp-duration-hue: 3s; + --rp-selected: color-mix(in srgb, var(--rp-accent) 10%, var(--rp-overlay)); + --rp-ink-mix: #000; + /* The sign of the inline direction: a shift or turn along the line multiplies by it, so right to left mirrors it. */ + --rp-dir: 1; +} +/* An element that sets its own direction, as React Aria's popovers and toasts do, sets the sign for what it holds. */ +[dir='rtl'] { + --rp-dir: -1; +} +[dir='ltr'] { + --rp-dir: 1; +} +/* A finger needs more than a pointer does; table rows are already 40px. */ +@media (pointer: coarse) { + :root { + --rp-control: 36px; + } +} +@media (max-width: 599px) { + :root { + --rp-control: 36px; + --rp-lg-inset-btn: var(--rp-space-3); + --rp-lg-inset-field: var(--rp-space-3); + --rp-lg-inset-compact: var(--rp-space-2); + --rp-lg-text-compact: var(--rp-text-xs); + } +} +:root[data-scheme='dark'] { + color-scheme: dark; + --rp-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45); + --rp-underlay: rgba(0, 0, 0, 0.55); + --rp-elevated: 0 4px 12px rgba(0, 0, 0, 0.24), 0 2px 6px rgba(0, 0, 0, 0.12), 0 0 2px rgba(0, 0, 0, 0.36); + --rp-popover-border: var(--rp-hl-med); + --rp-ink-mix: #fff; +} /* Pixel-sized icons stay aligned with the fixed 14px type regardless of the browser's default font size. */ :root { --rp-icon-size: 20px; diff --git a/src/ui/styles/motion.css b/src/ui/styles/motion.css index aa7e0739..bf95304d 100644 --- a/src/ui/styles/motion.css +++ b/src/ui/styles/motion.css @@ -133,278 +133,11 @@ opacity var(--rp-duration) var(--rp-ease), transform var(--rp-duration) var(--rp-ease); } -:root { - /* Touch browsers draw a square tap box over the pressed element; every control has its own rounded pressed state. */ - -webkit-tap-highlight-color: transparent; - color-scheme: light; - --rp-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12); - --rp-underlay: rgba(0, 0, 0, 0.32); - --rp-elevated: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04), 0 0 2px rgba(0, 0, 0, 0.12); - --rp-popover-border: transparent; - --rp-on-accent: var(--rp-surface); - /* Text on a success or error fill, such as a toast, or on a notice fill, such as a warning badge. Where the on-accent - colour is under 4.5:1 on that tone, the palette points these at another of its own colours. */ - --rp-on-positive: var(--rp-on-accent); - --rp-on-negative: var(--rp-on-accent); - --rp-on-notice: var(--rp-on-accent); - --rp-on-text: var(--rp-surface); - --rp-accent: var(--rp-pine); - /* The accent as text. Where a palette's accent is under 4.5:1 on its base or surface, the palette sets body text. */ - --rp-accent-text: var(--rp-accent); - --rp-negative: var(--rp-love); - --rp-positive: var(--rp-foam); - --rp-notice: var(--rp-gold); - --rp-info: var(--rp-pine); - /* The status tones as text, set by a palette to body text where the tone is under 4.5:1 in the same way. */ - --rp-negative-text: var(--rp-negative); - --rp-notice-text: var(--rp-notice); - --rp-positive-text: var(--rp-positive); - --rp-info-text: var(--rp-info); - /* The same roles on a tile, plain or selected, where a palette sets body text for a tone under 4.5:1 there. Page text - is judged on the base and the surface only, so a tone that passes there keeps its colour outside tiles. */ - --rp-accent-tile-text: var(--rp-accent-text); - --rp-negative-tile-text: var(--rp-negative-text); - --rp-notice-tile-text: var(--rp-notice-text); - --rp-positive-tile-text: var(--rp-positive-text); - --rp-info-tile-text: var(--rp-info-text); - /* Secondary text on a tile, plain or selected. Where a palette's subtle is under 4.5:1 there, the palette sets body - text; page-level secondary text keeps reading --rp-subtle. */ - --rp-subtle-text: var(--rp-subtle); - /* Dividers and quiet fills (hover, empty cells, tracks) drawn on a card. A palette whose highlight low is its - surface points both at a step that shows; the contrast spec holds them to 1.1:1 on the surface. */ - --rp-line: var(--rp-hl-low); - --rp-fill: var(--rp-hl-low); - --rp-ease: cubic-bezier(0.45, 0, 0.4, 1); - --rp-ease-in: cubic-bezier(0.5, 0, 1, 1); - --rp-ease-out: cubic-bezier(0, 0, 0.4, 1); - --rp-space-1: 4px; - --rp-space-2: calc(var(--rp-space-1) * 2); - --rp-space-6: calc(var(--rp-space-1) * 6); - --rp-r-xs: 3px; - --rp-r-sm: 6px; - --rp-r-md: 8px; - --rp-r-lg: 10px; - --rp-r-xl: 16px; - --rp-r-2xl: 20px; - --rp-r-pill: 999px; - /* The type scale stays in px, like the icons set beside it. */ - --rp-text-2xs: 11px; - --rp-text-xs: 12px; - --rp-text-sm: 13px; - --rp-text-md: 14px; - --rp-text-lg: 16px; - --rp-text-xl: 18px; - --rp-text-2xl: 20px; - --rp-text-3xl: 22px; - --rp-text-4xl: 24px; - --rp-text-5xl: 28px; - /* A tile value's line: its 3xl type, and the row a stacked tile keeps for it. */ - --rp-value-line: 28px; - --rp-space-half: 2px; - --rp-space-1: 4px; - --rp-space-1h: 6px; - --rp-space-2: 8px; - --rp-space-2h: 10px; - --rp-space-3: 12px; - --rp-space-3h: 14px; - --rp-space-4: 16px; - --rp-space-5: 20px; - --rp-space-6: 24px; - --rp-space-8: 32px; - --rp-space-10: 40px; - --rp-space-12: 48px; - --rp-space-16: 64px; - --rp-font-mono: - 'Twemoji Country Flags', ui-monospace, 'SF Mono', Menlo, Consolas, 'JetBrains Mono', 'Fira Code', 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono', - monospace; - --rp-line-body: 20px; - --rp-line-caption: 16px; - --rp-focus-width: 2px; - --rp-focus-color: var(--rp-accent); - --rp-focus-offset: var(--rp-space-half); - --rp-control-inset: var(--rp-space-half); - /* Segment items fill the track's height at every size, so a selected segment is as tall as the button beside it. */ - --rp-control-block-inset: 0px; - /* Global stacking, low to high: the floating panel, then modals and tooltips (tooltips are portaled after the modal - they sit on), then toasts. */ - --rp-z-panel: 9; - --rp-z-modal: 10; - --rp-z-tooltip: 10; - --rp-z-toast: 20; - --rp-sidebar-width: 240px; - --rp-sidebar-padding: 16px; - /* The overlay scroll classes draw a scrollbar this thick. */ - --rp-scrollbar: 6px; - --rp-control: 32px; - --rp-control-lg: 40px; - /* L's inline padding; phones take M's (below), so a row of L controls fits as a row of M controls does. L's text is M's text size at every width. */ - --rp-lg-inset-btn: calc(var(--rp-control-lg) / 2); - --rp-lg-inset-field: calc(var(--rp-control-lg) * 3 / 8); - --rp-lg-inset-compact: calc(var(--rp-control-lg) * 3 / 8); - --rp-lg-text: var(--rp-text-md); - --rp-lg-text-compact: var(--rp-text-lg); - --rp-control-xs: 24px; - --rp-duration: 150ms; - --rp-duration-panel: 200ms; - --rp-duration-modal-in: 250ms; - --rp-duration-modal-out: 130ms; - --rp-duration-toast: 400ms; - --rp-duration-slow: 400ms; - --rp-duration-tab: 120ms; - --rp-delay-tab: 100ms; - --rp-delay-dialog: 160ms; - --rp-duration-hop: 360ms; - --rp-duration-pop: 240ms; - --rp-duration-view: 300ms; - --rp-duration-spin: 800ms; - /* One turn of the refresh and reload arrows, as long as one turn of S2's indeterminate ProgressCircle. */ - --rp-duration-refresh: 1000ms; - --rp-duration-hue: 3s; - --rp-selected: color-mix(in srgb, var(--rp-accent) 10%, var(--rp-overlay)); - --rp-ink-mix: #000; - /* The sign of the inline direction: a shift or turn along the line multiplies by it, so right to left mirrors it. */ - --rp-dir: 1; -} -/* An element that sets its own direction, as React Aria's popovers and toasts do, sets the sign for what it holds. */ -[dir='rtl'] { - --rp-dir: -1; -} -[dir='ltr'] { - --rp-dir: 1; -} -/* A finger needs more than a pointer does; table rows are already 40px. */ -@media (pointer: coarse) { - :root { - --rp-control: 36px; - } -} -@media (max-width: 599px) { - :root { - --rp-control: 36px; - --rp-lg-inset-btn: var(--rp-space-3); - --rp-lg-inset-field: var(--rp-space-3); - --rp-lg-inset-compact: var(--rp-space-2); - --rp-lg-text-compact: var(--rp-text-xs); - } -} -:root[data-scheme='dark'] { - color-scheme: dark; - --rp-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45); - --rp-underlay: rgba(0, 0, 0, 0.55); - --rp-elevated: 0 4px 12px rgba(0, 0, 0, 0.24), 0 2px 6px rgba(0, 0, 0, 0.12), 0 0 2px rgba(0, 0, 0, 0.36); - --rp-popover-border: var(--rp-hl-med); - --rp-ink-mix: #fff; -} .rp-bar .fill { height: 100%; border-radius: 2px; transition: width var(--rp-duration-panel) var(--rp-ease-out); } -/* Segmented control: the selection slides between items (200ms, ease-out). */ -.rp-seg { - display: inline-flex; - /* Counts in segment labels tick without the neighbouring segments shifting. */ - font-variant-numeric: tabular-nums; - gap: var(--rp-space-1); - max-width: 100%; - background: var(--rp-overlay); - border-radius: var(--rp-r-lg); - padding: var(--rp-control-block-inset) var(--rp-control-inset); - position: relative; -} -/* Always S2 size L (40px): every segmented control matches, in a page toolbar, a card or a panel alike. */ -.rp-seg[data-size='L'] { - min-block-size: var(--rp-control-lg); -} -/* Flush with the track at L, so the items and the slider take the track's radius, as a tab does. */ -.rp-seg[data-size='L'] > .rp-slider, -.rp-seg[data-size='L'] .rp-btn { - border-radius: var(--rp-r-lg); -} -.rp-seg[data-size='L'] .rp-btn { - height: var(--rp-control-lg); - padding-inline: var(--rp-lg-inset-compact); - font-size: var(--rp-lg-text); -} -/* Too narrow for its items, the track stays as a hidden placeholder and a picker sits over it at the same height. The - track hugs its items in a column or a grid too, where a flex or grid item would otherwise stretch. */ -.rp-segfit { - position: relative; - display: inline-flex; - width: fit-content; - min-width: 0; - max-width: 100%; -} -.rp-segfit > .rp-seg { - flex: 1 1 auto; - min-width: 0; -} -/* Filling its line, the segments share the width equally and each label sits at the centre of its own segment. In a - flex row it grows far ahead of what sits beside it, which so keeps about its own width; alone on a line it fills it. */ -.rp-segfit[data-fill] { - flex: 1000 1 auto; -} -.rp-segfit[data-fill] > .rp-seg .rp-btn { - flex: 1 1 0; - min-inline-size: 0; - justify-content: center; - text-align: center; -} -.rp-segfit[data-collapsed] > .rp-seg { - visibility: hidden; - overflow: hidden; -} -.rp-segpick { - position: absolute; - inset-block: 0; - inset-inline: 0 auto; - display: flex; - align-items: center; - max-width: 100%; -} -.rp-segpick > * { - min-width: 0; - max-width: 100%; -} -.rp-segpick .rp-selectbtn { - max-width: 100%; -} -.rp-slider { - position: absolute; - top: var(--rp-control-block-inset); - bottom: var(--rp-control-block-inset); - /* Physical on purpose: useSlider places it from offsetLeft, which counts from the left in either direction. */ - left: 0; - border-radius: var(--rp-r-md); - background: var(--rp-surface); - border: 2px solid var(--rp-accent); - /* Animate layout to avoid text rasterisation flicker from a composited slider beneath the labels. */ - transition: - left var(--rp-duration-panel) var(--rp-ease-out), - width var(--rp-duration-panel) var(--rp-ease-out); - pointer-events: none; -} -.rp-slider[data-still] { - transition: none; -} -.rp-seg .rp-btn { - flex: none; - padding: 0 var(--rp-space-2); - min-height: 0; - background: transparent; - color: var(--rp-text); - /* Regular labels keep small ideograph counters open at 1x rasterisation. */ - font-weight: 400; - border-radius: var(--rp-r-md); - border: 2px solid transparent; - position: relative; - z-index: 1; - /* Like a tab: the label recolours as the slider arrives. */ - transition: - color var(--rp-duration-tab) var(--rp-ease) var(--rp-delay-tab), - background-color var(--rp-duration) var(--rp-ease), - transform var(--rp-duration) var(--rp-ease); -} /* Popovers, menus, tooltips: fade and drift 4px from the trigger side. */ .rp-popover, .rp-tip { diff --git a/src/ui/styles/segmented.css b/src/ui/styles/segmented.css new file mode 100644 index 00000000..60e04328 --- /dev/null +++ b/src/ui/styles/segmented.css @@ -0,0 +1,105 @@ +/* Segmented control: the selection slides between items (200ms, ease-out). */ +.rp-seg { + display: inline-flex; + /* Counts in segment labels tick without the neighbouring segments shifting. */ + font-variant-numeric: tabular-nums; + gap: var(--rp-space-1); + max-width: 100%; + background: var(--rp-overlay); + border-radius: var(--rp-r-lg); + padding: var(--rp-control-block-inset) var(--rp-control-inset); + position: relative; +} +/* Always S2 size L (40px): every segmented control matches, in a page toolbar, a card or a panel alike. */ +.rp-seg[data-size='L'] { + min-block-size: var(--rp-control-lg); +} +/* Flush with the track at L, so the items and the slider take the track's radius, as a tab does. */ +.rp-seg[data-size='L'] > .rp-slider, +.rp-seg[data-size='L'] .rp-btn { + border-radius: var(--rp-r-lg); +} +.rp-seg[data-size='L'] .rp-btn { + height: var(--rp-control-lg); + padding-inline: var(--rp-lg-inset-compact); + font-size: var(--rp-lg-text); +} +/* Too narrow for its items, the track stays as a hidden placeholder and a picker sits over it at the same height. The + track hugs its items in a column or a grid too, where a flex or grid item would otherwise stretch. */ +.rp-segfit { + position: relative; + display: inline-flex; + width: fit-content; + min-width: 0; + max-width: 100%; +} +.rp-segfit > .rp-seg { + flex: 1 1 auto; + min-width: 0; +} +/* Filling its line, the segments share the width equally and each label sits at the centre of its own segment. In a + flex row it grows far ahead of what sits beside it, which so keeps about its own width; alone on a line it fills it. */ +.rp-segfit[data-fill] { + flex: 1000 1 auto; +} +.rp-segfit[data-fill] > .rp-seg .rp-btn { + flex: 1 1 0; + min-inline-size: 0; + justify-content: center; + text-align: center; +} +.rp-segfit[data-collapsed] > .rp-seg { + visibility: hidden; + overflow: hidden; +} +.rp-segpick { + position: absolute; + inset-block: 0; + inset-inline: 0 auto; + display: flex; + align-items: center; + max-width: 100%; +} +.rp-segpick > * { + min-width: 0; + max-width: 100%; +} +.rp-segpick .rp-selectbtn { + max-width: 100%; +} +.rp-slider { + position: absolute; + top: var(--rp-control-block-inset); + bottom: var(--rp-control-block-inset); + /* Physical on purpose: useSlider places it from offsetLeft, which counts from the left in either direction. */ + left: 0; + border-radius: var(--rp-r-md); + background: var(--rp-surface); + border: 2px solid var(--rp-accent); + /* Animate layout to avoid text rasterisation flicker from a composited slider beneath the labels. */ + transition: + left var(--rp-duration-panel) var(--rp-ease-out), + width var(--rp-duration-panel) var(--rp-ease-out); + pointer-events: none; +} +.rp-slider[data-still] { + transition: none; +} +.rp-seg .rp-btn { + flex: none; + padding: 0 var(--rp-space-2); + min-height: 0; + background: transparent; + color: var(--rp-text); + /* Regular labels keep small ideograph counters open at 1x rasterisation. */ + font-weight: 400; + border-radius: var(--rp-r-md); + border: 2px solid transparent; + position: relative; + z-index: 1; + /* Like a tab: the label recolours as the slider arrives. */ + transition: + color var(--rp-duration-tab) var(--rp-ease) var(--rp-delay-tab), + background-color var(--rp-duration) var(--rp-ease), + transform var(--rp-duration) var(--rp-ease); +} diff --git a/src/ui/theme.css b/src/ui/theme.css index 6141c7af..97c0150e 100644 --- a/src/ui/theme.css +++ b/src/ui/theme.css @@ -11,6 +11,7 @@ @import './styles/fields.css'; @import './styles/tables-forms.css'; @import './styles/motion.css'; +@import './styles/segmented.css'; @import './styles/toasts.css'; @import './styles/tags-bars.css'; @import './styles/feature-details.css';