diff --git a/README.md b/README.md
index 5f8bbd4..2da3d1f 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# form-builder-sample
-Two small apps built with [form-builder](https://whatsaaaa.github.io/form-builder/) `1.0.0-rc.0`, using only what a new user has: the documentation site and the packages on npm. The repository is the release-candidate trial for form-builder 1.0: it shows that real forms can be built from the public material, and records every problem met on the way.
+Two small apps built with [form-builder](https://whatsaaaa.github.io/form-builder/) `1.0.0-rc.0`, using only what a new user has: the documentation site and the packages on npm. The repository is the release-candidate trial for form-builder 1.0: it shows that real forms can be built from the public material, and records every problem met on the way. The apps take their look from the [Whatsaaaa design system](https://github.com/whatsaaaa/design-system), installed from npm as `@whatsaaaa/design-system` like any other package: the Vue app now, the React app once its own restyle lands.
**The record of the trial is [FRICTION-LOG.md](FRICTION-LOG.md).** Start there if you work on form-builder.
@@ -11,9 +11,9 @@ Two small apps built with [form-builder](https://whatsaaaa.github.io/form-builde
| [`vue-event-registration`](vue-event-registration) | A multi-step event registration in Vue | Steps, rows, a section and a slot, conditional fields and a conditional step, a repeating guest list, form rules, a definition loaded from a JSON file |
| [`react-checkout`](react-checkout) | A checkout in React, with a small server | A definition served by the server and validated again there, messages in English and German, a repeating list of items, conditional fields, server errors shown on the fields |
-Each app is self-contained: its own `package.json`, lockfile and tooling. Both need Node 20.19 or later and pnpm 11.
+Each app is self-contained: its own `package.json`, lockfile and tooling. Both need pnpm 11. The Vue app needs Node 22.18 or a later 22, or Node 24.12 or later, as the design system does. The React app needs Node 20.19 or later.
-Both look plain on purpose. Everything visual lives in each app's `src/ui` folder (field, layout and page components) and its one stylesheet, `src/styles.css`, so a later restyle swaps those and leaves the forms alone.
+Everything visual lives in each app's `src/ui` folder (field, layout and page components) and its one stylesheet, `src/styles.css`, so a restyle swaps those and leaves the forms alone. The Vue app is restyled on the design system: its page is the system's terminal frame, with a tab bar, a status line that switches the theme and the shortcut keys, and a dark and a light theme. The React app still looks plain until its own restyle lands.
## Run the Vue app
diff --git a/vue-event-registration/e2e/frame.spec.ts b/vue-event-registration/e2e/frame.spec.ts
new file mode 100644
index 0000000..d7ddd48
--- /dev/null
+++ b/vue-event-registration/e2e/frame.spec.ts
@@ -0,0 +1,203 @@
+import { expect, test, type Page } from '@playwright/test'
+
+/** The item of the status line that names the theme on show, and switches it. */
+function themeName(page: Page, name: 'rose-pine' | 'rose-pine-dawn') {
+ return page.getByRole('button', {
+ name: `Switch theme, now ${name}`,
+ exact: true,
+ })
+}
+
+function keysSwitch(page: Page) {
+ return page.getByRole('switch', { name: 'Shortcut keys' })
+}
+
+/**
+ * Fails when the status line cuts what it holds. It fits in the line, and its path shows whole or
+ * not at all: when it shows, "~…" fits in its text box, and the text has as much room before the
+ * keys switch as after the mode. It is gone only when "~…" and its padding have no room there.
+ */
+async function expectStatusLineWhole(page: Page) {
+ const line = await page.locator('.ws-status-line').evaluate((line) => {
+ const find = (selector: string) => {
+ const element = line.querySelector(selector)
+ if (!element) throw new Error(`The status line has no ${selector}`)
+ return element
+ }
+ const path = find('.ws-status-line__file')
+ const text = find('.ws-status-line__file > span')
+ const pathStyle = getComputedStyle(path)
+ const textStyle = getComputedStyle(text)
+ const probe = document.createElement('span')
+ probe.style.position = 'absolute'
+ probe.style.font = textStyle.font
+ probe.textContent = '~…'
+ document.body.append(probe)
+ const shortest = probe.getBoundingClientRect().width
+ probe.remove()
+ const mode = find('.ws-status-line__mode').getBoundingClientRect().right
+ const keys = find('.ws-status-line__switch').getBoundingClientRect().left
+ const box = text.getBoundingClientRect()
+ const left = box.left + parseFloat(textStyle.paddingLeft)
+ const right = box.right - parseFloat(textStyle.paddingRight)
+ return {
+ overflow: line.scrollWidth - line.clientWidth,
+ shown: path.checkVisibility(),
+ room: keys - mode,
+ needed:
+ shortest +
+ parseFloat(pathStyle.paddingLeft) +
+ parseFloat(pathStyle.paddingRight) +
+ parseFloat(textStyle.paddingLeft) +
+ parseFloat(textStyle.paddingRight),
+ text: right - left,
+ shortest,
+ before: left - mode,
+ after: keys - right,
+ }
+ })
+ expect(line.overflow, 'the status line cuts its end').toBeLessThanOrEqual(0)
+ if (line.shown) {
+ expect(line.text, 'the path shows a cut glyph').toBeGreaterThanOrEqual(
+ line.shortest,
+ )
+ expect(
+ line.after,
+ 'the path runs into the keys switch',
+ ).toBeGreaterThanOrEqual(line.before)
+ } else {
+ expect(line.room, 'the path is gone with room for "~…"').toBeLessThan(
+ line.needed,
+ )
+ }
+ return line.shown
+}
+
+/** The color of the page behind the window: it changes with the theme. */
+function pageColor(page: Page) {
+ return page.evaluate(() => getComputedStyle(document.body).backgroundColor)
+}
+
+test.beforeEach(async ({ page }) => {
+ await page.goto('/')
+})
+
+test.describe('on a light system', () => {
+ test.use({ colorScheme: 'light' })
+
+ test('switches the theme, and remembers it', async ({ page }) => {
+ const html = page.locator('html')
+
+ // Until it is switched, the theme is the system's.
+ await expect(html).not.toHaveAttribute('data-theme')
+ await expect(themeName(page, 'rose-pine-dawn')).toBeVisible()
+ await expect(themeName(page, 'rose-pine')).toBeHidden()
+ const light = await pageColor(page)
+
+ await themeName(page, 'rose-pine-dawn').click()
+ await expect(html).toHaveAttribute('data-theme', 'dark')
+ await expect(themeName(page, 'rose-pine')).toBeVisible()
+ await expect(themeName(page, 'rose-pine-dawn')).toBeHidden()
+ const dark = await pageColor(page)
+ expect(dark).not.toBe(light)
+
+ // The head script applies the choice again before the page is drawn.
+ await page.reload()
+ await expect(html).toHaveAttribute('data-theme', 'dark')
+ expect(await pageColor(page)).toBe(dark)
+
+ await themeName(page, 'rose-pine').click()
+ await expect(html).toHaveAttribute('data-theme', 'light')
+ expect(await pageColor(page)).toBe(light)
+ })
+})
+
+test('switches the shortcut keys off and on, and remembers it', async ({
+ page,
+}) => {
+ const html = page.locator('html')
+ await expect(keysSwitch(page)).toBeChecked()
+ await expect(keysSwitch(page)).toHaveText(/keys\s*on/, {
+ useInnerText: true,
+ })
+ await expect(html).toHaveAttribute('data-ws-keys', 'on')
+
+ await keysSwitch(page).click()
+ await expect(keysSwitch(page)).not.toBeChecked()
+ await expect(keysSwitch(page)).toHaveText(/keys\s*off/, {
+ useInnerText: true,
+ })
+ await expect(html).toHaveAttribute('data-ws-keys', 'off')
+
+ await page.reload()
+ await expect(keysSwitch(page)).not.toBeChecked()
+ await expect(html).toHaveAttribute('data-ws-keys', 'off')
+
+ await keysSwitch(page).click()
+ await expect(keysSwitch(page)).toBeChecked()
+ await expect(html).toHaveAttribute('data-ws-keys', 'on')
+})
+
+test.describe('on a dark system', () => {
+ test.use({ colorScheme: 'dark' })
+
+ test('switches the theme with the t key while the keys are on', async ({
+ page,
+ isMobile,
+ }) => {
+ test.skip(isMobile, 'Key hints show on a wide screen only')
+ const html = page.locator('html')
+ const hint = page.getByRole('button', { name: 'Switch theme', exact: true })
+ const mode = page.locator('.ws-status-line__mode')
+ await expect(hint.locator('kbd')).toBeVisible()
+ await expect(mode).toHaveText('NORMAL')
+
+ await page.keyboard.press('t')
+ await expect(html).toHaveAttribute('data-theme', 'light')
+ await page.keyboard.press('t')
+ await expect(html).toHaveAttribute('data-theme', 'dark')
+
+ // A key typed into a field is only a letter.
+ const firstName = page.getByRole('textbox', { name: 'First name' })
+ await firstName.press('t')
+ await expect(firstName).toHaveValue('t')
+ await expect(mode).toHaveText('INSERT')
+ await expect(html).toHaveAttribute('data-theme', 'dark')
+ await firstName.blur()
+ await expect(mode).toHaveText('NORMAL')
+
+ // With the keys off, the key rests and its cap goes, but the button still works by hand.
+ await keysSwitch(page).click()
+ await expect(hint.locator('kbd')).toBeHidden()
+ await page.keyboard.press('t')
+ await expect(html).toHaveAttribute('data-theme', 'dark')
+ await hint.click()
+ await expect(html).toHaveAttribute('data-theme', 'light')
+ })
+})
+
+for (const colorScheme of ['dark', 'light'] as const) {
+ test.describe(`in the ${colorScheme} theme`, () => {
+ test.use({ colorScheme })
+
+ // From the width the content must reflow to (WCAG 1.4.10) up, with each width of the switch.
+ test('keeps the status line whole on a narrow screen', async ({ page }) => {
+ let shown = 0
+ for (const keys of ['on', 'off']) {
+ if (keys === 'off') await keysSwitch(page).click()
+ await expect(keysSwitch(page)).toHaveText(
+ new RegExp(`keys\\s*${keys}`),
+ {
+ useInnerText: true,
+ },
+ )
+ for (let width = 320; width <= 400; width += 2) {
+ await page.setViewportSize({ width, height: 700 })
+ if (await expectStatusLineWhole(page)) shown++
+ }
+ }
+ // The path showed at some width, so the checks of a shown path ran too.
+ expect(shown).toBeGreaterThan(0)
+ })
+ })
+}
diff --git a/vue-event-registration/e2e/registration.spec.ts b/vue-event-registration/e2e/registration.spec.ts
index 853a46e..3b7dd4f 100644
--- a/vue-event-registration/e2e/registration.spec.ts
+++ b/vue-event-registration/e2e/registration.spec.ts
@@ -15,14 +15,25 @@ async function next(page: Page) {
await page.getByRole('button', { name: 'Next' }).click()
}
-/** Fails when the page scrolls sideways: something is wider than the screen. */
+/**
+ * Fails when something is wider than the screen: the page scrolls sideways, or a part of the
+ * window frame clips it or scrolls it sideways: the window, its main area, its status line, or a
+ * code block on show.
+ */
async function expectNoSidewaysScroll(page: Page) {
- const overflow = await page.evaluate(
- () =>
- document.documentElement.scrollWidth -
- document.documentElement.clientWidth,
- )
- expect(overflow).toBeLessThanOrEqual(0)
+ const boxes = [
+ page.locator('html'),
+ page.locator('.page'),
+ page.locator('.page__main'),
+ page.locator('.ws-status-line'),
+ ...(await page.locator('.ws-code, .ws-code > pre').all()),
+ ]
+ for (const box of boxes) {
+ const overflow = await box.evaluate(
+ (element) => element.scrollWidth - element.clientWidth,
+ )
+ expect(overflow, `${box} is wider than its box`).toBeLessThanOrEqual(0)
+ }
}
async function fillAboutYou(
@@ -306,3 +317,90 @@ test('moves with Enter and with the step indicator', async ({ page }) => {
await expect(currentStep(page)).toHaveText(/Invoice/)
await expect(page.getByText('Enter the company name')).toBeVisible()
})
+
+// 320 px is the width the content must reflow to (WCAG 1.4.10), and 390 px a common phone.
+for (const width of [320, 390]) {
+ for (const colorScheme of ['dark', 'light'] as const) {
+ test.describe(`on a ${width} px screen, in the ${colorScheme} theme`, () => {
+ test.use({ viewport: { width, height: 844 }, colorScheme })
+
+ test('fits the screen at every step, with its errors', async ({
+ page,
+ }) => {
+ // The page follows the system's theme, and names it in the status line.
+ const name = colorScheme === 'dark' ? 'rose-pine' : 'rose-pine-dawn'
+ await expect(
+ page.getByRole('button', {
+ name: `Switch theme, now ${name}`,
+ exact: true,
+ }),
+ ).toBeVisible()
+
+ await next(page)
+ await expect(page.getByText('Enter your first name')).toBeVisible()
+ await expectNoSidewaysScroll(page)
+ // The keys switch is a letter wider off than on, and the status line still holds it.
+ const keys = page.getByRole('switch', { name: 'Shortcut keys' })
+ await keys.click()
+ await expect(keys).toHaveText(/keys\s*off/, { useInnerText: true })
+ await expectNoSidewaysScroll(page)
+ await fillAboutYou(page, 'Business')
+ await page
+ .getByRole('textbox', { name: 'Phone' })
+ .fill('+381 61 234 5678')
+ await next(page)
+
+ await next(page)
+ await expect(page.getByText('Pick at least one session')).toBeVisible()
+ await expectNoSidewaysScroll(page)
+ await page
+ .getByRole('checkbox', { name: 'Hands-on forms workshop' })
+ .check()
+ await page.getByLabel('Workshop level').selectOption('Advanced')
+ await page
+ .getByRole('checkbox', { name: 'I have access or dietary needs' })
+ .check()
+ await page
+ .getByLabel('What do you need?')
+ .fill('Pristup bez stepenica, i čaj bez šećera za večeru.')
+ await expectNoSidewaysScroll(page)
+ await next(page)
+
+ await page.getByRole('button', { name: 'Add guest' }).click()
+ await next(page)
+ await expect(page.getByText("Enter the guest's name")).toBeVisible()
+ await expectNoSidewaysScroll(page)
+ await page
+ .getByRole('region', { name: 'Guest 1' })
+ .getByRole('textbox', { name: 'Name' })
+ .fill('Đurđa Živković')
+ await next(page)
+
+ await next(page)
+ await expect(page.getByText('Enter the company name')).toBeVisible()
+ await expectNoSidewaysScroll(page)
+ await page.getByLabel('Company name').fill('Petrović d.o.o.')
+ await page.getByLabel('Street and number').fill('Knez Mihailova 1')
+ await page.getByLabel('City').fill('Belgrade')
+ await page.getByLabel('ZIP code').fill('11000')
+ await page.getByLabel('Country').selectOption('Serbia')
+ await next(page)
+
+ await expect(currentStep(page)).toHaveText(/Confirm/)
+ await page.getByRole('button', { name: 'Register' }).click()
+ await expect(
+ page.getByText('Please accept the code of conduct'),
+ ).toBeVisible()
+ await expectNoSidewaysScroll(page)
+ await page
+ .getByRole('checkbox', { name: 'I accept the code of conduct' })
+ .check()
+ await page.getByRole('button', { name: 'Register' }).click()
+ await expect(
+ page.getByRole('heading', { name: "You're registered" }),
+ ).toBeVisible()
+ await expectNoSidewaysScroll(page)
+ })
+ })
+ }
+}
diff --git a/vue-event-registration/index.html b/vue-event-registration/index.html
index c8006d5..9833b40 100644
--- a/vue-event-registration/index.html
+++ b/vue-event-registration/index.html
@@ -2,9 +2,11 @@
+
+
diff --git a/vue-event-registration/src/ui/assets/mark-on-dark.svg b/vue-event-registration/src/ui/assets/mark-on-dark.svg
new file mode 100644
index 0000000..dd3b4ae
--- /dev/null
+++ b/vue-event-registration/src/ui/assets/mark-on-dark.svg
@@ -0,0 +1 @@
+
diff --git a/vue-event-registration/src/ui/assets/mark-on-light.svg b/vue-event-registration/src/ui/assets/mark-on-light.svg
new file mode 100644
index 0000000..fee9952
--- /dev/null
+++ b/vue-event-registration/src/ui/assets/mark-on-light.svg
@@ -0,0 +1 @@
+
diff --git a/vue-event-registration/src/ui/fields/FieldShell.vue b/vue-event-registration/src/ui/fields/FieldShell.vue
index 649198a..8ba9be6 100644
--- a/vue-event-registration/src/ui/fields/FieldShell.vue
+++ b/vue-event-registration/src/ui/fields/FieldShell.vue
@@ -2,7 +2,8 @@
import { describedBy } from './a11y'
// The frame every field shares: its label, hint and error. A set of inputs, like radios, is a
-// fieldset with a legend instead of a label.
+// fieldset with a legend instead of a label. No input has a placeholder: the hint, from the
+// definition's `description`, goes under it.
defineProps<{
id: string
label?: string
diff --git a/vue-event-registration/src/ui/fields/SelectInput.vue b/vue-event-registration/src/ui/fields/SelectInput.vue
index c94f24e..81d2897 100644
--- a/vue-event-registration/src/ui/fields/SelectInput.vue
+++ b/vue-event-registration/src/ui/fields/SelectInput.vue
@@ -25,25 +25,28 @@ const selected = computed(() =>
:errors="errors"
:required="required"
>
-
+
+
+
+
diff --git a/vue-event-registration/src/ui/fields/TextInput.vue b/vue-event-registration/src/ui/fields/TextInput.vue
index eec40b6..6ebd135 100644
--- a/vue-event-registration/src/ui/fields/TextInput.vue
+++ b/vue-event-registration/src/ui/fields/TextInput.vue
@@ -31,7 +31,6 @@ const inputTypes: Record = {
class="input"
:type="inputTypes[field.type] ?? 'text'"
:value="input ?? ''"
- :placeholder="field.placeholder"
:required="required"
:autocomplete="uiHint(field, 'autocomplete')"
:aria-invalid="errors ? 'true' : undefined"
diff --git a/vue-event-registration/src/ui/fields/TextareaInput.vue b/vue-event-registration/src/ui/fields/TextareaInput.vue
index 10bdf34..c3b7fb2 100644
--- a/vue-event-registration/src/ui/fields/TextareaInput.vue
+++ b/vue-event-registration/src/ui/fields/TextareaInput.vue
@@ -23,7 +23,6 @@ const id = useId()
class="input input--multiline"
rows="4"
:value="String(input ?? '')"
- :placeholder="field.placeholder"
:required="required"
:aria-invalid="errors ? 'true' : undefined"
:aria-describedby="describedBy(id, field.description, errors)"
diff --git a/vue-event-registration/src/ui/highlight.ts b/vue-event-registration/src/ui/highlight.ts
new file mode 100644
index 0000000..58d08a7
--- /dev/null
+++ b/vue-event-registration/src/ui/highlight.ts
@@ -0,0 +1,21 @@
+import { codeTheme } from '@whatsaaaa/design-system/shiki'
+import {
+ codeToTokensBase,
+ createShikiPrimitive,
+ type ThemedToken,
+} from 'shiki/core'
+import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'
+import json from 'shiki/langs/json.mjs'
+
+// JSON is the one language the app shows. Shiki's primitive gives tokens and leaves out its HTML
+// renderer, and the JavaScript engine needs no WebAssembly, so a block is highlighted at once.
+const shiki = createShikiPrimitive({
+ themes: [codeTheme],
+ langs: [json],
+ engine: createJavaScriptRegexEngine(),
+})
+
+/** The lines of a piece of JSON, as tokens colored by the design system's code theme. */
+export function highlightJson(code: string): ThemedToken[][] {
+ return codeToTokensBase(shiki, code, { lang: 'json', theme: codeTheme.name })
+}
diff --git a/vue-event-registration/vite.config.ts b/vue-event-registration/vite.config.ts
index 20f96d1..1c35be6 100644
--- a/vue-event-registration/vite.config.ts
+++ b/vue-event-registration/vite.config.ts
@@ -1,9 +1,31 @@
+import { keysInitScript } from '@whatsaaaa/design-system/shortcuts'
+import { themeInitScript } from '@whatsaaaa/design-system/theme'
import vue from '@vitejs/plugin-vue'
+import type { Plugin } from 'vite'
import { defineConfig } from 'vitest/config'
+/**
+ * The design system's head scripts, inline in the before the stylesheet: a remembered
+ * theme and a remembered "keys off" apply before the first paint. They come from the installed
+ * package, so they stay in step with it.
+ */
+function designSystemHead(): Plugin {
+ return {
+ name: 'design-system-head',
+ transformIndexHtml: {
+ // before Vite adds the stylesheet and the app's script at the end of the
+ order: 'pre',
+ handler: () => [
+ { tag: 'script', children: themeInitScript, injectTo: 'head' },
+ { tag: 'script', children: keysInitScript, injectTo: 'head' },
+ ],
+ },
+ }
+}
+
// https://vite.dev/config/
export default defineConfig({
- plugins: [vue()],
+ plugins: [vue(), designSystemHead()],
test: {
include: ['src/**/*.test.ts'],
},