@yamada-ui/checkbox 0.3.18 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,15 @@
1
+ import { CheckboxProps } from './checkbox.mjs';
1
2
  import * as react from 'react';
2
3
  import { ChangeEvent, Ref } from 'react';
3
4
  import { ThemeProps, ComponentArgs } from '@yamada-ui/core';
4
5
  import { FormControlOptions } from '@yamada-ui/form-control';
5
6
  import { FlexProps } from '@yamada-ui/layouts';
6
7
  import { PropGetter, DOMAttributes } from '@yamada-ui/utils';
8
+ import '@yamada-ui/motion';
7
9
 
10
+ type CheckboxItem<Y extends string | number = string> = CheckboxProps<Y> & {
11
+ label?: string;
12
+ };
8
13
  type UseCheckboxGroupProps<Y extends string | number = string> = {
9
14
  /**
10
15
  * The value of the checkbox group.
@@ -45,15 +50,29 @@ declare const useCheckboxGroup: <Y extends string | number = string>({ isNative,
45
50
  }>;
46
51
  };
47
52
  type UseCheckboxGroupReturn = ReturnType<typeof useCheckboxGroup>;
48
- type CheckboxGroupProps<Y extends string | number = string> = ThemeProps<'Checkbox'> & Omit<FlexProps, 'onChange'> & UseCheckboxGroupProps<Y> & FormControlOptions;
49
- type CheckboxContext = ThemeProps<'Checkbox'> & FormControlOptions & {
53
+ type CheckboxGroupProps<Y extends string | number = string> = ThemeProps<"Checkbox"> & Omit<FlexProps, "onChange"> & UseCheckboxGroupProps<Y> & FormControlOptions & {
54
+ /**
55
+ * If provided, generate checkboxes based on items.
56
+ *
57
+ * @default '[]'
58
+ */
59
+ items?: CheckboxItem<Y>[];
60
+ };
61
+ type CheckboxContext = ThemeProps<"Checkbox"> & FormControlOptions & {
50
62
  value: (string | number)[];
51
63
  onChange: (evOrValue: ChangeEvent<HTMLInputElement> | string | number) => void;
52
64
  };
53
65
  declare const useCheckboxGroupContext: () => CheckboxContext | undefined;
54
66
 
55
67
  declare const CheckboxGroup: (<Y extends string | number = string>(props: ThemeProps<"Checkbox"> & Omit<FlexProps, "onChange"> & UseCheckboxGroupProps<Y> & FormControlOptions & {
68
+ /**
69
+ * If provided, generate checkboxes based on items.
70
+ *
71
+ * @default '[]'
72
+ */
73
+ items?: CheckboxItem<Y>[] | undefined;
74
+ } & {
56
75
  ref?: Ref<HTMLDivElement> | undefined;
57
76
  }) => JSX.Element) & ComponentArgs;
58
77
 
59
- export { CheckboxGroup, CheckboxGroupProps, UseCheckboxGroupProps, UseCheckboxGroupReturn, useCheckboxGroup, useCheckboxGroupContext };
78
+ export { CheckboxGroup, CheckboxGroupProps, CheckboxItem, UseCheckboxGroupProps, UseCheckboxGroupReturn, useCheckboxGroup, useCheckboxGroupContext };
@@ -1,10 +1,15 @@
1
+ import { CheckboxProps } from './checkbox.js';
1
2
  import * as react from 'react';
2
3
  import { ChangeEvent, Ref } from 'react';
3
4
  import { ThemeProps, ComponentArgs } from '@yamada-ui/core';
4
5
  import { FormControlOptions } from '@yamada-ui/form-control';
5
6
  import { FlexProps } from '@yamada-ui/layouts';
6
7
  import { PropGetter, DOMAttributes } from '@yamada-ui/utils';
8
+ import '@yamada-ui/motion';
7
9
 
10
+ type CheckboxItem<Y extends string | number = string> = CheckboxProps<Y> & {
11
+ label?: string;
12
+ };
8
13
  type UseCheckboxGroupProps<Y extends string | number = string> = {
9
14
  /**
10
15
  * The value of the checkbox group.
@@ -45,15 +50,29 @@ declare const useCheckboxGroup: <Y extends string | number = string>({ isNative,
45
50
  }>;
46
51
  };
47
52
  type UseCheckboxGroupReturn = ReturnType<typeof useCheckboxGroup>;
48
- type CheckboxGroupProps<Y extends string | number = string> = ThemeProps<'Checkbox'> & Omit<FlexProps, 'onChange'> & UseCheckboxGroupProps<Y> & FormControlOptions;
49
- type CheckboxContext = ThemeProps<'Checkbox'> & FormControlOptions & {
53
+ type CheckboxGroupProps<Y extends string | number = string> = ThemeProps<"Checkbox"> & Omit<FlexProps, "onChange"> & UseCheckboxGroupProps<Y> & FormControlOptions & {
54
+ /**
55
+ * If provided, generate checkboxes based on items.
56
+ *
57
+ * @default '[]'
58
+ */
59
+ items?: CheckboxItem<Y>[];
60
+ };
61
+ type CheckboxContext = ThemeProps<"Checkbox"> & FormControlOptions & {
50
62
  value: (string | number)[];
51
63
  onChange: (evOrValue: ChangeEvent<HTMLInputElement> | string | number) => void;
52
64
  };
53
65
  declare const useCheckboxGroupContext: () => CheckboxContext | undefined;
54
66
 
55
67
  declare const CheckboxGroup: (<Y extends string | number = string>(props: ThemeProps<"Checkbox"> & Omit<FlexProps, "onChange"> & UseCheckboxGroupProps<Y> & FormControlOptions & {
68
+ /**
69
+ * If provided, generate checkboxes based on items.
70
+ *
71
+ * @default '[]'
72
+ */
73
+ items?: CheckboxItem<Y>[] | undefined;
74
+ } & {
56
75
  ref?: Ref<HTMLDivElement> | undefined;
57
76
  }) => JSX.Element) & ComponentArgs;
58
77
 
59
- export { CheckboxGroup, CheckboxGroupProps, UseCheckboxGroupProps, UseCheckboxGroupReturn, useCheckboxGroup, useCheckboxGroupContext };
78
+ export { CheckboxGroup, CheckboxGroupProps, CheckboxItem, UseCheckboxGroupProps, UseCheckboxGroupReturn, useCheckboxGroup, useCheckboxGroupContext };
@@ -26,24 +26,457 @@ __export(checkbox_group_exports, {
26
26
  useCheckboxGroupContext: () => useCheckboxGroupContext
27
27
  });
28
28
  module.exports = __toCommonJS(checkbox_group_exports);
29
- var import_form_control = require("@yamada-ui/form-control");
29
+ var import_form_control2 = require("@yamada-ui/form-control");
30
30
  var import_layouts = require("@yamada-ui/layouts");
31
31
  var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
32
+ var import_utils2 = require("@yamada-ui/utils");
33
+ var import_react2 = require("react");
34
+
35
+ // src/checkbox.tsx
36
+ var import_core = require("@yamada-ui/core");
37
+ var import_form_control = require("@yamada-ui/form-control");
38
+ var import_motion = require("@yamada-ui/motion");
39
+ var import_use_focus_visible = require("@yamada-ui/use-focus-visible");
32
40
  var import_utils = require("@yamada-ui/utils");
