@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.
Files changed (97) hide show
  1. package/MIGRATION-5.0.md +38 -0
  2. package/USAGE.md +20 -0
  3. package/dist/components/DatePicker/DatePicker.types.d.ts +12 -0
  4. package/dist/components/DatePicker/DatePicker.types.d.ts.map +1 -0
  5. package/dist/components/DatePicker/RangeDatePicker.d.ts +2 -1
  6. package/dist/components/DatePicker/RangeDatePicker.d.ts.map +1 -1
  7. package/dist/components/DatePicker/RangeDatePicker.js +4 -2
  8. package/dist/components/DatePicker/RangeDatePicker.js.map +1 -1
  9. package/dist/components/DatePicker/RangeDatePicker.mjs +4 -2
  10. package/dist/components/DatePicker/RangeDatePicker.mjs.map +1 -1
  11. package/dist/components/DatePicker/SingleDatePicker.d.ts +2 -1
  12. package/dist/components/DatePicker/SingleDatePicker.d.ts.map +1 -1
  13. package/dist/components/DatePicker/SingleDatePicker.js +4 -2
  14. package/dist/components/DatePicker/SingleDatePicker.js.map +1 -1
  15. package/dist/components/DatePicker/SingleDatePicker.mjs +4 -2
  16. package/dist/components/DatePicker/SingleDatePicker.mjs.map +1 -1
  17. package/dist/components/DatePicker/index.d.ts +1 -0
  18. package/dist/components/DatePicker/index.d.ts.map +1 -1
  19. package/dist/components/MonthPicker/MonthPicker.d.ts.map +1 -1
  20. package/dist/components/MonthPicker/MonthPicker.js +3 -2
  21. package/dist/components/MonthPicker/MonthPicker.js.map +1 -1
  22. package/dist/components/MonthPicker/MonthPicker.mjs +3 -2
  23. package/dist/components/MonthPicker/MonthPicker.mjs.map +1 -1
  24. package/dist/components/MonthPicker/MonthPicker.types.d.ts +7 -1
  25. package/dist/components/MonthPicker/MonthPicker.types.d.ts.map +1 -1
  26. package/dist/components/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  27. package/dist/components/SegmentedControl/SegmentedControl.js +7 -18
  28. package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
  29. package/dist/components/SegmentedControl/SegmentedControl.mjs +8 -19
  30. package/dist/components/SegmentedControl/SegmentedControl.mjs.map +1 -1
  31. package/dist/components/SegmentedControl/SegmentedControl.styles.d.ts +18 -0
  32. package/dist/components/SegmentedControl/SegmentedControl.styles.d.ts.map +1 -1
  33. package/dist/components/SegmentedControl/SegmentedControl.styles.js +24 -0
  34. package/dist/components/SegmentedControl/SegmentedControl.styles.js.map +1 -1
  35. package/dist/components/SegmentedControl/SegmentedControl.styles.mjs +23 -1
  36. package/dist/components/SegmentedControl/SegmentedControl.styles.mjs.map +1 -1
  37. package/dist/components/Tag/Tag.d.ts.map +1 -1
  38. package/dist/components/Tag/Tag.js +14 -2
  39. package/dist/components/Tag/Tag.js.map +1 -1
  40. package/dist/components/Tag/Tag.mjs +15 -3
  41. package/dist/components/Tag/Tag.mjs.map +1 -1
  42. package/dist/components/Tag/Tag.styles.d.ts +20 -2
  43. package/dist/components/Tag/Tag.styles.d.ts.map +1 -1
  44. package/dist/components/Tag/Tag.styles.js +81 -0
  45. package/dist/components/Tag/Tag.styles.js.map +1 -1
  46. package/dist/components/Tag/Tag.styles.mjs +81 -1
  47. package/dist/components/Tag/Tag.styles.mjs.map +1 -1
  48. package/dist/components/Tag/Tag.types.d.ts +15 -2
  49. package/dist/components/Tag/Tag.types.d.ts.map +1 -1
  50. package/dist/components/Tag/index.d.ts +2 -2
  51. package/dist/components/Tag/index.d.ts.map +1 -1
  52. package/dist/index.d.ts +1 -0
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +9 -0
  55. package/dist/index.js.map +1 -1
  56. package/dist/index.mjs +2 -1
  57. package/dist/index.mjs.map +1 -1
  58. package/dist/theme/controlSizes.d.ts +91 -0
  59. package/dist/theme/controlSizes.d.ts.map +1 -0
  60. package/dist/theme/controlSizes.js +143 -0
  61. package/dist/theme/controlSizes.js.map +1 -0
  62. package/dist/theme/controlSizes.mjs +135 -0
  63. package/dist/theme/controlSizes.mjs.map +1 -0
  64. package/dist/theme/index.d.ts.map +1 -1
  65. package/dist/theme/index.js +12 -43
  66. package/dist/theme/index.js.map +1 -1
  67. package/dist/theme/index.mjs +12 -43
  68. package/dist/theme/index.mjs.map +1 -1
  69. package/dist/theme/recipes/controls.d.ts +94 -0
  70. package/dist/theme/recipes/controls.d.ts.map +1 -0
  71. package/dist/theme/recipes/controls.js +154 -0
  72. package/dist/theme/recipes/controls.js.map +1 -0
  73. package/dist/theme/recipes/controls.mjs +144 -0
  74. package/dist/theme/recipes/controls.mjs.map +1 -0
  75. package/package.json +1 -1
  76. package/src/components/DatePicker/DatePicker.types.ts +12 -0
  77. package/src/components/DatePicker/RangeDatePicker.tsx +7 -1
  78. package/src/components/DatePicker/SingleDatePicker.tsx +7 -1
  79. package/src/components/DatePicker/index.ts +1 -0
  80. package/src/components/MonthPicker/MonthPicker.tsx +7 -1
  81. package/src/components/MonthPicker/MonthPicker.types.ts +8 -1
  82. package/src/components/SegmentedControl/SegmentedControl.styles.ts +31 -0
  83. package/src/components/SegmentedControl/SegmentedControl.tsx +15 -22
  84. package/src/components/SegmentedControl/SegmentedControl.usage.mdx +15 -8
  85. package/src/components/Tag/Tag.styles.ts +117 -2
  86. package/src/components/Tag/Tag.test.tsx +87 -1
  87. package/src/components/Tag/Tag.tsx +22 -1
  88. package/src/components/Tag/Tag.types.ts +16 -2
  89. package/src/components/Tag/index.ts +2 -0
  90. package/src/components/claude.md +23 -0
  91. package/src/index.ts +12 -0
  92. package/src/theme/ControlSizes.stories.tsx +586 -0
  93. package/src/theme/claude.md +8 -0
  94. package/src/theme/controlSizes.test.ts +148 -0
  95. package/src/theme/controlSizes.ts +162 -0
  96. package/src/theme/index.ts +21 -46
  97. package/src/theme/recipes/controls.ts +171 -0
