@mindlogic-ai/logician-ui 5.0.0-alpha.28 → 5.0.0-alpha.29
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/MIGRATION-5.0.md +38 -0
- package/USAGE.md +20 -0
- package/dist/components/DatePicker/DatePicker.types.d.ts +12 -0
- package/dist/components/DatePicker/DatePicker.types.d.ts.map +1 -0
- package/dist/components/DatePicker/RangeDatePicker.d.ts +2 -1
- package/dist/components/DatePicker/RangeDatePicker.d.ts.map +1 -1
- package/dist/components/DatePicker/RangeDatePicker.js +4 -2
- package/dist/components/DatePicker/RangeDatePicker.js.map +1 -1
- package/dist/components/DatePicker/RangeDatePicker.mjs +4 -2
- package/dist/components/DatePicker/RangeDatePicker.mjs.map +1 -1
- package/dist/components/DatePicker/SingleDatePicker.d.ts +2 -1
- package/dist/components/DatePicker/SingleDatePicker.d.ts.map +1 -1
- package/dist/components/DatePicker/SingleDatePicker.js +4 -2
- package/dist/components/DatePicker/SingleDatePicker.js.map +1 -1
- package/dist/components/DatePicker/SingleDatePicker.mjs +4 -2
- package/dist/components/DatePicker/SingleDatePicker.mjs.map +1 -1
- package/dist/components/DatePicker/index.d.ts +1 -0
- package/dist/components/DatePicker/index.d.ts.map +1 -1
- package/dist/components/MonthPicker/MonthPicker.d.ts.map +1 -1
- package/dist/components/MonthPicker/MonthPicker.js +3 -2
- package/dist/components/MonthPicker/MonthPicker.js.map +1 -1
- package/dist/components/MonthPicker/MonthPicker.mjs +3 -2
- package/dist/components/MonthPicker/MonthPicker.mjs.map +1 -1
- package/dist/components/MonthPicker/MonthPicker.types.d.ts +7 -1
- package/dist/components/MonthPicker/MonthPicker.types.d.ts.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.d.ts.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.js +7 -18
- package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.mjs +8 -19
- package/dist/components/SegmentedControl/SegmentedControl.mjs.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.styles.d.ts +18 -0
- package/dist/components/SegmentedControl/SegmentedControl.styles.d.ts.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.styles.js +24 -0
- package/dist/components/SegmentedControl/SegmentedControl.styles.js.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.styles.mjs +23 -1
- package/dist/components/SegmentedControl/SegmentedControl.styles.mjs.map +1 -1
- package/dist/components/Tag/Tag.d.ts.map +1 -1
- package/dist/components/Tag/Tag.js +14 -2
- package/dist/components/Tag/Tag.js.map +1 -1
- package/dist/components/Tag/Tag.mjs +15 -3
- package/dist/components/Tag/Tag.mjs.map +1 -1
- package/dist/components/Tag/Tag.styles.d.ts +20 -2
- package/dist/components/Tag/Tag.styles.d.ts.map +1 -1
- package/dist/components/Tag/Tag.styles.js +81 -0
- package/dist/components/Tag/Tag.styles.js.map +1 -1
- package/dist/components/Tag/Tag.styles.mjs +81 -1
- package/dist/components/Tag/Tag.styles.mjs.map +1 -1
- package/dist/components/Tag/Tag.types.d.ts +15 -2
- package/dist/components/Tag/Tag.types.d.ts.map +1 -1
- package/dist/components/Tag/index.d.ts +2 -2
- package/dist/components/Tag/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/theme/controlSizes.d.ts +91 -0
- package/dist/theme/controlSizes.d.ts.map +1 -0
- package/dist/theme/controlSizes.js +143 -0
- package/dist/theme/controlSizes.js.map +1 -0
- package/dist/theme/controlSizes.mjs +135 -0
- package/dist/theme/controlSizes.mjs.map +1 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +12 -43
- package/dist/theme/index.js.map +1 -1
- package/dist/theme/index.mjs +12 -43
- package/dist/theme/index.mjs.map +1 -1
- package/dist/theme/recipes/controls.d.ts +94 -0
- package/dist/theme/recipes/controls.d.ts.map +1 -0
- package/dist/theme/recipes/controls.js +154 -0
- package/dist/theme/recipes/controls.js.map +1 -0
- package/dist/theme/recipes/controls.mjs +144 -0
- package/dist/theme/recipes/controls.mjs.map +1 -0
- package/package.json +1 -1
- package/src/components/DatePicker/DatePicker.types.ts +12 -0
- package/src/components/DatePicker/RangeDatePicker.tsx +7 -1
- package/src/components/DatePicker/SingleDatePicker.tsx +7 -1
- package/src/components/DatePicker/index.ts +1 -0
- package/src/components/MonthPicker/MonthPicker.tsx +7 -1
- package/src/components/MonthPicker/MonthPicker.types.ts +8 -1
- package/src/components/SegmentedControl/SegmentedControl.styles.ts +31 -0
- package/src/components/SegmentedControl/SegmentedControl.tsx +15 -22
- package/src/components/SegmentedControl/SegmentedControl.usage.mdx +15 -8
- package/src/components/Tag/Tag.styles.ts +117 -2
- package/src/components/Tag/Tag.test.tsx +87 -1
- package/src/components/Tag/Tag.tsx +22 -1
- package/src/components/Tag/Tag.types.ts +16 -2
- package/src/components/Tag/index.ts +2 -0
- package/src/components/claude.md +23 -0
- package/src/index.ts +12 -0
- package/src/theme/ControlSizes.stories.tsx +586 -0
- package/src/theme/claude.md +8 -0
- package/src/theme/controlSizes.test.ts +148 -0
- package/src/theme/controlSizes.ts +162 -0
- package/src/theme/index.ts +21 -46
- package/src/theme/recipes/controls.ts +171 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { defaultSystem } from '@chakra-ui/react';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { segmentItemHeight } from '../components/SegmentedControl/SegmentedControl.styles';
|
|
5
|
+
import { getTagSizeStyles } from '../components/Tag/Tag.styles';
|
|
6
|
+
import {
|
|
7
|
+
CONTROL_RADIUS,
|
|
8
|
+
CONTROL_SIZES,
|
|
9
|
+
controlHeightToken,
|
|
10
|
+
controlSizes,
|
|
11
|
+
CORE_CONTROL_SIZES,
|
|
12
|
+
} from './controlSizes';
|
|
13
|
+
import { system } from './index';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Every control that takes `size` must resolve it through `controlSizes`.
|
|
17
|
+
*
|
|
18
|
+
* These read the recipes the shipped `system` actually ends up with (Chakra's
|
|
19
|
+
* defaults deep-merged with ours) and the helpers the components call, so a
|
|
20
|
+
* component that grows its own height or type map again fails here — the
|
|
21
|
+
* QA #18 toolbar (SegmentedControl 36px next to Input 28px next to Tag 20px)
|
|
22
|
+
* is what that looked like.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
type Variant = Record<string, any>;
|
|
26
|
+
const sizeVariants = (recipe: { variants?: { size?: Variant } }) =>
|
|
27
|
+
recipe.variants?.size ?? {};
|
|
28
|
+
|
|
29
|
+
describe('controlSizes — Button is the reference', () => {
|
|
30
|
+
it('restates Chakra’s own button sizes exactly (no Button changes size)', () => {
|
|
31
|
+
const chakra = sizeVariants(defaultSystem.getRecipe('button'));
|
|
32
|
+
for (const size of CONTROL_SIZES) {
|
|
33
|
+
const s = controlSizes[size];
|
|
34
|
+
expect(chakra[size], size).toMatchObject({
|
|
35
|
+
h: s.height,
|
|
36
|
+
minW: s.height,
|
|
37
|
+
textStyle: s.textStyle,
|
|
38
|
+
px: s.actionPaddingX,
|
|
39
|
+
gap: s.gap,
|
|
40
|
+
_icon: { width: s.iconSize, height: s.iconSize },
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('the shipped button recipe resolves to the scale', () => {
|
|
46
|
+
const shipped = sizeVariants(system.getRecipe('button'));
|
|
47
|
+
for (const size of CONTROL_SIZES) {
|
|
48
|
+
expect(shipped[size].h, size).toBe(controlSizes[size].height);
|
|
49
|
+
expect(shipped[size].textStyle, size).toBe(controlSizes[size].textStyle);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('controlSizes — every other control resolves to the same scale', () => {
|
|
55
|
+
it.each(CORE_CONTROL_SIZES)('Input %s', (size) => {
|
|
56
|
+
const v = sizeVariants(system.getRecipe('input'))[size];
|
|
57
|
+
expect(v['--input-height']).toBe(controlHeightToken(size));
|
|
58
|
+
expect(v.textStyle).toBe(controlSizes[size].textStyle);
|
|
59
|
+
expect(v.px).toBe(controlSizes[size].fieldPaddingX);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it.each(CORE_CONTROL_SIZES)('Textarea %s (type and padding)', (size) => {
|
|
63
|
+
const v = sizeVariants(system.getRecipe('textarea'))[size];
|
|
64
|
+
expect(v.textStyle).toBe(controlSizes[size].textStyle);
|
|
65
|
+
expect(v.px).toBe(controlSizes[size].fieldPaddingX);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it.each(CORE_CONTROL_SIZES)('Select %s', (size) => {
|
|
69
|
+
const v = sizeVariants(system.getSlotRecipe('select'))[size];
|
|
70
|
+
expect(v.root['--select-trigger-height']).toBe(controlHeightToken(size));
|
|
71
|
+
expect(v.trigger.textStyle).toBe(controlSizes[size].textStyle);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it.each(CORE_CONTROL_SIZES)('Combobox %s', (size) => {
|
|
75
|
+
const v = sizeVariants(system.getSlotRecipe('combobox'))[size];
|
|
76
|
+
expect(v.root['--combobox-input-height']).toBe(controlHeightToken(size));
|
|
77
|
+
expect(v.input.textStyle).toBe(controlSizes[size].textStyle);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it.each(['sm', 'md', 'lg'] as const)('Tabs %s', (size) => {
|
|
81
|
+
const v = sizeVariants(system.getSlotRecipe('tabs'))[size];
|
|
82
|
+
expect(v.root['--tabs-height']).toBe(controlHeightToken(size));
|
|
83
|
+
expect(v.trigger.textStyle).toBe(controlSizes[size].textStyle);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it.each(CORE_CONTROL_SIZES)('Checkbox / Radio / Switch label %s', (size) => {
|
|
87
|
+
const t = controlSizes[size].textStyle;
|
|
88
|
+
expect(
|
|
89
|
+
sizeVariants(system.getSlotRecipe('checkbox'))[size].label.textStyle
|
|
90
|
+
).toBe(t);
|
|
91
|
+
expect(
|
|
92
|
+
sizeVariants(system.getSlotRecipe('radioGroup'))[size].item.textStyle
|
|
93
|
+
).toBe(t);
|
|
94
|
+
expect(
|
|
95
|
+
sizeVariants(system.getSlotRecipe('switch'))[size].label.textStyle
|
|
96
|
+
).toBe(t);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it.each(CORE_CONTROL_SIZES)(
|
|
100
|
+
'SegmentedControl %s: item + 2×4px root padding = the height token',
|
|
101
|
+
(size) => {
|
|
102
|
+
expect(segmentItemHeight(size)).toBe(
|
|
103
|
+
`calc(var(--chakra-sizes-${controlSizes[size].height}) - 8px)`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
it.each(CORE_CONTROL_SIZES)('interactive Tag %s', (size) => {
|
|
109
|
+
const { sizeStyles } = getTagSizeStyles(size, true);
|
|
110
|
+
expect(sizeStyles).toMatchObject({
|
|
111
|
+
h: controlSizes[size].height,
|
|
112
|
+
textStyle: controlSizes[size].textStyle,
|
|
113
|
+
px: controlSizes[size].actionPaddingX,
|
|
114
|
+
borderRadius: CONTROL_RADIUS,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('a static Tag keeps the badge sizes', () => {
|
|
119
|
+
expect(getTagSizeStyles('lg', false).sizeStyles).toEqual({
|
|
120
|
+
fontSize: 'sm',
|
|
121
|
+
});
|
|
122
|
+
expect(getTagSizeStyles('xs', false).recipeSize).toBe('sm');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('boxed fields share Button’s corner', () => {
|
|
126
|
+
expect(system.getRecipe('input').base.borderRadius).toBe(CONTROL_RADIUS);
|
|
127
|
+
expect(system.getRecipe('textarea').base.borderRadius).toBe(CONTROL_RADIUS);
|
|
128
|
+
expect(system.getSlotRecipe('select').base.trigger.borderRadius).toBe(
|
|
129
|
+
CONTROL_RADIUS
|
|
130
|
+
);
|
|
131
|
+
expect(system.getSlotRecipe('combobox').base.input.borderRadius).toBe(
|
|
132
|
+
CONTROL_RADIUS
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('slot recipe overrides keep Chakra’s anatomy', () => {
|
|
138
|
+
// Chakra merges configs array-by-index: a partial `slots` list overwrites
|
|
139
|
+
// the first entries of the default list instead of adding to it.
|
|
140
|
+
it.each(['select', 'combobox', 'tabs', 'checkbox', 'radioGroup', 'switch'])(
|
|
141
|
+
'%s',
|
|
142
|
+
(key) => {
|
|
143
|
+
expect(system.getSlotRecipe(key).slots).toEqual(
|
|
144
|
+
defaultSystem.getSlotRecipe(key).slots
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One size scale for every control.
|
|
3
|
+
*
|
|
4
|
+
* A row of controls — a table filter bar, a toolbar, an inline form — only
|
|
5
|
+
* lines up when every control resolves the same `size` value to the same
|
|
6
|
+
* height, type size, icon size and corner. Each component used to carry its own
|
|
7
|
+
* map (Chakra's recipe here, a local table there), and they drifted: in the
|
|
8
|
+
* FactChat coding-agent toolbar a `SegmentedControl size="sm"` drew 36px, an
|
|
9
|
+
* `Input size="xs"` 28px and an `lg` `Tag` 20.4px side by side (R28 3차 QA #18).
|
|
10
|
+
* Every height-bearing control and every recipe override now reads this table,
|
|
11
|
+
* and `controlSizes.test.ts` fails if one stops doing so.
|
|
12
|
+
*
|
|
13
|
+
* ## The scale is Button's
|
|
14
|
+
*
|
|
15
|
+
* `Button` was the reference and does not change: the values below are exactly
|
|
16
|
+
* Chakra's button recipe. Everything else is aligned to it.
|
|
17
|
+
*
|
|
18
|
+
* | size | height token | px at the 14px root | in a 16px `ScaledContext` (desktop) |
|
|
19
|
+
* |------|--------------|---------------------|-------------------------------------|
|
|
20
|
+
* | 2xs | `sizes.6` | 21 | 21 (2xs type is 0.875em) |
|
|
21
|
+
* | xs | `sizes.8` | 28 | 28 (xs type is 0.875em) |
|
|
22
|
+
* | sm | `sizes.9` | 31.5 | 36 |
|
|
23
|
+
* | md | `sizes.10` | 35 | 40 |
|
|
24
|
+
* | lg | `sizes.11` | 38.5 | 44 |
|
|
25
|
+
* | xl | `sizes.12` | 42 | 48 |
|
|
26
|
+
*
|
|
27
|
+
* ## Why one type step per size, not just one height
|
|
28
|
+
*
|
|
29
|
+
* `html` is 14px, and the sizes tokens are rem, so outside a `ScaledContext`
|
|
30
|
+
* the height alone decides. Inside one (FactChat's `ReadingScale` is
|
|
31
|
+
* `<ScaledContext fontSize="16px">`) the sizes tokens become **em**, and an em
|
|
32
|
+
* resolves against the control's *own* font size. Two controls with the same
|
|
33
|
+
* height token but different type therefore stop matching there — that is how
|
|
34
|
+
* `Input lg` (1.143em type) drew 50px next to a 44px `Button lg`. The same
|
|
35
|
+
* happens at the mobile breakpoint, where the textStyles drop to 0.875em. So
|
|
36
|
+
* every control takes its type from `textStyle` here too: equal type per size
|
|
37
|
+
* is what keeps equal height everywhere, not only at the root.
|
|
38
|
+
*
|
|
39
|
+
* Text-entry controls still raise their type to 16px under `pointer: coarse`
|
|
40
|
+
* (`noZoomOnFocus`, iOS zoom). At the root that changes nothing about height;
|
|
41
|
+
* inside a `ScaledContext` on a touch device it makes an `Input` taller than
|
|
42
|
+
* its neighbours. That is the price of not zooming, and it is left alone.
|
|
43
|
+
*
|
|
44
|
+
* ## Two padding ramps
|
|
45
|
+
*
|
|
46
|
+
* Action controls (Button, SegmentedControl items, interactive Tag) and field
|
|
47
|
+
* controls (Input, Select, Combobox, Textarea) keep different inline padding on
|
|
48
|
+
* purpose: a field's text starts near its edge, a button's label is centred in
|
|
49
|
+
* air. Each ramp is shared by its whole family.
|
|
50
|
+
*
|
|
51
|
+
* ## Icons
|
|
52
|
+
*
|
|
53
|
+
* `iconSize` is Button's `_icon` ramp as a sizes token; `iconBoxSize` is the
|
|
54
|
+
* `Icon` `boxSize` name with the same size, for icons a control draws itself
|
|
55
|
+
* (DatePicker / MonthPicker triggers) and for call sites placing an icon in a
|
|
56
|
+
* control (`<SearchIcon boxSize={controlSizes[size].iconBoxSize} />`).
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
export const CONTROL_SIZES = ['2xs', 'xs', 'sm', 'md', 'lg', 'xl'] as const;
|
|
60
|
+
|
|
61
|
+
export type ControlSize = (typeof CONTROL_SIZES)[number];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The four sizes a control row is built from. Every height-bearing control
|
|
65
|
+
* supports these; `2xs` / `xl` exist only where the component already had them.
|
|
66
|
+
*/
|
|
67
|
+
export const CORE_CONTROL_SIZES = ['xs', 'sm', 'md', 'lg'] as const;
|
|
68
|
+
|
|
69
|
+
export type CoreControlSize = (typeof CORE_CONTROL_SIZES)[number];
|
|
70
|
+
|
|
71
|
+
export interface ControlSizeSpec {
|
|
72
|
+
/** `sizes` token key — the outer height of every height-bearing control. */
|
|
73
|
+
height: string;
|
|
74
|
+
/** textStyle every control uses at this size (font size + line height). */
|
|
75
|
+
textStyle: 'xs' | 'sm' | 'md';
|
|
76
|
+
/** `sizes` token key for an icon inside the control (Button's `_icon`). */
|
|
77
|
+
iconSize: string;
|
|
78
|
+
/** The `Icon` `boxSize` name that renders at `iconSize`. */
|
|
79
|
+
iconBoxSize: '2xs' | 'xs' | 'sm';
|
|
80
|
+
/** Inline padding of action controls (spacing token). */
|
|
81
|
+
actionPaddingX: string;
|
|
82
|
+
/** Inline padding of field controls (spacing token). */
|
|
83
|
+
fieldPaddingX: string;
|
|
84
|
+
/** Gap between an icon and the label (spacing token). */
|
|
85
|
+
gap: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const controlSizes: Record<ControlSize, ControlSizeSpec> = {
|
|
89
|
+
'2xs': {
|
|
90
|
+
height: '6',
|
|
91
|
+
textStyle: 'xs',
|
|
92
|
+
iconSize: '3.5',
|
|
93
|
+
iconBoxSize: '2xs',
|
|
94
|
+
actionPaddingX: '2',
|
|
95
|
+
fieldPaddingX: '2',
|
|
96
|
+
gap: '1',
|
|
97
|
+
},
|
|
98
|
+
xs: {
|
|
99
|
+
height: '8',
|
|
100
|
+
textStyle: 'xs',
|
|
101
|
+
iconSize: '4',
|
|
102
|
+
iconBoxSize: 'xs',
|
|
103
|
+
actionPaddingX: '2.5',
|
|
104
|
+
fieldPaddingX: '2',
|
|
105
|
+
gap: '1',
|
|
106
|
+
},
|
|
107
|
+
sm: {
|
|
108
|
+
height: '9',
|
|
109
|
+
textStyle: 'sm',
|
|
110
|
+
iconSize: '4',
|
|
111
|
+
iconBoxSize: 'xs',
|
|
112
|
+
actionPaddingX: '3.5',
|
|
113
|
+
fieldPaddingX: '2.5',
|
|
114
|
+
gap: '2',
|
|
115
|
+
},
|
|
116
|
+
md: {
|
|
117
|
+
height: '10',
|
|
118
|
+
textStyle: 'sm',
|
|
119
|
+
iconSize: '5',
|
|
120
|
+
iconBoxSize: 'sm',
|
|
121
|
+
actionPaddingX: '4',
|
|
122
|
+
fieldPaddingX: '3',
|
|
123
|
+
gap: '2',
|
|
124
|
+
},
|
|
125
|
+
lg: {
|
|
126
|
+
height: '11',
|
|
127
|
+
textStyle: 'md',
|
|
128
|
+
iconSize: '5',
|
|
129
|
+
iconBoxSize: 'sm',
|
|
130
|
+
actionPaddingX: '5',
|
|
131
|
+
// 12px at a 16px font — kept from the lg padding fix (f2820c8) so lg reads
|
|
132
|
+
// as a step up from md rather than a wider box.
|
|
133
|
+
fieldPaddingX: '3',
|
|
134
|
+
gap: '3',
|
|
135
|
+
},
|
|
136
|
+
xl: {
|
|
137
|
+
height: '12',
|
|
138
|
+
textStyle: 'md',
|
|
139
|
+
iconSize: '5',
|
|
140
|
+
iconBoxSize: 'sm',
|
|
141
|
+
actionPaddingX: '5',
|
|
142
|
+
fieldPaddingX: '4.5',
|
|
143
|
+
gap: '2.5',
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/** Corner radius of every boxed control, at every size (Button's). */
|
|
148
|
+
export const CONTROL_RADIUS = 'md';
|
|
149
|
+
|
|
150
|
+
/** `sizes.N` token path of a size's height, for recipe CSS variables. */
|
|
151
|
+
export const controlHeightToken = (size: ControlSize): string =>
|
|
152
|
+
`sizes.${controlSizes[size].height}`;
|
|
153
|
+
|
|
154
|
+
/** The same height as a CSS value, for `calc()` and inline styles. */
|
|
155
|
+
export const controlHeightVar = (size: ControlSize): string =>
|
|
156
|
+
`var(--chakra-sizes-${controlSizes[size].height})`;
|
|
157
|
+
|
|
158
|
+
/** Resolve an arbitrary `size` prop to a spec, falling back to `md`. */
|
|
159
|
+
export const getControlSize = (size: unknown): ControlSizeSpec =>
|
|
160
|
+
typeof size === 'string' && size in controlSizes
|
|
161
|
+
? controlSizes[size as ControlSize]
|
|
162
|
+
: controlSizes.md;
|
package/src/theme/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
createSystem,
|
|
3
3
|
defaultConfig,
|
|
4
4
|
defineConfig,
|
|
5
|
-
defineSlotRecipe,
|
|
6
5
|
defineTextStyles,
|
|
7
6
|
type SystemConfig,
|
|
8
7
|
} from '@chakra-ui/react';
|
|
@@ -16,6 +15,17 @@ import { globalCss } from './global';
|
|
|
16
15
|
import { animationStyles, durations, easings, keyframes } from './motion';
|
|
17
16
|
import { accordionSlotRecipe } from './recipes/accordion';
|
|
18
17
|
import { avatarSlotRecipe } from './recipes/avatar';
|
|
18
|
+
import {
|
|
19
|
+
buttonRecipe,
|
|
20
|
+
checkboxSlotRecipe,
|
|
21
|
+
comboboxSlotRecipe,
|
|
22
|
+
inputRecipe,
|
|
23
|
+
radioGroupSlotRecipe,
|
|
24
|
+
selectSlotRecipe,
|
|
25
|
+
switchSlotRecipe,
|
|
26
|
+
tabsSlotRecipe,
|
|
27
|
+
textareaRecipe,
|
|
28
|
+
} from './recipes/controls';
|
|
19
29
|
import { tableSlotRecipe } from './recipes/table';
|
|
20
30
|
|
|
21
31
|
/**
|
|
@@ -213,49 +223,6 @@ export const textStyles = defineTextStyles({
|
|
|
213
223
|
},
|
|
214
224
|
});
|
|
215
225
|
|
|
216
|
-
/**
|
|
217
|
-
* `lg`/`xl` form-control font size.
|
|
218
|
-
*
|
|
219
|
-
* Chakra's input, textarea and select recipes put `sm`/`md` on the `sm`
|
|
220
|
-
* textStyle and `lg`/`xl` on `md`. This theme maps both textStyles to
|
|
221
|
-
* `subtitleAndP`, so every size rendered at the same 14px and only the height
|
|
222
|
-
* changed. `lg`/`xl` get their own step here (desktop 16px, phone 14px);
|
|
223
|
-
* `xs`/`sm`/`md` keep their current size on purpose, so call sites that do not
|
|
224
|
-
* pass `size` render exactly as before.
|
|
225
|
-
*
|
|
226
|
-
* Spacing tokens are em-based, so Chakra's `lg` `px: 4` grows with the font to
|
|
227
|
-
* 16px. `lg` drops to `px: 3` (12px) to stay close to `md`'s 10.5px.
|
|
228
|
-
*/
|
|
229
|
-
const FORM_CONTROL_LG_FONT_SIZE = { base: '1em', md: '1.143em' } as const;
|
|
230
|
-
|
|
231
|
-
const formControlLgOverride = {
|
|
232
|
-
variants: {
|
|
233
|
-
size: {
|
|
234
|
-
lg: { fontSize: FORM_CONTROL_LG_FONT_SIZE, px: '3' },
|
|
235
|
-
xl: { fontSize: FORM_CONTROL_LG_FONT_SIZE },
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
// Same `lg` step as Input, and the same height as Input `lg` (Chakra puts the
|
|
241
|
-
// select trigger one token taller). Chakra's `py: 3` is em-based, so at 16px it
|
|
242
|
-
// alone pushes the trigger past the min height; let the height token win.
|
|
243
|
-
const selectSlotRecipe = defineSlotRecipe({
|
|
244
|
-
slots: ['root', 'trigger', 'content'],
|
|
245
|
-
variants: {
|
|
246
|
-
size: {
|
|
247
|
-
lg: {
|
|
248
|
-
root: {
|
|
249
|
-
'--select-trigger-height': 'sizes.11',
|
|
250
|
-
'--select-trigger-padding-x': 'spacing.3',
|
|
251
|
-
},
|
|
252
|
-
trigger: { fontSize: FORM_CONTROL_LG_FONT_SIZE, py: '1.5' },
|
|
253
|
-
content: { fontSize: FORM_CONTROL_LG_FONT_SIZE },
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
});
|
|
258
|
-
|
|
259
226
|
type TokenNode = { value?: unknown; [key: string]: unknown };
|
|
260
227
|
|
|
261
228
|
const normalizeNode = (node: TokenNode): TokenNode => {
|
|
@@ -398,15 +365,23 @@ export function createLogicianTheme(options: LogicianThemeOptions = {}) {
|
|
|
398
365
|
colors: createSemanticColors(options),
|
|
399
366
|
},
|
|
400
367
|
textStyles,
|
|
368
|
+
// Every control's `size` variant reads the shared scale in
|
|
369
|
+
// ./controlSizes — see ./recipes/controls.
|
|
401
370
|
recipes: {
|
|
402
|
-
|
|
403
|
-
|
|
371
|
+
button: buttonRecipe,
|
|
372
|
+
input: inputRecipe,
|
|
373
|
+
textarea: textareaRecipe,
|
|
404
374
|
},
|
|
405
375
|
slotRecipes: {
|
|
406
376
|
accordion: accordionSlotRecipe,
|
|
407
377
|
avatar: avatarSlotRecipe,
|
|
408
378
|
table: tableSlotRecipe,
|
|
409
379
|
select: selectSlotRecipe,
|
|
380
|
+
combobox: comboboxSlotRecipe,
|
|
381
|
+
tabs: tabsSlotRecipe,
|
|
382
|
+
checkbox: checkboxSlotRecipe,
|
|
383
|
+
radioGroup: radioGroupSlotRecipe,
|
|
384
|
+
switch: switchSlotRecipe,
|
|
410
385
|
},
|
|
411
386
|
},
|
|
412
387
|
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { defineRecipe, defineSlotRecipe } from '@chakra-ui/react';
|
|
2
|
+
import {
|
|
3
|
+
checkboxAnatomy,
|
|
4
|
+
comboboxAnatomy,
|
|
5
|
+
radioGroupAnatomy,
|
|
6
|
+
selectAnatomy,
|
|
7
|
+
switchAnatomy,
|
|
8
|
+
tabsAnatomy,
|
|
9
|
+
} from '@chakra-ui/react/anatomy';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
CONTROL_RADIUS,
|
|
13
|
+
CONTROL_SIZES,
|
|
14
|
+
controlHeightToken,
|
|
15
|
+
type ControlSize,
|
|
16
|
+
controlSizes,
|
|
17
|
+
CORE_CONTROL_SIZES,
|
|
18
|
+
} from '../controlSizes';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Chakra recipe overrides that put every control's `size` variant on the
|
|
22
|
+
* shared scale in `../controlSizes`. Chakra deep-merges these into its own
|
|
23
|
+
* recipes, so only the keys written here change.
|
|
24
|
+
*
|
|
25
|
+
* Nothing here holds a literal: every height, textStyle, padding and icon size
|
|
26
|
+
* comes from `controlSizes`, so a change to the scale lands everywhere at once
|
|
27
|
+
* and `controlSizes.test.ts` can check the resolved recipes against it.
|
|
28
|
+
*
|
|
29
|
+
* **Slot recipes pass Chakra's full anatomy, never a partial `slots` list.**
|
|
30
|
+
* Chakra merges configs array-by-index, so `slots: ['label']` does not add
|
|
31
|
+
* to the default list — it overwrites its first entry. For Checkbox that
|
|
32
|
+
* dropped the `root` slot (the label lost its line box); the old
|
|
33
|
+
* `['root', 'trigger', 'content']` Select override had been overwriting
|
|
34
|
+
* Select's `label` and `positioner` slots the same way.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
const bySize = <T>(
|
|
38
|
+
sizes: readonly ControlSize[],
|
|
39
|
+
build: (size: ControlSize) => T
|
|
40
|
+
): Record<string, T> =>
|
|
41
|
+
Object.fromEntries(sizes.map((size) => [size, build(size)]));
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Button (and IconButton, which uses the same recipe). These are Chakra's own
|
|
45
|
+
* values — Button is the reference — restated from the scale so the scale is
|
|
46
|
+
* the single source and the test can prove nothing else drifted from it.
|
|
47
|
+
*/
|
|
48
|
+
export const buttonRecipe = defineRecipe({
|
|
49
|
+
variants: {
|
|
50
|
+
size: bySize(CONTROL_SIZES, (size) => {
|
|
51
|
+
const s = controlSizes[size];
|
|
52
|
+
return {
|
|
53
|
+
h: s.height,
|
|
54
|
+
minW: s.height,
|
|
55
|
+
textStyle: s.textStyle,
|
|
56
|
+
px: s.actionPaddingX,
|
|
57
|
+
gap: s.gap,
|
|
58
|
+
_icon: { width: s.iconSize, height: s.iconSize },
|
|
59
|
+
};
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Field sizes, xs–xl. `2xs` is left on Chakra's own value (a 24.5px field):
|
|
66
|
+
* no field ships a 2xs today and shrinking it to Button's 21px would put a text
|
|
67
|
+
* box under the 24px target.
|
|
68
|
+
*/
|
|
69
|
+
const FIELD_SIZES = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
|
|
70
|
+
|
|
71
|
+
export const inputRecipe = defineRecipe({
|
|
72
|
+
base: { borderRadius: CONTROL_RADIUS },
|
|
73
|
+
variants: {
|
|
74
|
+
size: bySize(FIELD_SIZES, (size) => ({
|
|
75
|
+
textStyle: controlSizes[size].textStyle,
|
|
76
|
+
px: controlSizes[size].fieldPaddingX,
|
|
77
|
+
'--input-height': controlHeightToken(size),
|
|
78
|
+
})),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
/** Textarea: same type and inline padding as Input; its height is its rows. */
|
|
83
|
+
export const textareaRecipe = defineRecipe({
|
|
84
|
+
base: { borderRadius: CONTROL_RADIUS },
|
|
85
|
+
variants: {
|
|
86
|
+
size: bySize(FIELD_SIZES, (size) => ({
|
|
87
|
+
textStyle: controlSizes[size].textStyle,
|
|
88
|
+
px: controlSizes[size].fieldPaddingX,
|
|
89
|
+
})),
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export const selectSlotRecipe = defineSlotRecipe({
|
|
94
|
+
slots: selectAnatomy.keys(),
|
|
95
|
+
base: { trigger: { borderRadius: CONTROL_RADIUS } },
|
|
96
|
+
variants: {
|
|
97
|
+
size: bySize(CORE_CONTROL_SIZES, (size) => ({
|
|
98
|
+
root: {
|
|
99
|
+
'--select-trigger-height': controlHeightToken(size),
|
|
100
|
+
'--select-trigger-padding-x': `spacing.${controlSizes[size].fieldPaddingX}`,
|
|
101
|
+
},
|
|
102
|
+
trigger: {
|
|
103
|
+
textStyle: controlSizes[size].textStyle,
|
|
104
|
+
// Chakra's lg `py: 3` is em-based and alone pushes the trigger past
|
|
105
|
+
// the height token; let the token decide (637d0fe).
|
|
106
|
+
...(size === 'lg' && { py: '1.5' }),
|
|
107
|
+
},
|
|
108
|
+
content: { textStyle: controlSizes[size].textStyle },
|
|
109
|
+
})),
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export const comboboxSlotRecipe = defineSlotRecipe({
|
|
114
|
+
slots: comboboxAnatomy.keys(),
|
|
115
|
+
base: { input: { borderRadius: CONTROL_RADIUS } },
|
|
116
|
+
variants: {
|
|
117
|
+
size: bySize(CORE_CONTROL_SIZES, (size) => ({
|
|
118
|
+
root: {
|
|
119
|
+
'--combobox-input-height': controlHeightToken(size),
|
|
120
|
+
'--combobox-input-padding-x': `spacing.${controlSizes[size].fieldPaddingX}`,
|
|
121
|
+
},
|
|
122
|
+
input: { textStyle: controlSizes[size].textStyle },
|
|
123
|
+
content: { textStyle: controlSizes[size].textStyle },
|
|
124
|
+
})),
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Tabs: the trigger height is the tab list's `--tabs-height`, set by the
|
|
130
|
+
* `Tabs` root's `size` (sm / md / lg — Chakra's tabs have no xs). A `size` on
|
|
131
|
+
* a single `Tab` does not reach it.
|
|
132
|
+
*/
|
|
133
|
+
const TAB_SIZES = ['sm', 'md', 'lg'] as const;
|
|
134
|
+
|
|
135
|
+
export const tabsSlotRecipe = defineSlotRecipe({
|
|
136
|
+
slots: tabsAnatomy.keys(),
|
|
137
|
+
variants: {
|
|
138
|
+
size: bySize(TAB_SIZES, (size) => ({
|
|
139
|
+
root: { '--tabs-height': controlHeightToken(size) },
|
|
140
|
+
trigger: { textStyle: controlSizes[size].textStyle },
|
|
141
|
+
})),
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/** Checkbox / Radio / Switch: the label takes the control type per size. */
|
|
146
|
+
export const checkboxSlotRecipe = defineSlotRecipe({
|
|
147
|
+
slots: checkboxAnatomy.keys(),
|
|
148
|
+
variants: {
|
|
149
|
+
size: bySize(CORE_CONTROL_SIZES, (size) => ({
|
|
150
|
+
label: { textStyle: controlSizes[size].textStyle },
|
|
151
|
+
})),
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export const radioGroupSlotRecipe = defineSlotRecipe({
|
|
156
|
+
slots: radioGroupAnatomy.keys(),
|
|
157
|
+
variants: {
|
|
158
|
+
size: bySize(CORE_CONTROL_SIZES, (size) => ({
|
|
159
|
+
item: { textStyle: controlSizes[size].textStyle },
|
|
160
|
+
})),
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
export const switchSlotRecipe = defineSlotRecipe({
|
|
165
|
+
slots: switchAnatomy.keys(),
|
|
166
|
+
variants: {
|
|
167
|
+
size: bySize(CORE_CONTROL_SIZES, (size) => ({
|
|
168
|
+
label: { textStyle: controlSizes[size].textStyle },
|
|
169
|
+
})),
|
|
170
|
+
},
|
|
171
|
+
});
|