@aleph-alpha/ui-library 6.2.1 → 6.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/system/components/UiButtonGroup/index.d.ts +1 -0
  2. package/dist/system/components/UiDialog/types.d.ts +3 -2
  3. package/dist/system/components/UiInputGroup/UiInputGroup.vue.d.ts +20 -0
  4. package/dist/system/components/UiInputGroup/UiInputGroupAddon.vue.d.ts +20 -0
  5. package/dist/system/components/UiInputGroup/UiInputGroupButton.vue.d.ts +17 -0
  6. package/dist/system/components/UiInputGroup/UiInputGroupInput.vue.d.ts +11 -0
  7. package/dist/system/components/UiInputGroup/UiInputGroupTextarea.vue.d.ts +11 -0
  8. package/dist/system/components/UiInputGroup/index.d.ts +7 -0
  9. package/dist/system/components/UiInputGroup/types.d.ts +151 -0
  10. package/dist/system/components/UiLabel/UiLabel.vue.d.ts +3 -1
  11. package/dist/system/components/UiLabel/types.d.ts +7 -0
  12. package/dist/system/components/core/input-group/InputGroup.vue.d.ts +25 -0
  13. package/dist/system/components/core/input-group/InputGroupAddon.vue.d.ts +25 -0
  14. package/dist/system/components/core/input-group/InputGroupButton.vue.d.ts +28 -0
  15. package/dist/system/components/core/input-group/InputGroupInput.vue.d.ts +12 -0
  16. package/dist/system/components/core/input-group/InputGroupText.vue.d.ts +21 -0
  17. package/dist/system/components/core/input-group/InputGroupTextarea.vue.d.ts +12 -0
  18. package/dist/system/components/core/input-group/index.d.ts +18 -0
  19. package/dist/system/components/index.d.ts +1 -0
  20. package/dist/system/lib.js +14622 -14279
  21. package/package.json +2 -2
  22. package/src/components/UiButtonGroup/index.ts +4 -0
  23. package/src/components/UiDialog/UiDialog.stories.ts +151 -54
  24. package/src/components/UiDialog/UiDialogContent.vue +23 -32
  25. package/src/components/UiDialog/types.ts +3 -2
  26. package/src/components/UiField/UiField.stories.ts +329 -52
  27. package/src/components/UiField/UiFieldLabelInfo.vue +1 -1
  28. package/src/components/UiInput/UiInput.stories.ts +3 -1
  29. package/src/components/UiInput/UiInput.vue +26 -5
  30. package/src/components/UiInputGroup/UiInputGroup.stories.ts +2083 -0
  31. package/src/components/UiInputGroup/UiInputGroup.vue +18 -0
  32. package/src/components/UiInputGroup/UiInputGroupAddon.vue +18 -0
  33. package/src/components/UiInputGroup/UiInputGroupButton.vue +30 -0
  34. package/src/components/UiInputGroup/UiInputGroupInput.vue +16 -0
  35. package/src/components/UiInputGroup/UiInputGroupTextarea.vue +16 -0
  36. package/src/components/UiInputGroup/__tests__/UiInputGroup.test.ts +195 -0
  37. package/src/components/UiInputGroup/index.ts +10 -0
  38. package/src/components/UiInputGroup/types.ts +171 -0
  39. package/src/components/UiLabel/UiLabel.vue +7 -2
  40. package/src/components/UiLabel/types.ts +8 -0
  41. package/src/components/core/button/index.ts +23 -13
  42. package/src/components/core/button-group/ButtonGroupText.vue +4 -0
  43. package/src/components/core/button-group/index.ts +6 -2
  44. package/src/components/core/field/FieldError.vue +1 -1
  45. package/src/components/core/field/FieldLabel.vue +1 -1
  46. package/src/components/core/field/index.ts +7 -1
  47. package/src/components/core/input/Input.vue +4 -1
  48. package/src/components/core/input-group/InputGroup.vue +27 -0
  49. package/src/components/core/input-group/InputGroupAddon.vue +53 -0
  50. package/src/components/core/input-group/InputGroupButton.vue +35 -0
  51. package/src/components/core/input-group/InputGroupInput.vue +65 -0
  52. package/src/components/core/input-group/InputGroupText.vue +26 -0
  53. package/src/components/core/input-group/InputGroupTextarea.vue +62 -0
  54. package/src/components/core/input-group/index.ts +103 -0
  55. package/src/components/core/label/Label.vue +1 -1
  56. package/src/components/index.ts +1 -0
  57. package/src/theme/Typography.stories.ts +144 -6
  58. package/src/theme/__tests__/typography.test.ts +136 -0
