@conveyorhq/arrow-ds 1.83.0 → 1.84.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.
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { InputProps } from "../Input";
|
|
2
2
|
import { StackProps } from "../Stack";
|
|
3
|
-
export declare type CheckboxProps = InputProps & {
|
|
3
|
+
export declare type CheckboxProps = Omit<InputProps, "checked"> & {
|
|
4
4
|
label?: string;
|
|
5
5
|
hideRequiredStyles?: boolean;
|
|
6
6
|
isRequired?: boolean;
|
|
7
7
|
checked?: boolean | "indeterminate";
|
|
8
8
|
};
|
|
9
|
+
export declare enum CheckboxState {
|
|
10
|
+
CHECKED = "checked",
|
|
11
|
+
UNCHECKED = "unchecked",
|
|
12
|
+
INDETERMINATE = "indeterminate"
|
|
13
|
+
}
|
|
9
14
|
export declare const Checkbox: {
|
|
10
15
|
({ checked, children, className, disabled, id: idProp, label, onBlur, onChange, onClick, onFocus, hideRequiredStyles, isRequired, tabIndex, theme: themeProp, ...rest }: CheckboxProps): JSX.Element;
|
|
11
16
|
Group: (props: StackProps) => JSX.Element;
|
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.Checkbox = void 0;
|
|
25
|
+
exports.Checkbox = exports.CheckboxState = void 0;
|
|
26
26
|
const react_1 = __importStar(require("react"));
|
|
27
27
|
const classnames_1 = __importDefault(require("classnames"));
|
|
28
28
|
const auto_id_1 = require("@reach/auto-id");
|
|
@@ -41,6 +41,12 @@ const CheckboxGroup = (props) => {
|
|
|
41
41
|
const { orientation = types_1.ORIENTATION.VERTICAL, ...rest } = props;
|
|
42
42
|
return react_1.default.createElement(Stack_1.Stack, Object.assign({ orientation: orientation }, rest));
|
|
43
43
|
};
|
|
44
|
+
var CheckboxState;
|
|
45
|
+
(function (CheckboxState) {
|
|
46
|
+
CheckboxState["CHECKED"] = "checked";
|
|
47
|
+
CheckboxState["UNCHECKED"] = "unchecked";
|
|
48
|
+
CheckboxState["INDETERMINATE"] = "indeterminate";
|
|
49
|
+
})(CheckboxState = exports.CheckboxState || (exports.CheckboxState = {}));
|
|
44
50
|
const Checkbox = ({ checked, children, className, disabled = false, id: idProp, label, onBlur, onChange = () => { }, onClick, onFocus, hideRequiredStyles = true, isRequired = undefined, tabIndex, theme: themeProp, ...rest }) => {
|
|
45
51
|
const { isRequired: isRequiredContext, theme: themeContext } = react_1.useContext(FormGroupContext_1.FormGroupContext);
|
|
46
52
|
const fallbackId = `checkbox:${auto_id_1.useId()}`;
|
|
@@ -59,14 +65,45 @@ const Checkbox = ({ checked, children, className, disabled = false, id: idProp,
|
|
|
59
65
|
else if (isRequiredContext !== undefined) {
|
|
60
66
|
calculatedRequired = isRequiredContext;
|
|
61
67
|
}
|
|
62
|
-
const [
|
|
68
|
+
const [checkedState, setCheckedState] = react_1.useState(CheckboxState.UNCHECKED);
|
|
63
69
|
react_1.useEffect(() => {
|
|
64
|
-
|
|
70
|
+
if (checked) {
|
|
71
|
+
if (typeof checked === "string" && checked === "indeterminate") {
|
|
72
|
+
setCheckedState(CheckboxState.INDETERMINATE);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
setCheckedState(CheckboxState.CHECKED);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
65
78
|
}, [checked]);
|
|
79
|
+
const handleChange = (event) => {
|
|
80
|
+
let updatedChecked;
|
|
81
|
+
if (checkedState === CheckboxState.CHECKED) {
|
|
82
|
+
updatedChecked = CheckboxState.UNCHECKED;
|
|
83
|
+
}
|
|
84
|
+
else if (checkedState === CheckboxState.UNCHECKED) {
|
|
85
|
+
updatedChecked = CheckboxState.CHECKED;
|
|
86
|
+
}
|
|
87
|
+
setCheckedState(updatedChecked);
|
|
88
|
+
if (onChange) {
|
|
89
|
+
onChange(event);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const ariaChecked = () => {
|
|
93
|
+
if (checkedState === CheckboxState.INDETERMINATE) {
|
|
94
|
+
return "mixed";
|
|
95
|
+
}
|
|
96
|
+
if (checkedState === CheckboxState.CHECKED) {
|
|
97
|
+
return "true";
|
|
98
|
+
}
|
|
99
|
+
return "false";
|
|
100
|
+
};
|
|
66
101
|
const bareCheckbox = (react_1.default.createElement(Box_1.Box, { className: bem_1.bem(cn, { e: "BoxWrapper" }) },
|
|
67
|
-
react_1.default.createElement(Input_1.Input, Object.assign({ "aria-checked":
|
|
102
|
+
react_1.default.createElement(Input_1.Input, Object.assign({ "aria-checked": ariaChecked(), checked: checkedState === CheckboxState.CHECKED, className: bem_1.bem(cn, { e: "Input" }), disabled: disabled, id: id, onChange: handleChange, type: "checkbox", onFocus: onFocus, onBlur: onBlur, onClick: label ? handleClick : undefined, tabIndex: tabIndex }, rest)),
|
|
68
103
|
react_1.default.createElement(Box_1.Box, { className: classnames_1.default(bem_1.bem(cn, { e: "Box" }), bem_1.bem(cn, { e: "Box", m: theme }), checked && bem_1.bem(cn, { e: "Box", m: "checked" })) }),
|
|
69
|
-
checked && (react_1.default.createElement(Icon_1.Icon, { className: classnames_1.default(bem_1.bem(cn, { e: "Check" }), bem_1.bem(cn, { e: "Check", m: theme })), icon:
|
|
104
|
+
checked && (react_1.default.createElement(Icon_1.Icon, { className: classnames_1.default(bem_1.bem(cn, { e: "Check" }), bem_1.bem(cn, { e: "Check", m: theme })), icon: checkedState === CheckboxState.INDETERMINATE
|
|
105
|
+
? Icon_1.ICON_TYPE.MINUS
|
|
106
|
+
: Icon_1.ICON_TYPE.CHECK }))));
|
|
70
107
|
const checkboxWithLabel = label || children ? (react_1.default.createElement(Label_1.Label, { className: bem_1.bem(cn, { e: "Label" }), isRequired: calculatedRequired && !hideRequiredStyles },
|
|
71
108
|
bareCheckbox,
|
|
72
109
|
react_1.default.createElement(Text_1.Text, { as: "span", className: classnames_1.default(bem_1.bem(cn, { e: "LabelText" }), bem_1.bem(cn, { e: "LabelText", m: theme })) },
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
ChangeEvent,
|
|
3
|
+
MouseEvent,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useState,
|
|
7
|
+
} from "react";
|
|
2
8
|
import classnames from "classnames";
|
|
3
9
|
import { useId } from "@reach/auto-id";
|
|
4
10
|
import { Box } from "../Box";
|
|
@@ -14,7 +20,7 @@ import { FormGroupContext } from "../FormGroup/FormGroupContext";
|
|
|
14
20
|
|
|
15
21
|
const cn = "Checkbox";
|
|
16
22
|
|
|
17
|
-
export type CheckboxProps = InputProps & {
|
|
23
|
+
export type CheckboxProps = Omit<InputProps, "checked"> & {
|
|
18
24
|
label?: string;
|
|
19
25
|
/**
|
|
20
26
|
* Hides required styling on Label if it is within a FormGroupContext with
|
|
@@ -38,6 +44,12 @@ const CheckboxGroup = (props: StackProps) => {
|
|
|
38
44
|
return <Stack orientation={orientation} {...rest} />;
|
|
39
45
|
};
|
|
40
46
|
|
|
47
|
+
export enum CheckboxState {
|
|
48
|
+
CHECKED = "checked",
|
|
49
|
+
UNCHECKED = "unchecked",
|
|
50
|
+
INDETERMINATE = "indeterminate",
|
|
51
|
+
}
|
|
52
|
+
|
|
41
53
|
export const Checkbox = ({
|
|
42
54
|
checked,
|
|
43
55
|
children,
|
|
@@ -77,22 +89,57 @@ export const Checkbox = ({
|
|
|
77
89
|
calculatedRequired = isRequiredContext;
|
|
78
90
|
}
|
|
79
91
|
|
|
80
|
-
const [
|
|
92
|
+
const [checkedState, setCheckedState] = useState<CheckboxState>(
|
|
93
|
+
CheckboxState.UNCHECKED,
|
|
94
|
+
);
|
|
95
|
+
|
|
81
96
|
useEffect(() => {
|
|
82
|
-
|
|
83
|
-
typeof checked === "string" && checked === "indeterminate"
|
|
84
|
-
|
|
97
|
+
if (checked) {
|
|
98
|
+
if (typeof checked === "string" && checked === "indeterminate") {
|
|
99
|
+
setCheckedState(CheckboxState.INDETERMINATE);
|
|
100
|
+
} else {
|
|
101
|
+
setCheckedState(CheckboxState.CHECKED);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
85
104
|
}, [checked]);
|
|
86
105
|
|
|
106
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
107
|
+
let updatedChecked;
|
|
108
|
+
|
|
109
|
+
if (checkedState === CheckboxState.CHECKED) {
|
|
110
|
+
updatedChecked = CheckboxState.UNCHECKED;
|
|
111
|
+
} else if (checkedState === CheckboxState.UNCHECKED) {
|
|
112
|
+
updatedChecked = CheckboxState.CHECKED;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setCheckedState(updatedChecked as CheckboxState);
|
|
116
|
+
|
|
117
|
+
if (onChange) {
|
|
118
|
+
onChange(event);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const ariaChecked = () => {
|
|
123
|
+
if (checkedState === CheckboxState.INDETERMINATE) {
|
|
124
|
+
return "mixed";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (checkedState === CheckboxState.CHECKED) {
|
|
128
|
+
return "true";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return "false";
|
|
132
|
+
};
|
|
133
|
+
|
|
87
134
|
const bareCheckbox = (
|
|
88
135
|
<Box className={bem(cn, { e: "BoxWrapper" })}>
|
|
89
136
|
<Input
|
|
90
|
-
aria-checked={
|
|
91
|
-
checked={
|
|
137
|
+
aria-checked={ariaChecked()}
|
|
138
|
+
checked={checkedState === CheckboxState.CHECKED}
|
|
92
139
|
className={bem(cn, { e: "Input" })}
|
|
93
140
|
disabled={disabled}
|
|
94
141
|
id={id}
|
|
95
|
-
onChange={
|
|
142
|
+
onChange={handleChange}
|
|
96
143
|
type="checkbox"
|
|
97
144
|
onFocus={onFocus}
|
|
98
145
|
onBlur={onBlur}
|
|
@@ -113,7 +160,11 @@ export const Checkbox = ({
|
|
|
113
160
|
bem(cn, { e: "Check" }),
|
|
114
161
|
bem(cn, { e: "Check", m: theme }),
|
|
115
162
|
)}
|
|
116
|
-
icon={
|
|
163
|
+
icon={
|
|
164
|
+
checkedState === CheckboxState.INDETERMINATE
|
|
165
|
+
? ICON_TYPE.MINUS
|
|
166
|
+
: ICON_TYPE.CHECK
|
|
167
|
+
}
|
|
117
168
|
/>
|
|
118
169
|
)}
|
|
119
170
|
</Box>
|