@karakuri-ui/react 0.3.6 → 0.3.8

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 (71) hide show
  1. package/dist/components/ui/accordion.d.mts +1 -1
  2. package/dist/components/ui/accordion.d.ts +1 -1
  3. package/dist/components/ui/alert.d.mts +2 -2
  4. package/dist/components/ui/alert.d.ts +2 -2
  5. package/dist/components/ui/avatar.d.mts +2 -2
  6. package/dist/components/ui/avatar.d.ts +2 -2
  7. package/dist/components/ui/badge.d.mts +1 -1
  8. package/dist/components/ui/badge.d.ts +1 -1
  9. package/dist/components/ui/button.d.mts +3 -3
  10. package/dist/components/ui/button.d.ts +3 -3
  11. package/dist/components/ui/card.d.mts +1 -1
  12. package/dist/components/ui/card.d.ts +1 -1
  13. package/dist/components/ui/checkbox.d.mts +1 -1
  14. package/dist/components/ui/checkbox.d.ts +1 -1
  15. package/dist/components/ui/divider.d.mts +1 -1
  16. package/dist/components/ui/divider.d.ts +1 -1
  17. package/dist/components/ui/field.d.mts +6 -1
  18. package/dist/components/ui/field.d.ts +6 -1
  19. package/dist/components/ui/field.js +22 -4
  20. package/dist/components/ui/field.js.map +1 -1
  21. package/dist/components/ui/field.mjs +22 -4
  22. package/dist/components/ui/field.mjs.map +1 -1
  23. package/dist/components/ui/icon-button.d.mts +2 -2
  24. package/dist/components/ui/icon-button.d.ts +2 -2
  25. package/dist/components/ui/input.d.mts +3 -3
  26. package/dist/components/ui/input.d.ts +3 -3
  27. package/dist/components/ui/input.js +2 -0
  28. package/dist/components/ui/input.js.map +1 -1
  29. package/dist/components/ui/input.mjs +2 -0
  30. package/dist/components/ui/input.mjs.map +1 -1
  31. package/dist/components/ui/metric-card.d.mts +2 -2
  32. package/dist/components/ui/metric-card.d.ts +2 -2
  33. package/dist/components/ui/popover.d.mts +1 -1
  34. package/dist/components/ui/popover.d.ts +1 -1
  35. package/dist/components/ui/progress.d.mts +1 -1
  36. package/dist/components/ui/progress.d.ts +1 -1
  37. package/dist/components/ui/radio-group.d.mts +1 -1
  38. package/dist/components/ui/radio-group.d.ts +1 -1
  39. package/dist/components/ui/radio-group.js +1 -0
  40. package/dist/components/ui/radio-group.js.map +1 -1
  41. package/dist/components/ui/radio-group.mjs +1 -0
  42. package/dist/components/ui/radio-group.mjs.map +1 -1
  43. package/dist/components/ui/segmented.d.mts +5 -5
  44. package/dist/components/ui/segmented.d.ts +5 -5
  45. package/dist/components/ui/select.js +1 -0
  46. package/dist/components/ui/select.js.map +1 -1
  47. package/dist/components/ui/select.mjs +1 -0
  48. package/dist/components/ui/select.mjs.map +1 -1
  49. package/dist/components/ui/slider.d.mts +1 -1
  50. package/dist/components/ui/slider.d.ts +1 -1
  51. package/dist/components/ui/spinner.d.mts +1 -1
  52. package/dist/components/ui/spinner.d.ts +1 -1
  53. package/dist/components/ui/switch.d.mts +1 -1
  54. package/dist/components/ui/switch.d.ts +1 -1
  55. package/dist/components/ui/tabs.d.mts +1 -1
  56. package/dist/components/ui/tabs.d.ts +1 -1
  57. package/dist/components/ui/textarea.d.mts +2 -2
  58. package/dist/components/ui/textarea.d.ts +2 -2
  59. package/dist/components/ui/textarea.js +1 -0
  60. package/dist/components/ui/textarea.js.map +1 -1
  61. package/dist/components/ui/textarea.mjs +1 -0
  62. package/dist/components/ui/textarea.mjs.map +1 -1
  63. package/dist/components/ui/toast.d.mts +1 -1
  64. package/dist/components/ui/toast.d.ts +1 -1
  65. package/dist/components/ui/toggle-group.d.mts +2 -2
  66. package/dist/components/ui/toggle-group.d.ts +2 -2
  67. package/dist/components/ui/toggle.d.mts +2 -2
  68. package/dist/components/ui/toggle.d.ts +2 -2
  69. package/dist/components/ui/tooltip.d.mts +1 -1
  70. package/dist/components/ui/tooltip.d.ts +1 -1
  71. package/package.json +3 -1
@@ -25,7 +25,7 @@ interface AccordionItemProps extends React.ComponentPropsWithoutRef<typeof Accor
25
25
  }
26
26
  declare const AccordionItem: React.ForwardRefExoticComponent<AccordionItemProps & React.RefAttributes<HTMLDivElement>>;
27
27
  declare const accordionTriggerVariants: (props?: ({
28
- size?: "default" | "sm" | "lg" | null | undefined;
28
+ size?: "sm" | "default" | "lg" | null | undefined;
29
29
  iconPosition?: "left" | "right" | null | undefined;
30
30
  } & class_variance_authority_types.ClassProp) | undefined) => string;
31
31
  interface AccordionTriggerProps extends React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger> {
@@ -25,7 +25,7 @@ interface AccordionItemProps extends React.ComponentPropsWithoutRef<typeof Accor
25
25
  }
26
26
  declare const AccordionItem: React.ForwardRefExoticComponent<AccordionItemProps & React.RefAttributes<HTMLDivElement>>;
27
27
  declare const accordionTriggerVariants: (props?: ({
28
- size?: "default" | "sm" | "lg" | null | undefined;
28
+ size?: "sm" | "default" | "lg" | null | undefined;
29
29
  iconPosition?: "left" | "right" | null | undefined;
30
30
  } & class_variance_authority_types.ClassProp) | undefined) => string;