@@ -0,0 +1,27 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue';
3
+ import type { InputGroupType } from '.';
4
+ import { cn } from '@/lib/utils';
5
+ import { inputGroupVariants } from '.';
6
+
7
+ const props = withDefaults(
8
+ defineProps<{
9
+ type?: InputGroupType;
10
+ class?: HTMLAttributes['class'];
11
+ }>(),
12
+ {
13
+ type: 'input',
14
+ },
15
+ );
16
+ </script>
17
+
18
+ <template>
19
+ <div
20
+ data-slot="input-group"
21
+ role="group"
22
+ :data-type="props.type"
23
+ :class="cn(inputGroupVariants(), props.class)"
24
+ >
25
+ <slot />
26
+ </div>
27
+ </template>
@@ -0,0 +1,53 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue';
3
+ import type { InputGroupAddonVariants } from '.';
4
+ import { cn } from '@/lib/utils';
5
+ import { inputGroupAddonVariants } from '.';
6
+
7
+ const props = withDefaults(
8
+ defineProps<{
9
+ align?: InputGroupAddonVariants['align'];
10
+ class?: HTMLAttributes['class'];
11
+ }>(),
12
+ {
13
+ align: 'inline-start',
14
+ },
15
+ );
16
+
17
+ /**
18
+ * Clicking the addon (icon, prefix text, …) moves focus into the group's
19
+ * control, so the whole boundary behaves like one field. Clicks on
20
+ * interactive children (buttons) are left alone.
21
+ * @param e The mouse event from the addon container.
22
+ */
23
+ function handleInputGroupAddonClick(e: MouseEvent) {
24
+ const currentTarget = e.currentTarget as HTMLElement | null;
25
+ const target = e.target as HTMLElement | null;
26
+ if (target && target.closest('button')) {
27
+ return;
28
+ }
29
+ currentTarget?.parentElement
30
+ ?.querySelector<HTMLElement>('input, textarea')
31
+ ?.focus();
32
+ }
33
+ </script>
34
+
35
+ <template>
36
+ <!--
37
+ eslint-disable vuejs-accessibility/click-events-have-key-events,
38
+ vuejs-accessibility/no-static-element-interactions --
39
+ the click handler is a pointer-only convenience that forwards focus to the
40
+ group's control (mirroring how a native field reacts to clicks on its own
41
+ padding). Keyboard and assistive-tech users reach the control directly via
42
+ Tab, so the addon itself must NOT be focusable or interactive.
43
+ -->
44
+ <div
45
+ role="group"
46
+ data-slot="input-group-addon"
47
+ :data-align="props.align"
48
+ :class="cn(inputGroupAddonVariants({ align: props.align }), props.class)"
49
+ @click="handleInputGroupAddonClick"
50
+ >
51
+ <slot />
52
+ </div>
53
+ </template>
@@ -0,0 +1,35 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue';
3
+ import type { ButtonVariants } from '@/components/core/button';
4
+ import type { InputGroupButtonVariants } from '.';
5
+ import { Button } from '@/components/core/button';
6
+ import { cn } from '@/lib/utils';
7
+ import { inputGroupButtonVariants } from '.';
8
+
9
+ const props = withDefaults(
10
+ defineProps<{
11
+ variant?: ButtonVariants['variant'];
12
+ size?: InputGroupButtonVariants['size'];
13
+ class?: HTMLAttributes['class'];
14
+ }>(),
15
+ {
16
+ variant: 'ghost',
17
+ size: 'xs',
18
+ },
19
+ );
20
+ </script>
21
+
22
+ <template>
23
+ <!--
24
+ The geometry (height, padding, radius) comes from inputGroupButtonVariants;
25
+ the base "sm" button size supplies the compact typography.
26
+ -->
27
+ <Button
28
+ :data-size="props.size"
29
+ :variant="props.variant"
30
+ size="sm"
31
+ :class="cn(inputGroupButtonVariants({ size: props.size }), props.class)"
32
+ >
33
+ <slot />
34
+ </Button>
35
+ </template>
@@ -0,0 +1,65 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue';
3
+ import { computed, useAttrs } from 'vue';
4
+ import { useVModel } from '@vueuse/core';
5
+ import { cn } from '@/lib/utils';
6
+
7
+ const props = defineProps<{
8
+ defaultValue?: string | number;
9
+ modelValue?: string | number;
10
+ class?: HTMLAttributes['class'];
11
+ }>();
12
+
13
+ const emits = defineEmits<{
14
+ (e: 'update:modelValue', payload: string | number): void;
15
+ }>();
16
+
17
+ const modelValue = useVModel(props, 'modelValue', emits, {
18
+ passive: true,
19
+ defaultValue: props.defaultValue,
20
+ });
21
+
22
+ // Fallthrough attributes would override the normalized aria-invalid binding
23
+ // below, so they are spread manually instead.
24
+ defineOptions({ inheritAttrs: false });
25
+
26
+ const attrs = useAttrs();
27
+
28
+ // Normalize the common Vue spellings of aria-invalid — a bare attribute
29
+ // renders "" and a boolean binding renders true — to the canonical "true"
30
+ // token, so both the group's CSS error ring and assistive technology
31
+ // recognize the state. Other valid tokens ("grammar", "spelling") pass
32
+ // through unchanged.
33
+ const ariaInvalid = computed(() => {
34
+ const value = attrs['aria-invalid'];
35
+ if (value === '' || value === true || value === 'true') return 'true';
36
+ // Matches the DOM typing of aria-invalid (Booleanish | token).
37
+ return value as 'false' | 'grammar' | 'spelling' | undefined;
38
+ });
39
+
40
+ const forwardedAttrs = computed(() => {
41
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- rest-destructuring to drop aria-invalid
42
+ const { 'aria-invalid': _ariaInvalid, ...rest } = attrs;
43
+ return rest;
44
+ });
45
+ </script>
46
+
47
+ <template>
48
+ <!--
49
+ Border, background, focus ring and error ring live on the InputGroup
50
+ container; the control itself stays transparent so the group reads as
51
+ a single field.
52
+ -->
53
+ <input
54
+ v-bind="forwardedAttrs"
55
+ v-model="modelValue"
56
+ data-slot="input-group-control"
57
+ :aria-invalid="ariaInvalid"
58
+ :class="
59
+ cn(
60
+ 'placeholder:text-content-on-surface-muted selection:bg-primary selection:text-primary-foreground w-full min-w-0 flex-1 rounded-none border-0 bg-transparent px-3 py-2.5 body-s-regular outline-none transition-[color] disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',
61
+ props.class,
62
+ )
63
+ "
64
+ />
65
+ </template>
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue';
3
+ import { cn } from '@/lib/utils';
4
+
5
+ defineOptions({
6
+ name: 'UiInputGroupText',
7
+ });
8
+
9
+ const props = defineProps<{
10
+ class?: HTMLAttributes['class'];
11
+ }>();
12
+ </script>
13
+
14
+ <template>
15
+ <span
16
+ data-slot="input-group-text"
17
+ :class="
18
+ cn(
19
+ `text-content-on-surface-muted group-data-[invalid=true]/field:text-border-input-error flex items-center gap-2 label-14-regular [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4`,
20
+ props.class,
21
+ )
22
+ "
23
+ >
24
+ <slot />
25
+ </span>
26
+ </template>
@@ -0,0 +1,62 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes } from 'vue';
3
+ import { computed, useAttrs } from 'vue';
4
+ import { useVModel } from '@vueuse/core';
5
+ import { cn } from '@/lib/utils';
6
+
7
+ const props = defineProps<{
8
+ defaultValue?: string | number;
9
+ modelValue?: string | number;
10
+ class?: HTMLAttributes['class'];
11
+ }>();
12
+
13
+ const emits = defineEmits<{
14
+ (e: 'update:modelValue', payload: string | number): void;
15
+ }>();
16
+
17
+ const modelValue = useVModel(props, 'modelValue', emits, {
18
+ passive: true,
19
+ defaultValue: props.defaultValue,
20
+ });
21
+
22
+ // Fallthrough attributes would override the normalized aria-invalid binding
23
+ // below, so they are spread manually instead.
24
+ defineOptions({ inheritAttrs: false });
25
+
26
+ const attrs = useAttrs();
27
+
28
+ // Same aria-invalid normalization as InputGroupInput: bare attributes ("")
29
+ // and boolean bindings become the canonical "true" token.
30
+ const ariaInvalid = computed(() => {
31
+ const value = attrs['aria-invalid'];
32
+ if (value === '' || value === true || value === 'true') return 'true';
33
+ // Matches the DOM typing of aria-invalid (Booleanish | token).
34
+ return value as 'false' | 'grammar' | 'spelling' | undefined;
35
+ });
36
+
37
+ const forwardedAttrs = computed(() => {
38
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- rest-destructuring to drop aria-invalid
39
+ const { 'aria-invalid': _ariaInvalid, ...rest } = attrs;
40
+ return rest;
41
+ });
42
+ </script>
43
+
44
+ <template>
45
+ <!--
46
+ Border, background, focus ring and error ring live on the InputGroup
47
+ container; the control itself stays transparent so the group reads as
48
+ a single field.
49
+ -->
50
+ <textarea
51
+ v-bind="forwardedAttrs"
52
+ v-model="modelValue"
53
+ data-slot="input-group-control"
54
+ :aria-invalid="ariaInvalid"
55
+ :class="
56
+ cn(
57
+ 'placeholder:text-content-on-surface-muted flex field-sizing-content min-h-16 w-full flex-1 resize-none rounded-none border-0 bg-transparent px-3 py-2.5 body-s-regular outline-none transition-[color] disabled:cursor-not-allowed disabled:opacity-50',
58
+ props.class,
59
+ )
60
+ "
61
+ />
62
+ </template>
@@ -0,0 +1,103 @@
1
+ import type { VariantProps } from 'class-variance-authority';
2
+ import { cva } from 'class-variance-authority';
3
+
4
+ export { default as InputGroup } from './InputGroup.vue';
5
+ export { default as InputGroupAddon } from './InputGroupAddon.vue';
6
+ export { default as InputGroupButton } from './InputGroupButton.vue';
7
+ export { default as InputGroupInput } from './InputGroupInput.vue';
8
+ export { default as InputGroupText } from './InputGroupText.vue';
9
+ export { default as InputGroupTextarea } from './InputGroupTextarea.vue';
10
+
11
+ // The group carries no fixed height: it grows from the control's line-height
12
+ // and padding (20px + 2×10px = 40px by default), plus any block addons. The
13
+ // 1px boundary is painted as an inset outline instead of a border — an
14
+ // outline takes no layout space (the Figma "inside stroke" behavior, same
15
+ // trick as the shared `ui-focus-ring-outline` companion), so it does not push
16
+ // the field to 42px.
17
+ export const inputGroupVariants = cva(
18
+ [
19
+ 'group/input-group relative flex w-full items-center rounded-md bg-background-input-default outline outline-1 -outline-offset-1 outline-input transition-[color,box-shadow,outline-color]',
20
+ 'min-w-0 shadow-xs',
21
+ // Re-align the control padding when an inline addon sits next to it.
22
+ 'has-[>[data-align=inline-start]]:[&>input]:pl-2',
23
+ 'has-[>[data-align=inline-end]]:[&>input]:pr-2',
24
+ // Block addons stack the group vertically.
25
+ 'has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3',
26
+ 'has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3',
27
+ // Focus ring when the inner control is focused. Reproduces the shared
28
+ // "ui-focus-ring" treatment, but driven by the control inside the group
29
+ // (a plain :focus-within would also ring for focused addon buttons).
30
+ 'has-[[data-slot=input-group-control]:focus-visible]:outline-border-surface-focus-ring has-[[data-slot=input-group-control]:focus-visible]:ring-2 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50',
31
+ // Error state, surfaced from an invalid control inside the group. The
32
+ // selector matches the canonical `aria-invalid="true"`; the built-in
33
+ // controls normalize the other common Vue spellings (bare attribute,
34
+ // boolean binding) to that token. Raw custom controls must render
35
+ // `aria-invalid="true"` themselves.
36
+ 'has-[[data-slot=input-group-control][aria-invalid=true]]:outline-border-input-error has-[[data-slot=input-group-control][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot=input-group-control][aria-invalid=true]]:ring-destructive/40',
37
+ // Cascaded error state from a `data-invalid` UiField: the boundary and the
38
+ // inherited text (typed value, plain slot content) turn error-colored;
39
+ // placeholders keep their own muted color.
40
+ 'group-data-[invalid=true]/field:outline-border-input-error group-data-[invalid=true]/field:text-border-input-error',
41
+ // Disabled state, set via data-disabled="true" on the group.
42
+ 'data-[disabled=true]:pointer-events-none data-[disabled=true]:cursor-not-allowed',
43
+ ].join(' '),
44
+ );
45
+
46
+ /** The kind of control hosted by an InputGroup, exposed as `data-type`. */
47
+ export type InputGroupType = 'input' | 'textarea';
48
+
49
+ export const inputGroupAddonVariants = cva(
50
+ [
51
+ 'text-content-on-surface-muted flex h-auto cursor-text items-center justify-center gap-2 py-1.5 label-14-medium select-none',
52
+ "[&>svg:not([class*='size-'])]:size-4 [&>kbd]:rounded-sm",
53
+ 'group-data-[disabled=true]/input-group:opacity-50',
54
+ // Cascaded error state from a `data-invalid` UiField.
55
+ 'group-data-[invalid=true]/field:text-border-input-error',
56
+ ].join(' '),
57
+ {
58
+ variants: {
59
+ align: {
60
+ 'inline-start':
61
+ 'order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]',
62
+ 'inline-end':
63
+ 'order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]',
64
+ 'block-start':
65
+ 'order-first w-full justify-start px-3 pt-3 [.border-b]:pb-3 group-has-[>input]/input-group:pt-2.5',
66
+ 'block-end':
67
+ 'order-last w-full justify-start px-3 pb-3 [.border-t]:pt-3 group-has-[>input]/input-group:pb-2.5',
68
+ },
69
+ },
70
+ defaultVariants: {
71
+ align: 'inline-start',
72
+ },
73
+ },
74
+ );
75
+
76
+ export type InputGroupAddonVariants = VariantProps<
77
+ typeof inputGroupAddonVariants
78
+ >;
79
+
80
+ export const inputGroupButtonVariants = cva(
81
+ // Buttons inside an invalid UiField adopt the cascaded error color.
82
+ 'flex items-center shadow-none group-data-[invalid=true]/field:text-border-input-error',
83
+ {
84
+ variants: {
85
+ // Icon sizing is expressed as `[&_svg]:size-*` (same arbitrary variant
86
+ // the core button sizes use) so tailwind-merge replaces the base "sm"
87
+ // size's `[&_svg]:size-3` instead of competing with it in the cascade.
88
+ size: {
89
+ xs: 'h-6 gap-1 rounded-sm px-2 has-[>svg]:px-2 [&_svg]:size-3.5',
90
+ sm: 'h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5 [&_svg]:size-4',
91
+ 'icon-xs': 'size-6 rounded-sm p-0 has-[>svg]:p-0 [&_svg]:size-4',
92
+ 'icon-sm': 'size-8 rounded-md p-0 has-[>svg]:p-0 [&_svg]:size-4',
93
+ },
94
+ },
95
+ defaultVariants: {
96
+ size: 'xs',
97
+ },
98
+ },
99
+ );
100
+
101
+ export type InputGroupButtonVariants = VariantProps<
102
+ typeof inputGroupButtonVariants
103
+ >;
@@ -18,7 +18,7 @@ const delegatedProps = reactiveOmit(props, 'class', 'for');
18
18
  :for="props.for"
