@yamada-ui/checkbox 0.1.12 → 0.2.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.
@@ -6,9 +6,25 @@ import { FlexProps } from '@yamada-ui/layouts';
6
6
  import { PropGetter, DOMAttributes } from '@yamada-ui/utils';
7
7
 
8
8
  type UseCheckboxGroupProps<Y extends string | number = string> = {
9
+ /**
10
+ * The value of the checkbox group.
11
+ */
9
12
  value?: Y[];
13
+ /**
14
+ * The initial value of the checkbox group.
15
+ */
10
16
  defaultValue?: Y[];
17
+ /**
18
+ * The callback fired when any children checkbox is checked or unchecked.
19
+ */
11
20
  onChange?: (value: Y[]) => void;
21
+ /**
22
+ * If `true`, input elements will receive `checked` attribute instead of `isChecked`.
23
+ *
24
+ * This assumes, you're using native radio inputs.
25
+ *
26
+ * @default false
27
+ */
12
28
  isNative?: boolean;
13
29
  };
14
30
  declare const useCheckboxGroup: <Y extends string | number = string>({ isNative, ...props }: UseCheckboxGroupProps<Y>) => {
@@ -28,6 +44,7 @@ declare const useCheckboxGroup: <Y extends string | number = string>({ isNative,
28
44
  onChange: (ev: Y | ChangeEvent<HTMLInputElement>) => void;
29
45
  }>;
30
46
  };
47
+ type UseCheckboxGroupReturn = ReturnType<typeof useCheckboxGroup>;
31
48
  type CheckboxGroupProps<Y extends string | number = string> = ThemeProps<'Checkbox'> & Omit<FlexProps, 'onChange'> & UseCheckboxGroupProps<Y> & FormControlOptions;
32
49
  type CheckboxContext = ThemeProps<'Checkbox'> & FormControlOptions & {
33
50
  value: (string | number)[];
@@ -39,4 +56,4 @@ declare const CheckboxGroup: (<Y extends string | number = string>(props: ThemeP
39
56
  ref?: Ref<HTMLDivElement> | undefined;
40
57
  }) => JSX.Element) & ComponentArgs;
41
58
 
42
- export { CheckboxGroup, CheckboxGroupProps, UseCheckboxGroupProps, useCheckboxGroup, useCheckboxGroupContext };
59
+ export { CheckboxGroup, CheckboxGroupProps, UseCheckboxGroupProps, UseCheckboxGroupReturn, useCheckboxGroup, useCheckboxGroupContext };
@@ -5,15 +5,51 @@ import { PropGetter } from '@yamada-ui/utils';
5
5
  import { ChangeEventHandler, FocusEventHandler, Ref, FC, ReactElement, InputHTMLAttributes } from 'react';
6
6
 
7
7
  type UseCheckboxProps<Y extends string | number = string> = FormControlOptions & {
8
+ /**
9
+ * id assigned to input.
10
+ */
8
11
  id?: string;
12
+ /**
13
+ * The HTML `name` attribute used for forms.
14
+ */
9
15
  name?: string;
16
+ /**
17
+ * The value to be used in the checkbox input.
18
+ */
10
19
  value?: Y;
20
+ /**
21
+ * If `true`, the checkbox will be initially checked.
22
+ *
23
+ * @default false
24
+ */
11
25
  defaultChecked?: boolean;
26
+ /**
27
+ * If `true`, the checkbox will be checked.
28
+ *
29
+ * @default false
30
+ */
12
31
  isChecked?: boolean;
32
+ /**
33
+ * If `true`, the checkbox will be indeterminate.
34
+ *
35
+ * @default false
36
+ */
13
37
  isIndeterminate?: boolean;
38
+ /**
39
+ * The callback invoked when the checked state changes.
40
+ */
14
41
  onChange?: ChangeEventHandler<HTMLInputElement>;
42
+ /**
43
+ * The callback invoked when the checkbox is focused.
44
+ */
15
45
  onFocus?: FocusEventHandler<HTMLInputElement>;
46
+ /**
47
+ * The callback invoked when the checkbox is blurred.
48
+ */
16
49
  onBlur?: FocusEventHandler<HTMLInputElement>;
50
+ /**
51
+ * The tab-index property of the underlying input element.
52
+ */
17
53
  tabIndex?: number;
18
54
  };
19
55
  declare const useCheckbox: <Y extends string | number = string>(props: UseCheckboxProps<Y>) => {
@@ -28,32 +64,88 @@ declare const useCheckbox: <Y extends string | number = string>(props: UseCheckb
28
64
  getInputProps: PropGetter;
29
65
  getLabelProps: PropGetter;
30
66
  };
67
+ type UseCheckboxReturn = ReturnType<typeof useCheckbox>;
31
68
  type CheckboxOptions = {
69
+ /**
70
+ * Props for icon component.
71
+ */
32
72
  iconProps?: Omit<HTMLUIProps<'span'>, 'children'> & {
33
73
  children: ReactElement;
34
74
  };
75
+ /**
76
+ * Props for input element.
77
+ */
35
78
  inputProps?: InputHTMLAttributes<HTMLInputElement>;
79
+ /**
80
+ * Props for label element.
81
+ */
36
82
  labelProps?: HTMLUIProps<'span'>;
37
83
  };
38
84
  type CheckboxProps<Y extends string | number = string> = Omit<HTMLUIProps<'label'>, keyof UseCheckboxProps | 'checked'> & ThemeProps<'Checkbox'> & UseCheckboxProps<Y> & CheckboxOptions;
39
- 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 & {
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 & {
86
+ /**
87
+ * id assigned to input.
88
+ */
40
89
  id?: string | undefined;
90
+ /**
91
+ * The HTML `name` attribute used for forms.
92
+ */
41
93
  name?: string | undefined;
94
+ /**
95
+ * The value to be used in the checkbox input.
96
+ */
42
97
  value?: Y | undefined;
98
+ /**
99
+ * If `true`, the checkbox will be initially checked.
100
+ *
101
+ * @default false
102
+ */
43
103
  defaultChecked?: boolean | undefined;
104
+ /**
105
+ * If `true`, the checkbox will be checked.
106
+ *
107
+ * @default false
108
+ */
44
109
  isChecked?: boolean | undefined;
110
+ /**
111
+ * If `true`, the checkbox will be indeterminate.
112
+ *
113
+ * @default false
114
+ */
45
115
  isIndeterminate?: boolean | undefined;
116
+ /**
117
+ * The callback invoked when the checked state changes.
118
+ */
46
119
  onChange?: ChangeEventHandler<HTMLInputElement> | undefined;
120
+ /**
121
+ * The callback invoked when the checkbox is focused.
122
+ */
47
123
  onFocus?: FocusEventHandler<HTMLInputElement> | undefined;
124
+ /**
125
+ * The callback invoked when the checkbox is blurred.
126
+ */
48
127
  onBlur?: FocusEventHandler<HTMLInputElement> | undefined;
128
+ /**
129
+ * The tab-index property of the underlying input element.
130
+ */
49
131
  tabIndex?: number | undefined;
50
132
  } & CheckboxOptions & {
51
133
  ref?: Ref<HTMLInputElement> | undefined;
52
134
  }) => JSX.Element) & ComponentArgs;
53
135
  type CheckboxIconProps = HTMLUIProps<'svg'> & SVGMotionProps<SVGSVGElement> & FormControlOptions & {
136
+ /**
137
+ * If `true`, the icon will be indeterminate.
138
+ *
139
+ * @default false
140
+ */
54
141
  isIndeterminate?: boolean;
142
+ /**
143
+ * If `true`, the icon will be checked.
144
+ *
145
+ * @default false
146
+ */
55
147
  isChecked?: boolean;
56
148
  };
57
149
  declare const CheckboxIcon: FC<CheckboxIconProps>;
58
150
 
59
- export { Checkbox, CheckboxIcon, CheckboxIconProps, CheckboxProps, UseCheckboxProps, useCheckbox };
151
+ export { Checkbox, CheckboxIcon, CheckboxIconProps, CheckboxProps, UseCheckboxProps, UseCheckboxReturn, useCheckbox };
package/dist/checkbox.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  Checkbox,
3
3
  CheckboxIcon,
4
4
  useCheckbox
5
- } from "./chunk-H7YAGSVR.mjs";
5
+ } from "./chunk-EHSLGZE4.mjs";
6
6
  import "./chunk-VWDV5UM7.mjs";
