@react-aria/checkbox 3.9.2 → 3.11.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/dist/import.mjs +5 -3
- package/dist/main.js +5 -3
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -3
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/useCheckbox.ts +6 -3
- package/src/useCheckboxGroupItem.ts +2 -1
package/dist/import.mjs
CHANGED
|
@@ -27,7 +27,7 @@ import {useToggleState as $cKEhs$useToggleState} from "@react-stately/toggle";
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
|
|
30
|
-
let { inputProps: inputProps , isSelected: isSelected , isPressed: isPressed , isDisabled: isDisabled , isReadOnly: isReadOnly } = (0, $cKEhs$useToggle)(props, state, inputRef);
|
|
30
|
+
let { inputProps: inputProps , isSelected: isSelected , isPressed: isPressed , isDisabled: isDisabled , isReadOnly: isReadOnly , isInvalid: isInvalid } = (0, $cKEhs$useToggle)(props, state, inputRef);
|
|
31
31
|
let { isIndeterminate: isIndeterminate } = props;
|
|
32
32
|
(0, $cKEhs$useEffect)(()=>{
|
|
33
33
|
// indeterminate is a property, but it can only be set via javascript
|
|
@@ -42,7 +42,8 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
|
|
|
42
42
|
isSelected: isSelected,
|
|
43
43
|
isPressed: isPressed,
|
|
44
44
|
isDisabled: isDisabled,
|
|
45
|
-
isReadOnly: isReadOnly
|
|
45
|
+
isReadOnly: isReadOnly,
|
|
46
|
+
isInvalid: isInvalid
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
49
|
|
|
@@ -136,7 +137,8 @@ function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
|
|
|
136
137
|
inputProps: {
|
|
137
138
|
...res.inputProps,
|
|
138
139
|
"aria-describedby": [
|
|
139
|
-
|
|
140
|
+
props["aria-describedby"],
|
|
141
|
+
state.isInvalid ? (0, $1ae600c947479353$export$d5679492e2864181).get(state) : null,
|
|
140
142
|
(0, $1ae600c947479353$export$a3077e9c93f7360f).get(state)
|
|
141
143
|
].filter(Boolean).join(" ") || undefined
|
|
142
144
|
}
|
package/dist/main.js
CHANGED
|
@@ -34,7 +34,7 @@ $parcel$export(module.exports, "useCheckboxGroupItem", () => $07e03121d6ac83c8$e
|
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
|
|
37
|
-
let { inputProps: inputProps , isSelected: isSelected , isPressed: isPressed , isDisabled: isDisabled , isReadOnly: isReadOnly } = (0, $k0DcK$reactariatoggle.useToggle)(props, state, inputRef);
|
|
37
|
+
let { inputProps: inputProps , isSelected: isSelected , isPressed: isPressed , isDisabled: isDisabled , isReadOnly: isReadOnly , isInvalid: isInvalid } = (0, $k0DcK$reactariatoggle.useToggle)(props, state, inputRef);
|
|
38
38
|
let { isIndeterminate: isIndeterminate } = props;
|
|
39
39
|
(0, $k0DcK$react.useEffect)(()=>{
|
|
40
40
|
// indeterminate is a property, but it can only be set via javascript
|
|
@@ -49,7 +49,8 @@ function $468c774d7db917b7$export$e375f10ce42261c5(props, state, inputRef) {
|
|
|
49
49
|
isSelected: isSelected,
|
|
50
50
|
isPressed: isPressed,
|
|
51
51
|
isDisabled: isDisabled,
|
|
52
|
-
isReadOnly: isReadOnly
|
|
52
|
+
isReadOnly: isReadOnly,
|
|
53
|
+
isInvalid: isInvalid
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -143,7 +144,8 @@ function $07e03121d6ac83c8$export$353b32fc6898d37d(props, state, inputRef) {
|
|
|
143
144
|
inputProps: {
|
|
144
145
|
...res.inputProps,
|
|
145
146
|
"aria-describedby": [
|
|
146
|
-
|
|
147
|
+
props["aria-describedby"],
|
|
148
|
+
state.isInvalid ? (0, $64fc3370e682155f$export$d5679492e2864181).get(state) : null,
|
|
147
149
|
(0, $64fc3370e682155f$export$a3077e9c93f7360f).get(state)
|
|
148
150
|
].filter(Boolean).join(" ") || undefined
|
|
149
151
|
}
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AA4BM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAAqC;IAC7G,IAAI,cAAC,WAAU,cAAE,WAAU,aAAE,UAAS,cAAE,WAAU,cAAE,WAAU,EAAC,GAAG,CAAA,GAAA,gCAAQ,EAAE,OAAO,OAAO;IAE1F,IAAI,mBAAC,gBAAe,EAAC,GAAG;IACxB,CAAA,GAAA,sBAAQ,EAAE;QACR,qEAAqE;QACrE,mDAAmD;QACnD,IAAI,SAAS,SACX,SAAS,QAAQ,gBAAgB;IAErC;IAEA,OAAO;QACL,YAAY;YACV,GAAG,UAAU;YACb,SAAS;QACX;oBACA;mBACA;oBACA;oBACA;IACF;AACF;;CDlDC;AEVD;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAIM,MAAM,4CAAqB,IAAI;AAC/B,MAAM,4CAA8B,IAAI;AACxC,MAAM,4CAA+B,IAAI;;CDN/C;;;AA0BM,SAAS,0CAAiB,KAA6B,EAAE,KAAyB;IACvF,IAAI,cAAC,WAAU,QAAE,KAAI,EAAC,GAAG;IAEzB,IAAI,cAAC,WAAU,cAAE,WAAU,oBAAE,iBAAgB,qBAAE,kBAAiB,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;QAC3E,GAAG,KAAK;QACR,oDAAoD;QACpD,6CAA6C;QAC7C,kBAAkB;IACpB;IACA,CAAA,GAAA,yCAA0B,EAAE,IAAI,OAAO,iBAAiB;IACxD,CAAA,GAAA,yCAA2B,EAAE,IAAI,OAAO,kBAAkB;IAE1D,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,oEAAoE;IACpE,CAAA,GAAA,yCAAiB,EAAE,IAAI,OAAO;IAE9B,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EAAE,UAAU;YAC/B,MAAM;YACN,iBAAiB,cAAc;YAC/B,GAAG,UAAU;QACf;oBACA;0BACA;2BACA;IACF;AACF;;;AE/DA;;;;;;;;;;CAUC;;;AAgBM,SAAS,0CAAqB,KAAiC,EAAE,KAAyB,EAAE,QAAqC;IACtI,MAAM,cAAc,CAAA,GAAA,wCAAa,EAAE;QACjC,YAAY,MAAM,cAAc,MAAM;QACtC,YAAY,MAAM,WAAW,MAAM;QACnC,UAAS,UAAU;YACjB,IAAI,YACF,MAAM,SAAS,MAAM;iBAErB,MAAM,YAAY,MAAM;YAG1B,IAAI,MAAM,UACR,MAAM,SAAS;QAEnB;IACF;IAEA,IAAI,MAAM,CAAA,GAAA,yCAAU,EAAE;QACpB,GAAG,KAAK;QACR,YAAY,MAAM,cAAc,MAAM;QACtC,YAAY,MAAM,cAAc,MAAM;QACtC,MAAM,MAAM,QAAQ,CAAA,GAAA,yCAAiB,EAAE,IAAI;IAC7C,GAAG,aAAa;IAEhB,OAAO;QACL,GAAG,GAAG;QACN,YAAY;YACV,GAAG,IAAI,UAAU;YACjB,oBAAoB;gBAClB,MAAM,oBAAoB,YAAY,CAAA,GAAA,yCAA2B,EAAE,IAAI,SAAS;gBAChF,CAAA,GAAA,yCAA0B,EAAE,IAAI;aACjC,CAAC,OAAO,SAAS,KAAK,QAAQ;QACjC;IACF;AACF;;","sources":["packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useToggle} from '@react-aria/toggle';\n\nexport interface CheckboxAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the checkbox is selected. */\n isSelected: boolean,\n /** Whether the checkbox is in a pressed state. */\n isPressed: boolean,\n /** Whether the checkbox is disabled. */\n isDisabled: boolean,\n /** Whether the checkbox is read only. */\n isReadOnly: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n let {inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle(props, state, inputRef);\n\n let {isIndeterminate} = props;\n useEffect(() => {\n // indeterminate is a property, but it can only be set via javascript\n // https://css-tricks.com/indeterminate-checkboxes/\n if (inputRef.current) {\n inputRef.current.indeterminate = isIndeterminate;\n }\n });\n\n return {\n inputProps: {\n ...inputProps,\n checked: isSelected\n },\n isSelected,\n isPressed,\n isDisabled,\n isReadOnly\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\n\nexport interface CheckboxGroupAria {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n let {isDisabled, name} = props;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Checkbox group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span'\n });\n checkboxGroupDescriptionIds.set(state, descriptionProps.id);\n checkboxGroupErrorMessageIds.set(state, errorMessageProps.id);\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // Pass name prop from group to all items by attaching to the state.\n checkboxGroupNames.set(state, name);\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CheckboxGroupState} from '@react-stately/checkbox';\n\nexport const checkboxGroupNames = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupDescriptionIds = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupErrorMessageIds = new WeakMap<CheckboxGroupState, string>();\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {RefObject} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n onChange(isSelected) {\n if (isSelected) {\n state.addValue(props.value);\n } else {\n state.removeValue(props.value);\n }\n\n if (props.onChange) {\n props.onChange(isSelected);\n }\n }\n });\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || checkboxGroupNames.get(state)\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n state.validationState === 'invalid' ? checkboxGroupErrorMessageIds.get(state) : null,\n checkboxGroupDescriptionIds.get(state)\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AA8BM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAAqC;IAC7G,IAAI,cAAC,WAAU,cAAE,WAAU,aAAE,UAAS,cAAE,WAAU,cAAE,WAAU,aAAE,UAAS,EAAC,GAAG,CAAA,GAAA,gCAAQ,EAAE,OAAO,OAAO;IAErG,IAAI,mBAAC,gBA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MAAM;iBAErB,MAAM,YAAY,MAAM;YAG1B,IAAI,MAAM,UACR,MAAM,SAAS;QAEnB;IACF;IAEA,IAAI,MAAM,CAAA,GAAA,yCAAU,EAAE;QACpB,GAAG,KAAK;QACR,YAAY,MAAM,cAAc,MAAM;QACtC,YAAY,MAAM,cAAc,MAAM;QACtC,MAAM,MAAM,QAAQ,CAAA,GAAA,yCAAiB,EAAE,IAAI;IAC7C,GAAG,aAAa;IAEhB,OAAO;QACL,GAAG,GAAG;QACN,YAAY;YACV,GAAG,IAAI,UAAU;YACjB,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,YAAY,CAAA,GAAA,yCAA2B,EAAE,IAAI,SAAS;gBAC5D,CAAA,GAAA,yCAA0B,EAAE,IAAI;aACjC,CAAC,OAAO,SAAS,KAAK,QAAQ;QACjC;IACF;AACF;;","sources":["packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useToggle} from '@react-aria/toggle';\n\nexport interface CheckboxAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the checkbox is selected. */\n isSelected: boolean,\n /** Whether the checkbox is in a pressed state. */\n isPressed: boolean,\n /** Whether the checkbox is disabled. */\n isDisabled: boolean,\n /** Whether the checkbox is read only. */\n isReadOnly: boolean,\n /** Whether the checkbox is invalid. */\n isInvalid: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n let {inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid} = useToggle(props, state, inputRef);\n\n let {isIndeterminate} = props;\n useEffect(() => {\n // indeterminate is a property, but it can only be set via javascript\n // https://css-tricks.com/indeterminate-checkboxes/\n if (inputRef.current) {\n inputRef.current.indeterminate = isIndeterminate;\n }\n });\n\n return {\n inputProps: {\n ...inputProps,\n checked: isSelected\n },\n isSelected,\n isPressed,\n isDisabled,\n isReadOnly,\n isInvalid\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\n\nexport interface CheckboxGroupAria {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n let {isDisabled, name} = props;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Checkbox group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span'\n });\n checkboxGroupDescriptionIds.set(state, descriptionProps.id);\n checkboxGroupErrorMessageIds.set(state, errorMessageProps.id);\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // Pass name prop from group to all items by attaching to the state.\n checkboxGroupNames.set(state, name);\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CheckboxGroupState} from '@react-stately/checkbox';\n\nexport const checkboxGroupNames = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupDescriptionIds = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupErrorMessageIds = new WeakMap<CheckboxGroupState, string>();\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {RefObject} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n onChange(isSelected) {\n if (isSelected) {\n state.addValue(props.value);\n } else {\n state.removeValue(props.value);\n }\n\n if (props.onChange) {\n props.onChange(isSelected);\n }\n }\n });\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || checkboxGroupNames.get(state)\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? checkboxGroupErrorMessageIds.get(state) : null,\n checkboxGroupDescriptionIds.get(state)\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -27,7 +27,7 @@ import {useToggleState as $cKEhs$useToggleState} from "@react-stately/toggle";
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
|
|
30
|
-
let { inputProps: inputProps , isSelected: isSelected , isPressed: isPressed , isDisabled: isDisabled , isReadOnly: isReadOnly } = (0, $cKEhs$useToggle)(props, state, inputRef);
|
|
30
|
+
let { inputProps: inputProps , isSelected: isSelected , isPressed: isPressed , isDisabled: isDisabled , isReadOnly: isReadOnly , isInvalid: isInvalid } = (0, $cKEhs$useToggle)(props, state, inputRef);
|
|
31
31
|
let { isIndeterminate: isIndeterminate } = props;
|
|
32
32
|
(0, $cKEhs$useEffect)(()=>{
|
|
33
33
|
// indeterminate is a property, but it can only be set via javascript
|
|
@@ -42,7 +42,8 @@ function $406796ff087fe49b$export$e375f10ce42261c5(props, state, inputRef) {
|
|
|
42
42
|
isSelected: isSelected,
|
|
43
43
|
isPressed: isPressed,
|
|
44
44
|
isDisabled: isDisabled,
|
|
45
|
-
isReadOnly: isReadOnly
|
|
45
|
+
isReadOnly: isReadOnly,
|
|
46
|
+
isInvalid: isInvalid
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
49
|
|
|
@@ -136,7 +137,8 @@ function $fba3e38d5ca8983f$export$353b32fc6898d37d(props, state, inputRef) {
|
|
|
136
137
|
inputProps: {
|
|
137
138
|
...res.inputProps,
|
|
138
139
|
"aria-describedby": [
|
|
139
|
-
|
|
140
|
+
props["aria-describedby"],
|
|
141
|
+
state.isInvalid ? (0, $1ae600c947479353$export$d5679492e2864181).get(state) : null,
|
|
140
142
|
(0, $1ae600c947479353$export$a3077e9c93f7360f).get(state)
|
|
141
143
|
].filter(Boolean).join(" ") || undefined
|
|
142
144
|
}
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;AA4BM,SAAS,0CAAY,KAAwB,EAAE,KAAkB,EAAE,QAAqC;IAC7G,IAAI,cAAC,WAAU,cAAE,WAAU,aAAE,UAAS,cAAE,WAAU,cAAE,WAAU,EAAC,GAAG,CAAA,GAAA,gBAAQ,EAAE,OAAO,OAAO;IAE1F,IAAI,mBAAC,gBAAe,EAAC,GAAG;IACxB,CAAA,GAAA,gBAAQ,EAAE;QACR,qEAAqE;QACrE,mDAAmD;QACnD,IAAI,SAAS,SACX,SAAS,QAAQ,gBAAgB;IAErC;IAEA,OAAO;QACL,YAAY;YACV,GAAG,UAAU;YACb,SAAS;QACX;oBACA;mBACA;oBACA;oBACA;IACF;AACF;;CDlDC;AEVD;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAIM,MAAM,4CAAqB,IAAI;AAC/B,MAAM,4CAA8B,IAAI;AACxC,MAAM,4CAA+B,IAAI;;CDN/C;;;AA0BM,SAAS,0CAAiB,KAA6B,EAAE,KAAyB;IACvF,IAAI,cAAC,WAAU,QAAE,KAAI,EAAC,GAAG;IAEzB,IAAI,cAAC,WAAU,cA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AAS,KAAK,QAAQ;QACjC;IACF;AACF;;","sources":["packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useToggle} from '@react-aria/toggle';\n\nexport interface CheckboxAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the checkbox is selected. */\n isSelected: boolean,\n /** Whether the checkbox is in a pressed state. */\n isPressed: boolean,\n /** Whether the checkbox is disabled. */\n isDisabled: boolean,\n /** Whether the checkbox is read only. */\n isReadOnly: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n let {inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle(props, state, inputRef);\n\n let {isIndeterminate} = props;\n useEffect(() => {\n // indeterminate is a property, but it can only be set via javascript\n // https://css-tricks.com/indeterminate-checkboxes/\n if (inputRef.current) {\n inputRef.current.indeterminate = isIndeterminate;\n }\n });\n\n return {\n inputProps: {\n ...inputProps,\n checked: isSelected\n },\n isSelected,\n isPressed,\n isDisabled,\n isReadOnly\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\n\nexport interface CheckboxGroupAria {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n let {isDisabled, name} = props;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Checkbox group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span'\n });\n checkboxGroupDescriptionIds.set(state, descriptionProps.id);\n checkboxGroupErrorMessageIds.set(state, errorMessageProps.id);\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // Pass name prop from group to all items by attaching to the state.\n checkboxGroupNames.set(state, name);\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CheckboxGroupState} from '@react-stately/checkbox';\n\nexport const checkboxGroupNames = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupDescriptionIds = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupErrorMessageIds = new WeakMap<CheckboxGroupState, string>();\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {RefObject} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n onChange(isSelected) {\n if (isSelected) {\n state.addValue(props.value);\n } else {\n state.removeValue(props.value);\n }\n\n if (props.onChange) {\n props.onChange(isSelected);\n }\n }\n });\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || checkboxGroupNames.get(state)\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n state.validationState === 'invalid' ? checkboxGroupErrorMessageIds.get(state) : null,\n checkboxGroupDescriptionIds.get(state)\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";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A;0BACA;2BACA;IACF;AACF;;;AE/DA;;;;;;;;;;CAUC;;;AAgBM,SAAS,0CAAqB,KAAiC,EAAE,KAAyB,EAAE,QAAqC;IACtI,MAAM,cAAc,CAAA,GAAA,qBAAa,EAAE;QACjC,YAAY,MAAM,cAAc,MAAM;QACtC,YAAY,MAAM,WAAW,MAAM;QACnC,UAAS,UAAU;YACjB,IAAI,YACF,MAAM,SAAS,MAAM;iBAErB,MAAM,YAAY,MAAM;YAG1B,IAAI,MAAM,UACR,MAAM,SAAS;QAEnB;IACF;IAEA,IAAI,MAAM,CAAA,GAAA,yCAAU,EAAE;QACpB,GAAG,KAAK;QACR,YAAY,MAAM,cAAc,MAAM;QACtC,YAAY,MAAM,cAAc,MAAM;QACtC,MAAM,MAAM,QAAQ,CAAA,GAAA,yCAAiB,EAAE,IAAI;IAC7C,GAAG,aAAa;IAEhB,OAAO;QACL,GAAG,GAAG;QACN,YAAY;YACV,GAAG,IAAI,UAAU;YACjB,oBAAoB;gBAClB,KAAK,CAAC,mBAAmB;gBACzB,MAAM,YAAY,CAAA,GAAA,yCAA2B,EAAE,IAAI,SAAS;gBAC5D,CAAA,GAAA,yCAA0B,EAAE,IAAI;aACjC,CAAC,OAAO,SAAS,KAAK,QAAQ;QACjC;IACF;AACF;;","sources":["packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxProps} from '@react-types/checkbox';\nimport {InputHTMLAttributes, RefObject, useEffect} from 'react';\nimport {ToggleState} from '@react-stately/toggle';\nimport {useToggle} from '@react-aria/toggle';\n\nexport interface CheckboxAria {\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Whether the checkbox is selected. */\n isSelected: boolean,\n /** Whether the checkbox is in a pressed state. */\n isPressed: boolean,\n /** Whether the checkbox is disabled. */\n isDisabled: boolean,\n /** Whether the checkbox is read only. */\n isReadOnly: boolean,\n /** Whether the checkbox is invalid. */\n isInvalid: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component.\n * Checkboxes allow users to select multiple items from a list of individual items, or\n * to mark one individual item as selected.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useToggleState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n let {inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid} = useToggle(props, state, inputRef);\n\n let {isIndeterminate} = props;\n useEffect(() => {\n // indeterminate is a property, but it can only be set via javascript\n // https://css-tricks.com/indeterminate-checkboxes/\n if (inputRef.current) {\n inputRef.current.indeterminate = isIndeterminate;\n }\n });\n\n return {\n inputProps: {\n ...inputProps,\n checked: isSelected\n },\n isSelected,\n isPressed,\n isDisabled,\n isReadOnly,\n isInvalid\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupProps} from '@react-types/checkbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\n\nexport interface CheckboxGroupAria {\n /** Props for the checkbox group wrapper element. */\n groupProps: DOMAttributes,\n /** Props for the checkbox group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the checkbox group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the checkbox group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox group component.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox group.\n * @param state - State for the checkbox group, as returned by `useCheckboxGroupState`.\n */\nexport function useCheckboxGroup(props: AriaCheckboxGroupProps, state: CheckboxGroupState): CheckboxGroupAria {\n let {isDisabled, name} = props;\n\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n // Checkbox group is not an HTML input element so it\n // shouldn't be labeled by a <label> element.\n labelElementType: 'span'\n });\n checkboxGroupDescriptionIds.set(state, descriptionProps.id);\n checkboxGroupErrorMessageIds.set(state, errorMessageProps.id);\n\n let domProps = filterDOMProps(props, {labelable: true});\n\n // Pass name prop from group to all items by attaching to the state.\n checkboxGroupNames.set(state, name);\n\n return {\n groupProps: mergeProps(domProps, {\n role: 'group',\n 'aria-disabled': isDisabled || undefined,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CheckboxGroupState} from '@react-stately/checkbox';\n\nexport const checkboxGroupNames = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupDescriptionIds = new WeakMap<CheckboxGroupState, string>();\nexport const checkboxGroupErrorMessageIds = new WeakMap<CheckboxGroupState, string>();\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaCheckboxGroupItemProps} from '@react-types/checkbox';\nimport {CheckboxAria, useCheckbox} from './useCheckbox';\nimport {checkboxGroupDescriptionIds, checkboxGroupErrorMessageIds, checkboxGroupNames} from './utils';\nimport {CheckboxGroupState} from '@react-stately/checkbox';\nimport {RefObject} from 'react';\nimport {useToggleState} from '@react-stately/toggle';\n\n/**\n * Provides the behavior and accessibility implementation for a checkbox component contained within a checkbox group.\n * Checkbox groups allow users to select multiple items from a list of options.\n * @param props - Props for the checkbox.\n * @param state - State for the checkbox, as returned by `useCheckboxGroupState`.\n * @param inputRef - A ref for the HTML input element.\n */\nexport function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: CheckboxGroupState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {\n const toggleState = useToggleState({\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isSelected: state.isSelected(props.value),\n onChange(isSelected) {\n if (isSelected) {\n state.addValue(props.value);\n } else {\n state.removeValue(props.value);\n }\n\n if (props.onChange) {\n props.onChange(isSelected);\n }\n }\n });\n\n let res = useCheckbox({\n ...props,\n isReadOnly: props.isReadOnly || state.isReadOnly,\n isDisabled: props.isDisabled || state.isDisabled,\n name: props.name || checkboxGroupNames.get(state)\n }, toggleState, inputRef);\n\n return {\n ...res,\n inputProps: {\n ...res.inputProps,\n 'aria-describedby': [\n props['aria-describedby'],\n state.isInvalid ? checkboxGroupErrorMessageIds.get(state) : null,\n checkboxGroupDescriptionIds.get(state)\n ].filter(Boolean).join(' ') || undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface CheckboxAria {
|
|
|
14
14
|
isDisabled: boolean;
|
|
15
15
|
/** Whether the checkbox is read only. */
|
|
16
16
|
isReadOnly: boolean;
|
|
17
|
+
/** Whether the checkbox is invalid. */
|
|
18
|
+
isInvalid: boolean;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Provides the behavior and accessibility implementation for a checkbox component.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAiBA;IACE,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,kDAAkD;IAClD,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,yCAAyC;IACzC,UAAU,EAAE,OAAO,CAAA;
|
|
1
|
+
{"mappings":";;;;;AAiBA;IACE,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,kDAAkD;IAClD,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,UAAU,EAAE,OAAO,CAAC;IACpB,yCAAyC;IACzC,UAAU,EAAE,OAAO,CAAC;IACpB,uCAAuC;IACvC,SAAS,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;GAOG;AACH,4BAA4B,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GAAG,YAAY,CAuB7H;AE5CD;IACE,oDAAoD;IACpD,UAAU,EAAE,aAAa,CAAC;IAC1B,6DAA6D;IAC7D,UAAU,EAAE,aAAa,CAAC;IAC1B,gEAAgE;IAChE,gBAAgB,EAAE,aAAa,CAAC;IAChC,kEAAkE;IAClE,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED;;;;;GAKG;AACH,iCAAiC,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,kBAAkB,GAAG,iBAAiB,CA2B5G;AC5CD;;;;;;GAMG;AACH,qCAAqC,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,gBAAgB,CAAC,GAAG,YAAY,CAmCtJ;AC9CD,YAAY,EAAC,0BAA0B,EAAE,sBAAsB,EAAE,iBAAiB,EAAC,MAAM,uBAAuB,CAAC","sources":["packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckbox.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/utils.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckboxGroup.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/useCheckboxGroupItem.ts","packages/@react-aria/checkbox/src/packages/@react-aria/checkbox/src/index.ts","packages/@react-aria/checkbox/src/index.ts"],"sourcesContent":[null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport type {CheckboxAria} from './useCheckbox';\nexport {useCheckbox} from './useCheckbox';\nexport {useCheckboxGroup} from './useCheckboxGroup';\nexport {useCheckboxGroupItem} from './useCheckboxGroupItem';\nexport type {AriaCheckboxGroupItemProps, AriaCheckboxGroupProps, AriaCheckboxProps} from '@react-types/checkbox';\nexport type {CheckboxGroupAria} from './useCheckboxGroup';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/checkbox",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/label": "^3.
|
|
26
|
-
"@react-aria/toggle": "^3.
|
|
27
|
-
"@react-aria/utils": "^3.
|
|
28
|
-
"@react-stately/checkbox": "^3.
|
|
29
|
-
"@react-stately/toggle": "^3.6.
|
|
30
|
-
"@react-types/checkbox": "^3.
|
|
31
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/label": "^3.7.0",
|
|
26
|
+
"@react-aria/toggle": "^3.8.0",
|
|
27
|
+
"@react-aria/utils": "^3.20.0",
|
|
28
|
+
"@react-stately/checkbox": "^3.5.0",
|
|
29
|
+
"@react-stately/toggle": "^3.6.2",
|
|
30
|
+
"@react-types/checkbox": "^3.5.1",
|
|
31
|
+
"@react-types/shared": "^3.20.0",
|
|
32
32
|
"@swc/helpers": "^0.5.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "54fbaa67cc56867506811819fef765546d403253"
|
|
41
41
|
}
|
package/src/useCheckbox.ts
CHANGED
|
@@ -25,7 +25,9 @@ export interface CheckboxAria {
|
|
|
25
25
|
/** Whether the checkbox is disabled. */
|
|
26
26
|
isDisabled: boolean,
|
|
27
27
|
/** Whether the checkbox is read only. */
|
|
28
|
-
isReadOnly: boolean
|
|
28
|
+
isReadOnly: boolean,
|
|
29
|
+
/** Whether the checkbox is invalid. */
|
|
30
|
+
isInvalid: boolean
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
@@ -37,7 +39,7 @@ export interface CheckboxAria {
|
|
|
37
39
|
* @param inputRef - A ref for the HTML input element.
|
|
38
40
|
*/
|
|
39
41
|
export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputRef: RefObject<HTMLInputElement>): CheckboxAria {
|
|
40
|
-
let {inputProps, isSelected, isPressed, isDisabled, isReadOnly} = useToggle(props, state, inputRef);
|
|
42
|
+
let {inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid} = useToggle(props, state, inputRef);
|
|
41
43
|
|
|
42
44
|
let {isIndeterminate} = props;
|
|
43
45
|
useEffect(() => {
|
|
@@ -56,6 +58,7 @@ export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputR
|
|
|
56
58
|
isSelected,
|
|
57
59
|
isPressed,
|
|
58
60
|
isDisabled,
|
|
59
|
-
isReadOnly
|
|
61
|
+
isReadOnly,
|
|
62
|
+
isInvalid
|
|
60
63
|
};
|
|
61
64
|
}
|
|
@@ -53,7 +53,8 @@ export function useCheckboxGroupItem(props: AriaCheckboxGroupItemProps, state: C
|
|
|
53
53
|
inputProps: {
|
|
54
54
|
...res.inputProps,
|
|
55
55
|
'aria-describedby': [
|
|
56
|
-
|
|
56
|
+
props['aria-describedby'],
|
|
57
|
+
state.isInvalid ? checkboxGroupErrorMessageIds.get(state) : null,
|
|
57
58
|
checkboxGroupDescriptionIds.get(state)
|
|
58
59
|
].filter(Boolean).join(' ') || undefined
|
|
59
60
|
}
|