19
19
  :class="
20
20
  cn(
21
- 'flex items-center gap-2 label-14-medium leading-none select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50',
21
+ 'flex items-center gap-2 label-14-medium leading-none select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 group-data-[invalid=true]/field:text-border-input-error peer-disabled:cursor-not-allowed peer-disabled:opacity-50',
22
22
  props.class,
23
23
  )
24
24
  "
@@ -27,6 +27,7 @@ export * from './UiFileType';
27
27
  export * from './UiFileUploadBox';
28
28
  export * from './UiIcon';
29
29
  export * from './UiInput';
30
+ export * from './UiInputGroup';
30
31
  export * from './UiItem';
31
32
  export * from './UiKbd';
32
33
  export * from './UiLabel';
@@ -1,4 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { expect } from 'storybook/test';
2
3
  import { defineComponent, h } from 'vue';
3
4
 
4
5
  const ThemePlaceholder = defineComponent({
@@ -45,6 +46,81 @@ const copyChrome = `
45
46
  /** Weights every body and label step provides. */
46
47
  const WEIGHTS = ['regular', 'medium', 'bold'] as const;
47
48
 
49
+ // The `font-weight` value each weight suffix must compute to. Asserted by the
50
+ // story plays for every rendered `{family}-{step}-{weight}` sample.
51
+ const WEIGHT_VALUES: Record<(typeof WEIGHTS)[number], string> = {
52
+ regular: '400',
53
+ medium: '500',
54
+ bold: '700',
55
+ };
56
+
57
+ /**
58
+ * Computed style of the sample rendered with the given utility class.
59
+ * @param root Story canvas element.
60
+ * @param className Utility class whose sample to read.
61
+ * @returns The sample's computed style.
62
+ */
63
+ const sampleStyle = (root: HTMLElement, className: string) => {
64
+ const el = root.querySelector<HTMLElement>(
65
+ `[data-type-sample="${className}"]`,
66
+ );
67
+ if (!el) throw new Error(`No rendered sample for "${className}"`);
68
+ return getComputedStyle(el);
69
+ };
70
+
71
+ // `Body 16 / medium` is the one token that deviates from the 500 the `medium`
72
+ // suffix means everywhere else: it resolves to 600 in tokens.json. Documented
73
+ // here as the current token truth — if design confirms it should be 500, fix
74
+ // the token and delete this override.
75
+ const TOKEN_WEIGHT_OVERRIDES: Record<string, string> = {
76
+ 'body-m-medium': '600',
77
+ 'body-16-medium': '600',
78
+ };
79
+
80
+ /**
81
+ * Asserts every weight of a step computes the promised font-weight and the
82
+ * step's font-size.
83
+ * @param root Story canvas element.
84
+ * @param prefix Step prefix without the weight, e.g. `label-xs`.
85
+ * @param fontSize The step's expected computed font-size.
86
+ */
87
+ const expectStepWeights = async (
88
+ root: HTMLElement,
89
+ prefix: string,
90
+ fontSize: string,
91
+ ) => {
92
+ for (const weight of WEIGHTS) {
93
+ const className = `${prefix}-${weight}`;
94
+ const style = sampleStyle(root, className);
95
+ await expect(style.fontWeight).toBe(
96
+ TOKEN_WEIGHT_OVERRIDES[className] ?? WEIGHT_VALUES[weight],
97
+ );
98
+ await expect(style.fontSize).toBe(fontSize);
99
+ }
100
+ };
101
+
102
+ /**
103
+ * Asserts a deprecated numbered class computes identically to the step name
104
+ * replacing it, for every weight.
105
+ * @param root Story canvas element.
106
+ * @param from Deprecated prefix, e.g. `label-12`.
107
+ * @param to Replacement prefix, e.g. `label-xs`.
108
+ */
109
+ const expectDeprecatedAlias = async (
110
+ root: HTMLElement,
111
+ from: string,
112
+ to: string,
113
+ ) => {
114
+ for (const weight of WEIGHTS) {
115
+ const deprecated = sampleStyle(root, `${from}-${weight}`);
116
+ const replacement = sampleStyle(root, `${to}-${weight}`);
117
+ await expect(deprecated.fontWeight).toBe(replacement.fontWeight);
118
+ await expect(deprecated.fontSize).toBe(replacement.fontSize);
119
+ await expect(deprecated.lineHeight).toBe(replacement.lineHeight);
120
+ await expect(deprecated.fontFamily).toBe(replacement.fontFamily);
121
+ }
122
+ };
123
+
48
124
  type SampleTag = 'span' | 'p';
49
125
 
50
126
  /**
@@ -56,7 +132,7 @@ type SampleTag = 'span' | 'p';
56
132
  const row = (className: string, tag: SampleTag = 'span') => `
57
133
  <div class="flex flex-wrap items-baseline gap-4 border-b border-border-surface-default pb-4">
58
134
  <code class="copy-btn label-xs-medium text-content-on-surface-muted w-44 shrink-0" onclick="copyToClipboard('${className}', this)">${className}</code>
59
- <${tag} class="${className} text-content-on-surface-primary${tag === 'p' ? ' max-w-prose' : ''}">${sample}</${tag}>
135
+ <${tag} class="${className} text-content-on-surface-primary${tag === 'p' ? ' max-w-prose' : ''}" data-type-sample="${className}">${sample}</${tag}>
60
136
  </div>`;
61
137
 
62
138
  /**
@@ -135,6 +211,27 @@ ${deprecatedSection([
135
211
  </div>
136
212
  `,
137
213
  }),