7
7
  export {
8
8
  Checkbox,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { Checkbox, CheckboxIcon, CheckboxIconProps, CheckboxProps, UseCheckboxProps, useCheckbox } from './checkbox.js';
2
- export { CheckboxGroup, CheckboxGroupProps, UseCheckboxGroupProps, useCheckboxGroup, useCheckboxGroupContext } from './checkbox-group.js';
1
+ export { Checkbox, CheckboxIcon, CheckboxIconProps, CheckboxProps, UseCheckboxProps, UseCheckboxReturn, useCheckbox } from './checkbox.js';
2
+ export { CheckboxGroup, CheckboxGroupProps, 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
@@ -24,19 +24,119 @@ __export(src_exports, {
24
24
  CheckboxGroup: () => CheckboxGroup,
25
25
  CheckboxIcon: () => CheckboxIcon,
26
26
  useCheckbox: () => useCheckbox,
27
- useCheckboxGroup: () => useCheckboxGroup,
28
- useCheckboxGroupContext: () => useCheckboxGroupContext
27
+ useCheckboxGroup: () => useCheckboxGroup
29
28
  });
30
29
  module.exports = __toCommonJS(src_exports);
31
30
 
32
31
  // src/checkbox.tsx
33
32
  var import_core = require("@yamada-ui/core");
34
- var import_form_control = require("@yamada-ui/form-control");
33
+ var import_form_control2 = require("@yamada-ui/form-control");
35
34
  var import_motion = require("@yamada-ui/motion");
36
35
  var import_use_focus_visible = require("@yamada-ui/use-focus-visible");
36
+ var import_utils2 = require("@yamada-ui/utils");
37
+ var import_react2 = require("react");
38
+
39
+ // src/checkbox-group.tsx
40
+ var import_form_control = require("@yamada-ui/form-control");
41
+ var import_layouts = require("@yamada-ui/layouts");
42
+ var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
37
43
  var import_utils = require("@yamada-ui/utils");
38
44
  var import_react = require("react");
39
45
  var import_jsx_runtime = require("react/jsx-runtime");
46
+ var isEvent = (value) => value && (0, import_utils.isObject)(value) && (0, import_utils.isObject)(value.target);
47
+ var useCheckboxGroup = ({
48
+ isNative,
49
+ ...props
50
+ }) => {
51
+ props.onChange = (0, import_utils.useCallbackRef)(props.onChange);
52
+ const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
53
+ value: props.value,
54
+ defaultValue: props.defaultValue || [],
55
+ onChange: props.onChange
56
+ });
57
+ const onChange = (0, import_react.useCallback)(
58
+ (evOrValue) => {
59
+ const isChecked = isEvent(evOrValue) ? evOrValue.target.checked : !value.includes(evOrValue);
60
+ const selectedValue = isEvent(evOrValue) ? evOrValue.target.value : evOrValue;
61
+ const nextValue = isChecked ? [...value, selectedValue] : value.filter((v) => String(v) !== String(selectedValue));
62
+ setValue(nextValue);
63
+ },
64
+ [value, setValue]
65
+ );
66
+ const getCheckboxProps = (0, import_react.useCallback)(
67
+ (props2 = {}, ref = null) => ({
68
+ ...props2,
69
+ ref,
70
+ [isNative ? "checked" : "isChecked"]: value.some(
71
+ (val) => String(props2.value) === String(val)
72
+ ),
73
+ onChange
74
+ }),
75
+ [onChange, isNative, value]
76
+ );
77
+ return { value, setValue, onChange, getCheckboxProps };
78
+ };
79
+ var [CheckboxGroupProvider, useCheckboxGroupContext] = (0, import_utils.createContext)(
80
+ {
81
+ strict: false,
82
+ name: "CheckboxGroupContext"
83
+ }
84
+ );
85
+ var CheckboxGroup = (0, import_react.forwardRef)(
86
+ ({
87
+ className,
88
+ size,
89
+ variant,
90
+ colorScheme,
91
+ children,
92
+ direction = "column",
93
+ gap,
94
+ ...props
95
+ }, ref) => {
96
+ const { value, onChange } = useCheckboxGroup(props);
97
+ const { isRequired, isReadOnly, isDisabled, isInvalid } = (0, import_form_control.useFormControl)(props);
98
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
99
+ CheckboxGroupProvider,
100
+ {
101
+ value: {
102
+ size,
103
+ variant,
104
+ colorScheme,
105
+ isRequired,
106
+ isReadOnly,
107
+ isDisabled,
108
+ isInvalid,
109
+ value,
110
+ onChange
111
+ },
112
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
113
+ import_layouts.Flex,
114
+ {
115
+ ref,
116
+ className: (0, import_utils.cx)("ui-checkbox-group", className),
117
+ role: "group",
118
+ direction,
119
+ gap: gap != null ? gap : direction === "row" ? "1rem" : void 0,
120
+ ...(0, import_utils.omitObject)(props, [
121
+ "value",
122
+ "defaultValue",
123
+ "onChange",
124
+ "isInvalid",
125
+ "isDisabled",
126
+ "isRequired",
127
+ "isReadOnly"
128
+ ]),
129
+ children
130
+ }
131
+ )
132
+ }
133
+ );
134
+ }
135
+ );
136
+ CheckboxGroup.displayName = "CheckboxGroup";
137
+
138
+ // src/checkbox.tsx
139
+ var import_jsx_runtime2 = require("react/jsx-runtime");
40
140
  var useCheckbox = (props) => {
41
141
  const {
42
142
  id,
@@ -49,17 +149,17 @@ var useCheckbox = (props) => {
49
149
  readOnly,
50
150
  isIndeterminate,
51
151
  ...rest
52
- } = (0, import_form_control.useFormControlProps)(props);
53
- const [isFocusVisible, setIsFocusVisible] = (0, import_react.useState)(false);
54
- const [isFocused, setFocused] = (0, import_react.useState)(false);
55
- const [isHovered, setHovered] = (0, import_react.useState)(false);
56
- const [isActive, setActive] = (0, import_react.useState)(false);
57
- const inputRef = (0, import_react.useRef)(null);
58
- const [isLabel, setIsLabel] = (0, import_react.useState)(true);
59
- const [isChecked, setIsChecked] = (0, import_react.useState)(!!defaultChecked);
152
+ } = (0, import_form_control2.useFormControlProps)(props);
153
+ const [isFocusVisible, setIsFocusVisible] = (0, import_react2.useState)(false);
154
+ const [isFocused, setFocused] = (0, import_react2.useState)(false);
155
+ const [isHovered, setHovered] = (0, import_react2.useState)(false);
156
+ const [isActive, setActive] = (0, import_react2.useState)(false);
157
+ const inputRef = (0, import_react2.useRef)(null);
158
+ const [isLabel, setIsLabel] = (0, import_react2.useState)(true);
159
+ const [isChecked, setIsChecked] = (0, import_react2.useState)(!!defaultChecked);
60
160
  const isControlled = props.isChecked !== void 0;
61
161
  const checked = isControlled ? props.isChecked : isChecked;
62
- const onChange = (0, import_utils.useCallbackRef)(
162
+ const onChange = (0, import_utils2.useCallbackRef)(
63
163
  (ev) => {
64
164
  var _a;
65
165
  if (readOnly || disabled) {
@@ -72,55 +172,55 @@ var useCheckbox = (props) => {
72
172
  },
73
173
  [readOnly, disabled, isControlled, checked, isIndeterminate]
74
174
  );
75
- const onBlur = (0, import_utils.useCallbackRef)(rest.onBlur);
76
- const onFocus = (0, import_utils.useCallbackRef)(rest.onFocus);
77
- const onKeyDown = (0, import_react.useCallback)(
175
+ const onBlur = (0, import_utils2.useCallbackRef)(rest.onBlur);
176
+ const onFocus = (0, import_utils2.useCallbackRef)(rest.onFocus);
177
+ const onKeyDown = (0, import_react2.useCallback)(
78
178
  ({ key }) => {
79
179
  if (key === " ")
80
180
  setActive(true);
81
181
  },
82
182
  [setActive]
83
183
  );
84
- const onKeyUp = (0, import_react.useCallback)(
184
+ const onKeyUp = (0, import_react2.useCallback)(
85
185
  ({ key }) => {
86
186
  if (key === " ")
87
187
  setActive(false);
88
188
  },
89
189
  [setActive]
90
190
  );
91
- (0, import_react.useEffect)(() => {
191
+ (0, import_react2.useEffect)(() => {
92
192
  return (0, import_use_focus_visible.trackFocusVisible)(setIsFocusVisible);
93
193
  }, []);
94
- (0, import_utils.useSafeLayoutEffect)(() => {
194
+ (0, import_utils2.useSafeLayoutEffect)(() => {
95
195
  if (inputRef.current)
96
196
  inputRef.current.indeterminate = Boolean(isIndeterminate);
97
197
  }, [isIndeterminate]);
98
- (0, import_utils.useUpdateEffect)(() => {
198
+ (0, import_utils2.useUpdateEffect)(() => {
99
199
  if (disabled)
100
200
  setFocused(false);
101
201
  }, [disabled, setFocused]);
102
- (0, import_utils.useSafeLayoutEffect)(() => {
202
+ (0, import_utils2.useSafeLayoutEffect)(() => {
103
203
  var _a;
104
204
  if (!((_a = inputRef.current) == null ? void 0 : _a.form))
105
205
  return;
106
206
  inputRef.current.form.onreset = () => setIsChecked(!!defaultChecked);
107
207
  }, []);
108
- (0, import_utils.useSafeLayoutEffect)(() => {
208
+ (0, import_utils2.useSafeLayoutEffect)(() => {
109
209
  if (!inputRef.current)
110
210
  return;
111
211
  if (inputRef.current.checked !== checked)
112
212
  setIsChecked(inputRef.current.checked);
113
213
  }, [inputRef.current]);
114
- const getContainerProps = (0, import_react.useCallback)(
214
+ const getContainerProps = (0, import_react2.useCallback)(
115
215
  (props2 = {}, ref = null) => ({
116
- ...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
216
+ ...(0, import_utils2.pickObject)(rest, import_form_control2.formControlProperties),
117
217
  ...props2,
118
- ref: (0, import_utils.mergeRefs)(ref, (el) => {
218
+ ref: (0, import_utils2.mergeRefs)(ref, (el) => {
119
219
  if (el)
120
220
  setIsLabel(el.tagName === "LABEL");
121
221
  }),
122
- "data-checked": (0, import_utils.dataAttr)(checked),
123
- onClick: (0, import_utils.handlerAll)(props2.onClick, () => {
222
+ "data-checked": (0, import_utils2.dataAttr)(checked),
223
+ onClick: (0, import_utils2.handlerAll)(props2.onClick, () => {
124
224
  var _a;
125
225
  if (isLabel)
126
226
  return;
@@ -133,34 +233,34 @@ var useCheckbox = (props) => {
133
233
  }),
134
234
  [checked, isLabel, rest]
135
235
  );
136
- const getIconProps = (0, import_react.useCallback)(
236
+ const getIconProps = (0, import_react2.useCallback)(
137
237
  (props2 = {}, ref = null) => ({
138
- ...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
238
+ ...(0, import_utils2.pickObject)(rest, import_form_control2.formControlProperties),
139
239
  ...props2,
140
240
  ref,
141
- "data-active": (0, import_utils.dataAttr)(isActive),
142
- "data-hover": (0, import_utils.dataAttr)(isHovered),
143
- "data-checked": (0, import_utils.dataAttr)(checked),
144
- "data-focus": (0, import_utils.dataAttr)(isFocused),
145
- "data-focus-visible": (0, import_utils.dataAttr)(isFocused && isFocusVisible),
146
- "data-indeterminate": (0, import_utils.dataAttr)(isIndeterminate),
241
+ "data-active": (0, import_utils2.dataAttr)(isActive),
242
+ "data-hover": (0, import_utils2.dataAttr)(isHovered),
243
+ "data-checked": (0, import_utils2.dataAttr)(checked),
244
+ "data-focus": (0, import_utils2.dataAttr)(isFocused),
245
+ "data-focus-visible": (0, import_utils2.dataAttr)(isFocused && isFocusVisible),
246
+ "data-indeterminate": (0, import_utils2.dataAttr)(isIndeterminate),
147
247
  "aria-hidden": true,
148
- onMouseDown: (0, import_utils.handlerAll)(props2.onMouseDown, (ev) => {
248
+ onMouseDown: (0, import_utils2.handlerAll)(props2.onMouseDown, (ev) => {
149
249
  if (isFocused)
150
250
  ev.preventDefault();
151
251
  setActive(true);
152
252
  }),
153
- onMouseUp: (0, import_utils.handlerAll)(props2.onMouseUp, () => setActive(false)),
154
- onMouseEnter: (0, import_utils.handlerAll)(props2.onMouseEnter, () => setHovered(true)),
155
- onMouseLeave: (0, import_utils.handlerAll)(props2.onMouseLeave, () => setHovered(false))
253
+ onMouseUp: (0, import_utils2.handlerAll)(props2.onMouseUp, () => setActive(false)),
254
+ onMouseEnter: (0, import_utils2.handlerAll)(props2.onMouseEnter, () => setHovered(true)),
255
+ onMouseLeave: (0, import_utils2.handlerAll)(props2.onMouseLeave, () => setHovered(false))
156
256
  }),
157
257
  [isActive, checked, isFocused, isHovered, isFocusVisible, isIndeterminate, rest]
158
258
  );
159
- const getInputProps = (0, import_react.useCallback)(
259
+ const getInputProps = (0, import_react2.useCallback)(
160
260
  (props2 = {}, ref = null) => ({
161
- ...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
261
+ ...(0, import_utils2.pickObject)(rest, import_form_control2.formControlProperties),
162
262
  ...props2,
163
- ref: (0, import_utils.mergeRefs)(inputRef, ref),
263
+ ref: (0, import_utils2.mergeRefs)(inputRef, ref),
164
264
  id,
165
265
  type: "checkbox",
166
266
  name,
@@ -181,11 +281,11 @@ var useCheckbox = (props) => {
181
281
  whiteSpace: "nowrap",
182
282
  position: "absolute"
183
283
  },
184
- onChange: (0, import_utils.handlerAll)(props2.onChange, onChange),
185
- onBlur: (0, import_utils.handlerAll)(props2.onBlur, onBlur, () => setFocused(false)),
186
- onFocus: (0, import_utils.handlerAll)(props2.onFocus, onFocus, () => setFocused(true)),
187
- onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, onKeyDown),
188
- onKeyUp: (0, import_utils.handlerAll)(props2.onKeyUp, onKeyUp)
284
+ onChange: (0, import_utils2.handlerAll)(props2.onChange, onChange),
285
+ onBlur: (0, import_utils2.handlerAll)(props2.onBlur, onBlur, () => setFocused(false)),
286
+ onFocus: (0, import_utils2.handlerAll)(props2.onFocus, onFocus, () => setFocused(true)),
287
+ onKeyDown: (0, import_utils2.handlerAll)(props2.onKeyDown, onKeyDown),
288
+ onKeyUp: (0, import_utils2.handlerAll)(props2.onKeyUp, onKeyUp)
189
289
  }),
190
290
  [
191
291
  rest,
@@ -204,17 +304,17 @@ var useCheckbox = (props) => {
204
304
  onKeyUp
205
305
  ]
206
306
  );
207
- const getLabelProps = (0, import_react.useCallback)(
307
+ const getLabelProps = (0, import_react2.useCallback)(
208
308
  (props2 = {}, ref = null) => ({
209
- ...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
309
+ ...(0, import_utils2.pickObject)(rest, import_form_control2.formControlProperties),
210
310
  ...props2,
211
311
  ref,
212
- "data-checked": (0, import_utils.dataAttr)(checked),
213
- onMouseDown: (0, import_utils.handlerAll)(props2.onMouseDown, (ev) => {
312
+ "data-checked": (0, import_utils2.dataAttr)(checked),
313
+ onMouseDown: (0, import_utils2.handlerAll)(props2.onMouseDown, (ev) => {
214
314
  ev.preventDefault();
215
315
  ev.stopPropagation();
216
316
  }),
217
- onTouchStart: (0, import_utils.handlerAll)(props2.onTouchStart, (ev) => {
317
+ onTouchStart: (0, import_utils2.handlerAll)(props2.onTouchStart, (ev) => {
218
318
  ev.preventDefault();
219
319
  ev.stopPropagation();
220
320
  })
@@ -234,13 +334,13 @@ var useCheckbox = (props) => {
234
334
  getLabelProps
235
335
  };
236
336
  };
237
- var Checkbox = (0, import_react.forwardRef)(
337
+ var Checkbox = (0, import_react2.forwardRef)(
238
338
  (props, ref) => {
239
339
  var _a, _b, _c, _d, _e;
240
340
  const group = useCheckboxGroupContext();
241
- const control = (0, import_form_control.useFormControl)(props);
341
+ const control = (0, import_form_control2.useFormControl)(props);
242
342
  const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Checkbox", {
243
- ...group ? (0, import_utils.omitObject)(group, ["value"]) : {},
343
+ ...group ? (0, import_utils2.omitObject)(group, ["value"]) : {},
244
344
  ...props
245
345
  });
246
346
  const {
@@ -270,9 +370,9 @@ var Checkbox = (0, import_react.forwardRef)(
270
370
  isDisabled,
271
371
  isInvalid,
272
372
  isChecked: (group == null ? void 0 : group.value) && rest.value ? group.value.includes(rest.value) : rest.isChecked,
273
- onChange: (group == null ? void 0 : group.onChange) && rest.value ? (0, import_utils.funcAll)(group.onChange, rest.onChange) : rest.onChange
373
+ onChange: (group == null ? void 0 : group.onChange) && rest.value ? (0, import_utils2.funcAll)(group.onChange, rest.onChange) : rest.onChange
274
374
  });
275
- const cloneIcon = (0, import_react.cloneElement)((_e = iconProps == null ? void 0 : iconProps.children) != null ? _e : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckboxIcon, {}), {
375
+ const cloneIcon = (0, import_react2.cloneElement)((_e = iconProps == null ? void 0 : iconProps.children) != null ? _e : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CheckboxIcon, {}), {
276
376
  __css: {
277
377
  opacity: isChecked || isIndeterminate ? 1 : 0,
278
378
  transform: isChecked || isIndeterminate ? "scale(1)" : "scale(0.95)",
@@ -286,10 +386,10 @@ var Checkbox = (0, import_react.forwardRef)(
286
386
  isDisabled,
287
387
  isInvalid
288
388
  });
289
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
389
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
290
390
  import_core.ui.label,
291
391
  {
292
- className: (0, import_utils.cx)("ui-checkbox", className),
392
+ className: (0, import_utils2.cx)("ui-checkbox", className),
293
393
  ...getContainerProps(),
294
394
  __css: {
295
395
  cursor: "pointer",
@@ -300,7 +400,7 @@ var Checkbox = (0, import_react.forwardRef)(
300
400
  gap,
301
401
  ...styles.container
302
402
  },
303
- ...(0, import_utils.omitObject)(rest, [
403
+ ...(0, import_utils2.omitObject)(rest, [
304
404
  "id",
305
405
  "name",
306
406
  "value",
@@ -314,8 +414,8 @@ var Checkbox = (0, import_react.forwardRef)(
314
414
  "tabIndex"
315
415
  ]),
316
416
  children: [
317
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ui.input, { className: "ui-checkbox-input", ...getInputProps(inputProps, ref) }),
318
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
417
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core.ui.input, { className: "ui-checkbox-input", ...getInputProps(inputProps, ref) }),
418
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
319
419
  import_core.ui.span,
320
420
  {
321
421
  className: "ui-checkbox-icon",
@@ -326,11 +426,11 @@ var Checkbox = (0, import_react.forwardRef)(
326
426
  userSelect: "none",
327
427
  ...styles.icon
328
428
  },
329
- ...getIconProps((0, import_utils.omitObject)(iconProps != null ? iconProps : { children: void 0 }, ["children"])),
429
+ ...getIconProps((0, import_utils2.omitObject)(iconProps != null ? iconProps : { children: void 0 }, ["children"])),
330
430
  children: cloneIcon
331
431
  }
332
432
  ),
333
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
433
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
334
434
  import_core.ui.span,
335
435
  {
336
436
  className: "ui-checkbox-label",
@@ -354,7 +454,7 @@ var CheckboxIcon = ({
354
454
  isInvalid,
355
455
  ...rest
356
456
  }) => {
357
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_motion.AnimatePresence, { initial: false, children: isIndeterminate || isChecked ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
457
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_motion.AnimatePresence, { initial: false, children: isIndeterminate || isChecked ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
358
458
  import_core.ui.div,
359
459
  {
360
460
  __css: {
@@ -363,7 +463,7 @@ var CheckboxIcon = ({
363
463
  left: "50%",
364
464
  transform: "translate(-50%, -50%)"
365
465
  },
366
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
466
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
367
467
  import_core.ui.div,
368
468
  {
369
469
  as: import_motion.motion.div,
@@ -379,14 +479,14 @@ var CheckboxIcon = ({
379
479
  alignItems: "center",
380
480
  justifyContent: "center"
381
481
  },
382
- children: isIndeterminate ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IndeterminateIcon, { ...rest }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckIcon, { ...rest })
482
+ children: isIndeterminate ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IndeterminateIcon, { ...rest }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CheckIcon, { ...rest })
383
483
  }
384
484
  )
385
485
  }
386
486
  ) : null });
387
487
  };
388
488
  var CheckIcon = (props) => {
389
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
489
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
390
490
  import_core.ui.svg,
391
491
  {
392
492
  as: import_motion.motion.svg,
@@ -410,12 +510,12 @@ var CheckIcon = (props) => {
410
510
  strokeDasharray: 16
411
511
  },
412
512
  ...props,
413
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "1.5 6 4.5 9 10.5 1" })
513
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "1.5 6 4.5 9 10.5 1" })
414
514
  }
415
515
  );
416
516
  };
417
517
  var IndeterminateIcon = (props) => {
418
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
518
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
419
519
  import_core.ui.svg,
420
520
  {
421
521
  as: import_motion.motion.svg,
@@ -437,115 +537,15 @@ var IndeterminateIcon = (props) => {
437
537
  },
438
538
  style: { stroke: "currentColor", strokeWidth: 4 },
439
539
  ...props,
440
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "21", x2: "3", y1: "12", y2: "12" })
540
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "21", x2: "3", y1: "12", y2: "12" })
441
541
  }
442
542
  );
443
543
  };
444
-
445
- // src/checkbox-group.tsx
446
- var import_form_control2 = require("@yamada-ui/form-control");
447
- var import_layouts = require("@yamada-ui/layouts");
448
- var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
449
- var import_utils2 = require("@yamada-ui/utils");
450
- var import_react2 = require("react");
451
- var import_jsx_runtime2 = require("react/jsx-runtime");
452
- var isEvent = (value) => value && (0, import_utils2.isObject)(value) && (0, import_utils2.isObject)(value.target);
453
- var useCheckboxGroup = ({
454
- isNative,
455
- ...props
456
- }) => {
457
- props.onChange = (0, import_utils2.useCallbackRef)(props.onChange);
458
- const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
459
- value: props.value,
460
- defaultValue: props.defaultValue || [],
461
- onChange: props.onChange
462
- });
463
- const onChange = (0, import_react2.useCallback)(
464
- (evOrValue) => {
465
- const isChecked = isEvent(evOrValue) ? evOrValue.target.checked : !value.includes(evOrValue);
466
- const selectedValue = isEvent(evOrValue) ? evOrValue.target.value : evOrValue;
467
- const nextValue = isChecked ? [...value, selectedValue] : value.filter((v) => String(v) !== String(selectedValue));
468
- setValue(nextValue);
469
- },
470
- [value, setValue]
471
- );
472
- const getCheckboxProps = (0, import_react2.useCallback)(
473
- (props2 = {}, ref = null) => ({
474
- ...props2,
475
- ref,
476
- [isNative ? "checked" : "isChecked"]: value.some(
477
- (val) => String(props2.value) === String(val)
478
- ),
479
- onChange
480
- }),
481
- [onChange, isNative, value]
482
- );
483
- return { value, setValue, onChange, getCheckboxProps };
484
- };
485
- var [CheckboxGroupProvider, useCheckboxGroupContext] = (0, import_utils2.createContext)(
486
- {
487
- strict: false,
488
- name: "CheckboxGroupContext"
489
- }
490
- );
491
- var CheckboxGroup = (0, import_react2.forwardRef)(
492
- ({
493
- className,
494
- size,
495
- variant,
496
- colorScheme,
497
- children,
498
- direction = "column",
499
- gap,
500
- ...props
501
- }, ref) => {
502
- const { value, onChange } = useCheckboxGroup(props);
503
- const { isRequired, isReadOnly, isDisabled, isInvalid } = (0, import_form_control2.useFormControl)(props);
504
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
505
- CheckboxGroupProvider,
506
- {
507
- value: {
508
- size,
509
- variant,
510
- colorScheme,
511
- isRequired,
512
- isReadOnly,
513
- isDisabled,
514
- isInvalid,
515
- value,
516
- onChange
517
- },
518
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
519
- import_layouts.Flex,
520
- {
521
- ref,
522
- className: (0, import_utils2.cx)("ui-checkbox-group", className),
523
- role: "group",
524
- direction,
525
- gap: gap != null ? gap : direction === "row" ? "1rem" : void 0,
526
- ...(0, import_utils2.omitObject)(props, [
527
- "value",
528
- "defaultValue",
529
- "onChange",
530
- "isInvalid",
531
- "isDisabled",
532
- "isRequired",
533
- "isReadOnly"
534
- ]),
535
- children
536
- }
537
- )
538
- }
539
- );
540
- }
541
- );
542
- CheckboxGroup.displayName = "CheckboxGroup";
543
544
  // Annotate the CommonJS export names for ESM import in node:
544
545
  0 && (module.exports = {
545
546
  Checkbox,
546
547
  CheckboxGroup,
547
548
  CheckboxIcon,
548
549
  useCheckbox,
549
- useCheckboxGroup,
550
- useCheckboxGroupContext
550
+ useCheckboxGroup
551
551
  });
package/dist/index.mjs CHANGED
@@ -2,17 +2,15 @@ import {
2
2
  Checkbox,
3
3
  CheckboxIcon,
4
4
  useCheckbox
5
- } from "./chunk-H7YAGSVR.mjs";
5
+ } from "./chunk-EHSLGZE4.mjs";
6
6
  import {
7
7
  CheckboxGroup,
8
- useCheckboxGroup,
9
- useCheckboxGroupContext
8
+ useCheckboxGroup
10
9
  } from "./chunk-VWDV5UM7.mjs";
11
10
  export {
12
11
  Checkbox,
13
12
  CheckboxGroup,
14
13
  CheckboxIcon,
15
14
  useCheckbox,
16
- useCheckboxGroup,
17
- useCheckboxGroupContext
15
+ useCheckboxGroup
18
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamada-ui/checkbox",
3
- "version": "0.1.12",
3
+ "version": "0.2.0",
4
4
  "description": "Yamada UI checkbox component",
5
5
  "keywords": [
6
6
  "yamada",
@@ -35,11 +35,11 @@
35
35
  "url": "https://github.com/hirotomoyamada/yamada-ui/issues"
36
36
  },
37
37
  "dependencies": {
38
- "@yamada-ui/core": "0.3.0",
38
+ "@yamada-ui/core": "0.3.1",
39
39
  "@yamada-ui/utils": "0.1.1",
40
- "@yamada-ui/layouts": "0.1.11",
41
- "@yamada-ui/form-control": "0.1.11",
42
- "@yamada-ui/motion": "0.1.11",
40
+ "@yamada-ui/layouts": "0.2.0",
41
+ "@yamada-ui/form-control": "0.2.0",
42
+ "@yamada-ui/motion": "0.2.0",
43
43
  "@yamada-ui/use-focus-visible": "0.1.1",
44
44
  "@yamada-ui/use-controllable-state": "0.1.2"
45
45
  },
@@ -75,6 +75,6 @@
75
75
  "build:fast": "tsup src",
76
76
  "clean": "rimraf dist .turbo",
77
77
  "typecheck": "tsc --noEmit",
78
- "gen:types": "tsx ../../../scripts/generate-types"
78
+ "gen:docs": "tsx ../../../scripts/generate-docs"
79
79
  }
80
80
  }
File without changes