From fcba083d7a3f2c9a0cc54619a22cc85bc460d194 Mon Sep 17 00:00:00 2001 From: Andrian Leah Date: Tue, 24 Nov 2026 08:46:43 +0100 Subject: [PATCH] Animate the interface: theme reveal, sliding toggles, sheets, chips and ring The design system gains a motion layer: - tokens: a slow duration, plus ease-in and a gentle spring; - shared transitions (ui-fade, ui-swap, ui-pop) and keyframes; - revealChange(), which opens a whole-page change as a circle from the last tap, through the View Transitions API. What now moves: - the theme: it opens from the tapped button; - segmented controls: one thumb slides, and the label's weight eases; - sheets: the scrim fades and blurs in while the panel slides up whole, and on wider screens the dialog rises and grows; - buttons: a press springs back, and Start eases into Stop; - chips: the locked outline is a cursor that slides to the next string, and checks pop in; - the ring: notes swap, a confirmed arc fades out, and the final check draws itself with a small bounce; - the screen: it rises in piece by piece; - the tuning list: it cross-fades between instruments. Reduce Motion turns all of it off. The tuning engine is unchanged. Co-Authored-By: Claude Opus 5.5 --- src/components/GuitarTuner.vue | 98 +++++++++++++++++++------------ src/components/StringChips.vue | 68 +++++++++++++++------ src/components/TunerRing.vue | 61 ++++++++++++++----- src/components/TuningSelector.vue | 63 ++++++++++---------- src/components/components.test.ts | 17 ++++++ src/composables/useTheme.ts | 16 +++-- src/ui/README.md | 75 ++++++++++++++--------- src/ui/UiButton.vue | 6 ++ src/ui/UiIcon.vue | 15 ++++- src/ui/UiSegmentedControl.vue | 56 ++++++++++++++---- src/ui/UiSheet.vue | 47 ++++++++++++--- src/ui/UiStatusPill.vue | 9 ++- src/ui/index.css | 3 +- src/ui/index.ts | 1 + src/ui/motion.test.ts | 68 +++++++++++++++++++++ src/ui/motion.ts | 55 +++++++++++++++++ src/ui/styles/materials.css | 4 +- src/ui/styles/motion.css | 81 +++++++++++++++++++++++++ src/ui/styles/tokens.css | 6 +- src/ui/ui.test.ts | 19 ++++++ 20 files changed, 610 insertions(+), 158 deletions(-) create mode 100644 src/ui/motion.test.ts create mode 100644 src/ui/motion.ts create mode 100644 src/ui/styles/motion.css diff --git a/src/components/GuitarTuner.vue b/src/components/GuitarTuner.vue index a6276e8..aaf006e 100644 --- a/src/components/GuitarTuner.vue +++ b/src/components/GuitarTuner.vue @@ -106,45 +106,50 @@ const hintPill = computed(() => (hint.value ? HINTS[hint.value] : undefined)) :complete="allTuned" /> -

{{ t('tuner.allTuned') }}

- + + +

{{ t('tuner.allTuned') }}

+
+

+ {{ t('tuner.string', { n: guitarStringNum }) }} +

