@yamada-ui/checkbox 1.0.30-dev-20240508155232 → 1.0.30-dev-20240509145447
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/checkbox-group.d.mts +3 -2
- package/dist/checkbox-group.d.ts +3 -2
- package/dist/checkbox-group.js +62 -81
- package/dist/checkbox-group.js.map +1 -1
- package/dist/checkbox-group.mjs +1 -1
- package/dist/checkbox.d.mts +136 -5
- package/dist/checkbox.d.ts +136 -5
- package/dist/checkbox.js +62 -81
- package/dist/checkbox.js.map +1 -1
- package/dist/checkbox.mjs +1 -1
- package/dist/{chunk-YGXYTAEQ.mjs → chunk-H5URUECR.mjs} +66 -87
- package/dist/chunk-H5URUECR.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +62 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
- package/dist/chunk-YGXYTAEQ.mjs.map +0 -1
package/dist/checkbox.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ChangeEventHandler, FocusEventHandler, Ref, FC, ReactElement, InputHTMLAttributes } from 'react';
|
|
1
3
|
import { UIPropGetter, HTMLUIProps, ThemeProps, ComponentArgs } from '@yamada-ui/core';
|
|
2
4
|
import { FormControlOptions } from '@yamada-ui/form-control';
|
|
3
5
|
import { SVGMotionProps } from '@yamada-ui/motion';
|
|
4
|
-
import { PropGetter } from '@yamada-ui/utils';
|
|
5
|
-
import { ChangeEventHandler, FocusEventHandler, Ref, FC, ReactElement, InputHTMLAttributes } from 'react';
|
|
6
|
+
import { Dict, PropGetter, Merge } from '@yamada-ui/utils';
|
|
6
7
|
|
|
7
8
|
type UseCheckboxProps<Y extends string | number = string> = FormControlOptions & {
|
|
8
9
|
/**
|
|
@@ -52,13 +53,143 @@ type UseCheckboxProps<Y extends string | number = string> = FormControlOptions &
|
|
|
52
53
|
*/
|
|
53
54
|
tabIndex?: number;
|
|
54
55
|
};
|
|
55
|
-
declare const useCheckbox: <Y extends string | number = string>(props: UseCheckboxProps<Y>) => {
|
|
56
|
+
declare const useCheckbox: <Y extends string | number = string, M extends Dict = Dict>({ id, ...props }: UseCheckboxProps<Y> & M) => {
|
|
57
|
+
props: Omit<Omit<{
|
|
58
|
+
_hover?: {} | undefined;
|
|
59
|
+
_active?: {} | undefined;
|
|
60
|
+
_focus?: {} | undefined;
|
|
61
|
+
_invalid?: {} | undefined;
|
|
62
|
+
_focusVisible?: {} | undefined;
|
|
63
|
+
id: string | undefined;
|
|
64
|
+
disabled: boolean | undefined;
|
|
65
|
+
required: boolean | undefined;
|
|
66
|
+
readOnly: boolean | undefined;
|
|
67
|
+
"aria-disabled": boolean | undefined;
|
|
68
|
+
"aria-readonly": boolean | undefined;
|
|
69
|
+
"aria-required": boolean | undefined;
|
|
70
|
+
"aria-invalid": boolean | undefined;
|
|
71
|
+
"data-readonly": boolean | "true" | "false";
|
|
72
|
+
onFocus: (event: react.FocusEvent<HTMLElement, Element>) => void;
|
|
73
|
+
onBlur: (event: react.FocusEvent<HTMLElement, Element>) => void;
|
|
74
|
+
} & Omit<FormControlOptions & {
|
|
75
|
+
id?: string | undefined;
|
|
76
|
+
onFocus?: FocusEventHandler<HTMLElement> | undefined;
|
|
77
|
+
onBlur?: FocusEventHandler<HTMLElement> | undefined;
|
|
78
|
+
disabled?: boolean | undefined;
|
|
79
|
+
readOnly?: boolean | undefined;
|
|
80
|
+
required?: boolean | undefined;
|
|
81
|
+
} & {
|
|
82
|
+
id: string;
|
|
83
|
+
} & Omit<FormControlOptions & {
|
|
84
|
+
/**
|
|
85
|
+
* id assigned to input.
|
|
86
|
+
*/
|
|
87
|
+
id?: string | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* The HTML `name` attribute used for forms.
|
|
90
|
+
*/
|
|
91
|
+
name?: string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* The value to be used in the checkbox input.
|
|
94
|
+
*/
|
|
95
|
+
value?: Y | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* If `true`, the checkbox will be initially checked.
|
|
98
|
+
*
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
defaultIsChecked?: boolean | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* If `true`, the checkbox will be checked.
|
|
104
|
+
*
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
isChecked?: boolean | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* If `true`, the checkbox will be indeterminate.
|
|
110
|
+
*
|
|
111
|
+
* @default false
|
|
112
|
+
*/
|
|
113
|
+
isIndeterminate?: boolean | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* The callback invoked when the checked state changes.
|
|
116
|
+
*/
|
|
117
|
+
onChange?: ChangeEventHandler<HTMLInputElement> | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* The callback invoked when the checkbox is focused.
|
|
120
|
+
*/
|
|
121
|
+
onFocus?: FocusEventHandler<HTMLInputElement> | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* The callback invoked when the checkbox is blurred.
|
|
124
|
+
*/
|
|
125
|
+
onBlur?: FocusEventHandler<HTMLInputElement> | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* The tab-index property of the underlying input element.
|
|
128
|
+
*/
|
|
129
|
+
tabIndex?: number | undefined;
|
|
130
|
+
} & M, "id">, "id" | "onFocus" | "onBlur" | "isRequired" | "isDisabled" | "isInvalid" | "isReadOnly" | "disabled" | "readOnly" | "required">, "id" | "tabIndex" | "onFocus" | "onBlur" | "onChange" | "name" | "value" | "defaultIsChecked" | "isChecked" | "isIndeterminate" | "disabled" | "readOnly" | "required">, any>;
|
|
56
131
|
isFocusVisible: boolean;
|
|
57
132
|
isFocused: boolean;
|
|
58
133
|
isHovered: boolean;
|
|
59
134
|
isActive: boolean;
|
|
60
135
|
isChecked: boolean;
|
|
61
|
-
isIndeterminate:
|
|
136
|
+
isIndeterminate: (FormControlOptions & {
|
|
137
|
+
id?: string | undefined;
|
|
138
|
+
onFocus?: FocusEventHandler<HTMLElement> | undefined;
|
|
139
|
+
onBlur?: FocusEventHandler<HTMLElement> | undefined;
|
|
140
|
+
disabled?: boolean | undefined;
|
|
141
|
+
readOnly?: boolean | undefined;
|
|
142
|
+
required?: boolean | undefined;
|
|
143
|
+
} & {
|
|
144
|
+
id: string;
|
|
145
|
+
} & Omit<FormControlOptions & {
|
|
146
|
+
/**
|
|
147
|
+
* id assigned to input.
|
|
148
|
+
*/
|
|
149
|
+
id?: string | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* The HTML `name` attribute used for forms.
|
|
152
|
+
*/
|
|
153
|
+
name?: string | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* The value to be used in the checkbox input.
|
|
156
|
+
*/
|
|
157
|
+
value?: Y | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* If `true`, the checkbox will be initially checked.
|
|
160
|
+
*
|
|
161
|
+
* @default false
|
|
162
|
+
*/
|
|
163
|
+
defaultIsChecked?: boolean | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* If `true`, the checkbox will be checked.
|
|
166
|
+
*
|
|
167
|
+
* @default false
|
|
168
|
+
*/
|
|
169
|
+
isChecked?: boolean | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* If `true`, the checkbox will be indeterminate.
|
|
172
|
+
*
|
|
173
|
+
* @default false
|
|
174
|
+
*/
|
|
175
|
+
isIndeterminate?: boolean | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* The callback invoked when the checked state changes.
|
|
178
|
+
*/
|
|
179
|
+
onChange?: ChangeEventHandler<HTMLInputElement> | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* The callback invoked when the checkbox is focused.
|
|
182
|
+
*/
|
|
183
|
+
onFocus?: FocusEventHandler<HTMLInputElement> | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* The callback invoked when the checkbox is blurred.
|
|
186
|
+
*/
|
|
187
|
+
onBlur?: FocusEventHandler<HTMLInputElement> | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* The tab-index property of the underlying input element.
|
|
190
|
+
*/
|
|
191
|
+
tabIndex?: number | undefined;
|
|
192
|
+
} & M, "id">)["isIndeterminate"] | undefined;
|
|
62
193
|
getContainerProps: UIPropGetter;
|
|
63
194
|
getIconProps: UIPropGetter;
|
|
64
195
|
getInputProps: PropGetter;
|
|
@@ -81,7 +212,7 @@ type CheckboxOptions = {
|
|
|
81
212
|
*/
|
|
82
213
|
labelProps?: HTMLUIProps<"span">;
|
|
83
214
|
};
|
|
84
|
-
type CheckboxProps<Y extends string | number = string> = Omit<HTMLUIProps<"label">,
|
|
215
|
+
type CheckboxProps<Y extends string | number = string> = Omit<Merge<HTMLUIProps<"label">, UseCheckboxProps<Y>>, "checked"> & ThemeProps<"Checkbox"> & CheckboxOptions;
|
|
85
216
|
/**
|
|
86
217
|
* `Checkbox` is a component used for allowing users to select multiple values from multiple options.
|
|
87
218
|
*
|
package/dist/checkbox.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ChangeEventHandler, FocusEventHandler, Ref, FC, ReactElement, InputHTMLAttributes } from 'react';
|
|
1
3
|
import { UIPropGetter, HTMLUIProps, ThemeProps, ComponentArgs } from '@yamada-ui/core';
|
|
2
4
|
import { FormControlOptions } from '@yamada-ui/form-control';
|
|
3
5
|
import { SVGMotionProps } from '@yamada-ui/motion';
|
|
4
|
-
import { PropGetter } from '@yamada-ui/utils';
|
|
5
|
-
import { ChangeEventHandler, FocusEventHandler, Ref, FC, ReactElement, InputHTMLAttributes } from 'react';
|
|
6
|
+
import { Dict, PropGetter, Merge } from '@yamada-ui/utils';
|
|
6
7
|
|
|
7
8
|
type UseCheckboxProps<Y extends string | number = string> = FormControlOptions & {
|
|
8
9
|
/**
|
|
@@ -52,13 +53,143 @@ type UseCheckboxProps<Y extends string | number = string> = FormControlOptions &
|
|
|
52
53
|
*/
|
|
53
54
|
tabIndex?: number;
|
|
54
55
|
};
|
|
55
|
-
declare const useCheckbox: <Y extends string | number = string>(props: UseCheckboxProps<Y>) => {
|
|
56
|
+
declare const useCheckbox: <Y extends string | number = string, M extends Dict = Dict>({ id, ...props }: UseCheckboxProps<Y> & M) => {
|
|
57
|
+
props: Omit<Omit<{
|
|
58
|
+
_hover?: {} | undefined;
|
|
59
|
+
_active?: {} | undefined;
|
|
60
|
+
_focus?: {} | undefined;
|
|
61
|
+
_invalid?: {} | undefined;
|
|
62
|
+
_focusVisible?: {} | undefined;
|
|
63
|
+
id: string | undefined;
|
|
64
|
+
disabled: boolean | undefined;
|
|
65
|
+
required: boolean | undefined;
|
|
66
|
+
readOnly: boolean | undefined;
|
|
67
|
+
"aria-disabled": boolean | undefined;
|
|
68
|
+
"aria-readonly": boolean | undefined;
|
|
69
|
+
"aria-required": boolean | undefined;
|
|
70
|
+
"aria-invalid": boolean | undefined;
|
|
71
|
+
"data-readonly": boolean | "true" | "false";
|
|
72
|
+
onFocus: (event: react.FocusEvent<HTMLElement, Element>) => void;
|
|
73
|
+
onBlur: (event: react.FocusEvent<HTMLElement, Element>) => void;
|
|
74
|
+
} & Omit<FormControlOptions & {
|
|
75
|
+
id?: string | undefined;
|
|
76
|
+
onFocus?: FocusEventHandler<HTMLElement> | undefined;
|
|
77
|
+
onBlur?: FocusEventHandler<HTMLElement> | undefined;
|
|
78
|
+
disabled?: boolean | undefined;
|
|
79
|
+
readOnly?: boolean | undefined;
|
|
80
|
+
required?: boolean | undefined;
|
|
81
|
+
} & {
|
|
82
|
+
id: string;
|
|
83
|
+
} & Omit<FormControlOptions & {
|
|
84
|
+
/**
|
|
85
|
+
* id assigned to input.
|
|
86
|
+
*/
|
|
87
|
+
id?: string | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* The HTML `name` attribute used for forms.
|
|
90
|
+
*/
|
|
91
|
+
name?: string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* The value to be used in the checkbox input.
|
|
94
|
+
*/
|
|
95
|
+
value?: Y | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* If `true`, the checkbox will be initially checked.
|
|
98
|
+
*
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
defaultIsChecked?: boolean | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* If `true`, the checkbox will be checked.
|
|
104
|
+
*
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
isChecked?: boolean | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* If `true`, the checkbox will be indeterminate.
|
|
110
|
+
*
|
|
111
|
+
* @default false
|
|
112
|
+
*/
|
|
113
|
+
isIndeterminate?: boolean | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* The callback invoked when the checked state changes.
|
|
116
|
+
*/
|
|
117
|
+
onChange?: ChangeEventHandler<HTMLInputElement> | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* The callback invoked when the checkbox is focused.
|
|
120
|
+
*/
|
|
121
|
+
onFocus?: FocusEventHandler<HTMLInputElement> | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* The callback invoked when the checkbox is blurred.
|
|
124
|
+
*/
|
|
125
|
+
onBlur?: FocusEventHandler<HTMLInputElement> | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* The tab-index property of the underlying input element.
|
|
128
|
+
*/
|
|
129
|
+
tabIndex?: number | undefined;
|
|
130
|
+
} & M, "id">, "id" | "onFocus" | "onBlur" | "isRequired" | "isDisabled" | "isInvalid" | "isReadOnly" | "disabled" | "readOnly" | "required">, "id" | "tabIndex" | "onFocus" | "onBlur" | "onChange" | "name" | "value" | "defaultIsChecked" | "isChecked" | "isIndeterminate" | "disabled" | "readOnly" | "required">, any>;
|
|
56
131
|
isFocusVisible: boolean;
|
|
57
132
|
isFocused: boolean;
|
|
58
133
|
isHovered: boolean;
|
|
59
134
|
isActive: boolean;
|
|
60
135
|
isChecked: boolean;
|
|
61
|
-
isIndeterminate:
|
|
136
|
+
isIndeterminate: (FormControlOptions & {
|
|
137
|
+
id?: string | undefined;
|
|
138
|
+
onFocus?: FocusEventHandler<HTMLElement> | undefined;
|
|
139
|
+
onBlur?: FocusEventHandler<HTMLElement> | undefined;
|
|
140
|
+
disabled?: boolean | undefined;
|
|
141
|
+
readOnly?: boolean | undefined;
|
|
142
|
+
required?: boolean | undefined;
|
|
143
|
+
} & {
|
|
144
|
+
id: string;
|
|
145
|
+
} & Omit<FormControlOptions & {
|
|
146
|
+
/**
|
|
147
|
+
* id assigned to input.
|
|
148
|
+
*/
|
|
149
|
+
id?: string | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* The HTML `name` attribute used for forms.
|
|
152
|
+
*/
|
|
153
|
+
name?: string | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* The value to be used in the checkbox input.
|
|
156
|
+
*/
|
|
157
|
+
value?: Y | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* If `true`, the checkbox will be initially checked.
|
|
160
|
+
*
|
|
161
|
+
* @default false
|
|
162
|
+
*/
|
|
163
|
+
defaultIsChecked?: boolean | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* If `true`, the checkbox will be checked.
|
|
166
|
+
*
|
|
167
|
+
* @default false
|
|
168
|
+
*/
|
|
169
|
+
isChecked?: boolean | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* If `true`, the checkbox will be indeterminate.
|
|
172
|
+
*
|
|
173
|
+
* @default false
|
|
174
|
+
*/
|
|
175
|
+
isIndeterminate?: boolean | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* The callback invoked when the checked state changes.
|
|
178
|
+
*/
|
|
179
|
+
onChange?: ChangeEventHandler<HTMLInputElement> | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* The callback invoked when the checkbox is focused.
|
|
182
|
+
*/
|
|
183
|
+
onFocus?: FocusEventHandler<HTMLInputElement> | undefined;
|
|
184
|
+
/**
|
|
185
|
+
* The callback invoked when the checkbox is blurred.
|
|
186
|
+
*/
|
|
187
|
+
onBlur?: FocusEventHandler<HTMLInputElement> | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* The tab-index property of the underlying input element.
|
|
190
|
+
*/
|
|
191
|
+
tabIndex?: number | undefined;
|
|
192
|
+
} & M, "id">)["isIndeterminate"] | undefined;
|
|
62
193
|
getContainerProps: UIPropGetter;
|
|
63
194
|
getIconProps: UIPropGetter;
|
|
64
195
|
getInputProps: PropGetter;
|
|
@@ -81,7 +212,7 @@ type CheckboxOptions = {
|
|
|
81
212
|
*/
|
|
82
213
|
labelProps?: HTMLUIProps<"span">;
|
|
83
214
|
};
|
|
84
|
-
type CheckboxProps<Y extends string | number = string> = Omit<HTMLUIProps<"label">,
|
|
215
|
+
type CheckboxProps<Y extends string | number = string> = Omit<Merge<HTMLUIProps<"label">, UseCheckboxProps<Y>>, "checked"> & ThemeProps<"Checkbox"> & CheckboxOptions;
|
|
85
216
|
/**
|
|
86
217
|
* `Checkbox` is a component used for allowing users to select multiple values from multiple options.
|
|
87
218
|
*
|
package/dist/checkbox.js
CHANGED
|
@@ -42,14 +42,17 @@ var import_react = require("react");
|
|
|
42
42
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
43
|
var isEvent = (value) => value && (0, import_utils.isObject)(value) && (0, import_utils.isObject)(value.target);
|
|
44
44
|
var useCheckboxGroup = ({
|
|
45
|
+
value: valueProp,
|
|
46
|
+
defaultValue = [],
|
|
47
|
+
onChange: onChangeProp,
|
|
45
48
|
isNative,
|
|
46
49
|
...props
|
|
47
50
|
}) => {
|
|
48
|
-
|
|
51
|
+
const onChangeRef = (0, import_utils.useCallbackRef)(onChangeProp);
|
|
49
52
|
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
50
|
-
value:
|
|
51
|
-
defaultValue
|
|
52
|
-
onChange:
|
|
53
|
+
value: valueProp,
|
|
54
|
+
defaultValue,
|
|
55
|
+
onChange: onChangeRef
|
|
53
56
|
});
|
|
54
57
|
const onChange = (0, import_react.useCallback)(
|
|
55
58
|
(evOrValue) => {
|
|
@@ -71,7 +74,7 @@ var useCheckboxGroup = ({
|
|
|
71
74
|
}),
|
|
72
75
|
[onChange, isNative, value]
|
|
73
76
|
);
|
|
74
|
-
return { value, setValue, onChange, getCheckboxProps };
|
|
77
|
+
return { props, value, setValue, onChange, getCheckboxProps };
|
|
75
78
|
};
|
|
76
79
|
var [CheckboxGroupProvider, useCheckboxGroupContext] = (0, import_utils.createContext)({
|
|
77
80
|
strict: false,
|
|
@@ -89,8 +92,8 @@ var CheckboxGroup = (0, import_react.forwardRef)(
|
|
|
89
92
|
gap,
|
|
90
93
|
...props
|
|
91
94
|
}, ref) => {
|
|
92
|
-
const { value, onChange } = useCheckboxGroup(props);
|
|
93
|
-
const { isRequired, isReadOnly, isDisabled, isInvalid } = (0, import_form_control.useFormControl)(
|
|
95
|
+
const { value, onChange, props: computedProps } = useCheckboxGroup(props);
|
|
96
|
+
const { isRequired, isReadOnly, isDisabled, isInvalid, ...rest } = (0, import_form_control.useFormControl)(computedProps);
|
|
94
97
|
const validChildren = (0, import_utils.getValidChildren)(children);
|
|
95
98
|
let computedChildren = [];
|
|
96
99
|
if (!validChildren.length && items.length) {
|
|
@@ -118,15 +121,7 @@ var CheckboxGroup = (0, import_react.forwardRef)(
|
|
|
118
121
|
role: "group",
|
|
119
122
|
direction,
|
|
120
123
|
gap: gap != null ? gap : direction === "row" ? "1rem" : void 0,
|
|
121
|
-
...
|
|
122
|
-
"value",
|
|
123
|
-
"defaultValue",
|
|
124
|
-
"onChange",
|
|
125
|
-
"isInvalid",
|
|
126
|
-
"isDisabled",
|
|
127
|
-
"isRequired",
|
|
128
|
-
"isReadOnly"
|
|
129
|
-
]),
|
|
124
|
+
...rest,
|
|
130
125
|
children: children != null ? children : computedChildren
|
|
131
126
|
}
|
|
132
127
|
)
|
|
@@ -138,19 +133,28 @@ CheckboxGroup.displayName = "CheckboxGroup";
|
|
|
138
133
|
|
|
139
134
|
// src/checkbox.tsx
|
|
140
135
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
141
|
-
var useCheckbox = (
|
|
136
|
+
var useCheckbox = ({
|
|
137
|
+
id,
|
|
138
|
+
...props
|
|
139
|
+
}) => {
|
|
140
|
+
id != null ? id : id = (0, import_react2.useId)();
|
|
142
141
|
const {
|
|
142
|
+
id: _id,
|
|
143
143
|
name,
|
|
144
144
|
value,
|
|
145
|
+
isChecked: isCheckedProp,
|
|
145
146
|
defaultIsChecked,
|
|
146
147
|
tabIndex,
|
|
147
148
|
required,
|
|
148
149
|
disabled,
|
|
149
150
|
readOnly,
|
|
150
151
|
isIndeterminate,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
onChange: onChangeProp,
|
|
153
|
+
onFocus: onFocusProp,
|
|
154
|
+
onBlur: onBlurProp,
|
|
155
|
+
...computedProps
|
|
156
|
+
} = (0, import_form_control2.useFormControlProps)({ id, ...props });
|
|
157
|
+
const [{ "aria-readonly": _ariaReadonly, ...formControlProps }, rest] = (0, import_utils2.splitObject)(computedProps, import_form_control2.formControlProperties);
|
|
154
158
|
const [isFocusVisible, setIsFocusVisible] = (0, import_react2.useState)(false);
|
|
155
159
|
const [isFocused, setFocused] = (0, import_react2.useState)(false);
|
|
156
160
|
const [isHovered, setHovered] = (0, import_react2.useState)(false);
|
|
@@ -158,23 +162,22 @@ var useCheckbox = (props) => {
|
|
|
158
162
|
const inputRef = (0, import_react2.useRef)(null);
|
|
159
163
|
const [isLabel, setIsLabel] = (0, import_react2.useState)(true);
|
|
160
164
|
const [isChecked, setIsChecked] = (0, import_react2.useState)(!!defaultIsChecked);
|
|
161
|
-
const isControlled =
|
|
162
|
-
const checked = isControlled ?
|
|
165
|
+
const isControlled = isCheckedProp !== void 0;
|
|
166
|
+
const checked = isControlled ? isCheckedProp : isChecked;
|
|
163
167
|
const onChange = (0, import_utils2.useCallbackRef)(
|
|
164
168
|
(ev) => {
|
|
165
|
-
var _a;
|
|
166
169
|
if (readOnly || disabled) {
|
|
167
170
|
ev.preventDefault();
|
|
168
171
|
return;
|
|
169
172
|
}
|
|
170
173
|
if (!isControlled)
|
|
171
174
|
setIsChecked(!checked || isIndeterminate ? true : ev.target.checked);
|
|
172
|
-
|
|
175
|
+
onChangeProp == null ? void 0 : onChangeProp(ev);
|
|
173
176
|
},
|
|
174
177
|
[readOnly, disabled, isControlled, checked, isIndeterminate]
|
|
175
178
|
);
|
|
176
|
-
const
|
|
177
|
-
const
|
|
179
|
+
const onFocus = (0, import_utils2.useCallbackRef)(onFocusProp);
|
|
180
|
+
const onBlur = (0, import_utils2.useCallbackRef)(onBlurProp);
|
|
178
181
|
const onKeyDown = (0, import_react2.useCallback)(
|
|
179
182
|
({ key }) => {
|
|
180
183
|
if (key === " ")
|
|
@@ -214,10 +217,7 @@ var useCheckbox = (props) => {
|
|
|
214
217
|
}, [inputRef.current]);
|
|
215
218
|
const getContainerProps = (0, import_react2.useCallback)(
|
|
216
219
|
(props2 = {}, ref = null) => ({
|
|
217
|
-
...
|
|
218
|
-
rest,
|
|
219
|
-
(0, import_form_control2.getFormControlProperties)({ omit: ["aria-readonly"] })
|
|
220
|
-
),
|
|
220
|
+
...formControlProps,
|
|
221
221
|
...props2,
|
|
222
222
|
ref: (0, import_utils2.mergeRefs)(ref, (el) => {
|
|
223
223
|
if (el)
|
|
@@ -235,14 +235,11 @@ var useCheckbox = (props) => {
|
|
|
235
235
|
});
|
|
236
236
|
})
|
|
237
237
|
}),
|
|
238
|
-
[checked, isLabel,
|
|
238
|
+
[checked, isLabel, formControlProps]
|
|
239
239
|
);
|
|
240
240
|
const getIconProps = (0, import_react2.useCallback)(
|
|
241
241
|
(props2 = {}, ref = null) => ({
|
|
242
|
-
...
|
|
243
|
-
rest,
|
|
244
|
-
(0, import_form_control2.getFormControlProperties)({ omit: ["aria-readonly"] })
|
|
245
|
-
),
|
|
242
|
+
...formControlProps,
|
|
246
243
|
...props2,
|
|
247
244
|
ref,
|
|
248
245
|
"data-active": (0, import_utils2.dataAttr)(isActive),
|
|
@@ -268,15 +265,12 @@ var useCheckbox = (props) => {
|
|
|
268
265
|
isHovered,
|
|
269
266
|
isFocusVisible,
|
|
270
267
|
isIndeterminate,
|
|
271
|
-
|
|
268
|
+
formControlProps
|
|
272
269
|
]
|
|
273
270
|
);
|
|
274
271
|
const getInputProps = (0, import_react2.useCallback)(
|
|
275
272
|
(props2 = {}, ref = null) => ({
|
|
276
|
-
...
|
|
277
|
-
rest,
|
|
278
|
-
(0, import_form_control2.getFormControlProperties)({ omit: ["aria-readonly"] })
|
|
279
|
-
),
|
|
273
|
+
...formControlProps,
|
|
280
274
|
...props2,
|
|
281
275
|
ref: (0, import_utils2.mergeRefs)(inputRef, ref),
|
|
282
276
|
id,
|
|
@@ -306,7 +300,7 @@ var useCheckbox = (props) => {
|
|
|
306
300
|
onKeyUp: (0, import_utils2.handlerAll)(props2.onKeyUp, onKeyUp)
|
|
307
301
|
}),
|
|
308
302
|
[
|
|
309
|
-
|
|
303
|
+
formControlProps,
|
|
310
304
|
id,
|
|
311
305
|
name,
|
|
312
306
|
value,
|
|
@@ -324,10 +318,7 @@ var useCheckbox = (props) => {
|
|
|
324
318
|
);
|
|
325
319
|
const getLabelProps = (0, import_react2.useCallback)(
|
|
326
320
|
(props2 = {}, ref = null) => ({
|
|
327
|
-
...
|
|
328
|
-
rest,
|
|
329
|
-
(0, import_form_control2.getFormControlProperties)({ omit: ["aria-readonly"] })
|
|
330
|
-
),
|
|
321
|
+
...formControlProps,
|
|
331
322
|
...props2,
|
|
332
323
|
ref,
|
|
333
324
|
"data-checked": (0, import_utils2.dataAttr)(checked),
|
|
@@ -340,9 +331,10 @@ var useCheckbox = (props) => {
|
|
|
340
331
|
ev.stopPropagation();
|
|
341
332
|
})
|
|
342
333
|
}),
|
|
343
|
-
[checked,
|
|
334
|
+
[checked, formControlProps]
|
|
344
335
|
);
|
|
345
336
|
return {
|
|
337
|
+
props: rest,
|
|
346
338
|
isFocusVisible,
|
|
347
339
|
isFocused,
|
|
348
340
|
isHovered,
|
|
@@ -357,43 +349,48 @@ var useCheckbox = (props) => {
|
|
|
357
349
|
};
|
|
358
350
|
var Checkbox = (0, import_react2.forwardRef)(
|
|
359
351
|
(props, ref) => {
|
|
360
|
-
var _a, _b, _c, _d
|
|
352
|
+
var _a, _b, _c, _d;
|
|
361
353
|
const group = useCheckboxGroupContext();
|
|
354
|
+
const { value: groupValue, ...groupProps } = { ...group };
|
|
362
355
|
const control = (0, import_form_control2.useFormControl)(props);
|
|
363
356
|
const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("Checkbox", {
|
|
364
|
-
...
|
|
357
|
+
...groupProps,
|
|
365
358
|
...props
|
|
366
359
|
});
|
|
367
360
|
const {
|
|
368
361
|
className,
|
|
369
362
|
gap = "0.5rem",
|
|
370
|
-
isRequired = (_a =
|
|
371
|
-
isReadOnly = (_b =
|
|
372
|
-
isDisabled = (_c =
|
|
373
|
-
isInvalid = (_d =
|
|
363
|
+
isRequired = (_a = groupProps.isRequired) != null ? _a : control.isRequired,
|
|
364
|
+
isReadOnly = (_b = groupProps.isReadOnly) != null ? _b : control.isReadOnly,
|
|
365
|
+
isDisabled = (_c = groupProps.isDisabled) != null ? _c : control.isDisabled,
|
|
366
|
+
isInvalid = (_d = groupProps.isInvalid) != null ? _d : control.isInvalid,
|
|
374
367
|
iconProps,
|
|
375
368
|
inputProps,
|
|
376
369
|
labelProps,
|
|
377
370
|
children,
|
|
378
|
-
...
|
|
371
|
+
...computedProps
|
|
379
372
|
} = (0, import_core.omitThemeProps)(mergedProps);
|
|
373
|
+
const isCheckedProp = groupValue && computedProps.value ? groupValue.includes(computedProps.value) : computedProps.isChecked;
|
|
374
|
+
const onChange = groupProps.onChange && computedProps.value ? (0, import_utils2.funcAll)(groupProps.onChange, computedProps.onChange) : computedProps.onChange;
|
|
380
375
|
const {
|
|
381
376
|
isChecked,
|
|
382
377
|
isIndeterminate,
|
|
383
378
|
getContainerProps,
|
|
384
379
|
getInputProps,
|
|
385
380
|
getIconProps,
|
|
386
|
-
getLabelProps
|
|
381
|
+
getLabelProps,
|
|
382
|
+
props: rest
|
|
387
383
|
} = useCheckbox({
|
|
388
|
-
...
|
|
384
|
+
...computedProps,
|
|
389
385
|
isRequired,
|
|
390
386
|
isReadOnly,
|
|
391
387
|
isDisabled,
|
|
392
388
|
isInvalid,
|
|
393
|
-
isChecked:
|
|
394
|
-
onChange
|
|
389
|
+
isChecked: isCheckedProp,
|
|
390
|
+
onChange
|
|
395
391
|
});
|
|
396
|
-
const
|
|
392
|
+
const { children: customIcon, ...resolvedIconProps } = { ...iconProps };
|
|
393
|
+
const cloneIcon = (0, import_react2.cloneElement)(customIcon != null ? customIcon : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CheckboxIcon, {}), {
|
|
397
394
|
__css: {
|
|
398
395
|
opacity: isChecked || isIndeterminate ? 1 : 0,
|
|
399
396
|
transform: isChecked || isIndeterminate ? "scale(1)" : "scale(0.95)",
|
|
@@ -421,19 +418,7 @@ var Checkbox = (0, import_react2.forwardRef)(
|
|
|
421
418
|
gap,
|
|
422
419
|
...styles.container
|
|
423
420
|
},
|
|
424
|
-
...
|
|
425
|
-
"id",
|
|
426
|
-
"name",
|
|
427
|
-
"value",
|
|
428
|
-
"defaultValue",
|
|
429
|
-
"defaultIsChecked",
|
|
430
|
-
"isChecked",
|
|
431
|
-
"isIndeterminate",
|
|
432
|
-
"onChange",
|
|
433
|
-
"onBlur",
|
|
434
|
-
"onFocus",
|
|
435
|
-
"tabIndex"
|
|
436
|
-
]),
|
|
421
|
+
...rest,
|
|
437
422
|
children: [
|
|
438
423
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
439
424
|
import_core.ui.input,
|
|
@@ -453,9 +438,7 @@ var Checkbox = (0, import_react2.forwardRef)(
|
|
|
453
438
|
userSelect: "none",
|
|
454
439
|
...styles.icon
|
|
455
440
|
},
|
|
456
|
-
...getIconProps(
|
|
457
|
-
(0, import_utils2.omitObject)(iconProps != null ? iconProps : { children: void 0 }, ["children"])
|
|
458
|
-
),
|
|
441
|
+
...getIconProps(resolvedIconProps),
|
|
459
442
|
children: cloneIcon
|
|
460
443
|
}
|
|
461
444
|
),
|
|
@@ -477,14 +460,12 @@ Checkbox.displayName = "Checkbox";
|
|
|
477
460
|
var CheckboxIcon = ({
|
|
478
461
|
isIndeterminate,
|
|
479
462
|
isChecked,
|
|
463
|
+
isRequired: _isRequired,
|
|
464
|
+
isReadOnly: _isReadOnly,
|
|
465
|
+
isDisabled: _isDisabled,
|
|
466
|
+
isInvalid: _isInvalid,
|
|
480
467
|
...rest
|
|
481
468
|
}) => {
|
|
482
|
-
const iconProps = (0, import_utils2.omitObject)(rest, [
|
|
483
|
-
"isRequired",
|
|
484
|
-
"isReadOnly",
|
|
485
|
-
"isDisabled",
|
|
486
|
-
"isInvalid"
|
|
487
|
-
]);
|
|
488
469
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_motion.AnimatePresence, { initial: false, children: isIndeterminate || isChecked ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
489
470
|
import_core.ui.div,
|
|
490
471
|
{
|
|
@@ -510,7 +491,7 @@ var CheckboxIcon = ({
|
|
|
510
491
|
alignItems: "center",
|
|
511
492
|
justifyContent: "center"
|
|
512
493
|
},
|
|
513
|
-
children: isIndeterminate ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IndeterminateIcon, { ...
|
|
494
|
+
children: isIndeterminate ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IndeterminateIcon, { ...rest }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CheckIcon, { ...rest })
|
|
514
495
|
}
|
|
515
496
|
)
|
|
516
497
|
}
|