@@ -6,6 +6,7 @@ import {
6
6
  import { format } from 'date-fns';
7
7
 
8
8
  import useLanguage from '@/hooks/useLanguage';
9
+ import { getControlSize } from '@/theme/controlSizes';
9
10
 
10
11
  import { Button, ButtonProps } from '../Button';
11
12
  import { MdOutlineCalendarToday } from '../Icon';
@@ -15,13 +16,16 @@ import {
15
16
  getDefaultFullDateFormat,
16
17
  getMonthNames,
17
18
  } from '../MonthPicker/constants';
19
+ import type { DatePickerSizeProps } from './DatePicker.types';
18
20
 
19
21
  export const SingleDatePicker = ({
20
22
  propsConfigs,
21
23
  configs,
22
24
  usePortal = true,
25
+ size,
23
26
  ...rest
24
- }: SingleDatepickerProps) => {
27
+ }: SingleDatepickerProps & DatePickerSizeProps) => {
28
+ const control = getControlSize(size);
25
29
  const { language } = useLanguage();
26
30
  const dateFormat = configs?.dateFormat ?? getDefaultFullDateFormat(language);
27
31
  const dateFnsLocale = getDateFnsLocale(language);
@@ -121,9 +125,11 @@ export const SingleDatePicker = ({
121
125
  <Button
122
126
  pl={2}
123
127
  variant="secondary"
128
+ size={size}
124
129
  {...(propsConfigs?.triggerBtnProps as ButtonProps)}
125
130
  >
126
131
  <MdOutlineCalendarToday
132
+ boxSize={control.iconBoxSize}
127
133
  color="fg.subtle"
128
134
  style={{ marginInlineEnd: 3 }}
129
135
  />
@@ -1,2 +1,3 @@
1
+ export type { DatePickerSizeProps } from './DatePicker.types';
1
2
  export { RangeDatePicker } from './RangeDatePicker';
2
3
  export { SingleDatePicker } from './SingleDatePicker';
@@ -17,6 +17,7 @@ import { format, isAfter, isSameMonth } from 'date-fns';
17
17
  import { Text } from '@/components/Typography';
18
18
  import useLanguage from '@/hooks/useLanguage';
19
19
  import { useTranslate } from '@/hooks/useTranslate';
20
+ import { getControlSize } from '@/theme/controlSizes';
20
21
 
21
22
  import {
22
23
  IoChevronForward,
@@ -45,6 +46,7 @@ export const MonthPicker: React.FC<MonthPickerProps> = ({
45
46
  popoverProps,
46
47
  name,
47
48
  showClearButton = true,
49
+ size,
48
50
  ...boxProps
49
51
  }) => {
50
52
  const [isOpen, setIsOpen] = useState(false);
@@ -294,10 +296,14 @@ export const MonthPicker: React.FC<MonthPickerProps> = ({
294
296
  <Box>
295
297
  <InputGroup
296
298
  startElement={
297
- <MdOutlineCalendarToday boxSize="xs" color="fg.muted" />
299
+ <MdOutlineCalendarToday
300
+ boxSize={getControlSize(size).iconBoxSize}
301
+ color="fg.muted"
302
+ />
298
303
  }
299
304
  >
300
305
  <Input
306
+ size={size}
301
307
  name={name}
302
308
  value={displayValue}
303
309
  placeholder={effectivePlaceholder}
@@ -1,4 +1,4 @@
1
- import { BoxProps, Popover } from '@chakra-ui/react';
1
+ import { BoxProps, InputProps, Popover } from '@chakra-ui/react';
2
2
 
3
3
  export interface MonthRange {
4
4
  startMonth: Date;
@@ -6,6 +6,13 @@ export interface MonthRange {
6
6
  }
7
7
 
8
8
  export interface MonthPickerProps extends Omit<BoxProps, 'onChange'> {
9
+ /**
10
+ * Size of the trigger field, on the shared control scale (`controlSizes`) —
11
+ * the same height and type as an `Input` / `Button` of that size.
12
+ * @default 'md'
13
+ */
14
+ size?: InputProps['size'];
15
+
9
16
  /** The selected month range */
10
17
  selectedRange?: MonthRange | null;
11
18
 
@@ -1,5 +1,11 @@
1
1
  import type { SystemStyleObject } from '@chakra-ui/react';
2
2
 
3
+ import {
4
+ controlHeightVar,
5
+ type ControlSize,
6
+ controlSizes,
7
+ } from '@/theme/controlSizes';
8
+
3
9
  /**
4
10
  * `travel`, but delivered through custom properties.
5
11
  *
@@ -20,3 +26,28 @@ export const indicatorTravel: SystemStyleObject = {
20
26
  '--transition-duration': 'var(--chakra-durations-motion-instant)',
21
27
  },
22
28
  };
29
+
30
+ /**
31
+ * The root's padding in px (see `ROOT_PADDING` in SegmentedControl.tsx for
32
+ * why px). Shared with the item-height calc so the two cannot disagree.
33
+ */
34
+ export const SEGMENT_ROOT_PADDING_PX = 4;
35
+
36
+ /**
37
+ * Item height so that the OUTER height (item + 2 × ROOT_PADDING) equals the
38
+ * Button height for the same size — `controlSizes[size].height`, i.e. 28 /
39
+ * 31.5 / 35 / 38.5px for xs / sm / md / lg at the 14px root, and 36 / 40 / 44
40
+ * for sm / md / lg inside a 16px `ScaledContext`.
41
+ *
42
+ * A `calc()` on the height token rather than a smaller token: the root padding
43
+ * is a fixed 4px while the sizes tokens are rem (em inside a ScaledContext),
44
+ * so no single token equals "Button height − 8px" at every font size. The old
45
+ * one-token-smaller table (`6`/`7`/`8`/`9`) was written for a 16px rem and
46
+ * came out 1px taller than Button at the real 14px root.
47
+ */
48
+ export const segmentItemHeight = (size: unknown): string =>
49
+ `calc(${controlHeightVar(
50
+ (typeof size === 'string' && size in controlSizes
51
+ ? size
52
+ : 'md') as ControlSize
53
+ )} - ${SEGMENT_ROOT_PADDING_PX * 2}px)`;
@@ -1,35 +1,24 @@
1
1
  import { forwardRef } from 'react';
2
2
  import { SegmentGroup } from '@chakra-ui/react';
3
3
 
4
+ import { getControlSize } from '@/theme/controlSizes';
4
5
  import { mergeCss } from '@/utils/mergeCss';
5
6
 
6
- import { indicatorTravel } from './SegmentedControl.styles';
7
+ import {
8
+ indicatorTravel,
9
+ SEGMENT_ROOT_PADDING_PX,
10
+ segmentItemHeight,
11
+ } from './SegmentedControl.styles';
7
12
  import {
8
13
  SegmentedControlOption,
9
14
  SegmentedControlProps,
10
15
  } from './SegmentedControl.types';
11
16
 
12
- // Match font sizes to the equivalent Chakra button sizes
13
- const fontSizeBySize: Record<string, string> = {
14
- xs: 'xs',
15
- sm: 'sm',
16
- md: 'sm',
17
- lg: 'md',
18
- };
19
-
20
- // Item heights so that itemHeight + 2×ROOT_PADDING (4px) equals the Button height for each size
21
- const itemHeightBySize: Record<string, string> = {
22
- xs: '6', // 32 - 8 = 24px
23
- sm: '7', // 36 - 8 = 28px
24
- md: '8', // 40 - 8 = 32px
25
- lg: '9', // 44 - 8 = 36px
26
- };
27
-
28
17
  // Root padding in px, not the `1` spacing token: that token is 0.25em, so at a
29
18
  // 14px font it is 3.5px, and Ark positions the indicator from the item's
30
19
  // integer offsetTop/offsetLeft (3.5 rounds to 4). The thumb then sat 0.5px low
31
20
  // and its bottom gap was a pixel narrower than its top.
32
- const ROOT_PADDING = '4px';
21
+ const ROOT_PADDING = `${SEGMENT_ROOT_PADDING_PX}px`;
33
22
 
34
23
  export const SegmentedControl = forwardRef<
35
24
  HTMLDivElement,
@@ -46,8 +35,10 @@ export const SegmentedControl = forwardRef<
46
35
  ...rest
47
36
  } = props;
48
37
 
49
- const fontSize = fontSizeBySize[size as string] ?? 'sm';
50
- const itemHeight = itemHeightBySize[size as string] ?? '8';
38
+ // Same textStyle as every other control at this size (see controlSizes):
39
+ // the item height is em inside a ScaledContext, so equal type is what keeps
40
+ // the outer height equal to Button's there too.
41
+ const spec = getControlSize(size);
51
42
 
52
43
  // Normalize options to the format expected by SegmentGroup.Items
53
44
  const items = options.map((option: SegmentedControlOption) => ({
@@ -134,14 +125,16 @@ export const SegmentedControl = forwardRef<
134
125
  disabled={item.disabled}
135
126
  cursor={item.disabled ? 'not-allowed' : 'pointer'}
136
127
  flex="1"
137
- height={itemHeight}
128
+ height={segmentItemHeight(size)}
129
+ textStyle={spec.textStyle}
130
+ px={spec.actionPaddingX}
131
+ gap={spec.gap}
138
132
  _hover={{ bg: 'transparent' }}
139
133
  >
140
134
  <SegmentGroup.ItemText
141
135
  data-text={typeof item.label === 'string' ? item.label : undefined}
142
136
  color="fg.muted"
143
137
  fontWeight="500"
144
- fontSize={fontSize}
145
138
  whiteSpace="nowrap"
146
139
  display="inline-flex"
147
140
  flexDirection="column"
@@ -75,12 +75,16 @@ SegmentedControl의 모양은 하나입니다. `bg.subtle` 트랙 위에 선택
75
75
 
76
76
  <En>
77
77
 
78
+ Heights come from the shared control scale (`controlSizes`), so they are
79
+ always the `Button` height of the same size: px below at the 14px root, and in
80
+ brackets inside a 16px `ScaledContext` (FactChat's `ReadingScale`).
81
+
78
82
  | `size` | Height | Next to |
79
83
  | --- | --- | --- |
80
- | `xs` | 32px | A `Button size="xs"`, a dense field header |
81
- | `sm` | 36px | Settings rows and filters in admin tables |
82
- | `md` (default) | 40px | Page-level view switches |
83
- | `lg` | 44px | A `Button size="lg"` |
84
+ | `xs` | 28px (28px) | A `Button size="xs"`, a dense field header |
85
+ | `sm` | 31.5px (36px) | Settings rows and filters in admin tables |
86
+ | `md` (default) | 35px (40px) | Page-level view switches |
87
+ | `lg` | 38.5px (44px) | A `Button size="lg"` |
84
88
 
85
89
  ## Do / Don't
86
90
 
@@ -88,12 +92,15 @@ SegmentedControl의 모양은 하나입니다. `bg.subtle` 트랙 위에 선택
88
92
 
89
93
  <Ko>
90
94
 
95
+ 높이는 공통 컨트롤 스케일(`controlSizes`)에서 오므로 언제나 같은 크기 `Button`의 높이와 같습니다.
96
+ 아래 값은 14px 루트 기준이고, 괄호 안은 16px `ScaledContext`(FactChat `ReadingScale`) 안의 값입니다.
97
+
91
98
  | `size` | 높이 | 함께 두는 것 |
92
99
  | --- | --- | --- |
93
- | `xs` | 32px | `Button size="xs"`, 촘촘한 입력란 머리 |
94
- | `sm` | 36px | 관리 화면 표의 설정 줄과 필터 |
95
- | `md` (기본) | 40px | 페이지 전체의 보기 전환 |
96
- | `lg` | 44px | `Button size="lg"` |
100
+ | `xs` | 28px (28px) | `Button size="xs"`, 촘촘한 입력란 머리 |
101
+ | `sm` | 31.5px (36px) | 관리 화면 표의 설정 줄과 필터 |
102
+ | `md` (기본) | 35px (40px) | 페이지 전체의 보기 전환 |
103
+ | `lg` | 38.5px (44px) | `Button size="lg"` |
97
104
 
98
105
  ## 이렇게 하세요 / 이렇게 하지 마세요
99
106
 
@@ -1,10 +1,19 @@
1
- import { TagRootProps } from '@chakra-ui/react';
1
+ import type {
2
+ ConditionalValue,
3
+ SystemStyleObject,
4
+ TagRootProps,
5
+ } from '@chakra-ui/react';
2
6
 
3
7
  import type { SystemHue } from '@/theme/colors';
8
+ import {
9
+ CONTROL_RADIUS,
10
+ type ControlSizeSpec,
11
+ getControlSize,
12
+ } from '@/theme/controlSizes';
4
13
  import { disabledControl } from '@/utils/disabledControl';
5
14
  import { isDev } from '@/utils/isDev';
6
15
 
7
- import { TagColorPalette, TagTone, TagVariant } from './Tag.types';
16
+ import { TagColorPalette, TagSize, TagTone, TagVariant } from './Tag.types';
8
17
 
9
18
  type StyleProps = Partial<TagRootProps>;
10
19
 
@@ -111,6 +120,112 @@ export const getTagStyles = ({
111
120
  };
112
121
  };
113
122
 
123
+ type ResponsiveTagSize = ConditionalValue<TagSize>;
124
+
125
+ const isPlainObject = (value: unknown): value is Record<string, unknown> =>
126
+ typeof value === 'object' && value !== null && !Array.isArray(value);
127
+
128
+ /**
129
+ * Map every leaf of a Chakra conditional value (`'sm'`, `['xs', null, 'md']`,
130
+ * `{ base: 'xs', md: 'lg' }`, nested conditions) through `fn`, keeping its
131
+ * shape so Chakra still applies each result at its breakpoint. `null` array
132
+ * slots ("no change at this breakpoint") stay `null`.
133
+ */
134
+ const mapConditional = <R>(
135
+ value: ResponsiveTagSize,
136
+ fn: (size: TagSize) => R
137
+ ): ConditionalValue<R> => {
138
+ if (Array.isArray(value)) {
139
+ return value.map((v) => (v == null ? null : (mapConditional(v, fn) as R)));
140
+ }
141
+ if (isPlainObject(value)) {
142
+ return Object.fromEntries(
143
+ Object.entries(value).map(([k, v]) => [
144
+ k,
145
+ v == null ? v : mapConditional(v as ResponsiveTagSize, fn),
146
+ ])
147
+ ) as ConditionalValue<R>;
148
+ }
149
+ return fn(value as TagSize);
150
+ };
151
+
152
+ /**
153
+ * An interactive tag must draw a control size at every width. A responsive
154
+ * value that starts above `base` (`{ md: 'lg' }`, `[null, 'sm']`) would leave
155
+ * the narrowest screens on the badge recipe, so they start at the default `md`.
156
+ */
157
+ const withBaseSize = (
158
+ size: ResponsiveTagSize | undefined
159
+ ): ResponsiveTagSize => {
160
+ if (size == null) return 'md';
161
+ if (Array.isArray(size)) {
162
+ return size[0] == null ? ['md', ...size.slice(1)] : size;
163
+ }
164
+ if (isPlainObject(size)) {
165
+ return 'base' in size && size.base != null ? size : { base: 'md', ...size };
166
+ }
167
+ return size;
168
+ };
169
+
170
+ /**
171
+ * Size styles for a tag.
172
+ *
173
+ * - **Interactive** (a filter chip, a toggle, a link): the shared control
174
+ * scale — the same height, type, inline padding, gap, icon size and radius
175
+ * as a `Button` of that `size` (default `md`), so a chip row lines up with
176
+ * the search field and buttons next to it. A responsive `size` resolves the
177
+ * scale per breakpoint. A composed `TagLabel` inherits the control type
178
+ * instead of the badge recipe's smaller label type.
179
+ * - **Static** (a badge): Chakra's tag sizes, unchanged. `xs` exists only on
180
+ * the control scale, so a static `xs` falls back to the smallest badge.
181
+ */
182
+ export const getTagSizeStyles = (
183
+ size: ResponsiveTagSize | undefined,
184
+ interactive: boolean
185
+ ): {
186
+ sizeStyles: StyleProps;
187
+ recipeSize: TagRootProps['size'];
188
+ cssVars?: SystemStyleObject;
189
+ } => {
190
+ const recipeSize =
191
+ size == null
192
+ ? undefined
193
+ : (mapConditional(size, (s) =>
194
+ s === 'xs' ? 'sm' : s
195
+ ) as TagRootProps['size']);
196
+ if (!interactive) return { sizeStyles: { fontSize: 'sm' }, recipeSize };
197
+ const scale = withBaseSize(size);
198
+ const pick = <K extends keyof ControlSizeSpec>(key: K) =>
199
+ mapConditional(scale, (s) => getControlSize(s)[key]);
200
+ const height = pick('height');
201
+ return {
202
+ sizeStyles: {
203
+ h: height,
204
+ minH: height,
205
+ px: pick('actionPaddingX'),
206
+ gap: pick('gap'),
207
+ textStyle: pick('textStyle') as StyleProps['textStyle'],
208
+ borderRadius: CONTROL_RADIUS,
209
+ },
210
+ recipeSize,
211
+ cssVars: {
212
+ // The `icon` slot is sized by this variable.
213
+ '--tag-element-size': mapConditional(
214
+ scale,
215
+ (s) =>
216
+ `var(--chakra-sizes-${getControlSize(s).iconSize.replace('.', '\\.')})`
217
+ ),
218
+ // The tag recipe gives its label the badge type (`xs` at sm/md). Inside
219
+ // a control that would shrink the label below the root's control type
220
+ // (12.25px instead of Button's 14px at desktop md), so it inherits.
221
+ '& .chakra-tag__label': {
222
+ fontSize: 'inherit',
223
+ lineHeight: 'inherit',
224
+ },
225
+ } as SystemStyleObject,
226
+ };
227
+ };
228
+
114
229
  /**
115
230
  * Result of mapping a 4.x `colorPalette × variant` pair onto 5.0 Tag props.
116
231
  * `needsHuman` marks a pair 5.0 cannot render faithfully (a status `solid`
@@ -6,7 +6,12 @@ import { system } from '../../theme';
6
6
  import { Badge } from '../Badge';
7
7
  import { Chip } from '../Chip';
8
8
  import { Tag } from './Tag';
9
- import { getTagStyles, mapLegacyTagProps } from './Tag.styles';
9
+ import {
10
+ getTagSizeStyles,
11
+ getTagStyles,
12
+ mapLegacyTagProps,
13
+ } from './Tag.styles';
14
+ import { TagLabel } from './TagLabel';
10
15
 
11
16
  const wrap = (ui: React.ReactNode) =>
12
17
  render(<ChakraProvider value={system}>{ui}</ChakraProvider>);
@@ -113,3 +118,84 @@ describe('deprecated aliases', () => {
113
118
  expect(warn).toHaveBeenCalledTimes(1);
114
119
  });
115
120
  });
121
+
122
+ describe('Tag size', () => {
123
+ it('resolves a responsive size per breakpoint on an interactive tag', () => {
124
+ const { sizeStyles, cssVars, recipeSize } = getTagSizeStyles(
125
+ { base: 'xs', md: 'lg' },
126
+ true
127
+ );
128
+ expect(sizeStyles).toMatchObject({
129
+ h: { base: '8', md: '11' },
130
+ minH: { base: '8', md: '11' },
131
+ px: { base: '2.5', md: '5' },
132
+ gap: { base: '1', md: '3' },
133
+ textStyle: { base: 'xs', md: 'md' },
134
+ });
135
+ expect(cssVars?.['--tag-element-size']).toEqual({
136
+ base: 'var(--chakra-sizes-4)',
137
+ md: 'var(--chakra-sizes-5)',
138
+ });
139
+ // `xs` is not a badge recipe size.
140
+ expect(recipeSize).toEqual({ base: 'sm', md: 'lg' });
141
+ });
142
+
143
+ it('keeps array slots and starts a base-less value at md', () => {
144
+ expect(getTagSizeStyles(['sm', null, 'lg'], true).sizeStyles.h).toEqual([
145
+ '9',
146
+ null,
147
+ '11',
148
+ ]);
149
+ expect(getTagSizeStyles([null, 'xs'], true).sizeStyles.h).toEqual([
150
+ '10',
151
+ '8',
152
+ ]);
153
+ expect(getTagSizeStyles({ lg: 'xs' }, true).sizeStyles.h).toEqual({
154
+ base: '10',
155
+ lg: '8',
156
+ });
157
+ });
158
+
159
+ it('leaves a responsive static badge on the recipe', () => {
160
+ const { sizeStyles, recipeSize, cssVars } = getTagSizeStyles(
161
+ { base: 'xs', md: 'lg' },
162
+ false
163
+ );
164
+ expect(sizeStyles).toEqual({ fontSize: 'sm' });
165
+ expect(recipeSize).toEqual({ base: 'sm', md: 'lg' });
166
+ expect(cssVars).toBeUndefined();
167
+ });
168
+
169
+ it('a TagLabel inside an interactive tag inherits the control type', () => {
170
+ const { cssVars } = getTagSizeStyles('md', true);
171
+ expect(cssVars?.['& .chakra-tag__label']).toEqual({
172
+ fontSize: 'inherit',
173
+ lineHeight: 'inherit',
174
+ });
175
+ wrap(
176
+ <Tag as="button" selected={false} size={{ base: 'sm', md: 'lg' }}>
177
+ <TagLabel>Images</TagLabel>
178
+ </Tag>
179
+ );
180
+ const label = screen.getByText('Images');
181
+ expect(label.className).toContain('chakra-tag__label');
182
+ const css = Array.from(document.querySelectorAll('style'))
183
+ .map((s) => s.textContent)
184
+ .join('\n');
185
+ expect(css).toMatch(/\.chakra-tag__label\s*\{[^}]*font-size:\s*inherit/);
186
+ });
187
+
188
+ it('accepts responsive sizes on Tag and the Chip alias (type-level)', () => {
189
+ wrap(
190
+ <>
191
+ <Tag size={{ base: 'sm', md: 'lg' }}>Static</Tag>
192
+ <Tag size={['xs', 'md']} onClick={() => {}}>
193
+ Clickable
194
+ </Tag>
195
+ <Chip size={{ base: 'sm', lg: 'md' }}>Chip</Chip>
196
+ </>
197
+ );
198
+ expect(screen.getByText('Static')).toBeTruthy();
199
+ expect(screen.getByText('Chip')).toBeTruthy();
200
+ });
201
+ });
@@ -2,9 +2,11 @@ import { ElementType, ForwardedRef, forwardRef, MouseEvent } from 'react';
2
2
  import { Tag as ChakraTag } from '@chakra-ui/react';
3
3
 
4
4
  import { focusRing } from '@/utils/focusRing';
5
+ import { mergeCss } from '@/utils/mergeCss';
5
6
 
6
7
  import { polymorphic } from '../../types/polymorphic';
7
8
  import {
9
+ getTagSizeStyles,
8
10
  getTagStyles,
9
11
  mapLegacyTagProps,
10
12
  warnLegacyTagProps,
@@ -36,6 +38,13 @@ type LegacyTagInput = {
36
38
  * toggle (`selected` passed) or renders as a `button` / `a`. Render filter
37
39
  * chips `as="button"` so they are keyboard-operable.
38
40
  *
41
+ * **Size depends on that.** A static tag is a badge and keeps Chakra's badge
42
+ * sizes (`sm` 15.75px · `md` 17.5px · `lg` 21px · `xl` 28px at the 14px root).
43
+ * An interactive tag is a control that sits in a row with buttons and inputs,
44
+ * so its `size` (`xs`–`xl`, default `md`) follows the shared control scale
45
+ * (`controlSizes`): the same height, type, padding and icon size as a
46
+ * `Button` of that size.
47
+ *
39
48
  * @example
40
49
  * ```tsx
41
50
  * <Tag>Draft</Tag>
@@ -58,6 +67,8 @@ const TagImpl = forwardRef(
58
67
  colorPalette: legacyPalette,
59
68
  variant: legacyVariant,
60
69
  as,
70
+ size,
71
+ css: cssProp,
61
72
  __legacyComponent: legacyComponent,
62
73
  ...rest
63
74
  } = props as TagOwnProps & LegacyTagInput;
@@ -94,6 +105,14 @@ const TagImpl = forwardRef(
94
105
 
95
106
  const styles = getTagStyles({ tone, selected, category, interactive });
96
107
 
108
+ // Decided on `wantsInteraction`, not `interactive`, so disabling a filter
109
+ // chip does not shrink it.
110
+ const { sizeStyles, recipeSize, cssVars } = getTagSizeStyles(
111
+ size,
112
+ wantsInteraction
113
+ );
114
+ const css = cssVars ? mergeCss(cssVars, cssProp) : cssProp;
115
+
97
116
  const handleClick = disabled
98
117
  ? (event: MouseEvent<HTMLSpanElement>) => event.preventDefault()
99
118
  : onClick;
@@ -103,8 +122,9 @@ const TagImpl = forwardRef(
103
122
  border="1px solid"
104
123
  borderRadius="md"
105
124
  boxShadow="none"
106
- fontSize="sm"
107
125
  fontWeight="semibold"
126
+ size={recipeSize}
127
+ {...sizeStyles}
108
128
  {...styles}
109
129
  {...focusRing}
110
130
  data-selected={selected ? '' : undefined}
@@ -119,6 +139,7 @@ const TagImpl = forwardRef(
119
139
  // After `rest`: a disabled link must not stay reachable by Tab.
120
140
  {...(disabledNonNative && { tabIndex: -1 })}
121
141
  as={as}
142
+ css={css}
122
143
  ref={ref}
123
144
  >
124
145
  {icon != null ? (
@@ -1,5 +1,5 @@
1
1
  import type { ElementType, ReactNode } from 'react';
2
- import { TagRootProps } from '@chakra-ui/react';
2
+ import type { ConditionalValue, TagRootProps } from '@chakra-ui/react';
3
3
 
4
4
  import type { SystemHue } from '@/theme/colors';
5
5
 
@@ -13,6 +13,9 @@ import type { PolymorphicProps } from '../../types/polymorphic';
13
13
  * - `success` / `warning` / `danger` / `info`: status family `.bg` + `.fg`.
14
14
  * Use them only when the tag reports a status.
15
15
  */
16
+ /** Tag sizes: the badge sizes plus `xs`, which only interactive tags draw. */
17
+ export type TagSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
18
+
16
19
  export type TagTone = 'neutral' | 'success' | 'warning' | 'danger' | 'info';
17
20
 
18
21
  /**
@@ -36,8 +39,19 @@ export type TagVariant = 'soft' | 'solid' | 'outline';
36
39
 
37
40
  export type TagOwnProps = Omit<
38
41
  TagRootProps,
39
- 'colorPalette' | 'variant' | 'as'
42
+ 'colorPalette' | 'variant' | 'as' | 'size'
40
43
  > & {
44
+ /**
45
+ * A static tag uses the badge sizes (`sm` · `md` · `lg` · `xl`; `xs` falls
46
+ * back to `sm`). An interactive tag — `onClick`, `selected`, `as="button"`
47
+ * or a link — uses the shared control scale (`xs`–`xl`), so it matches a
48
+ * `Button` / `Input` of the same size in a row.
49
+ *
50
+ * Responsive values (`{ base: 'xs', md: 'sm' }`, arrays) work for both;
51
+ * an interactive tag resolves the control scale per breakpoint.
52
+ * @default 'md'
53
+ */
54
+ size?: ConditionalValue<TagSize>;
41
55
  /**
42
56
  * Colour role of the tag. Ignored while `selected` is true or `category`
43
57
  * is set.
@@ -3,6 +3,7 @@ import { Icon } from '@chakra-ui/react';
3
3
  export { Tag } from './Tag';
4
4
  export type { LegacyTagResolution, TagStyleOptions } from './Tag.styles';
5
5
  export {
6
+ getTagSizeStyles,
6
7
  getTagStyles,
7
8
  mapLegacyTagProps,
8
9
  tagTones,
@@ -12,6 +13,7 @@ export type {
12
13
  TagColorPalette,
13
14
  TagOwnProps,
14
15
  TagProps,
16
+ TagSize,
15
17
  TagTone,
16
18
  TagVariant,
17
19
  } from './Tag.types';
@@ -249,6 +249,29 @@ const createSyntheticEvent = (
249
249
  };
250
250
  ```
251
251
 
252
+ ## Control sizes
253
+
254
+ Every control that takes `size` resolves it through **one** table,
255
+ `controlSizes` in `src/theme/controlSizes.ts` — height token, textStyle, icon
256
+ size, inline padding (action vs field ramp) and `CONTROL_RADIUS`. `Button` is
257
+ the reference. Recipe-driven controls get it from `src/theme/recipes/controls.ts`;
258
+ components with their own maps (SegmentedControl, interactive Tag, the date
259
+ pickers, MonthPicker) call `getControlSize(size)`.
260
+
261
+ - Never add a per-component height / font-size map. Read the scale.
262
+ - Control type must be the textStyle of the size, not a fixed `fontSize`:
263
+ inside a `ScaledContext` the sizes tokens are em and resolve against the
264
+ control's own type, so a different type means a different height.
265
+ - Overriding a Chakra **slot** recipe: pass the full anatomy
266
+ (`selectAnatomy.keys()` from `@chakra-ui/react/anatomy`), never a partial
267
+ `slots` list — Chakra merges arrays by index and drops slots.
268
+ - Keep `size` responsive (`ConditionalValue<…>`) where Chakra allowed it, and
269
+ resolve the scale per breakpoint — never collapse an object/array to `md`.
270
+ A composed sub-part with its own recipe type (e.g. `TagLabel` in an
271
+ interactive Tag) must inherit the control's type, not keep the badge's.
272
+ - `src/theme/controlSizes.test.ts` fails if a control stops resolving to the
273
+ scale; the Storybook page **Foundations / Control sizes** measures it live.
274
+
252
275
  ## Component Props Best Practices
253
276
 
254
277
  ### Default Values
package/src/index.ts CHANGED
@@ -163,6 +163,18 @@ export {
163
163
  SYSTEM_HUE_NAMES,
164
164
  type SystemHue,
165
165
  } from './theme/colors';
166
+ export {
167
+ CONTROL_RADIUS,
168
+ CONTROL_SIZES,
169
+ controlHeightToken,
170
+ controlHeightVar,
171
+ type ControlSize,
172
+ controlSizes,
173
+ type ControlSizeSpec,
174
+ CORE_CONTROL_SIZES,
175
+ type CoreControlSize,
176
+ getControlSize,
177
+ } from './theme/controlSizes';
166
178
  export { noZoomOnFocus } from './theme/formControls';
167
179
  export {
168
180
  animationStyles,