31
31
  interface AccordionTriggerProps extends React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger> {
@@ -3,8 +3,8 @@ import * as React from 'react';
3
3
  import { VariantProps } from 'class-variance-authority';
4
4
 
5
5
  declare const alertVariants: (props?: ({
6
- size?: "default" | "sm" | "lg" | null | undefined;
7
- radius?: "sm" | "lg" | "base" | "none" | "md" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
6
+ size?: "sm" | "default" | "lg" | null | undefined;
7
+ radius?: "sm" | "lg" | "none" | "base" | "md" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
8
8
  } & class_variance_authority_types.ClassProp) | undefined) => string;
9
9
  type AlertVariant = 'default' | 'outline' | 'filled';
10
10
  type AlertColor = 'info' | 'success' | 'warning' | 'error';
@@ -3,8 +3,8 @@ import * as React from 'react';
3
3
  import { VariantProps } from 'class-variance-authority';
4
4
 
5
5
  declare const alertVariants: (props?: ({
6
- size?: "default" | "sm" | "lg" | null | undefined;
7
- radius?: "sm" | "lg" | "base" | "none" | "md" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
6
+ size?: "sm" | "default" | "lg" | null | undefined;
7
+ radius?: "sm" | "lg" | "none" | "base" | "md" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
8
8
  } & class_variance_authority_types.ClassProp) | undefined) => string;
9
9
  type AlertVariant = 'default' | 'outline' | 'filled';
10
10
  type AlertColor = 'info' | 'success' | 'warning' | 'error';
@@ -4,8 +4,8 @@ import * as AvatarPrimitive from '@radix-ui/react-avatar';
4
4
  import { VariantProps } from 'class-variance-authority';
5
5
 
6
6
  declare const avatarVariants: (props?: ({
7
- size?: "default" | "sm" | "lg" | "xl" | "2xl" | "xs" | null | undefined;
8
- shape?: "circle" | "square" | null | undefined;
7
+ size?: "sm" | "default" | "lg" | "xl" | "2xl" | "xs" | null | undefined;
8
+ shape?: "square" | "circle" | null | undefined;
9
9
  } & class_variance_authority_types.ClassProp) | undefined) => string;
10
10
  declare const avatarColors: readonly [{
11
11
  readonly vivid: {
@@ -4,8 +4,8 @@ import * as AvatarPrimitive from '@radix-ui/react-avatar';
4
4
  import { VariantProps } from 'class-variance-authority';
5
5
 
6
6
  declare const avatarVariants: (props?: ({
7
- size?: "default" | "sm" | "lg" | "xl" | "2xl" | "xs" | null | undefined;
8
- shape?: "circle" | "square" | null | undefined;
7
+ size?: "sm" | "default" | "lg" | "xl" | "2xl" | "xs" | null | undefined;
8
+ shape?: "square" | "circle" | null | undefined;
9
9
  } & class_variance_authority_types.ClassProp) | undefined) => string;
10
10
  declare const avatarColors: readonly [{
11
11
  readonly vivid: {
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { VariantProps } from 'class-variance-authority';
4
4
 
5
5
  declare const badgeVariants: (props?: ({
6
- size?: "default" | "sm" | "lg" | null | undefined;
6
+ size?: "sm" | "default" | "lg" | null | undefined;
7
7
  radius?: "sm" | "lg" | "base" | "md" | "full" | null | undefined;
8
8
  } & class_variance_authority_types.ClassProp) | undefined) => string;
9
9
  type BadgeVariant = 'solid' | 'subtle' | 'outline';
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { VariantProps } from 'class-variance-authority';
4
4
 
5
5
  declare const badgeVariants: (props?: ({
6
- size?: "default" | "sm" | "lg" | null | undefined;
6
+ size?: "sm" | "default" | "lg" | null | undefined;
7
7
  radius?: "sm" | "lg" | "base" | "md" | "full" | null | undefined;
8
8
  } & class_variance_authority_types.ClassProp) | undefined) => string;
9
9
  type BadgeVariant = 'solid' | 'subtle' | 'outline';
@@ -10,9 +10,9 @@ declare const solidColorMap: {
10
10
  };
11
11
  type ButtonColor = keyof typeof solidColorMap;
12
12
  declare const buttonVariants: (props?: ({
13
- variant?: "link" | "outline" | "solid" | "ghost" | null | undefined;
14
- size?: "default" | "sm" | "lg" | "icon" | "md" | "xs" | null | undefined;
15
- radius?: "default" | "sm" | "lg" | "base" | "none" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
13
+ variant?: "outline" | "link" | "solid" | "ghost" | null | undefined;
14
+ size?: "sm" | "default" | "lg" | "md" | "icon" | "xs" | null | undefined;
15
+ radius?: "sm" | "default" | "lg" | "none" | "base" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
16
16
  fullWidth?: boolean | null | undefined;
17
17
  } & class_variance_authority_types.ClassProp) | undefined) => string;
18
18
  interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
@@ -10,9 +10,9 @@ declare const solidColorMap: {
10
10
  };
11
11
  type ButtonColor = keyof typeof solidColorMap;
12
12
  declare const buttonVariants: (props?: ({
13
- variant?: "link" | "outline" | "solid" | "ghost" | null | undefined;
14
- size?: "default" | "sm" | "lg" | "icon" | "md" | "xs" | null | undefined;
15
- radius?: "default" | "sm" | "lg" | "base" | "none" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
13
+ variant?: "outline" | "link" | "solid" | "ghost" | null | undefined;
14
+ size?: "sm" | "default" | "lg" | "md" | "icon" | "xs" | null | undefined;
15
+ radius?: "sm" | "default" | "lg" | "none" | "base" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
16
16
  fullWidth?: boolean | null | undefined;
17
17
  } & class_variance_authority_types.ClassProp) | undefined) => string;
18
18
  interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
@@ -6,7 +6,7 @@ type CardSize = 'sm' | 'default' | 'lg';
6
6
  type CardDirection = 'vertical' | 'horizontal';
7
7
  declare const cardVariants: (props?: ({
8
8
  variant?: "default" | "outline" | "ghost" | null | undefined;
9
- size?: "default" | "sm" | "lg" | null | undefined;
9
+ size?: "sm" | "default" | "lg" | null | undefined;
10
10
  radius?: "sm" | "lg" | "base" | "md" | "xl" | "2xl" | null | undefined;
11
11
  direction?: "horizontal" | "vertical" | null | undefined;
12
12
  } & class_variance_authority_types.ClassProp) | undefined) => string;
@@ -6,7 +6,7 @@ type CardSize = 'sm' | 'default' | 'lg';
6
6
  type CardDirection = 'vertical' | 'horizontal';
7
7
  declare const cardVariants: (props?: ({
8
8
  variant?: "default" | "outline" | "ghost" | null | undefined;
9
- size?: "default" | "sm" | "lg" | null | undefined;
9
+ size?: "sm" | "default" | "lg" | null | undefined;
10
10
  radius?: "sm" | "lg" | "base" | "md" | "xl" | "2xl" | null | undefined;
11
11
  direction?: "horizontal" | "vertical" | null | undefined;
12
12
  } & class_variance_authority_types.ClassProp) | undefined) => string;
@@ -9,7 +9,7 @@ declare const checkboxColorMap: {
9
9
  };
10
10
  type CheckboxColor = keyof typeof checkboxColorMap;
11
11
  declare const checkboxVariants: (props?: ({
12
- size?: "default" | "sm" | "lg" | null | undefined;
12
+ size?: "sm" | "default" | "lg" | null | undefined;
13
13
  radius?: "sm" | "none" | "md" | null | undefined;
14
14
  weight?: "bold" | "thin" | null | undefined;
15
15
  } & class_variance_authority_types.ClassProp) | undefined) => string;
@@ -9,7 +9,7 @@ declare const checkboxColorMap: {
9
9
  };
10
10
  type CheckboxColor = keyof typeof checkboxColorMap;
11
11
  declare const checkboxVariants: (props?: ({
12
- size?: "default" | "sm" | "lg" | null | undefined;
12
+ size?: "sm" | "default" | "lg" | null | undefined;
13
13
  radius?: "sm" | "none" | "md" | null | undefined;
14
14
  weight?: "bold" | "thin" | null | undefined;
15
15
  } & class_variance_authority_types.ClassProp) | undefined) => string;
@@ -6,7 +6,7 @@ declare const dividerVariants: (props?: ({
6
6
  orientation?: "horizontal" | "vertical" | null | undefined;
7
7
  variant?: "solid" | "dashed" | "dotted" | null | undefined;
8
8
  color?: "default" | "strong" | "muted" | null | undefined;
9
- spacing?: "default" | "sm" | "lg" | "md" | null | undefined;
9
+ spacing?: "sm" | "default" | "lg" | "md" | null | undefined;
10
10
  } & class_variance_authority_types.ClassProp) | undefined) => string;
11
11
  interface DividerProps extends Omit<React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>, 'children' | 'color' | 'orientation'> {
12
12
  /** Direction of the divider */
@@ -6,7 +6,7 @@ declare const dividerVariants: (props?: ({
6
6
  orientation?: "horizontal" | "vertical" | null | undefined;
7
7
  variant?: "solid" | "dashed" | "dotted" | null | undefined;
8
8
  color?: "default" | "strong" | "muted" | null | undefined;
9
- spacing?: "default" | "sm" | "lg" | "md" | null | undefined;
9
+ spacing?: "sm" | "default" | "lg" | "md" | null | undefined;
10
10
  } & class_variance_authority_types.ClassProp) | undefined) => string;
11
11
  interface DividerProps extends Omit<React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>, 'children' | 'color' | 'orientation'> {
12
12
  /** Direction of the divider */
@@ -12,14 +12,17 @@ interface FieldContextValue {
12
12
  hasLabel: boolean;
13
13
  /** The Field holds labelled checkboxes / switches / a radio group and no single input */
14
14
  isGroup: boolean;
15
+ /** The FieldLabel is marked required; single controls set aria-required */
16
+ required: boolean;
15
17
  registerLabel: () => () => void;
18
+ registerRequired: () => () => void;
16
19
  registerControl: (kind: FieldControlKind) => () => void;
17
20
  }
18
21
  type FieldControlKind = 'single' | 'group' | 'labelled';
19
22
  declare function useFieldContext(): FieldContextValue | null;
20
23
  declare function useFieldControl(kind: FieldControlKind, enabled: boolean): void;
21
24
  declare const fieldVariants: (props?: ({
22
- gap?: "default" | "sm" | "lg" | "none" | "xs" | null | undefined;
25
+ gap?: "sm" | "default" | "lg" | "none" | "xs" | null | undefined;
23
26
  } & class_variance_authority_types.ClassProp) | undefined) => string;
24
27
  interface FieldProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof fieldVariants> {
25
28
  error?: boolean;
@@ -28,6 +31,8 @@ interface FieldProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<
28
31
  declare const Field: React.ForwardRefExoticComponent<FieldProps & React.RefAttributes<HTMLDivElement>>;
29
32
  interface FieldLabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> {
30
33
  required?: boolean;
34
+ /** Text of the required badge shown when `required` is set */
35
+ requiredLabel?: React.ReactNode;
31
36
  }
32
37
  declare const FieldLabel: React.ForwardRefExoticComponent<FieldLabelProps & React.RefAttributes<HTMLLabelElement>>;
33
38
  declare const FieldError: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
@@ -12,14 +12,17 @@ interface FieldContextValue {
12
12
  hasLabel: boolean;
13
13
  /** The Field holds labelled checkboxes / switches / a radio group and no single input */
14
14
  isGroup: boolean;
15
+ /** The FieldLabel is marked required; single controls set aria-required */
16
+ required: boolean;
15
17
  registerLabel: () => () => void;
18
+ registerRequired: () => () => void;
16
19
  registerControl: (kind: FieldControlKind) => () => void;
17
20
  }
18
21
  type FieldControlKind = 'single' | 'group' | 'labelled';
19
22
  declare function useFieldContext(): FieldContextValue | null;
20
23
  declare function useFieldControl(kind: FieldControlKind, enabled: boolean): void;
21
24
  declare const fieldVariants: (props?: ({
22
- gap?: "default" | "sm" | "lg" | "none" | "xs" | null | undefined;
25
+ gap?: "sm" | "default" | "lg" | "none" | "xs" | null | undefined;
23
26
  } & class_variance_authority_types.ClassProp) | undefined) => string;
24
27
  interface FieldProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof fieldVariants> {
25
28
  error?: boolean;
@@ -28,6 +31,8 @@ interface FieldProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<
28
31
  declare const Field: React.ForwardRefExoticComponent<FieldProps & React.RefAttributes<HTMLDivElement>>;
29
32
  interface FieldLabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> {
30
33
  required?: boolean;
34
+ /** Text of the required badge shown when `required` is set */
35
+ requiredLabel?: React.ReactNode;
31
36
  }
32
37
  declare const FieldLabel: React.ForwardRefExoticComponent<FieldLabelProps & React.RefAttributes<HTMLLabelElement>>;
33
38
  declare const FieldError: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
@@ -72,21 +72,27 @@ const Field = React.forwardRef(
72
72
  const id = React.useId();
73
73
  const labelId = `${id}-label`;
74
74
  const [labelCount, setLabelCount] = React.useState(0);
75
+ const [requiredCount, setRequiredCount] = React.useState(0);
75
76
  const [counts, setCounts] = React.useState({ single: 0, group: 0, labelled: 0 });
76
77
  const registerLabel = React.useCallback(() => {
77
78
  setLabelCount((n) => n + 1);
78
79
  return () => setLabelCount((n) => n - 1);
79
80
  }, []);
81
+ const registerRequired = React.useCallback(() => {
82
+ setRequiredCount((n) => n + 1);
83
+ return () => setRequiredCount((n) => n - 1);
84
+ }, []);
80
85
  const registerControl = React.useCallback((kind) => {
81
86
  setCounts((c) => ({ ...c, [kind]: c[kind] + 1 }));
82
87
  return () => setCounts((c) => ({ ...c, [kind]: c[kind] - 1 }));
83
88
  }, []);
84
89
  const hasLabel = labelCount > 0;
90
+ const required = requiredCount > 0;
85
91
  const isGroup = counts.single === 0 && (counts.group > 0 || counts.labelled > 0);
86
92
  const asGroup = counts.single === 0 && counts.group > 0;
87
93
  const contextValue = React.useMemo(
88
- () => ({ id, labelId, error, disabled, hasLabel, isGroup, registerLabel, registerControl }),
89
- [id, labelId, error, disabled, hasLabel, isGroup, registerLabel, registerControl]
94
+ () => ({ id, labelId, error, disabled, hasLabel, isGroup, required, registerLabel, registerRequired, registerControl }),
95
+ [id, labelId, error, disabled, hasLabel, isGroup, required, registerLabel, registerRequired, registerControl]
90
96
  );
91
97
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FieldContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
92
98
  "div",
@@ -105,10 +111,12 @@ const Field = React.forwardRef(
105
111
  );
106
112
  Field.displayName = "Field";
107
113
  const FieldLabel = React.forwardRef(
108
- ({ className, required, children, ...props }, ref) => {
114
+ ({ className, required, requiredLabel = "\u5FC5\u9808", children, ...props }, ref) => {
109
115
  const context = useFieldContext();
110
116
  const registerLabel = context?.registerLabel;
111
117
  React.useEffect(() => registerLabel?.(), [registerLabel]);
118
+ const registerRequired = context?.registerRequired;
119
+ React.useEffect(() => required ? registerRequired?.() : void 0, [required, registerRequired]);
112
120
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
113
121
  "label",
114
122
  {
@@ -124,7 +132,17 @@ const FieldLabel = React.forwardRef(
124
132
  ...props,
125
133
  children: [
126
134
  children,
127
- required && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-error ml-0.5", children: "*" })
135
+ required && // Neutral badge, not the error color: red stays reserved for errors.
136
+ // Inside a Field the single control carries aria-required, so the badge is hidden
137
+ // from assistive technology there to avoid announcing "required" twice.
138
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
139
+ "span",
140
+ {
141
+ "aria-hidden": context && !context.isGroup ? true : void 0,
142
+ className: "ml-1.5 inline-flex h-5 items-center rounded px-1.5 align-middle text-2xs font-semibold whitespace-nowrap bg-background-muted text-text-muted",
143
+ children: requiredLabel
144
+ }
145
+ )
128
146
  ]
129
147
  }
130
148
  );
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/ui/field.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport { cn } from '../../lib/utils'\n\n// Field Context for sharing state between components\ninterface FieldContextValue {\n id: string\n /** id of the FieldLabel, for aria-labelledby on grouped controls */\n labelId: string\n error?: boolean\n disabled?: boolean\n /** A FieldLabel is rendered inside this Field */\n hasLabel: boolean\n /** The Field holds labelled checkboxes / switches / a radio group and no single input */\n isGroup: boolean\n registerLabel: () => () => void\n registerControl: (kind: FieldControlKind) => () => void\n}\n\ntype FieldControlKind = 'single' | 'group' | 'labelled'\n\nconst FieldContext = React.createContext<FieldContextValue | null>(null)\n\nfunction useFieldContext() {\n return React.useContext(FieldContext)\n}\n\n// Controls tell their Field what they are, so FieldLabel can point at the right thing.\n// 'single': one input that takes the Field id (Input, Textarea, a bare Checkbox / Switch);\n// FieldLabel targets it with htmlFor.\n// 'group': a Checkbox / Switch with its own label keeps a unique id; the Field becomes\n// role=\"group\" named by FieldLabel instead of every item sharing one id.\n// 'labelled': a RadioGroup names itself from FieldLabel (aria-labelledby).\n// A single input wins: with one present, FieldLabel keeps pointing at it.\nfunction useFieldControl(kind: FieldControlKind, enabled: boolean) {\n const context = useFieldContext()\n const register = context?.registerControl\n React.useEffect(() => {\n if (!enabled || !register) return\n return register(kind)\n }, [enabled, register, kind])\n}\n\n// Field wrapper\nconst fieldVariants = cva('flex flex-col', {\n variants: {\n gap: {\n none: 'gap-0',\n xs: 'gap-1',\n sm: 'gap-1.5',\n default: 'gap-2',\n lg: 'gap-3',\n },\n },\n defaultVariants: {\n gap: 'default',\n },\n})\n\nexport interface FieldProps\n extends React.HTMLAttributes<HTMLDivElement>,\n VariantProps<typeof fieldVariants> {\n error?: boolean\n disabled?: boolean\n}\n\nconst Field = React.forwardRef<HTMLDivElement, FieldProps>(\n ({ className, gap, error, disabled, children, ...props }, ref) => {\n const id = React.useId()\n const labelId = `${id}-label`\n const [labelCount, setLabelCount] = React.useState(0)\n const [counts, setCounts] = React.useState({ single: 0, group: 0, labelled: 0 })\n\n const registerLabel = React.useCallback(() => {\n setLabelCount((n) => n + 1)\n return () => setLabelCount((n) => n - 1)\n }, [])\n const registerControl = React.useCallback((kind: FieldControlKind) => {\n setCounts((c) => ({ ...c, [kind]: c[kind] + 1 }))\n return () => setCounts((c) => ({ ...c, [kind]: c[kind] - 1 }))\n }, [])\n\n const hasLabel = labelCount > 0\n const isGroup = counts.single === 0 && (counts.group > 0 || counts.labelled > 0)\n const asGroup = counts.single === 0 && counts.group > 0\n const contextValue = React.useMemo(\n () => ({ id, labelId, error, disabled, hasLabel, isGroup, registerLabel, registerControl }),\n [id, labelId, error, disabled, hasLabel, isGroup, registerLabel, registerControl]\n )\n\n return (\n <FieldContext.Provider value={contextValue}>\n <div\n ref={ref}\n role={asGroup ? 'group' : undefined}\n aria-labelledby={asGroup && hasLabel ? labelId : undefined}\n className={cn(fieldVariants({ gap }), className)}\n data-error={error || undefined}\n data-disabled={disabled || undefined}\n {...props}\n >\n {children}\n </div>\n </FieldContext.Provider>\n )\n }\n)\nField.displayName = 'Field'\n\n// Field Label\nexport interface FieldLabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> {\n required?: boolean\n}\n\nconst FieldLabel = React.forwardRef<HTMLLabelElement, FieldLabelProps>(\n ({ className, required, children, ...props }, ref) => {\n const context = useFieldContext()\n const registerLabel = context?.registerLabel\n React.useEffect(() => registerLabel?.(), [registerLabel])\n\n return (\n <label\n ref={ref}\n id={context?.labelId}\n // Grouped controls have their own labels; the group title targets no input\n htmlFor={context && !context.isGroup ? context.id : undefined}\n className={cn(\n 'text-md font-semibold text-foreground', // 14px - primary field identifier\n context?.disabled && 'opacity-50 cursor-not-allowed',\n className\n )}\n {...props}\n >\n {children}\n {required && <span className=\"text-error ml-0.5\">*</span>}\n </label>\n )\n }\n)\nFieldLabel.displayName = 'FieldLabel'\n\n// Field Error\nconst FieldError = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, children, ...props }, ref) => {\n const context = useFieldContext()\n\n if (!children) return null\n\n return (\n <p\n ref={ref}\n id={context ? `${context.id}-error` : undefined}\n role=\"alert\"\n className={cn('text-xs text-error pl-1', className)} // 12px - color-distinguished, left-aligned with input text\n {...props}\n >\n {children}\n </p>\n )\n})\nFieldError.displayName = 'FieldError'\n\n// Field Character Count\nconst FieldCharCount = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\n const context = useFieldContext()\n\n return (\n <p\n ref={ref}\n id={context ? `${context.id}-charcount` : undefined}\n className={cn(\n 'text-xs text-text-muted text-right pr-1 -mt-1', // 12px - right-aligned, 4px gap from input (gap-2 8px - mt-1 4px)\n context?.disabled && 'opacity-50',\n className\n )}\n {...props}\n />\n )\n})\nFieldCharCount.displayName = 'FieldCharCount'\n\nexport { Field, FieldLabel, FieldError, FieldCharCount, useFieldContext, useFieldControl }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8FQ;AA5FR,YAAuB;AACvB,sCAAuC;AACvC,mBAAmB;AAmBnB,MAAM,eAAe,MAAM,cAAwC,IAAI;AAEvE,SAAS,kBAAkB;AACzB,SAAO,MAAM,WAAW,YAAY;AACtC;AASA,SAAS,gBAAgB,MAAwB,SAAkB;AACjE,QAAM,UAAU,gBAAgB;AAChC,QAAM,WAAW,SAAS;AAC1B,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,WAAW,CAAC,SAAU;AAC3B,WAAO,SAAS,IAAI;AAAA,EACtB,GAAG,CAAC,SAAS,UAAU,IAAI,CAAC;AAC9B;AAGA,MAAM,oBAAgB,qCAAI,iBAAiB;AAAA,EACzC,UAAU;AAAA,IACR,KAAK;AAAA,MACH,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,SAAS;AAAA,MACT,IAAI;AAAA,IACN;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,KAAK;AAAA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AC;AAAA;AAAA,MACC;AAAA,MACA,IAAI,UAAU,GAAG,QAAQ,EAAE,eAAe;AAAA,MAC1C,eAAW;AAAA,QACT;AAAA;AAAA,QACA,SAAS,YAAY;AAAA,QACrB;AAAA,MACF;AAAA,MACC,GAAG;AAAA;AAAA,EACN;AAEJ,CAAC;AACD,eAAe,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/ui/field.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport { cn } from '../../lib/utils'\n\n// Field Context for sharing state between components\ninterface FieldContextValue {\n id: string\n /** id of the FieldLabel, for aria-labelledby on grouped controls */\n labelId: string\n error?: boolean\n disabled?: boolean\n /** A FieldLabel is rendered inside this Field */\n hasLabel: boolean\n /** The Field holds labelled checkboxes / switches / a radio group and no single input */\n isGroup: boolean\n /** The FieldLabel is marked required; single controls set aria-required */\n required: boolean\n registerLabel: () => () => void\n registerRequired: () => () => void\n registerControl: (kind: FieldControlKind) => () => void\n}\n\ntype FieldControlKind = 'single' | 'group' | 'labelled'\n\nconst FieldContext = React.createContext<FieldContextValue | null>(null)\n\nfunction useFieldContext() {\n return React.useContext(FieldContext)\n}\n\n// Controls tell their Field what they are, so FieldLabel can point at the right thing.\n// 'single': one input that takes the Field id (Input, Textarea, a bare Checkbox / Switch);\n// FieldLabel targets it with htmlFor.\n// 'group': a Checkbox / Switch with its own label keeps a unique id; the Field becomes\n// role=\"group\" named by FieldLabel instead of every item sharing one id.\n// 'labelled': a RadioGroup names itself from FieldLabel (aria-labelledby).\n// A single input wins: with one present, FieldLabel keeps pointing at it.\nfunction useFieldControl(kind: FieldControlKind, enabled: boolean) {\n const context = useFieldContext()\n const register = context?.registerControl\n React.useEffect(() => {\n if (!enabled || !register) return\n return register(kind)\n }, [enabled, register, kind])\n}\n\n// Field wrapper\nconst fieldVariants = cva('flex flex-col', {\n variants: {\n gap: {\n none: 'gap-0',\n xs: 'gap-1',\n sm: 'gap-1.5',\n default: 'gap-2',\n lg: 'gap-3',\n },\n },\n defaultVariants: {\n gap: 'default',\n },\n})\n\nexport interface FieldProps\n extends React.HTMLAttributes<HTMLDivElement>,\n VariantProps<typeof fieldVariants> {\n error?: boolean\n disabled?: boolean\n}\n\nconst Field = React.forwardRef<HTMLDivElement, FieldProps>(\n ({ className, gap, error, disabled, children, ...props }, ref) => {\n const id = React.useId()\n const labelId = `${id}-label`\n const [labelCount, setLabelCount] = React.useState(0)\n const [requiredCount, setRequiredCount] = React.useState(0)\n const [counts, setCounts] = React.useState({ single: 0, group: 0, labelled: 0 })\n\n const registerLabel = React.useCallback(() => {\n setLabelCount((n) => n + 1)\n return () => setLabelCount((n) => n - 1)\n }, [])\n const registerRequired = React.useCallback(() => {\n setRequiredCount((n) => n + 1)\n return () => setRequiredCount((n) => n - 1)\n }, [])\n const registerControl = React.useCallback((kind: FieldControlKind) => {\n setCounts((c) => ({ ...c, [kind]: c[kind] + 1 }))\n return () => setCounts((c) => ({ ...c, [kind]: c[kind] - 1 }))\n }, [])\n\n const hasLabel = labelCount > 0\n const required = requiredCount > 0\n const isGroup = counts.single === 0 && (counts.group > 0 || counts.labelled > 0)\n const asGroup = counts.single === 0 && counts.group > 0\n const contextValue = React.useMemo(\n () => ({ id, labelId, error, disabled, hasLabel, isGroup, required, registerLabel, registerRequired, registerControl }),\n [id, labelId, error, disabled, hasLabel, isGroup, required, registerLabel, registerRequired, registerControl]\n )\n\n return (\n <FieldContext.Provider value={contextValue}>\n <div\n ref={ref}\n role={asGroup ? 'group' : undefined}\n aria-labelledby={asGroup && hasLabel ? labelId : undefined}\n className={cn(fieldVariants({ gap }), className)}\n data-error={error || undefined}\n data-disabled={disabled || undefined}\n {...props}\n >\n {children}\n </div>\n </FieldContext.Provider>\n )\n }\n)\nField.displayName = 'Field'\n\n// Field Label\nexport interface FieldLabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> {\n required?: boolean\n /** Text of the required badge shown when `required` is set */\n requiredLabel?: React.ReactNode\n}\n\nconst FieldLabel = React.forwardRef<HTMLLabelElement, FieldLabelProps>(\n ({ className, required, requiredLabel = '必須', children, ...props }, ref) => {\n const context = useFieldContext()\n const registerLabel = context?.registerLabel\n React.useEffect(() => registerLabel?.(), [registerLabel])\n const registerRequired = context?.registerRequired\n React.useEffect(() => (required ? registerRequired?.() : undefined), [required, registerRequired])\n\n return (\n <label\n ref={ref}\n id={context?.labelId}\n // Grouped controls have their own labels; the group title targets no input\n htmlFor={context && !context.isGroup ? context.id : undefined}\n className={cn(\n 'text-md font-semibold text-foreground', // 14px - primary field identifier\n context?.disabled && 'opacity-50 cursor-not-allowed',\n className\n )}\n {...props}\n >\n {children}\n {required && (\n // Neutral badge, not the error color: red stays reserved for errors.\n // Inside a Field the single control carries aria-required, so the badge is hidden\n // from assistive technology there to avoid announcing \"required\" twice.\n <span\n aria-hidden={context && !context.isGroup ? true : undefined}\n className=\"ml-1.5 inline-flex h-5 items-center rounded px-1.5 align-middle text-2xs font-semibold whitespace-nowrap bg-background-muted text-text-muted\"\n >\n {requiredLabel}\n </span>\n )}\n </label>\n )\n }\n)\nFieldLabel.displayName = 'FieldLabel'\n\n// Field Error\nconst FieldError = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, children, ...props }, ref) => {\n const context = useFieldContext()\n\n if (!children) return null\n\n return (\n <p\n ref={ref}\n id={context ? `${context.id}-error` : undefined}\n role=\"alert\"\n className={cn('text-xs text-error pl-1', className)} // 12px - color-distinguished, left-aligned with input text\n {...props}\n >\n {children}\n </p>\n )\n})\nFieldError.displayName = 'FieldError'\n\n// Field Character Count\nconst FieldCharCount = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\n const context = useFieldContext()\n\n return (\n <p\n ref={ref}\n id={context ? `${context.id}-charcount` : undefined}\n className={cn(\n 'text-xs text-text-muted text-right pr-1 -mt-1', // 12px - right-aligned, 4px gap from input (gap-2 8px - mt-1 4px)\n context?.disabled && 'opacity-50',\n className\n )}\n {...props}\n />\n )\n})\nFieldCharCount.displayName = 'FieldCharCount'\n\nexport { Field, FieldLabel, FieldError, FieldCharCount, useFieldContext, useFieldControl }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuGQ;AArGR,YAAuB;AACvB,sCAAuC;AACvC,mBAAmB;AAsBnB,MAAM,eAAe,MAAM,cAAwC,IAAI;AAEvE,SAAS,kBAAkB;AACzB,SAAO,MAAM,WAAW,YAAY;AACtC;AASA,SAAS,gBAAgB,MAAwB,SAAkB;AACjE,QAAM,UAAU,gBAAgB;AAChC,QAAM,WAAW,SAAS;AAC1B,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,WAAW,CAAC,SAAU;AAC3B,WAAO,SAAS,IAAI;AAAA,EACtB,GAAG,CAAC,SAAS,UAAU,IAAI,CAAC;AAC9B;AAGA,MAAM,oBAAgB,qCAAI,iBAAiB;AAAA,EACzC,UAAU;AAAA,IACR,KAAK;AAAA,MACH,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,SAAS;AAAA,MACT,IAAI;AAAA,IACN;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,KAAK;AAAA,EACP;AACF,CAAC;AASD,MAAM,QAAQ,MAAM;AAAA,EAClB,CAAC,EAAE,WAAW,KAAK,OAAO,UAAU,UAAU,GAAG,MAAM,GAAG,QAAQ;AAChE,UAAM,KAAK,MAAM,MAAM;AACvB,UAAM,UAAU,GAAG,EAAE;AACrB,UAAM,CAAC,YAAY,aAAa,IAAI,MAAM,SAAS,CAAC;AACpD,UAAM,CAAC,eAAe,gBAAgB,IAAI,MAAM,SAAS,CAAC;AAC1D,UAAM,CAAC,QAAQ,SAAS,IAAI,MAAM,SAAS,EAAE,QAAQ,GAAG,OAAO,GAAG,U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MAAM,iBAAiB,MAAM,WAG3B,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ;AAClC,QAAM,UAAU,gBAAgB;AAEhC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,IAAI,UAAU,GAAG,QAAQ,EAAE,eAAe;AAAA,MAC1C,eAAW;AAAA,QACT;AAAA;AAAA,QACA,SAAS,YAAY;AAAA,QACrB;AAAA,MACF;AAAA,MACC,GAAG;AAAA;AAAA,EACN;AAEJ,CAAC;AACD,eAAe,cAAc;","names":[]}
@@ -34,21 +34,27 @@ const Field = React.forwardRef(
34
34
  const id = React.useId();
35
35
  const labelId = `${id}-label`;
36
36
  const [labelCount, setLabelCount] = React.useState(0);
37
+ const [requiredCount, setRequiredCount] = React.useState(0);
37
38
  const [counts, setCounts] = React.useState({ single: 0, group: 0, labelled: 0 });
38
39
  const registerLabel = React.useCallback(() => {
39
40
  setLabelCount((n) => n + 1);
40
41
  return () => setLabelCount((n) => n - 1);
41
42
  }, []);
43
+ const registerRequired = React.useCallback(() => {
44
+ setRequiredCount((n) => n + 1);
45
+ return () => setRequiredCount((n) => n - 1);
46
+ }, []);
42
47
  const registerControl = React.useCallback((kind) => {
43
48
  setCounts((c) => ({ ...c, [kind]: c[kind] + 1 }));
44
49
  return () => setCounts((c) => ({ ...c, [kind]: c[kind] - 1 }));
45
50
  }, []);
46
51
  const hasLabel = labelCount > 0;
52
+ const required = requiredCount > 0;
47
53
  const isGroup = counts.single === 0 && (counts.group > 0 || counts.labelled > 0);
48
54
  const asGroup = counts.single === 0 && counts.group > 0;
49
55
  const contextValue = React.useMemo(
50
- () => ({ id, labelId, error, disabled, hasLabel, isGroup, registerLabel, registerControl }),
51
- [id, labelId, error, disabled, hasLabel, isGroup, registerLabel, registerControl]
56
+ () => ({ id, labelId, error, disabled, hasLabel, isGroup, required, registerLabel, registerRequired, registerControl }),
57
+ [id, labelId, error, disabled, hasLabel, isGroup, required, registerLabel, registerRequired, registerControl]
52
58
  );
53
59
  return /* @__PURE__ */ jsx(FieldContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
54
60
  "div",
@@ -67,10 +73,12 @@ const Field = React.forwardRef(
67
73
  );
68
74
  Field.displayName = "Field";
69
75
  const FieldLabel = React.forwardRef(
70
- ({ className, required, children, ...props }, ref) => {
76
+ ({ className, required, requiredLabel = "\u5FC5\u9808", children, ...props }, ref) => {
71
77
  const context = useFieldContext();
72
78
  const registerLabel = context?.registerLabel;
73
79
  React.useEffect(() => registerLabel?.(), [registerLabel]);
80
+ const registerRequired = context?.registerRequired;
81
+ React.useEffect(() => required ? registerRequired?.() : void 0, [required, registerRequired]);
74
82
  return /* @__PURE__ */ jsxs(
75
83
  "label",
76
84
  {
@@ -86,7 +94,17 @@ const FieldLabel = React.forwardRef(
86
94
  ...props,
87
95
  children: [
88
96
  children,
89
- required && /* @__PURE__ */ jsx("span", { className: "text-error ml-0.5", children: "*" })
97
+ required && // Neutral badge, not the error color: red stays reserved for errors.
98
+ // Inside a Field the single control carries aria-required, so the badge is hidden
99
+ // from assistive technology there to avoid announcing "required" twice.
100
+ /* @__PURE__ */ jsx(
101
+ "span",
102
+ {
103
+ "aria-hidden": context && !context.isGroup ? true : void 0,
104
+ className: "ml-1.5 inline-flex h-5 items-center rounded px-1.5 align-middle text-2xs font-semibold whitespace-nowrap bg-background-muted text-text-muted",
105
+ children: requiredLabel
106
+ }
107
+ )
90
108
  ]
91
109
  }
92
110
  );
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/ui/field.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport { cn } from '../../lib/utils'\n\n// Field Context for sharing state between components\ninterface FieldContextValue {\n id: string\n /** id of the FieldLabel, for aria-labelledby on grouped controls */\n labelId: string\n error?: boolean\n disabled?: boolean\n /** A FieldLabel is rendered inside this Field */\n hasLabel: boolean\n /** The Field holds labelled checkboxes / switches / a radio group and no single input */\n isGroup: boolean\n registerLabel: () => () => void\n registerControl: (kind: FieldControlKind) => () => void\n}\n\ntype FieldControlKind = 'single' | 'group' | 'labelled'\n\nconst FieldContext = React.createContext<FieldContextValue | null>(null)\n\nfunction useFieldContext() {\n return React.useContext(FieldContext)\n}\n\n// Controls tell their Field what they are, so FieldLabel can point at the right thing.\n// 'single': one input that takes the Field id (Input, Textarea, a bare Checkbox / Switch);\n// FieldLabel targets it with htmlFor.\n// 'group': a Checkbox / Switch with its own label keeps a unique id; the Field becomes\n// role=\"group\" named by FieldLabel instead of every item sharing one id.\n// 'labelled': a RadioGroup names itself from FieldLabel (aria-labelledby).\n// A single input wins: with one present, FieldLabel keeps pointing at it.\nfunction useFieldControl(kind: FieldControlKind, enabled: boolean) {\n const context = useFieldContext()\n const register = context?.registerControl\n React.useEffect(() => {\n if (!enabled || !register) return\n return register(kind)\n }, [enabled, register, kind])\n}\n\n// Field wrapper\nconst fieldVariants = cva('flex flex-col', {\n variants: {\n gap: {\n none: 'gap-0',\n xs: 'gap-1',\n sm: 'gap-1.5',\n default: 'gap-2',\n lg: 'gap-3',\n },\n },\n defaultVariants: {\n gap: 'default',\n },\n})\n\nexport interface FieldProps\n extends React.HTMLAttributes<HTMLDivElement>,\n VariantProps<typeof fieldVariants> {\n error?: boolean\n disabled?: boolean\n}\n\nconst Field = React.forwardRef<HTMLDivElement, FieldProps>(\n ({ className, gap, error, disabled, children, ...props }, ref) => {\n const id = React.useId()\n const labelId = `${id}-label`\n const [labelCount, setLabelCount] = React.useState(0)\n const [counts, setCounts] = React.useState({ single: 0, group: 0, labelled: 0 })\n\n const registerLabel = React.useCallback(() => {\n setLabelCount((n) => n + 1)\n return () => setLabelCount((n) => n - 1)\n }, [])\n const registerControl = React.useCallback((kind: FieldControlKind) => {\n setCounts((c) => ({ ...c, [kind]: c[kind] + 1 }))\n return () => setCounts((c) => ({ ...c, [kind]: c[kind] - 1 }))\n }, [])\n\n const hasLabel = labelCount > 0\n const isGroup = counts.single === 0 && (counts.group > 0 || counts.labelled > 0)\n const asGroup = counts.single === 0 && counts.group > 0\n const contextValue = React.useMemo(\n () => ({ id, labelId, error, disabled, hasLabel, isGroup, registerLabel, registerControl }),\n [id, labelId, error, disabled, hasLabel, isGroup, registerLabel, registerControl]\n )\n\n return (\n <FieldContext.Provider value={contextValue}>\n <div\n ref={ref}\n role={asGroup ? 'group' : undefined}\n aria-labelledby={asGroup && hasLabel ? labelId : undefined}\n className={cn(fieldVariants({ gap }), className)}\n data-error={error || undefined}\n data-disabled={disabled || undefined}\n {...props}\n >\n {children}\n </div>\n </FieldContext.Provider>\n )\n }\n)\nField.displayName = 'Field'\n\n// Field Label\nexport interface FieldLabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> {\n required?: boolean\n}\n\nconst FieldLabel = React.forwardRef<HTMLLabelElement, FieldLabelProps>(\n ({ className, required, children, ...props }, ref) => {\n const context = useFieldContext()\n const registerLabel = context?.registerLabel\n React.useEffect(() => registerLabel?.(), [registerLabel])\n\n return (\n <label\n ref={ref}\n id={context?.labelId}\n // Grouped controls have their own labels; the group title targets no input\n htmlFor={context && !context.isGroup ? context.id : undefined}\n className={cn(\n 'text-md font-semibold text-foreground', // 14px - primary field identifier\n context?.disabled && 'opacity-50 cursor-not-allowed',\n className\n )}\n {...props}\n >\n {children}\n {required && <span className=\"text-error ml-0.5\">*</span>}\n </label>\n )\n }\n)\nFieldLabel.displayName = 'FieldLabel'\n\n// Field Error\nconst FieldError = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, children, ...props }, ref) => {\n const context = useFieldContext()\n\n if (!children) return null\n\n return (\n <p\n ref={ref}\n id={context ? `${context.id}-error` : undefined}\n role=\"alert\"\n className={cn('text-xs text-error pl-1', className)} // 12px - color-distinguished, left-aligned with input text\n {...props}\n >\n {children}\n </p>\n )\n})\nFieldError.displayName = 'FieldError'\n\n// Field Character Count\nconst FieldCharCount = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\n const context = useFieldContext()\n\n return (\n <p\n ref={ref}\n id={context ? `${context.id}-charcount` : undefined}\n className={cn(\n 'text-xs text-text-muted text-right pr-1 -mt-1', // 12px - right-aligned, 4px gap from input (gap-2 8px - mt-1 4px)\n context?.disabled && 'opacity-50',\n className\n )}\n {...props}\n />\n )\n})\nFieldCharCount.displayName = 'FieldCharCount'\n\nexport { Field, FieldLabel, FieldError, FieldCharCount, useFieldContext, useFieldControl }\n"],"mappings":";AA8FQ,cA6BF,YA7BE;AA5FR,YAAY,WAAW;AACvB,SAAS,WAA8B;AACvC,SAAS,UAAU;AAmBnB,MAAM,eAAe,MAAM,cAAwC,IAAI;AAEvE,SAAS,kBAAkB;AACzB,SAAO,MAAM,WAAW,YAAY;AACtC;AASA,SAAS,gBAAgB,MAAwB,SAAkB;AACjE,QAAM,UAAU,gBAAgB;AAChC,QAAM,WAAW,SAAS;AAC1B,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,WAAW,CAAC,SAAU;AAC3B,WAAO,SAAS,IAAI;AAAA,EACtB,GAAG,CAAC,SAAS,UAAU,IAAI,CAAC;AAC9B;AAGA,MAAM,gBAAgB,IAAI,iBAAiB;AAAA,EACzC,UAAU;AAAA,IACR,KAAK;AAAA,MACH,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,SAAS;AAAA,MACT,IAAI;AAAA,IACN;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,KAAK;AAAA,EACP;AACF,CAAC;AASD,MAAM,QAAQ,MAAM;AAAA,EAClB,CAAC,EAAE,WAAW,KAAK,OAAO,UAAU,UAAU,GAAG,MAAM,GAAG,QAAQ;AAChE,UAAM,KAAK,MAAM,MAAM;AACvB,UAAM,UAAU,GAAG,EAAE;AACrB,UAAM,CAAC,YAAY,aAAa,IAAI,MAAM,SAAS,CAAC;AACpD,UAAM,CAAC,QAAQ,SAAS,IAAI,MAAM,SAA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* as React from 'react'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport { cn } from '../../lib/utils'\n\n// Field Context for sharing state between components\ninterface FieldContextValue {\n id: string\n /** id of the FieldLabel, for aria-labelledby on grouped controls */\n labelId: string\n error?: boolean\n disabled?: boolean\n /** A FieldLabel is rendered inside this Field */\n hasLabel: boolean\n /** The Field holds labelled checkboxes / switches / a radio group and no single input */\n isGroup: boolean\n /** The FieldLabel is marked required; single controls set aria-required */\n required: boolean\n registerLabel: () => () => void\n registerRequired: () => () => void\n registerControl: (kind: FieldControlKind) => () => void\n}\n\ntype FieldControlKind = 'single' | 'group' | 'labelled'\n\nconst FieldContext = React.createContext<FieldContextValue | null>(null)\n\nfunction useFieldContext() {\n return React.useContext(FieldContext)\n}\n\n// Controls tell their Field what they are, so FieldLabel can point at the right thing.\n// 'single': one input that takes the Field id (Input, Textarea, a bare Checkbox / Switch);\n// FieldLabel targets it with htmlFor.\n// 'group': a Checkbox / Switch with its own label keeps a unique id; the Field becomes\n// role=\"group\" named by FieldLabel instead of every item sharing one id.\n// 'labelled': a RadioGroup names itself from FieldLabel (aria-labelledby).\n// A single input wins: with one present, FieldLabel keeps pointing at it.\nfunction useFieldControl(kind: FieldControlKind, enabled: boolean) {\n const context = useFieldContext()\n const register = context?.registerControl\n React.useEffect(() => {\n if (!enabled || !register) return\n return register(kind)\n }, [enabled, register, kind])\n}\n\n// Field wrapper\nconst fieldVariants = cva('flex flex-col', {\n variants: {\n gap: {\n none: 'gap-0',\n xs: 'gap-1',\n sm: 'gap-1.5',\n default: 'gap-2',\n lg: 'gap-3',\n },\n },\n defaultVariants: {\n gap: 'default',\n },\n})\n\nexport interface FieldProps\n extends React.HTMLAttributes<HTMLDivElement>,\n VariantProps<typeof fieldVariants> {\n error?: boolean\n disabled?: boolean\n}\n\nconst Field = React.forwardRef<HTMLDivElement, FieldProps>(\n ({ className, gap, error, disabled, children, ...props }, ref) => {\n const id = React.useId()\n const labelId = `${id}-label`\n const [labelCount, setLabelCount] = React.useState(0)\n const [requiredCount, setRequiredCount] = React.useState(0)\n const [counts, setCounts] = React.useState({ single: 0, group: 0, labelled: 0 })\n\n const registerLabel = React.useCallback(() => {\n setLabelCount((n) => n + 1)\n return () => setLabelCount((n) => n - 1)\n }, [])\n const registerRequired = React.useCallback(() => {\n setRequiredCount((n) => n + 1)\n return () => setRequiredCount((n) => n - 1)\n }, [])\n const registerControl = React.useCallback((kind: FieldControlKind) => {\n setCounts((c) => ({ ...c, [kind]: c[kind] + 1 }))\n return () => setCounts((c) => ({ ...c, [kind]: c[kind] - 1 }))\n }, [])\n\n const hasLabel = labelCount > 0\n const required = requiredCount > 0\n const isGroup = counts.single === 0 && (counts.group > 0 || counts.labelled > 0)\n const asGroup = counts.single === 0 && counts.group > 0\n const contextValue = React.useMemo(\n () => ({ id, labelId, error, disabled, hasLabel, isGroup, required, registerLabel, registerRequired, registerControl }),\n [id, labelId, error, disabled, hasLabel, isGroup, required, registerLabel, registerRequired, registerControl]\n )\n\n return (\n <FieldContext.Provider value={contextValue}>\n <div\n ref={ref}\n role={asGroup ? 'group' : undefined}\n aria-labelledby={asGroup && hasLabel ? labelId : undefined}\n className={cn(fieldVariants({ gap }), className)}\n data-error={error || undefined}\n data-disabled={disabled || undefined}\n {...props}\n >\n {children}\n </div>\n </FieldContext.Provider>\n )\n }\n)\nField.displayName = 'Field'\n\n// Field Label\nexport interface FieldLabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> {\n required?: boolean\n /** Text of the required badge shown when `required` is set */\n requiredLabel?: React.ReactNode\n}\n\nconst FieldLabel = React.forwardRef<HTMLLabelElement, FieldLabelProps>(\n ({ className, required, requiredLabel = '必須', children, ...props }, ref) => {\n const context = useFieldContext()\n const registerLabel = context?.registerLabel\n React.useEffect(() => registerLabel?.(), [registerLabel])\n const registerRequired = context?.registerRequired\n React.useEffect(() => (required ? registerRequired?.() : undefined), [required, registerRequired])\n\n return (\n <label\n ref={ref}\n id={context?.labelId}\n // Grouped controls have their own labels; the group title targets no input\n htmlFor={context && !context.isGroup ? context.id : undefined}\n className={cn(\n 'text-md font-semibold text-foreground', // 14px - primary field identifier\n context?.disabled && 'opacity-50 cursor-not-allowed',\n className\n )}\n {...props}\n >\n {children}\n {required && (\n // Neutral badge, not the error color: red stays reserved for errors.\n // Inside a Field the single control carries aria-required, so the badge is hidden\n // from assistive technology there to avoid announcing \"required\" twice.\n <span\n aria-hidden={context && !context.isGroup ? true : undefined}\n className=\"ml-1.5 inline-flex h-5 items-center rounded px-1.5 align-middle text-2xs font-semibold whitespace-nowrap bg-background-muted text-text-muted\"\n >\n {requiredLabel}\n </span>\n )}\n </label>\n )\n }\n)\nFieldLabel.displayName = 'FieldLabel'\n\n// Field Error\nconst FieldError = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, children, ...props }, ref) => {\n const context = useFieldContext()\n\n if (!children) return null\n\n return (\n <p\n ref={ref}\n id={context ? `${context.id}-error` : undefined}\n role=\"alert\"\n className={cn('text-xs text-error pl-1', className)} // 12px - color-distinguished, left-aligned with input text\n {...props}\n >\n {children}\n </p>\n )\n})\nFieldError.displayName = 'FieldError'\n\n// Field Character Count\nconst FieldCharCount = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\n const context = useFieldContext()\n\n return (\n <p\n ref={ref}\n id={context ? `${context.id}-charcount` : undefined}\n className={cn(\n 'text-xs text-text-muted text-right pr-1 -mt-1', // 12px - right-aligned, 4px gap from input (gap-2 8px - mt-1 4px)\n context?.disabled && 'opacity-50',\n className\n )}\n {...props}\n />\n )\n})\nFieldCharCount.displayName = 'FieldCharCount'\n\nexport { Field, FieldLabel, FieldError, FieldCharCount, useFieldContext, useFieldControl }\n"],"mappings":";AAuGQ,cAiCF,YAjCE;AArGR,YAAY,WAAW;AACvB,SAAS,WAA8B;AACvC,SAAS,UAAU;AAsBnB,MAAM,eAAe,MAAM,cAAwC,IA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8 @@ import { ButtonColor } from './button.mjs';
5
5
 
6
6
  declare const iconButtonVariants: (props?: ({
7
7
  variant?: "outline" | "solid" | "subtle" | "ghost" | null | undefined;
8
- size?: "default" | "sm" | "lg" | "md" | "xs" | null | undefined;
9
- radius?: "default" | "sm" | "lg" | "base" | "none" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
8
+ size?: "sm" | "default" | "lg" | "md" | "xs" | null | undefined;
9
+ radius?: "sm" | "default" | "lg" | "none" | "base" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
10
10
  } & class_variance_authority_types.ClassProp) | undefined) => string;
11
11
  interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof iconButtonVariants> {
12
12
  /** Solid variant color */
@@ -5,8 +5,8 @@ import { ButtonColor } from './button.js';
5
5
 
6
6
  declare const iconButtonVariants: (props?: ({
7
7
  variant?: "outline" | "solid" | "subtle" | "ghost" | null | undefined;
8
- size?: "default" | "sm" | "lg" | "md" | "xs" | null | undefined;
9
- radius?: "default" | "sm" | "lg" | "base" | "none" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
8
+ size?: "sm" | "default" | "lg" | "md" | "xs" | null | undefined;
9
+ radius?: "sm" | "default" | "lg" | "none" | "base" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
10
10
  } & class_variance_authority_types.ClassProp) | undefined) => string;
11
11
  interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof iconButtonVariants> {
12
12
  /** Solid variant color */
@@ -5,9 +5,9 @@ import { VariantProps } from 'class-variance-authority';
5
5
  declare const inputVariants: (props?: ({
6
6
  variant?: "default" | "filled" | null | undefined;
7
7
  focusRing?: boolean | null | undefined;
8
- size?: "default" | "sm" | "lg" | "xl" | "xs" | null | undefined;
9
- radius?: "default" | "sm" | "lg" | "base" | "none" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
10
- state?: "default" | "error" | null | undefined;
8
+ size?: "sm" | "default" | "lg" | "xl" | "xs" | null | undefined;
9
+ radius?: "sm" | "default" | "lg" | "none" | "base" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
10
+ state?: "error" | "default" | null | undefined;
11
11
  } & class_variance_authority_types.ClassProp) | undefined) => string;
12
12
  interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'>, VariantProps<typeof inputVariants> {
13
13
  leftIcon?: React.ReactNode;
@@ -5,9 +5,9 @@ import { VariantProps } from 'class-variance-authority';
5
5
  declare const inputVariants: (props?: ({
6
6
  variant?: "default" | "filled" | null | undefined;
7
7
  focusRing?: boolean | null | undefined;
8
- size?: "default" | "sm" | "lg" | "xl" | "xs" | null | undefined;
9
- radius?: "default" | "sm" | "lg" | "base" | "none" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
10
- state?: "default" | "error" | null | undefined;
8
+ size?: "sm" | "default" | "lg" | "xl" | "xs" | null | undefined;
9
+ radius?: "sm" | "default" | "lg" | "none" | "base" | "xl" | "2xl" | "3xl" | "full" | null | undefined;
10
+ state?: "error" | "default" | null | undefined;
11
11
  } & class_variance_authority_types.ClassProp) | undefined) => string;
12
12
  interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'>, VariantProps<typeof inputVariants> {
13
13
  leftIcon?: React.ReactNode;
@@ -213,6 +213,7 @@ const Input = React.forwardRef(
213
213
  className
214
214
  ),
215
215
  "aria-invalid": resolvedError || void 0,
216
+ "aria-required": fieldContext?.required || void 0,
216
217
  "aria-describedby": ariaDescribedBy,
217
218
  disabled: isDisabled,
218
219
  ref,
@@ -238,6 +239,7 @@ const Input = React.forwardRef(
238
239
  className
239
240
  ),
240
241
  "aria-invalid": resolvedError || void 0,
242
+ "aria-required": fieldContext?.required || void 0,
241
243
  "aria-describedby": ariaDescribedBy,
242
244
  disabled: isDisabled,
243
245
  ref,