214
+ play: async ({ canvasElement, step }) => {
215
+ // Scenario (typography scale): every label step ships all three weights,
216
+ // and the deprecated numbered classes stay identical to their step names.
217
+ await step(
218
+ 'interaction: every label step renders regular/medium/bold at its step size',
219
+ async () => {
220
+ await expectStepWeights(canvasElement, 'label-xs', '12px');
221
+ await expectStepWeights(canvasElement, 'label-s', '14px');
222
+ await expectStepWeights(canvasElement, 'label-m', '16px');
223
+ },
224
+ );
225
+
226
+ await step(
227
+ 'interaction: deprecated numbered label classes compute identically to their step names',
228
+ async () => {
229
+ await expectDeprecatedAlias(canvasElement, 'label-12', 'label-xs');
230
+ await expectDeprecatedAlias(canvasElement, 'label-14', 'label-s');
231
+ await expectDeprecatedAlias(canvasElement, 'label-16', 'label-m');
232
+ },
233
+ );
234
+ },
138
235
  };
139
236
 
140
237
  /**
@@ -166,6 +263,25 @@ ${deprecatedSection(
166
263
  </div>
167
264
  `,
168
265
  }),
266
+ play: async ({ canvasElement, step }) => {
267
+ // Scenario (typography scale): every body step ships all three weights,
268
+ // and the deprecated numbered classes stay identical to their step names.
269
+ await step(
270
+ 'interaction: every body step renders regular/medium/bold at its step size',
271
+ async () => {
272
+ await expectStepWeights(canvasElement, 'body-s', '14px');
273
+ await expectStepWeights(canvasElement, 'body-m', '16px');
274
+ },
275
+ );
276
+
277
+ await step(
278
+ 'interaction: deprecated numbered body classes compute identically to their step names',
279
+ async () => {
280
+ await expectDeprecatedAlias(canvasElement, 'body-14', 'body-s');
281
+ await expectDeprecatedAlias(canvasElement, 'body-16', 'body-m');
282
+ },
283
+ );
284
+ },
169
285
  };
170
286
 
171
287
  /**
@@ -193,40 +309,62 @@ export const Headings: Story = {
193
309
  <code class="copy-btn block label-xs-medium text-content-on-surface-muted" onclick="copyToClipboard('heading-s', this)">heading-s</code>
194
310
  <span class="label-xs-regular text-content-on-surface-muted">Heading S</span>
195
311
  </div>
196
- <span class="heading-s text-content-on-surface-primary min-w-0 flex-1">${sample}</span>
312
+ <span class="heading-s text-content-on-surface-primary min-w-0 flex-1" data-type-sample="heading-s">${sample}</span>
197
313
  </div>
198
314
  <div class="flex flex-wrap items-baseline gap-x-4 gap-y-2 border-b border-border-surface-default pb-4">
199
315
  <div class="w-52 shrink-0 gap-y-1">
200
316
  <code class="copy-btn block label-xs-medium text-content-on-surface-muted" onclick="copyToClipboard('heading-m', this)">heading-m</code>
201
317
  <span class="label-xs-regular text-content-on-surface-muted">Heading M</span>
202
318
  </div>
203
- <span class="heading-m text-content-on-surface-primary min-w-0 flex-1">${sample}</span>
319
+ <span class="heading-m text-content-on-surface-primary min-w-0 flex-1" data-type-sample="heading-m">${sample}</span>
204
320
  </div>
205
321
  <div class="flex flex-wrap items-baseline gap-x-4 gap-y-2 border-b border-border-surface-default pb-4">
206
322
  <div class="w-52 shrink-0 gap-y-1">
207
323
  <code class="copy-btn block label-xs-medium text-content-on-surface-muted" onclick="copyToClipboard('heading-l', this)">heading-l</code>
208
324
  <span class="label-xs-regular text-content-on-surface-muted">Heading L</span>
209
325
  </div>
210
- <span class="heading-l text-content-on-surface-primary min-w-0 flex-1">${sample}</span>
326
+ <span class="heading-l text-content-on-surface-primary min-w-0 flex-1" data-type-sample="heading-l">${sample}</span>
211
327
  </div>
212
328
  <div class="flex flex-wrap items-baseline gap-x-4 gap-y-2 border-b border-border-surface-default pb-4">
213
329
  <div class="w-52 shrink-0 gap-y-1">
214
330
  <code class="copy-btn block label-xs-medium text-content-on-surface-muted" onclick="copyToClipboard('heading-xl', this)">heading-xl</code>
215
331
  <span class="label-xs-regular text-content-on-surface-muted">Heading XL</span>
216
332
  </div>
217
- <span class="heading-xl text-content-on-surface-primary min-w-0 flex-1">${sample}</span>
333
+ <span class="heading-xl text-content-on-surface-primary min-w-0 flex-1" data-type-sample="heading-xl">${sample}</span>
218
334
  </div>
219
335
  <div class="flex flex-wrap items-baseline gap-x-4 gap-y-2">
220
336
  <div class="w-52 shrink-0 gap-y-1">
221
337
  <code class="copy-btn block label-xs-medium text-content-on-surface-muted" onclick="copyToClipboard('heading-2xl', this)">heading-2xl</code>
222
338
  <span class="label-xs-regular text-content-on-surface-muted">Heading 2XL</span>
223
339
  </div>
224
- <span class="heading-2xl text-content-on-surface-primary min-w-0 flex-1">${sample}</span>
340
+ <span class="heading-2xl text-content-on-surface-primary min-w-0 flex-1" data-type-sample="heading-2xl">${sample}</span>
225
341
  </div>
226
342
  </div>
227
343
  </div>
228
344
  `,
229
345
  }),
346
+ play: async ({ canvasElement, step }) => {
347
+ // Scenario (typography scale): each heading step is a single utility whose
348
+ // size and weight come from its global heading token — the expectations
349
+ // below mirror those token values.
350
+ await step(
351
+ 'interaction: every heading step computes its token size and weight',
352
+ async () => {
353
+ const expected: [className: string, size: string, weight: string][] = [
354
+ ['heading-s', '20px', '600'],
355
+ ['heading-m', '24px', '700'],
356
+ ['heading-l', '30px', '600'],
357
+ ['heading-xl', '36px', '500'],
358
+ ['heading-2xl', '96px', '700'],
359
+ ];
360
+ for (const [className, fontSize, fontWeight] of expected) {
361
+ const style = sampleStyle(canvasElement, className);
362
+ await expect(style.fontSize).toBe(fontSize);
363
+ await expect(style.fontWeight).toBe(fontWeight);
364
+ }
365
+ },
366
+ );
367
+ },
230
368
  };
231
369
 
232
370
  /**