+ + {{ hintPill ? t(hintPill.text) : '' }} + +
+
-
- - - - - - {{ starting ? t('tuner.starting') : isListening ? t('tuner.stop') : t('tuner.start') }} - -
+ +
+ + + + + + {{ starting ? t('tuner.starting') : isListening ? t('tuner.stop') : t('tuner.start') }} + +
+
@@ -233,6 +238,13 @@ const hintPill = computed(() => (hint.value ? HINTS[hint.value] : undefined)) gap: var(--space-3); } +.readout { + display: flex; + flex-direction: column; + align-items: center; + gap: inherit; +} + .controls { grid-area: controls; display: flex; @@ -277,6 +289,20 @@ const hintPill = computed(() => (hint.value ? HINTS[hint.value] : undefined)) text-align: center; } +/* The screen comes in piece by piece, top to bottom */ +.tuner-card > * { + animation: ui-rise var(--duration-slow) var(--ease-out) both; +} +.tuner-card > :nth-child(2) { + animation-delay: 50ms; +} +.tuner-card > :nth-child(3) { + animation-delay: 100ms; +} +.tuner-card > :nth-child(4) { + animation-delay: 150ms; +} + /* All in tune: the ring and the message take the space of the controls */ .is-complete .tuner-card { justify-content: flex-start; diff --git a/src/components/StringChips.vue b/src/components/StringChips.vue index b78c47b..d2aaf7c 100644 --- a/src/components/StringChips.vue +++ b/src/components/StringChips.vue @@ -26,11 +26,28 @@ function isLocked(di: number): boolean { const index = arrayIdx(di) return props.isListening && props.lockedStringIndex === index && !props.tunedStrings.has(index) } + +// The locked outline is one cursor that slides from string to string +const cursorIndex = computed(() => displayStrings.value.findIndex((_, di) => isLocked(di))) @@ -79,10 +98,30 @@ function isLocked(di: number): boolean { color: var(--text-primary); font-variant-numeric: tabular-nums; transition: - background var(--duration-fast), - box-shadow var(--duration-fast), - transform var(--duration-fast) var(--ease-out), - opacity var(--duration-fast); + background-color var(--duration-slow) var(--ease-out), + transform var(--duration-base) var(--ease-spring), + opacity var(--duration-base); +} +.string-chip > span { + transition: color var(--duration-base) var(--ease-out); +} + +/* The string being tuned: accent tint and outline, sliding from chip to chip. The chips share + the width equally, so its place follows from the index alone */ +.chip-cursor { + position: absolute; + top: var(--space-1); + bottom: var(--space-1); + left: var(--space-1); + width: calc((100% - (var(--count) + 1) * var(--space-1)) / var(--count)); + border-radius: var(--radius-lg); + background: var(--accent-tint); + box-shadow: inset 0 0 0 1.5px var(--accent); + transform: translateX(calc(var(--index) * (100% + var(--space-1)))); + transition: + transform var(--duration-slow) var(--ease-spring), + opacity var(--duration-base); + pointer-events: none; } .chip-num, @@ -105,11 +144,6 @@ function isLocked(di: number): boolean { right: 3px; } -/* The string being tuned: accent tint and outline */ -.string-chip.locked { - background: var(--accent-tint); - box-shadow: inset 0 0 0 1.5px var(--accent); -} .string-chip.locked .chip-num, .string-chip.locked .chip-octave { color: var(--accent); diff --git a/src/components/TunerRing.vue b/src/components/TunerRing.vue index a5a1171..2077395 100644 --- a/src/components/TunerRing.vue +++ b/src/components/TunerRing.vue @@ -36,22 +36,36 @@ const head = computed(() => { - - -
- {{ note }} - {{ octave }} -
+
+ {{ note }} + {{ octave }} +
+ @@ -106,7 +120,11 @@ const head = computed(() => { gap: 0.77cqi; color: var(--note-idle); line-height: 1; - transition: color var(--duration-fast); + /* Its own transition replaces ui-swap's, so it carries opacity and transform too */ + transition: + color var(--duration-base) var(--ease-out), + opacity var(--duration-base) var(--ease-out), + transform var(--duration-slow) var(--ease-spring); } .note-display.in-tune { color: var(--green); @@ -127,8 +145,19 @@ const head = computed(() => { } .ring-check { + --ui-icon-draw-delay: 120ms; position: relative; color: var(--green); filter: var(--glow-green); } + +/* Every string in tune: the ring gives a small happy bounce */ +.ring-wrapper.complete { + animation: ring-celebrate 700ms var(--ease-spring); +} +@keyframes ring-celebrate { + 40% { + transform: scale(1.05); + } +} diff --git a/src/components/TuningSelector.vue b/src/components/TuningSelector.vue index 031afa6..fb5c93b 100644 --- a/src/components/TuningSelector.vue +++ b/src/components/TuningSelector.vue @@ -83,37 +83,40 @@ function handleSelect(id: string) { /> -
-

- {{ t('selector.noResults') }} -

- - - - - {{ formatNote(str.note, tuning.preferFlats) }}{{ str.octave }} + +
+

+ {{ t('selector.noResults') }} +

+ + - - -
+ + + {{ formatNote(str.note, tuning.preferFlats) }}{{ str.octave }} + +
+
+ diff --git a/src/components/components.test.ts b/src/components/components.test.ts index eff85b3..af4d301 100644 --- a/src/components/components.test.ts +++ b/src/components/components.test.ts @@ -48,6 +48,23 @@ describe('StringChips', () => { expect(all.every((c) => c.find('.chip-check').exists())).toBe(true) }) + it('puts one sliding cursor on the string being tuned, none when not listening', () => { + const mountChips = (props = {}) => + mount(StringChips, { + props: { + tuning: preset('std6'), + isListening: true, + tunedStrings: new Set(), + lockedStringIndex: 1, + ...props, + }, + }) + const cursor = mountChips().findAll('.chip-cursor') + expect(cursor).toHaveLength(1) + expect(cursor[0].attributes('style')).toContain('--index: 4') // A2 is the 5th chip + expect(mountChips({ isListening: false }).find('.chip-cursor').exists()).toBe(false) + }) + it('marks the locked and the tuned strings, and selects by position in the tuning', async () => { const wrapper = mount(StringChips, { props: { diff --git a/src/composables/useTheme.ts b/src/composables/useTheme.ts index 1fa499a..de12cde 100644 --- a/src/composables/useTheme.ts +++ b/src/composables/useTheme.ts @@ -1,4 +1,5 @@ -import { computed, watch } from 'vue' +import { computed, nextTick, watch } from 'vue' +import { revealChange } from '../ui/motion' import { useSettings } from './useSettings' const { settings, setTheme: _setTheme } = useSettings() @@ -21,12 +22,17 @@ watch( export function useTheme() { const isDark = computed(() => settings.value.theme === 'dark') - function toggleTheme() { - _setTheme(settings.value.theme === 'dark' ? 'light' : 'dark') + // The new theme opens as a circle from where the user tapped + function setTheme(t: 'dark' | 'light') { + if (t === settings.value.theme) return + return revealChange(async () => { + _setTheme(t) + await nextTick() // the watch above has put data-theme on the page + }) } - function setTheme(t: 'dark' | 'light') { - _setTheme(t) + function toggleTheme() { + return setTheme(settings.value.theme === 'dark' ? 'light' : 'dark') } return { isDark, toggleTheme, setTheme } diff --git a/src/ui/README.md b/src/ui/README.md index 2e5e376..4af486b 100644 --- a/src/ui/README.md +++ b/src/ui/README.md @@ -10,25 +10,27 @@ them here first. ## Layers -| File | What it holds | -| --- | --- | -| `styles/tokens.css` | Every colour (dark and light), spacing, radius, size, font, shadow, blur and duration, as custom properties | -| `styles/base.css` | Page defaults: reset, font, the focus ring, reduced motion | -| `styles/materials.css` | The three materials as classes, and the shared interaction states | -| `index.css` | Imports the three above; `main.ts` loads it once | -| `icons.ts` | The icon set, on a 24 px grid | -| `index.ts` | Exports every component | +| File | What it holds | +| ---------------------- | ----------------------------------------------------------------------------------------------------------- | +| `styles/tokens.css` | Every colour (dark and light), spacing, radius, size, font, shadow, blur and duration, as custom properties | +| `styles/base.css` | Page defaults: reset, font, the focus ring, reduced motion | +| `styles/materials.css` | The three materials as classes, and the shared interaction states | +| `styles/motion.css` | The shared transitions (`ui-fade`, `ui-swap`, `ui-pop`) and keyframes (`ui-rise`, `ui-draw`) | +| `index.css` | Imports the styles above; `main.ts` loads it once | +| `icons.ts` | The icon set, on a 24 px grid | +| `motion.ts` | `revealChange()`: a whole-page change that opens as a circle from the last tap | +| `index.ts` | Exports every component | ## Materials Liquid Glass is used sparingly: never in the content layer, and never on top of another glass. -| Class | Use | -| --- | --- | -| `.ui-glass` | Controls on the background: the tuning pill, icon buttons, the chip track, Start/Stop | -| `.ui-glass--sheet` | Sheets and dialogs. Inside them use filled controls only | -| `.ui-material` | Content: the ring lens, the meter, the card on tablet and desktop | -| `.ui-pressable` | Hover and pressed veils, a slight swell when pressed, 40 % when disabled | +| Class | Use | +| ------------------ | ------------------------------------------------------------------------------------- | +| `.ui-glass` | Controls on the background: the tuning pill, icon buttons, the chip track, Start/Stop | +| `.ui-glass--sheet` | Sheets and dialogs. Inside them use filled controls only | +| `.ui-material` | Content: the ring lens, the meter, the card on tablet and desktop | +| `.ui-pressable` | Hover and pressed veils, a slight swell when pressed, 40 % when disabled | ## Colour @@ -43,22 +45,41 @@ Everything else is neutral. Selected segments are white or grey, not coloured. ## Components -| Component | Props | Notes | -| --- | --- | --- | -| `UiIcon` | `name`, `size`, `strokeWidth`, `label` | Decorative unless it has a `label` | -| `UiSurface` | `material` (`glass` / `sheet` / `thin`), `radius`, `as` | A container made of one material | -| `UiButton` | `variant` (`primary` / `glass`), `size` (`lg` / `xl`), `align`, `block`, `loading`, `disabled` | Slots: `leading`, default, `trailing`. With `loading` it is busy and shows a spinner | -| `UiIconButton` | `icon`, `label`, `variant` (`glass` / `fill` / `plain`) | `label` is required: the button has no text | -| `UiSegmentedControl` | `options`, `label`, `size` (`sm` / `md` / `lg`), `v-model` | A radio group: arrow keys move the choice | -| `UiSearchField` | `label`, `clearLabel`, `placeholder`, `size`, `autofocus`, `v-model` | Clear button while there is text | -| `UiListRow` | `title`, `selected` | Slots: `meta`, default (second line), `action` (kept outside the row's button) | -| `UiStatusPill` | `tone` (`success` / `warning` / `neutral`), `icon`, `hidden` | Tokens: `--status-pill-height`, `--status-pill-font-size` | -| `UiSection` | `label` | A labelled group inside a sheet | -| `UiSheet` | `title`, `closeLabel`, `size` (`md` / `lg`) | Slots: default (scrolls), `toolbar`, `subheader`. A bottom sheet on a phone, a dialog on wider screens. Closes with Escape or a tap outside, and keeps focus inside. Animate with `` | +| Component | Props | Notes | +| -------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `UiIcon` | `name`, `size`, `strokeWidth`, `label`, `draw` | Decorative unless it has a `label`. With `draw` its strokes draw themselves in | +| `UiSurface` | `material` (`glass` / `sheet` / `thin`), `radius`, `as` | A container made of one material | +| `UiButton` | `variant` (`primary` / `glass`), `size` (`lg` / `xl`), `align`, `block`, `loading`, `disabled` | Slots: `leading`, default, `trailing`. With `loading` it is busy and shows a spinner | +| `UiIconButton` | `icon`, `label`, `variant` (`glass` / `fill` / `plain`) | `label` is required: the button has no text | +| `UiSegmentedControl` | `options`, `label`, `size` (`sm` / `md` / `lg`), `v-model` | A radio group: arrow keys move the choice | +| `UiSearchField` | `label`, `clearLabel`, `placeholder`, `size`, `autofocus`, `v-model` | Clear button while there is text | +| `UiListRow` | `title`, `selected` | Slots: `meta`, default (second line), `action` (kept outside the row's button) | +| `UiStatusPill` | `tone` (`success` / `warning` / `neutral`), `icon`, `hidden` | Tokens: `--status-pill-height`, `--status-pill-font-size` | +| `UiSection` | `label` | A labelled group inside a sheet | +| `UiSheet` | `title`, `closeLabel`, `size` (`md` / `lg`) | Slots: default (scrolls), `toolbar`, `subheader`. A bottom sheet on a phone, a dialog on wider screens. Closes with Escape or a tap outside, and keeps focus inside. Animate with `` | + +## Motion + +Things arrive with `--ease-out` or a gentle `--ease-spring` and leave faster with `--ease-in`. +Durations are `--duration-fast` (150 ms), `--duration-base` (250 ms) and `--duration-slow` (420 ms). + +| What moves | How | +| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | +| Theme | The new theme opens as a circle from the tapped button (`revealChange`, View Transitions API). Browsers without the API switch at once | +| Segmented control | One thumb slides under the chosen option; the label's weight eases (Nunito is variable) | +| Sheet | The scrim darkens and blurs in while the panel slides up whole. On wider screens the dialog rises and grows a little | +| Buttons | Press: a slight swell that springs back. Start turning into Stop eases between the two colours | +| String chips | The locked outline is one cursor that slides to the next string; a tuned string's check pops in | +| Ring | The note is replaced by the next one (`ui-swap`). A confirmed string's arc fades out. At the end the check draws itself and the ring bounces | +| Screen | The pieces rise into place one after another when the app opens | + +Use the shared transitions with Vue: ``, ``, ``. An element that declares its own `transition` replaces theirs, so it must list `opacity` and `transform` too. + +**Reduce Motion** turns every animation off, the theme reveal included. ## Accessibility - Every control is at least 44 pt. - Keyboard focus shows a 3 pt accent ring. - A state is never shown by colour alone: tuned chips carry a check, hints carry an arrow and a word. -- *Reduce Transparency* makes the materials solid. *Increase Contrast* strengthens their edges. *Reduce Motion* removes the animations. +- _Reduce Transparency_ makes the materials solid. _Increase Contrast_ strengthens their edges. _Reduce Motion_ removes the animations. diff --git a/src/ui/UiButton.vue b/src/ui/UiButton.vue index d67bbd7..1b28a9c 100644 --- a/src/ui/UiButton.vue +++ b/src/ui/UiButton.vue @@ -54,6 +54,12 @@ withDefaults( font-size: var(--font-size-headline); font-weight: var(--font-weight-semibold); white-space: nowrap; + /* Start turning into Stop eases from accent to glass */ + transition: + background-color var(--duration-base) var(--ease-out), + color var(--duration-base) var(--ease-out), + transform var(--duration-base) var(--ease-spring), + opacity var(--duration-fast); } .ui-button--lg { diff --git a/src/ui/UiIcon.vue b/src/ui/UiIcon.vue index 6672101..ea807c1 100644 --- a/src/ui/UiIcon.vue +++ b/src/ui/UiIcon.vue @@ -11,6 +11,8 @@ const props = withDefaults( strokeWidth?: number /** Accessible name; without it the icon is decorative and hidden from screen readers */ label?: string + /** Draw the strokes in when the icon appears (a check that writes itself) */ + draw?: boolean }>(), { size: 24, strokeWidth: undefined, label: undefined }, ) @@ -34,7 +36,13 @@ const icon = computed(() => ICONS[props.name]) :aria-hidden="label ? undefined : 'true'" focusable="false" > - + @@ -43,4 +51,9 @@ const icon = computed(() => ICONS[props.name]) flex: none; display: block; } + +.ui-icon__draw { + stroke-dasharray: 1; + animation: ui-draw var(--duration-slow) var(--ease-out) var(--ui-icon-draw-delay, 0ms) both; +} diff --git a/src/ui/UiSegmentedControl.vue b/src/ui/UiSegmentedControl.vue index 09636be..33b7c1c 100644 --- a/src/ui/UiSegmentedControl.vue +++ b/src/ui/UiSegmentedControl.vue @@ -1,5 +1,5 @@