33
41
  var import_react = require("react");
34
42
  var import_jsx_runtime = require("react/jsx-runtime");
35
- var isEvent = (value) => value && (0, import_utils.isObject)(value) && (0, import_utils.isObject)(value.target);
43
+ var useCheckbox = (props) => {
44
+ const {
45
+ id,
46
+ name,
47
+ value,
48
+ defaultChecked,
49
+ tabIndex,
50
+ required,
51
+ disabled,
52
+ readOnly,
53
+ isIndeterminate,
54
+ ...rest
55
+ } = (0, import_form_control.useFormControlProps)(props);
56
+ const [isFocusVisible, setIsFocusVisible] = (0, import_react.useState)(false);
57
+ const [isFocused, setFocused] = (0, import_react.useState)(false);
58
+ const [isHovered, setHovered] = (0, import_react.useState)(false);
59
+ const [isActive, setActive] = (0, import_react.useState)(false);
60
+ const inputRef = (0, import_react.useRef)(null);
61
+ const [isLabel, setIsLabel] = (0, import_react.useState)(true);
62
+ const [isChecked, setIsChecked] = (0, import_react.useState)(!!defaultChecked);
63
+ const isControlled = props.isChecked !== void 0;
64
+ const checked = isControlled ? props.isChecked : isChecked;
65
+ const onChange = (0, import_utils.useCallbackRef)(
66
+ (ev) => {
67
+ var _a;
68
+ if (readOnly || disabled) {
69
+ ev.preventDefault();
70
+ return;
71
+ }
72
+ if (!isControlled)
73
+ setIsChecked(!checked || isIndeterminate ? true : ev.target.checked);
74
+ (_a = rest.onChange) == null ? void 0 : _a.call(rest, ev);
75
+ },
76
+ [readOnly, disabled, isControlled, checked, isIndeterminate]
77
+ );
78
+ const onBlur = (0, import_utils.useCallbackRef)(rest.onBlur);
79
+ const onFocus = (0, import_utils.useCallbackRef)(rest.onFocus);
80
+ const onKeyDown = (0, import_react.useCallback)(
81
+ ({ key }) => {
82
+ if (key === " ")
83
+ setActive(true);
84
+ },
85
+ [setActive]
86
+ );
87
+ const onKeyUp = (0, import_react.useCallback)(
88
+ ({ key }) => {
89
+ if (key === " ")
90
+ setActive(false);
91
+ },
92
+ [setActive]
93
+ );
94
+ (0, import_react.useEffect)(() => {
95
+ return (0, import_use_focus_visible.trackFocusVisible)(setIsFocusVisible);
96
+ }, []);
97
+ (0, import_utils.useSafeLayoutEffect)(() => {
98
+ if (inputRef.current)
99
+ inputRef.current.indeterminate = Boolean(isIndeterminate);
100
+ }, [isIndeterminate]);
101
+ (0, import_utils.useUpdateEffect)(() => {
102
+ if (disabled)
103
+ setFocused(false);
104
+ }, [disabled, setFocused]);
105
+ (0, import_utils.useSafeLayoutEffect)(() => {
106
+ var _a;
107
+ if (!((_a = inputRef.current) == null ? void 0 : _a.form))
108
+ return;
109
+ inputRef.current.form.onreset = () => setIsChecked(!!defaultChecked);
110
+ }, []);
111
+ (0, import_utils.useSafeLayoutEffect)(() => {
112
+ if (!inputRef.current)
113
+ return;
114
+ if (inputRef.current.checked !== checked)
115
+ setIsChecked(inputRef.current.checked);
116
+ }, [inputRef.current]);
117
+ const getContainerProps = (0, import_react.useCallback)(
118
+ (props2 = {}, ref = null) => ({
119
+ ...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
120
+ ...props2,
121
+ ref: (0, import_utils.mergeRefs)(ref, (el) => {
122
+ if (el)
123
+ setIsLabel(el.tagName === "LABEL");
124
+ }),
125
+ "data-checked": (0, import_utils.dataAttr)(checked),
126
+ onClick: (0, import_utils.handlerAll)(props2.onClick, () => {
127
+ var _a;
128
+ if (isLabel)
129
+ return;
130
+ (_a = inputRef.current) == null ? void 0 : _a.click();
131
+ requestAnimationFrame(() => {
132
+ var _a2;
133
+ return (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
134
+ });
135
+ })
136
+ }),
137
+ [checked, isLabel, rest]
138
+ );
139
+ const getIconProps = (0, import_react.useCallback)(
140
+ (props2 = {}, ref = null) => ({
141
+ ...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
142
+ ...props2,
143
+ ref,
144
+ "data-active": (0, import_utils.dataAttr)(isActive),
145
+ "data-hover": (0, import_utils.dataAttr)(isHovered),
146
+ "data-checked": (0, import_utils.dataAttr)(checked),
147
+ "data-focus": (0, import_utils.dataAttr)(isFocused),
148
+ "data-focus-visible": (0, import_utils.dataAttr)(isFocused && isFocusVisible),
149
+ "data-indeterminate": (0, import_utils.dataAttr)(isIndeterminate),
150
+ "aria-hidden": true,
151
+ onMouseDown: (0, import_utils.handlerAll)(props2.onMouseDown, (ev) => {
152
+ if (isFocused)
153
+ ev.preventDefault();
154
+ setActive(true);
155
+ }),
156
+ onMouseUp: (0, import_utils.handlerAll)(props2.onMouseUp, () => setActive(false)),
157
+ onMouseEnter: (0, import_utils.handlerAll)(props2.onMouseEnter, () => setHovered(true)),
158
+ onMouseLeave: (0, import_utils.handlerAll)(props2.onMouseLeave, () => setHovered(false))
159
+ }),
160
+ [
161
+ isActive,
162
+ checked,
163
+ isFocused,
164
+ isHovered,
165
+ isFocusVisible,
166
+ isIndeterminate,
167
+ rest
168
+ ]
169
+ );
170
+ const getInputProps = (0, import_react.useCallback)(
171
+ (props2 = {}, ref = null) => ({
172
+ ...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
173
+ ...props2,
174
+ ref: (0, import_utils.mergeRefs)(inputRef, ref),
175
+ id,
176
+ type: "checkbox",
177
+ name,
178
+ value,
179
+ tabIndex,
180
+ required,
181
+ disabled,
182
+ readOnly,
183
+ checked,
184
+ style: {
185
+ border: "0px",
186
+ clip: "rect(0px, 0px, 0px, 0px)",
187
+ height: "1px",
188
+ width: "1px",
189
+ margin: "-1px",
190
+ padding: "0px",
191
+ overflow: "hidden",
192
+ whiteSpace: "nowrap",
193
+ position: "absolute"
194
+ },
195
+ onChange: (0, import_utils.handlerAll)(props2.onChange, onChange),
196
+ onBlur: (0, import_utils.handlerAll)(props2.onBlur, onBlur, () => setFocused(false)),
197
+ onFocus: (0, import_utils.handlerAll)(props2.onFocus, onFocus, () => setFocused(true)),
198
+ onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, onKeyDown),
199
+ onKeyUp: (0, import_utils.handlerAll)(props2.onKeyUp, onKeyUp)
200
+ }),
201
+ [
202
+ rest,
203
+ id,
204
+ name,
205
+ value,
206
+ tabIndex,
207
+ required,
208
+ disabled,
209
+ readOnly,
210
+ checked,
211
+ onChange,
212
+ onBlur,
213
+ onFocus,
214
+ onKeyDown,
215
+ onKeyUp
216
+ ]
217
+ );
218
+ const getLabelProps = (0, import_react.useCallback)(
219
+ (props2 = {}, ref = null) => ({
220
+ ...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
221
+ ...props2,
222
+ ref,
223
+ "data-checked": (0, import_utils.dataAttr)(checked),
224
+ onMouseDown: (0, import_utils.handlerAll)(props2.onMouseDown, (ev) => {
225
+ ev.preventDefault();
226
+ ev.stopPropagation();
227
+ }),
228
+ onTouchStart: (0, import_utils.handlerAll)(props2.onTouchStart, (ev) => {
229
+ ev.preventDefault();
230
+ ev.stopPropagation();
231
+ })
232
+ }),
233
+ [checked, rest]
234
+ );
235
+ return {
236
+ isFocusVisible,
237
+ isFocused,
238
+ isHovered,
239
+ isActive,
240
+ isChecked: checked,
241
+ isIndeterminate,
242
+ getContainerProps,
243
+ getIconProps,
244
+ getInputProps,
245
+ getLabelProps
246
+ };
247
+ };
248
+ var Checkbox = (0, import_react.forwardRef)(
249
+ (props, ref) => {
250
+ var _a, _b, _c, _d, _e;
251
+ const group = useCheckboxGroupContext();
252
+ const control = (0, import_form_control.useFormControl)(props);
253
+ const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Checkbox", {
254
+ ...group ? (0, import_utils.omitObject)(group, ["value"]) : {},
255
+ ...props
256
+ });
257
+ const {
258
+ className,
259
+ gap = "0.5rem",
260
+ isRequired = (_a = group == null ? void 0 : group.isRequired) != null ? _a : control.isRequired,
261
+ isReadOnly = (_b = group == null ? void 0 : group.isReadOnly) != null ? _b : control.isReadOnly,
262
+ isDisabled = (_c = group == null ? void 0 : group.isDisabled) != null ? _c : control.isDisabled,
263
+ isInvalid = (_d = group == null ? void 0 : group.isInvalid) != null ? _d : control.isInvalid,
264
+ iconProps,
265
+ inputProps,
266
+ labelProps,
267
+ children,
268
+ ...rest
269
+ } = (0, import_core.omitThemeProps)(mergedProps);
270
+ const {
271
+ isChecked,
272
+ isIndeterminate,
273
+ getContainerProps,
274
+ getInputProps,
275
+ getIconProps,
276
+ getLabelProps
277
+ } = useCheckbox({
278
+ ...rest,
279
+ isRequired,
280
+ isReadOnly,
281
+ isDisabled,
282
+ isInvalid,
283
+ isChecked: (group == null ? void 0 : group.value) && rest.value ? group.value.includes(rest.value) : rest.isChecked,
284
+ onChange: (group == null ? void 0 : group.onChange) && rest.value ? (0, import_utils.funcAll)(group.onChange, rest.onChange) : rest.onChange
285
+ });
286
+ const cloneIcon = (0, import_react.cloneElement)((_e = iconProps == null ? void 0 : iconProps.children) != null ? _e : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxIcon, {}), {
287
+ __css: {
288
+ opacity: isChecked || isIndeterminate ? 1 : 0,
289
+ transform: isChecked || isIndeterminate ? "scale(1)" : "scale(0.95)",
290
+ transitionProperty: "transform",
291
+ transitionDuration: "normal"
292
+ },
293
+ isIndeterminate,
294
+ isChecked,
295
+ isRequired,
296
+ isReadOnly,
297
+ isDisabled,
298
+ isInvalid
299
+ });
300
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
301
+ import_core.ui.label,
302
+ {
303
+ className: (0, import_utils.cx)("ui-checkbox", className),
304
+ ...getContainerProps(),
305
+ __css: {
306
+ cursor: "pointer",
307
+ position: "relative",
308
+ display: "inline-flex",
309
+ alignItems: "center",
310
+ verticalAlign: "top",
311
+ gap,
312
+ ...styles.container
313
+ },
314
+ ...(0, import_utils.omitObject)(rest, [
315
+ "id",
316
+ "name",
317
+ "value",
318
+ "defaultValue",
319
+ "defaultChecked",
320
+ "isChecked",
321
+ "isIndeterminate",
322
+ "onChange",
323
+ "onBlur",
324
+ "onFocus",
325
+ "tabIndex"
326
+ ]),
327
+ children: [
328
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
329
+ import_core.ui.input,
330
+ {
331
+ className: "ui-checkbox__input",
332
+ ...getInputProps(inputProps, ref)
333
+ }
334
+ ),
335
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
336
+ import_core.ui.span,
337
+ {
338
+ className: "ui-checkbox__icon",
339
+ __css: {
340
+ pointerEvents: isReadOnly ? "none" : void 0,
341
+ position: "relative",
342
+ display: "inline-block",
343
+ userSelect: "none",
344
+ ...styles.icon
345
+ },
346
+ ...getIconProps(
347
+ (0, import_utils.omitObject)(iconProps != null ? iconProps : { children: void 0 }, ["children"])
348
+ ),
349
+ children: cloneIcon
350
+ }
351
+ ),
352
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
353
+ import_core.ui.span,
354
+ {
355
+ className: "ui-checkbox__label",
356
+ __css: { ...styles.label },
357
+ ...getLabelProps(labelProps),
358
+ children
359
+ }
360
+ )
361
+ ]
362
+ }
363
+ );
364
+ }
365
+ );
366
+ Checkbox.displayName = "Checkbox";
367
+ var CheckboxIcon = ({
368
+ isIndeterminate,
369
+ isChecked,
370
+ ...rest
371
+ }) => {
372
+ const iconProps = (0, import_utils.omitObject)(rest, [
373
+ "isRequired",
374
+ "isReadOnly",
375
+ "isDisabled",
376
+ "isInvalid"
377
+ ]);
378
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_motion.AnimatePresence, { initial: false, children: isIndeterminate || isChecked ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
379
+ import_core.ui.div,
380
+ {
381
+ __css: {
382
+ position: "absolute",
383
+ top: "50%",
384
+ left: "50%",
385
+ transform: "translate(-50%, -50%)"
386
+ },
387
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
388
+ import_core.ui.div,
389
+ {
390
+ as: import_motion.motion.div,
391
+ variants: {
392
+ unchecked: { scale: 0.5 },
393
+ checked: { scale: 1 }
394
+ },
395
+ initial: "unchecked",
396
+ animate: "checked",
397
+ exit: "unchecked",
398
+ style: {
399
+ display: "flex",
400
+ alignItems: "center",
401
+ justifyContent: "center"
402
+ },
403
+ children: isIndeterminate ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IndeterminateIcon, { ...iconProps }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckIcon, { ...iconProps })
404
+ }
405
+ )
406
+ }
407
+ ) : null });
408
+ };
409
+ var CheckIcon = (props) => {
410
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
411
+ import_core.ui.svg,
412
+ {
413
+ as: import_motion.motion.svg,
414
+ width: "1.2em",
415
+ viewBox: "0 0 12 10",
416
+ variants: {
417
+ unchecked: {
418
+ opacity: 0,
419
+ strokeDashoffset: 16
420
+ },
421
+ checked: {
422
+ opacity: 1,
423
+ strokeDashoffset: 0,
424
+ transition: { duration: 0.2 }
425
+ }
426
+ },
427
+ style: {
428
+ fill: "none",
429
+ strokeWidth: 2,
430
+ stroke: "currentColor",
431
+ strokeDasharray: 16
432
+ },
433
+ ...props,
434
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "1.5 6 4.5 9 10.5 1" })
435
+ }
436
+ );
437
+ };
438
+ var IndeterminateIcon = (props) => {
439
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
440
+ import_core.ui.svg,
441
+ {
442
+ as: import_motion.motion.svg,
443
+ width: "1.2em",
444
+ viewBox: "0 0 24 24",
445
+ variants: {
446
+ unchecked: {
447
+ scaleX: 0.65,
448
+ opacity: 0
449
+ },
450
+ checked: {
451
+ scaleX: 1,
452
+ opacity: 1,
453
+ transition: {
454
+ scaleX: { duration: 0 },
455
+ opacity: { duration: 0.02 }
456
+ }
457
+ }
458
+ },
459
+ style: { stroke: "currentColor", strokeWidth: 4 },
460
+ ...props,
461
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "21", x2: "3", y1: "12", y2: "12" })
462
+ }
463
+ );
464
+ };
465
+
466
+ // src/checkbox-group.tsx
467
+ var import_jsx_runtime2 = require("react/jsx-runtime");
468
+ var isEvent = (value) => value && (0, import_utils2.isObject)(value) && (0, import_utils2.isObject)(value.target);
36
469
  var useCheckboxGroup = ({
37
470
  isNative,
38
471
  ...props
39
472
  }) => {
40
- props.onChange = (0, import_utils.useCallbackRef)(props.onChange);
473
+ props.onChange = (0, import_utils2.useCallbackRef)(props.onChange);
41
474
  const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
42
475
  value: props.value,
43
476
  defaultValue: props.defaultValue || [],
44
477
  onChange: props.onChange
45
478
  });
