@aleph-alpha/ui-library 6.2.0 → 6.3.0
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.
- package/dist/system/components/UiButtonGroup/index.d.ts +1 -0
- package/dist/system/components/UiCodeBlock/types.d.ts +11 -0
- package/dist/system/components/UiInputGroup/UiInputGroup.vue.d.ts +20 -0
- package/dist/system/components/UiInputGroup/UiInputGroupAddon.vue.d.ts +20 -0
- package/dist/system/components/UiInputGroup/UiInputGroupButton.vue.d.ts +17 -0
- package/dist/system/components/UiInputGroup/UiInputGroupInput.vue.d.ts +11 -0
- package/dist/system/components/UiInputGroup/UiInputGroupTextarea.vue.d.ts +11 -0
- package/dist/system/components/UiInputGroup/index.d.ts +7 -0
- package/dist/system/components/UiInputGroup/types.d.ts +151 -0
- package/dist/system/components/UiLabel/UiLabel.vue.d.ts +3 -1
- package/dist/system/components/UiLabel/types.d.ts +7 -0
- package/dist/system/components/core/input-group/InputGroup.vue.d.ts +25 -0
- package/dist/system/components/core/input-group/InputGroupAddon.vue.d.ts +25 -0
- package/dist/system/components/core/input-group/InputGroupButton.vue.d.ts +28 -0
- package/dist/system/components/core/input-group/InputGroupInput.vue.d.ts +12 -0
- package/dist/system/components/core/input-group/InputGroupText.vue.d.ts +21 -0
- package/dist/system/components/core/input-group/InputGroupTextarea.vue.d.ts +12 -0
- package/dist/system/components/core/input-group/index.d.ts +18 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib.js +14300 -13931
- package/package.json +1 -1
- package/src/components/UiButtonGroup/index.ts +4 -0
- package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +83 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +30 -2
- package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +21 -0
- package/src/components/UiCodeBlock/types.ts +11 -0
- package/src/components/UiField/UiField.stories.ts +329 -52
- package/src/components/UiField/UiFieldLabelInfo.vue +1 -1
- package/src/components/UiInput/UiInput.stories.ts +3 -1
- package/src/components/UiInput/UiInput.vue +26 -5
- package/src/components/UiInputGroup/UiInputGroup.stories.ts +2083 -0
- package/src/components/UiInputGroup/UiInputGroup.vue +18 -0
- package/src/components/UiInputGroup/UiInputGroupAddon.vue +18 -0
- package/src/components/UiInputGroup/UiInputGroupButton.vue +30 -0
- package/src/components/UiInputGroup/UiInputGroupInput.vue +16 -0
- package/src/components/UiInputGroup/UiInputGroupTextarea.vue +16 -0
- package/src/components/UiInputGroup/__tests__/UiInputGroup.test.ts +195 -0
- package/src/components/UiInputGroup/index.ts +10 -0
- package/src/components/UiInputGroup/types.ts +171 -0
- package/src/components/UiLabel/UiLabel.vue +7 -2
- package/src/components/UiLabel/types.ts +8 -0
- package/src/components/core/button/index.ts +23 -13
- package/src/components/core/button-group/ButtonGroupText.vue +4 -0
- package/src/components/core/button-group/index.ts +6 -2
- package/src/components/core/field/FieldError.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +1 -1
- package/src/components/core/field/index.ts +7 -1
- package/src/components/core/input/Input.vue +4 -1
- package/src/components/core/input-group/InputGroup.vue +27 -0
- package/src/components/core/input-group/InputGroupAddon.vue +53 -0
- package/src/components/core/input-group/InputGroupButton.vue +35 -0
- package/src/components/core/input-group/InputGroupInput.vue +65 -0
- package/src/components/core/input-group/InputGroupText.vue +26 -0
- package/src/components/core/input-group/InputGroupTextarea.vue +62 -0
- package/src/components/core/input-group/index.ts +103 -0
- package/src/components/core/label/Label.vue +1 -1
- package/src/components/index.ts +1 -0
- package/src/theme/Typography.stories.ts +144 -6
- package/src/theme/__tests__/typography.test.ts +136 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// @vitest-environment node
|
|
2
|
+
// (config.js reads tokens.json via a file URL from import.meta.url, which the
|
|
3
|
+
// jsdom environment rewrites to an http scheme.)
|
|
4
|
+
import { describe, expect, test } from 'vitest';
|
|
5
|
+
import { getUiLibraryTypographyShortcuts } from '../../../config.js';
|
|
6
|
+
|
|
7
|
+
// The typography utility contract: `{family}-{step}-{weight}` for labels and
|
|
8
|
+
// body text, `heading-{step}` for headings. Every label/body step must exist
|
|
9
|
+
// in every weight; the `normal` alias mirrors `regular`; the deprecated
|
|
10
|
+
// numbered names (removed in 7.0.0) must resolve to the same declarations as
|
|
11
|
+
// the step name replacing them.
|
|
12
|
+
|
|
13
|
+
const shortcuts = new Map(getUiLibraryTypographyShortcuts());
|
|
14
|
+
|
|
15
|
+
/** Weight suffix → the `font-weight` value the utility must declare. */
|
|
16
|
+
const WEIGHTS: Record<string, number> = {
|
|
17
|
+
regular: 400,
|
|
18
|
+
normal: 400,
|
|
19
|
+
medium: 500,
|
|
20
|
+
bold: 700,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Every label/body step prefix, current step names and deprecated numbered names. */
|
|
24
|
+
const STEP_PREFIXES = [
|
|
25
|
+
'label-xs',
|
|
26
|
+
'label-s',
|
|
27
|
+
'label-m',
|
|
28
|
+
'body-s',
|
|
29
|
+
'body-m',
|
|
30
|
+
// Deprecated numbered aliases, removed in 7.0.0.
|
|
31
|
+
'label-12',
|
|
32
|
+
'label-14',
|
|
33
|
+
'label-16',
|
|
34
|
+
'body-14',
|
|
35
|
+
'body-16',
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
/** Deprecated numbered prefix → the step name that replaces it. */
|
|
39
|
+
const DEPRECATED_RENAMES: [from: string, to: string][] = [
|
|
40
|
+
['label-12', 'label-xs'],
|
|
41
|
+
['label-14', 'label-s'],
|
|
42
|
+
['label-16', 'label-m'],
|
|
43
|
+
['body-14', 'body-s'],
|
|
44
|
+
['body-16', 'body-m'],
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const HEADING_CLASSES = [
|
|
48
|
+
'heading-s',
|
|
49
|
+
'heading-m',
|
|
50
|
+
'heading-l',
|
|
51
|
+
'heading-xl',
|
|
52
|
+
'heading-2xl',
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Reads one declaration out of a shortcut's `prop:value;prop:value` CSS string.
|
|
57
|
+
* @param css Shortcut CSS.
|
|
58
|
+
* @param property Declaration name to extract.
|
|
59
|
+
*/
|
|
60
|
+
const declaration = (css: string, property: string): string | undefined =>
|
|
61
|
+
css
|
|
62
|
+
.split(';')
|
|
63
|
+
.map((entry) => entry.split(':'))
|
|
64
|
+
.find(([name]) => name === property)?.[1];
|
|
65
|
+
|
|
66
|
+
// `Body 16 / medium` is the one token that deviates from the 500 the `medium`
|
|
67
|
+
// suffix means everywhere else: it references `fontWeights.saans-4` (600)
|
|
68
|
+
// instead of `fontWeights.saans-1` (500) in tokens.json. Documented here as
|
|
69
|
+
// the current token truth — if design confirms it should be 500, fix the
|
|
70
|
+
// token and delete this override.
|
|
71
|
+
const TOKEN_WEIGHT_OVERRIDES: Record<string, number> = {
|
|
72
|
+
'body-m-medium': 600,
|
|
73
|
+
'body-16-medium': 600,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
describe('typography utility classes', () => {
|
|
77
|
+
describe.each(STEP_PREFIXES)('%s', (prefix) => {
|
|
78
|
+
test.each(Object.entries(WEIGHTS))(
|
|
79
|
+
'provides the %s weight (font-weight %i)',
|
|
80
|
+
(suffix, fontWeight) => {
|
|
81
|
+
const className = `${prefix}-${suffix}`;
|
|
82
|
+
const css = shortcuts.get(className) ?? '';
|
|
83
|
+
expect(css).not.toBe('');
|
|
84
|
+
expect(declaration(css, 'font-weight')).toBe(
|
|
85
|
+
String(TOKEN_WEIGHT_OVERRIDES[className] ?? fontWeight),
|
|
86
|
+
);
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
test('every weight declares the same size and line height', () => {
|
|
91
|
+
const variants = Object.keys(WEIGHTS).map(
|
|
92
|
+
(suffix) => shortcuts.get(`${prefix}-${suffix}`) ?? '',
|
|
93
|
+
);
|
|
94
|
+
const sizes = new Set(
|
|
95
|
+
variants.map((css) => declaration(css, 'font-size')),
|
|
96
|
+
);
|
|
97
|
+
const lineHeights = new Set(
|
|
98
|
+
variants.map((css) => declaration(css, 'line-height')),
|
|
99
|
+
);
|
|
100
|
+
expect(sizes.size).toBe(1);
|
|
101
|
+
expect(lineHeights.size).toBe(1);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test.each(DEPRECATED_RENAMES)(
|
|
106
|
+
'deprecated %s-* resolves to the same declarations as %s-*',
|
|
107
|
+
(from, to) => {
|
|
108
|
+
for (const suffix of Object.keys(WEIGHTS)) {
|
|
109
|
+
expect(shortcuts.get(`${from}-${suffix}`)).toBe(
|
|
110
|
+
shortcuts.get(`${to}-${suffix}`),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
test.each(HEADING_CLASSES)(
|
|
117
|
+
'%s exists and declares a font weight',
|
|
118
|
+
(className) => {
|
|
119
|
+
const css = shortcuts.get(className) ?? '';
|
|
120
|
+
expect(css).not.toBe('');
|
|
121
|
+
expect(declaration(css, 'font-weight')).toMatch(/^\d+$/);
|
|
122
|
+
},
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
test('no generated label/body class is missing its weight suffix', () => {
|
|
126
|
+
const weightSuffixes = new Set(Object.keys(WEIGHTS));
|
|
127
|
+
for (const name of shortcuts.keys()) {
|
|
128
|
+
if (name.startsWith('heading-')) continue;
|
|
129
|
+
const suffix = name.split('-').at(-1) ?? '';
|
|
130
|
+
expect(
|
|
131
|
+
weightSuffixes.has(suffix),
|
|
132
|
+
`"${name}" does not end in a known weight suffix`,
|
|
133
|
+
).toBe(true);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|