46
- const onChange = (0, import_react.useCallback)(
479
+ const onChange = (0, import_react2.useCallback)(
47
480
  (evOrValue) => {
48
481
  const isChecked = isEvent(evOrValue) ? evOrValue.target.checked : !value.includes(evOrValue);
49
482
  const selectedValue = isEvent(evOrValue) ? evOrValue.target.value : evOrValue;
@@ -52,7 +485,7 @@ var useCheckboxGroup = ({
52
485
  },
53
486
  [value, setValue]
54
487
  );
55
- const getCheckboxProps = (0, import_react.useCallback)(
488
+ const getCheckboxProps = (0, import_react2.useCallback)(
56
489
  (props2 = {}, ref = null) => ({
57
490
  ...props2,
58
491
  ref,
@@ -65,24 +498,30 @@ var useCheckboxGroup = ({
65
498
  );
66
499
  return { value, setValue, onChange, getCheckboxProps };
67
500
  };
68
- var [CheckboxGroupProvider, useCheckboxGroupContext] = (0, import_utils.createContext)({
501
+ var [CheckboxGroupProvider, useCheckboxGroupContext] = (0, import_utils2.createContext)({
69
502
  strict: false,
70
503
  name: "CheckboxGroupContext"
71
504
  });
72
- var CheckboxGroup = (0, import_react.forwardRef)(
505
+ var CheckboxGroup = (0, import_react2.forwardRef)(
73
506
  ({
74
507
  className,
75
508
  size,
76
509
  variant,
77
510
  colorScheme,
78
511
  children,
512
+ items = [],
79
513
  direction = "column",
80
514
  gap,
81
515
  ...props
82
516
  }, ref) => {
83
517
  const { value, onChange } = useCheckboxGroup(props);
84
- const { isRequired, isReadOnly, isDisabled, isInvalid } = (0, import_form_control.useFormControl)(props);
85
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
518
+ const { isRequired, isReadOnly, isDisabled, isInvalid } = (0, import_form_control2.useFormControl)(props);
519
+ const validChildren = (0, import_utils2.getValidChildren)(children);
520
+ let computedChildren = [];
521
+ if (!validChildren.length && items.length) {
522
+ computedChildren = items.map(({ label, value: value2, ...props2 }, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Checkbox, { value: value2, ...props2, children: label }, i));
523
+ }
524
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
86
525
  CheckboxGroupProvider,
87
526
  {
88
527
  value: {
@@ -96,15 +535,15 @@ var CheckboxGroup = (0, import_react.forwardRef)(
96
535
  value,
97
536
  onChange
98
537
  },
99
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
538
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
100
539
  import_layouts.Flex,
101
540
  {
102
541
  ref,
103
- className: (0, import_utils.cx)("ui-checkbox-group", className),
542
+ className: (0, import_utils2.cx)("ui-checkbox-group", className),
104
543
  role: "group",
105
544
  direction,
106
545
  gap: gap != null ? gap : direction === "row" ? "1rem" : void 0,
107
- ...(0, import_utils.omitObject)(props, [
546
+ ...(0, import_utils2.omitObject)(props, [
108
547
  "value",
109
548
  "defaultValue",
110
549
  "onChange",
@@ -113,7 +552,7 @@ var CheckboxGroup = (0, import_react.forwardRef)(
113
552
  "isRequired",
114
553
  "isReadOnly"
115
554
  ]),
116
- children
555
+ children: children != null ? children : computedChildren
117
556
  }
118
557
  )
119
558
  }
@@ -3,7 +3,7 @@ import {
3
3
  CheckboxGroup,
4
4
  useCheckboxGroup,
5
5
  useCheckboxGroupContext
6
- } from "./chunk-SFCPW2O4.mjs";
6
+ } from "./chunk-2TIBZ5OE.mjs";
7
7
  export {
8
8
  CheckboxGroup,
9
9
  useCheckboxGroup,
@@ -69,7 +69,7 @@ type CheckboxOptions = {
69
69
  /**
70
70
  * Props for icon component.
71
71
  */
72
- iconProps?: Omit<HTMLUIProps<'span'>, 'children'> & {
72
+ iconProps?: Omit<HTMLUIProps<"span">, "children"> & {
73
73
  children: ReactElement;
74
74
  };
75
75
  /**
@@ -79,10 +79,10 @@ type CheckboxOptions = {
79
79
  /**
80
80
  * Props for label element.
81
81
  */
82
- labelProps?: HTMLUIProps<'span'>;
82
+ labelProps?: HTMLUIProps<"span">;
83
83
  };
84
- type CheckboxProps<Y extends string | number = string> = Omit<HTMLUIProps<'label'>, keyof UseCheckboxProps | 'checked'> & ThemeProps<'Checkbox'> & UseCheckboxProps<Y> & CheckboxOptions;
85
- declare const Checkbox: (<Y extends string | number = string>(props: Omit<HTMLUIProps<"label">, "id" | "onFocus" | "onBlur" | keyof FormControlOptions | "name" | "value" | "defaultChecked" | "tabIndex" | "isIndeterminate" | "isChecked" | "onChange" | "checked"> & ThemeProps<"Checkbox"> & FormControlOptions & {
84
+ type CheckboxProps<Y extends string | number = string> = Omit<HTMLUIProps<"label">, keyof UseCheckboxProps | "checked"> & ThemeProps<"Checkbox"> & UseCheckboxProps<Y> & CheckboxOptions;
85
+ declare const Checkbox: (<Y extends string | number = string>(props: Omit<HTMLUIProps<"label">, "defaultChecked" | "id" | "tabIndex" | "onFocus" | "onBlur" | "onChange" | keyof FormControlOptions | "name" | "value" | "isChecked" | "isIndeterminate" | "checked"> & ThemeProps<"Checkbox"> & FormControlOptions & {
86
86
  /**
87
87
  * id assigned to input.
88
88
  */
@@ -132,7 +132,7 @@ declare const Checkbox: (<Y extends string | number = string>(props: Omit<HTMLUI
132
132
  } & CheckboxOptions & {
133
133
  ref?: Ref<HTMLInputElement> | undefined;
134
134
  }) => JSX.Element) & ComponentArgs;
135
- type CheckboxIconProps = HTMLUIProps<'svg'> & SVGMotionProps<SVGSVGElement> & FormControlOptions & {
135
+ type CheckboxIconProps = HTMLUIProps<"svg"> & SVGMotionProps<SVGSVGElement> & FormControlOptions & {
136
136
  /**
137
137
  * If `true`, the icon will be indeterminate.
138
138
  *
@@ -69,7 +69,7 @@ type CheckboxOptions = {
69
69
  /**
70
70
  * Props for icon component.
71
71
  */
72
- iconProps?: Omit<HTMLUIProps<'span'>, 'children'> & {
72
+ iconProps?: Omit<HTMLUIProps<"span">, "children"> & {
73
73
  children: ReactElement;
74
74
  };
75
75
  /**
@@ -79,10 +79,10 @@ type CheckboxOptions = {
79
79
  /**
80
80
  * Props for label element.
81
81
  */
82
- labelProps?: HTMLUIProps<'span'>;
82
+ labelProps?: HTMLUIProps<"span">;
83
83
  };
84
- type CheckboxProps<Y extends string | number = string> = Omit<HTMLUIProps<'label'>, keyof UseCheckboxProps | 'checked'> & ThemeProps<'Checkbox'> & UseCheckboxProps<Y> & CheckboxOptions;
85
- declare const Checkbox: (<Y extends string | number = string>(props: Omit<HTMLUIProps<"label">, "id" | "onFocus" | "onBlur" | keyof FormControlOptions | "name" | "value" | "defaultChecked" | "tabIndex" | "isIndeterminate" | "isChecked" | "onChange" | "checked"> & ThemeProps<"Checkbox"> & FormControlOptions & {
84
+ type CheckboxProps<Y extends string | number = string> = Omit<HTMLUIProps<"label">, keyof UseCheckboxProps | "checked"> & ThemeProps<"Checkbox"> & UseCheckboxProps<Y> & CheckboxOptions;
85
+ declare const Checkbox: (<Y extends string | number = string>(props: Omit<HTMLUIProps<"label">, "defaultChecked" | "id" | "tabIndex" | "onFocus" | "onBlur" | "onChange" | keyof FormControlOptions | "name" | "value" | "isChecked" | "isIndeterminate" | "checked"> & ThemeProps<"Checkbox"> & FormControlOptions & {
86
86
  /**
87
87
  * id assigned to input.
88
88
  */
@@ -132,7 +132,7 @@ declare const Checkbox: (<Y extends string | number = string>(props: Omit<HTMLUI
132
132
  } & CheckboxOptions & {
133
133
  ref?: Ref<HTMLInputElement> | undefined;
134
134
  }) => JSX.Element) & ComponentArgs;
135
- type CheckboxIconProps = HTMLUIProps<'svg'> & SVGMotionProps<SVGSVGElement> & FormControlOptions & {
135
+ type CheckboxIconProps = HTMLUIProps<"svg"> & SVGMotionProps<SVGSVGElement> & FormControlOptions & {
136
136
  /**
137
137
  * If `true`, the icon will be indeterminate.
138
138
  *
package/dist/checkbox.js CHANGED
@@ -84,12 +84,18 @@ var CheckboxGroup = (0, import_react.forwardRef)(
84
84
  variant,
85
85
  colorScheme,
86
86
  children,
87
+ items = [],
87
88
  direction = "column",
88
89
  gap,
89
90
  ...props
90
91
  }, ref) => {
91
92
  const { value, onChange } = useCheckboxGroup(props);
92
93
  const { isRequired, isReadOnly, isDisabled, isInvalid } = (0, import_form_control.useFormControl)(props);
94
+ const validChildren = (0, import_utils.getValidChildren)(children);
95
+ let computedChildren = [];
96
+ if (!validChildren.length && items.length) {
97
+ computedChildren = items.map(({ label, value: value2, ...props2 }, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checkbox, { value: value2, ...props2, children: label }, i));
98
+ }
93
99
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
94
100
  CheckboxGroupProvider,
95
101
  {
@@ -121,7 +127,7 @@ var CheckboxGroup = (0, import_react.forwardRef)(
121
127
  "isRequired",
122
128
  "isReadOnly"
123
129
  ]),
124
- children
130
+ children: children != null ? children : computedChildren
125
131
  }
126
132
  )
127
133
  }
package/dist/checkbox.mjs CHANGED
@@ -3,8 +3,7 @@ import {
3
3
  Checkbox,
4
4
  CheckboxIcon,
5
5
  useCheckbox
6
- } from "./chunk-KZ5TSBSA.mjs";
7
- import "./chunk-SFCPW2O4.mjs";
6
+ } from "./chunk-2TIBZ5OE.mjs";
8
7
  export {
9
8
  Checkbox,
10
9
  CheckboxIcon,
@@ -1,7 +1,4 @@
1
1
  "use client"
2
- import {
3
- useCheckboxGroupContext
4
- } from "./chunk-SFCPW2O4.mjs";
5
2
 
6
3
  // src/checkbox.tsx
7
4
  import {
@@ -10,17 +7,17 @@ import {
10
7
  omitThemeProps
11
8
  } from "@yamada-ui/core";
12
9
  import {
13
- useFormControl,
10
+ useFormControl as useFormControl2,
14
11
  useFormControlProps,
15
12
  formControlProperties
16
13
  } from "@yamada-ui/form-control";
17
14
  import { AnimatePresence, motion } from "@yamada-ui/motion";
18
15
  import { trackFocusVisible } from "@yamada-ui/use-focus-visible";
19
16
  import {
20
- cx,
21
- omitObject,
17
+ cx as cx2,
18
+ omitObject as omitObject2,
22
19
  pickObject,
23
- useCallbackRef,
20
+ useCallbackRef as useCallbackRef2,
24
21
  useSafeLayoutEffect,
25
22
  useUpdateEffect,
26
23
  handlerAll,
@@ -30,13 +27,128 @@ import {
30
27
  } from "@yamada-ui/utils";
31
28
  import {
32
29
  cloneElement,
33
- useCallback,
30
+ useCallback as useCallback2,
34
31
  useEffect,
35
32
  useRef,
36
33
  useState,
37
- forwardRef
34
+ forwardRef as forwardRef2
35
+ } from "react";
36
+
37
+ // src/checkbox-group.tsx
38
+ import { useFormControl } from "@yamada-ui/form-control";
39
+ import { Flex } from "@yamada-ui/layouts";
40
+ import { useControllableState } from "@yamada-ui/use-controllable-state";
41
+ import {
42
+ createContext,
43
+ cx,
44
+ isObject,
45
+ omitObject,
46
+ useCallbackRef,
47
+ getValidChildren
48
+ } from "@yamada-ui/utils";
49
+ import {
50
+ forwardRef,
51
+ useCallback
38
52
  } from "react";
39
- import { jsx, jsxs } from "react/jsx-runtime";
53
+ import { jsx } from "react/jsx-runtime";
54
+ var isEvent = (value) => value && isObject(value) && isObject(value.target);
55
+ var useCheckboxGroup = ({
56
+ isNative,
57
+ ...props
58
+ }) => {
59
+ props.onChange = useCallbackRef(props.onChange);
60
+ const [value, setValue] = useControllableState({
61
+ value: props.value,
62
+ defaultValue: props.defaultValue || [],
63
+ onChange: props.onChange
64
+ });
65
+ const onChange = useCallback(
66
+ (evOrValue) => {
67
+ const isChecked = isEvent(evOrValue) ? evOrValue.target.checked : !value.includes(evOrValue);
68
+ const selectedValue = isEvent(evOrValue) ? evOrValue.target.value : evOrValue;
69
+ const nextValue = isChecked ? [...value, selectedValue] : value.filter((v) => String(v) !== String(selectedValue));
70
+ setValue(nextValue);
71
+ },
72
+ [value, setValue]
73
+ );
74
+ const getCheckboxProps = useCallback(
75
+ (props2 = {}, ref = null) => ({
76
+ ...props2,
77
+ ref,
78
+ [isNative ? "checked" : "isChecked"]: value.some(
79
+ (val) => String(props2.value) === String(val)
80
+ ),
81
+ onChange
82
+ }),
83
+ [onChange, isNative, value]
84
+ );
85
+ return { value, setValue, onChange, getCheckboxProps };
86
+ };
87
+ var [CheckboxGroupProvider, useCheckboxGroupContext] = createContext({
88
+ strict: false,
89
+ name: "CheckboxGroupContext"
90
+ });
91
+ var CheckboxGroup = forwardRef(
92
+ ({
93
+ className,
94
+ size,
95
+ variant,
96
+ colorScheme,
97
+ children,
98
+ items = [],
99
+ direction = "column",
100
+ gap,
101
+ ...props
102
+ }, ref) => {
103
+ const { value, onChange } = useCheckboxGroup(props);
104
+ const { isRequired, isReadOnly, isDisabled, isInvalid } = useFormControl(props);
105
+ const validChildren = getValidChildren(children);
106
+ let computedChildren = [];
107
+ if (!validChildren.length && items.length) {
108
+ computedChildren = items.map(({ label, value: value2, ...props2 }, i) => /* @__PURE__ */ jsx(Checkbox, { value: value2, ...props2, children: label }, i));
109
+ }
110
+ return /* @__PURE__ */ jsx(
111
+ CheckboxGroupProvider,
112
+ {
113
+ value: {
114
+ size,
115
+ variant,
116
+ colorScheme,
117
+ isRequired,
118
+ isReadOnly,
119
+ isDisabled,
120
+ isInvalid,
121
+ value,
122
+ onChange
123
+ },
124
+ children: /* @__PURE__ */ jsx(
125
+ Flex,
126
+ {
127
+ ref,
128
+ className: cx("ui-checkbox-group", className),
129
+ role: "group",
130
+ direction,
131
+ gap: gap != null ? gap : direction === "row" ? "1rem" : void 0,
132
+ ...omitObject(props, [
133
+ "value",
134
+ "defaultValue",
135
+ "onChange",
136
+ "isInvalid",
137
+ "isDisabled",
138
+ "isRequired",
139
+ "isReadOnly"
140
+ ]),
141
+ children: children != null ? children : computedChildren
142
+ }
143
+ )
144
+ }
145
+ );
146
+ }
147
+ );
148
+ CheckboxGroup.displayName = "CheckboxGroup";
149
+
150
+ // src/checkbox.tsx
151
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
40
152
  var useCheckbox = (props) => {
41
153
  const {
42
154
  id,
@@ -59,7 +171,7 @@ var useCheckbox = (props) => {
59
171
  const [isChecked, setIsChecked] = useState(!!defaultChecked);
60
172
  const isControlled = props.isChecked !== void 0;
61
173
  const checked = isControlled ? props.isChecked : isChecked;
62
- const onChange = useCallbackRef(
174
+ const onChange = useCallbackRef2(
63
175
  (ev) => {
64
176
  var _a;
65
177
  if (readOnly || disabled) {
@@ -72,16 +184,16 @@ var useCheckbox = (props) => {
72
184
  },
73
185
  [readOnly, disabled, isControlled, checked, isIndeterminate]
74
186
  );
75
- const onBlur = useCallbackRef(rest.onBlur);
76
- const onFocus = useCallbackRef(rest.onFocus);
77
- const onKeyDown = useCallback(
187
+ const onBlur = useCallbackRef2(rest.onBlur);
188
+ const onFocus = useCallbackRef2(rest.onFocus);
189
+ const onKeyDown = useCallback2(
78
190
  ({ key }) => {
79
191
  if (key === " ")
80
192
  setActive(true);
81
193
  },
82
194
  [setActive]
83
195
  );
84
- const onKeyUp = useCallback(
196
+ const onKeyUp = useCallback2(
85
197
  ({ key }) => {
86
198
  if (key === " ")
87
199
  setActive(false);
@@ -111,7 +223,7 @@ var useCheckbox = (props) => {
111
223
  if (inputRef.current.checked !== checked)
112
224
  setIsChecked(inputRef.current.checked);
113
225
  }, [inputRef.current]);
114
- const getContainerProps = useCallback(
226
+ const getContainerProps = useCallback2(
115
227
  (props2 = {}, ref = null) => ({
116
228
  ...pickObject(rest, formControlProperties),
117
229
  ...props2,
@@ -133,7 +245,7 @@ var useCheckbox = (props) => {
133
245
  }),
134
246
  [checked, isLabel, rest]
135
247
  );
136
- const getIconProps = useCallback(
248
+ const getIconProps = useCallback2(
137
249
  (props2 = {}, ref = null) => ({
138
250
  ...pickObject(rest, formControlProperties),
139
251
  ...props2,
@@ -164,7 +276,7 @@ var useCheckbox = (props) => {
164
276
  rest
165
277
  ]
166
278
  );
167
- const getInputProps = useCallback(
279
+ const getInputProps = useCallback2(
168
280
  (props2 = {}, ref = null) => ({
169
281
  ...pickObject(rest, formControlProperties),
170
282
  ...props2,
@@ -212,7 +324,7 @@ var useCheckbox = (props) => {
212
324
  onKeyUp
213
325
  ]
214
326
  );
215
- const getLabelProps = useCallback(
327
+ const getLabelProps = useCallback2(
216
328
  (props2 = {}, ref = null) => ({
217
329
  ...pickObject(rest, formControlProperties),
218
330
  ...props2,
@@ -242,13 +354,13 @@ var useCheckbox = (props) => {
242
354
  getLabelProps
243
355
  };
244
356
  };
245
- var Checkbox = forwardRef(
357
+ var Checkbox = forwardRef2(
246
358
  (props, ref) => {
247
359
  var _a, _b, _c, _d, _e;
248
360
  const group = useCheckboxGroupContext();
249
- const control = useFormControl(props);
361
+ const control = useFormControl2(props);
250
362
  const [styles, mergedProps] = useMultiComponentStyle("Checkbox", {
251
- ...group ? omitObject(group, ["value"]) : {},
363
+ ...group ? omitObject2(group, ["value"]) : {},
252
364
  ...props
253
365
  });
254
366
  const {
@@ -280,7 +392,7 @@ var Checkbox = forwardRef(
280
392
  isChecked: (group == null ? void 0 : group.value) && rest.value ? group.value.includes(rest.value) : rest.isChecked,
281
393
  onChange: (group == null ? void 0 : group.onChange) && rest.value ? funcAll(group.onChange, rest.onChange) : rest.onChange
282
394
  });
283
- const cloneIcon = cloneElement((_e = iconProps == null ? void 0 : iconProps.children) != null ? _e : /* @__PURE__ */ jsx(CheckboxIcon, {}), {
395
+ const cloneIcon = cloneElement((_e = iconProps == null ? void 0 : iconProps.children) != null ? _e : /* @__PURE__ */ jsx2(CheckboxIcon, {}), {
284
396
  __css: {
285
397
  opacity: isChecked || isIndeterminate ? 1 : 0,
286
398
  transform: isChecked || isIndeterminate ? "scale(1)" : "scale(0.95)",
@@ -297,7 +409,7 @@ var Checkbox = forwardRef(
297
409
  return /* @__PURE__ */ jsxs(
298
410
  ui.label,
299
411
  {
300
- className: cx("ui-checkbox", className),
412
+ className: cx2("ui-checkbox", className),
301
413
  ...getContainerProps(),
302
414
  __css: {
303
415
  cursor: "pointer",
@@ -308,7 +420,7 @@ var Checkbox = forwardRef(
308
420
  gap,
309
421
  ...styles.container
310
422
  },
311
- ...omitObject(rest, [
423
+ ...omitObject2(rest, [
312
424
  "id",
313
425
  "name",
314
426
  "value",
@@ -322,14 +434,14 @@ var Checkbox = forwardRef(
322
434
  "tabIndex"
323
435
  ]),
324
436
  children: [
325
- /* @__PURE__ */ jsx(
437
+ /* @__PURE__ */ jsx2(
326
438
  ui.input,
327
439
  {
328
440
  className: "ui-checkbox__input",
329
441
  ...getInputProps(inputProps, ref)
330
442
  }
331
443
  ),
332
- /* @__PURE__ */ jsx(
444
+ /* @__PURE__ */ jsx2(
333
445
  ui.span,
334
446
  {
335
447
  className: "ui-checkbox__icon",
@@ -341,12 +453,12 @@ var Checkbox = forwardRef(
341
453
  ...styles.icon
342
454
  },
343
455
  ...getIconProps(
344
- omitObject(iconProps != null ? iconProps : { children: void 0 }, ["children"])
456
+ omitObject2(iconProps != null ? iconProps : { children: void 0 }, ["children"])
345
457
  ),
346
458
  children: cloneIcon
347
459
  }
348
460
  ),
349
- /* @__PURE__ */ jsx(
461
+ /* @__PURE__ */ jsx2(
350
462
  ui.span,
351
463
  {
352
464
  className: "ui-checkbox__label",
@@ -366,13 +478,13 @@ var CheckboxIcon = ({
366
478
  isChecked,
367
479
  ...rest
368
480
  }) => {
369
- const iconProps = omitObject(rest, [
481
+ const iconProps = omitObject2(rest, [
370
482
  "isRequired",
371
483
  "isReadOnly",
372
484
  "isDisabled",
373
485
  "isInvalid"
374
486
  ]);
375
- return /* @__PURE__ */ jsx(AnimatePresence, { initial: false, children: isIndeterminate || isChecked ? /* @__PURE__ */ jsx(
487
+ return /* @__PURE__ */ jsx2(AnimatePresence, { initial: false, children: isIndeterminate || isChecked ? /* @__PURE__ */ jsx2(
376
488
  ui.div,
377
489
  {
378
490
  __css: {
@@ -381,7 +493,7 @@ var CheckboxIcon = ({
381
493
  left: "50%",
382
494
  transform: "translate(-50%, -50%)"
383
495
  },
384
- children: /* @__PURE__ */ jsx(
496
+ children: /* @__PURE__ */ jsx2(
385
497
  ui.div,
386
498
  {
387
499
  as: motion.div,
@@ -397,14 +509,14 @@ var CheckboxIcon = ({
397
509
  alignItems: "center",
398
510
  justifyContent: "center"
399
511
  },
400
- children: isIndeterminate ? /* @__PURE__ */ jsx(IndeterminateIcon, { ...iconProps }) : /* @__PURE__ */ jsx(CheckIcon, { ...iconProps })
512
+ children: isIndeterminate ? /* @__PURE__ */ jsx2(IndeterminateIcon, { ...iconProps }) : /* @__PURE__ */ jsx2(CheckIcon, { ...iconProps })
401
513
  }
402
514
  )
403
515
  }
404
516
  ) : null });
405
517
  };
406
518
  var CheckIcon = (props) => {
407
- return /* @__PURE__ */ jsx(
519
+ return /* @__PURE__ */ jsx2(
408
520
  ui.svg,
409
521
  {
410
522
  as: motion.svg,
@@ -428,12 +540,12 @@ var CheckIcon = (props) => {
428
540
  strokeDasharray: 16
429
541
  },
430
542
  ...props,
431
- children: /* @__PURE__ */ jsx("polyline", { points: "1.5 6 4.5 9 10.5 1" })
543
+ children: /* @__PURE__ */ jsx2("polyline", { points: "1.5 6 4.5 9 10.5 1" })
432
544
  }
433
545
  );
434
546
  };
435
547
  var IndeterminateIcon = (props) => {
436
- return /* @__PURE__ */ jsx(
548
+ return /* @__PURE__ */ jsx2(
437
549
  ui.svg,
438
550
  {
439
551
  as: motion.svg,
@@ -455,7 +567,7 @@ var IndeterminateIcon = (props) => {
455
567
  },
456
568
  style: { stroke: "currentColor", strokeWidth: 4 },
457
569
  ...props,
458
- children: /* @__PURE__ */ jsx("line", { x1: "21", x2: "3", y1: "12", y2: "12" })
570
+ children: /* @__PURE__ */ jsx2("line", { x1: "21", x2: "3", y1: "12", y2: "12" })
459
571
  }
460
572
  );
461
573
  };
@@ -463,5 +575,8 @@ var IndeterminateIcon = (props) => {
463
575
  export {
464
576
  useCheckbox,
465
577
  Checkbox,
466
- CheckboxIcon
578
+ CheckboxIcon,
579
+ useCheckboxGroup,
580
+ useCheckboxGroupContext,
581
+ CheckboxGroup
467
582
  };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Checkbox, CheckboxIcon, CheckboxIconProps, CheckboxProps, UseCheckboxProps, UseCheckboxReturn, useCheckbox } from './checkbox.mjs';
2
- export { CheckboxGroup, CheckboxGroupProps, UseCheckboxGroupProps, useCheckboxGroup } from './checkbox-group.mjs';
2
+ export { CheckboxGroup, CheckboxGroupProps, CheckboxItem, UseCheckboxGroupProps, useCheckboxGroup } from './checkbox-group.mjs';
3
3
  import '@yamada-ui/core';
4
4
  import '@yamada-ui/form-control';
5
5
  import '@yamada-ui/motion';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { Checkbox, CheckboxIcon, CheckboxIconProps, CheckboxProps, UseCheckboxProps, UseCheckboxReturn, useCheckbox } from './checkbox.js';
2
- export { CheckboxGroup, CheckboxGroupProps, UseCheckboxGroupProps, useCheckboxGroup } from './checkbox-group.js';
2
+ export { CheckboxGroup, CheckboxGroupProps, CheckboxItem, UseCheckboxGroupProps, useCheckboxGroup } from './checkbox-group.js';
3
3
  import '@yamada-ui/core';
4
4
  import '@yamada-ui/form-control';
5
5
  import '@yamada-ui/motion';
package/dist/index.js CHANGED
@@ -88,12 +88,18 @@ var CheckboxGroup = (0, import_react.forwardRef)(
88
88
  variant,
89
89
  colorScheme,
90
90
  children,
91
+ items = [],
91
92
  direction = "column",
92
93
  gap,
93
94
  ...props
94
95
  }, ref) => {
95
96
  const { value, onChange } = useCheckboxGroup(props);
96
97
  const { isRequired, isReadOnly, isDisabled, isInvalid } = (0, import_form_control.useFormControl)(props);
98
+ const validChildren = (0, import_utils.getValidChildren)(children);
99
+ let computedChildren = [];
100
+ if (!validChildren.length && items.length) {
101
+ computedChildren = items.map(({ label, value: value2, ...props2 }, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Checkbox, { value: value2, ...props2, children: label }, i));
102
+ }
97
103
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
98
104
  CheckboxGroupProvider,
99
105
  {
@@ -125,7 +131,7 @@ var CheckboxGroup = (0, import_react.forwardRef)(
125
131
  "isRequired",
126
132
  "isReadOnly"
127
133
  ]),
128
- children
134
+ children: children != null ? children : computedChildren
129
135
  }
130
136
  )
131
137
  }
package/dist/index.mjs CHANGED
@@ -1,13 +1,11 @@
1
1
  "use client"
2
2
  import {
3
3
  Checkbox,
4
- CheckboxIcon,
5
- useCheckbox
6
- } from "./chunk-KZ5TSBSA.mjs";
7
- import {
8
4
  CheckboxGroup,
5
+ CheckboxIcon,
6
+ useCheckbox,
9
7
  useCheckboxGroup
10
- } from "./chunk-SFCPW2O4.mjs";
8
+ } from "./chunk-2TIBZ5OE.mjs";
11
9
  export {
12
10
  Checkbox,
13
11
  CheckboxGroup,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamada-ui/checkbox",
3
- "version": "0.3.18",
3
+ "version": "0.4.0",
4
4
  "description": "Yamada UI checkbox component",
5
5
  "keywords": [
6
6
  "yamada",
@@ -37,11 +37,11 @@
37
37
  "dependencies": {
38
38
  "@yamada-ui/core": "0.12.5",
39
39
  "@yamada-ui/utils": "0.3.3",
40
- "@yamada-ui/layouts": "0.3.15",
41
- "@yamada-ui/motion": "0.4.15",
40
+ "@yamada-ui/layouts": "0.3.16",
42
41
  "@yamada-ui/form-control": "0.3.18",
42
+ "@yamada-ui/motion": "0.4.15",
43
43
  "@yamada-ui/use-focus-visible": "0.2.5",
44
- "@yamada-ui/use-controllable-state": "0.2.5"
44
+ "@yamada-ui/use-controllable-state": "0.3.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "react": "^18.0.0",
@@ -1,110 +0,0 @@
1
- "use client"
2
-
3
- // src/checkbox-group.tsx
4
- import { useFormControl } from "@yamada-ui/form-control";
5
- import { Flex } from "@yamada-ui/layouts";
6
- import { useControllableState } from "@yamada-ui/use-controllable-state";
7
- import {
8
- createContext,
9
- cx,
10
- isObject,
11
- omitObject,
12
- useCallbackRef
13
- } from "@yamada-ui/utils";
14
- import { forwardRef, useCallback } from "react";
15
- import { jsx } from "react/jsx-runtime";
16
- var isEvent = (value) => value && isObject(value) && isObject(value.target);
17
- var useCheckboxGroup = ({
18
- isNative,
19
- ...props
20
- }) => {
21
- props.onChange = useCallbackRef(props.onChange);
22
- const [value, setValue] = useControllableState({
23
- value: props.value,
24
- defaultValue: props.defaultValue || [],
25
- onChange: props.onChange
26
- });
27
- const onChange = useCallback(
28
- (evOrValue) => {
29
- const isChecked = isEvent(evOrValue) ? evOrValue.target.checked : !value.includes(evOrValue);
30
- const selectedValue = isEvent(evOrValue) ? evOrValue.target.value : evOrValue;
31
- const nextValue = isChecked ? [...value, selectedValue] : value.filter((v) => String(v) !== String(selectedValue));
32
- setValue(nextValue);
33
- },
34
- [value, setValue]
35
- );
36
- const getCheckboxProps = useCallback(
37
- (props2 = {}, ref = null) => ({
38
- ...props2,
39
- ref,
40
- [isNative ? "checked" : "isChecked"]: value.some(
41
- (val) => String(props2.value) === String(val)
42
- ),
43
- onChange
44
- }),
45
- [onChange, isNative, value]
46
- );
47
- return { value, setValue, onChange, getCheckboxProps };
48
- };
49
- var [CheckboxGroupProvider, useCheckboxGroupContext] = createContext({
50
- strict: false,
51
- name: "CheckboxGroupContext"
52
- });
53
- var CheckboxGroup = forwardRef(
54
- ({
55
- className,
56
- size,
57
- variant,
58
- colorScheme,
59
- children,
60
- direction = "column",
61
- gap,
62
- ...props
63
- }, ref) => {
64
- const { value, onChange } = useCheckboxGroup(props);
65
- const { isRequired, isReadOnly, isDisabled, isInvalid } = useFormControl(props);
66
- return /* @__PURE__ */ jsx(
67
- CheckboxGroupProvider,
68
- {
69
- value: {
70
- size,
71
- variant,
72
- colorScheme,
73
- isRequired,
74
- isReadOnly,
75
- isDisabled,
76
- isInvalid,
77
- value,
78
- onChange
79
- },
80
- children: /* @__PURE__ */ jsx(
81
- Flex,
82
- {
83
- ref,
84
- className: cx("ui-checkbox-group", className),
85
- role: "group",
86
- direction,
87
- gap: gap != null ? gap : direction === "row" ? "1rem" : void 0,
88
- ...omitObject(props, [
89
- "value",
90
- "defaultValue",
91
- "onChange",
92
- "isInvalid",
93
- "isDisabled",
94
- "isRequired",
95
- "isReadOnly"
96
- ]),
97
- children
98
- }
99
- )
100
- }
101
- );
102
- }
103
- );
104
- CheckboxGroup.displayName = "CheckboxGroup";
105
-
106
- export {
107
- useCheckboxGroup,
108
- useCheckboxGroupContext,
109
- CheckboxGroup
110
- };