@react-spectrum/checkbox 3.10.6 → 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 +3 -3
- package/dist/main.js +4 -4
- package/dist/main.js.map +1 -1
- package/dist/module.js +3 -3
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +4 -0
- package/package.json +13 -35
- package/src/index.ts +5 -3
- package/dist/Checkbox.main.js +0 -117
- package/dist/Checkbox.main.js.map +0 -1
- package/dist/Checkbox.mjs +0 -112
- package/dist/Checkbox.module.js +0 -112
- package/dist/Checkbox.module.js.map +0 -1
- package/dist/CheckboxGroup.main.js +0 -68
- package/dist/CheckboxGroup.main.js.map +0 -1
- package/dist/CheckboxGroup.mjs +0 -63
- package/dist/CheckboxGroup.module.js +0 -63
- package/dist/CheckboxGroup.module.js.map +0 -1
- package/dist/checkbox.155bd254.css +0 -488
- package/dist/checkbox.155bd254.css.map +0 -1
- package/dist/checkbox.f39d58be.css +0 -94
- package/dist/checkbox.f39d58be.css.map +0 -1
- package/dist/checkbox_vars_css.main.js +0 -59
- package/dist/checkbox_vars_css.main.js.map +0 -1
- package/dist/checkbox_vars_css.mjs +0 -61
- package/dist/checkbox_vars_css.module.js +0 -61
- package/dist/checkbox_vars_css.module.js.map +0 -1
- package/dist/context.main.js +0 -27
- package/dist/context.main.js.map +0 -1
- package/dist/context.mjs +0 -18
- package/dist/context.module.js +0 -18
- package/dist/context.module.js.map +0 -1
- package/dist/fieldgroup_vars_css.main.js +0 -32
- package/dist/fieldgroup_vars_css.main.js.map +0 -1
- package/dist/fieldgroup_vars_css.mjs +0 -34
- package/dist/fieldgroup_vars_css.module.js +0 -34
- package/dist/fieldgroup_vars_css.module.js.map +0 -1
- package/dist/types.d.ts +0 -15
- package/dist/types.d.ts.map +0 -1
- package/src/Checkbox.tsx +0 -122
- package/src/CheckboxGroup.tsx +0 -67
- package/src/context.ts +0 -16
package/src/Checkbox.tsx
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {CheckboxContext, useContextProps} from 'react-aria-components';
|
|
14
|
-
import {CheckboxGroupContext} from './context';
|
|
15
|
-
import CheckmarkSmall from '@spectrum-icons/ui/CheckmarkSmall';
|
|
16
|
-
import {classNames, useFocusableRef, useStyleProps} from '@react-spectrum/utils';
|
|
17
|
-
import DashSmall from '@spectrum-icons/ui/DashSmall';
|
|
18
|
-
import {FocusableRef} from '@react-types/shared';
|
|
19
|
-
import {FocusRing} from '@react-aria/focus';
|
|
20
|
-
import React, {forwardRef, useContext, useRef} from 'react';
|
|
21
|
-
import {SpectrumCheckboxProps} from '@react-types/checkbox';
|
|
22
|
-
import styles from '@adobe/spectrum-css-temp/components/checkbox/vars.css';
|
|
23
|
-
import {useCheckbox, useCheckboxGroupItem} from '@react-aria/checkbox';
|
|
24
|
-
import {useFormProps} from '@react-spectrum/form';
|
|
25
|
-
import {useHover} from '@react-aria/interactions';
|
|
26
|
-
import {useProviderProps} from '@react-spectrum/provider';
|
|
27
|
-
import {useToggleState} from '@react-stately/toggle';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Checkboxes allow users to select multiple items from a list of individual items,
|
|
31
|
-
* or to mark one individual item as selected.
|
|
32
|
-
*/
|
|
33
|
-
export const Checkbox = forwardRef(function Checkbox(props: SpectrumCheckboxProps, ref: FocusableRef<HTMLLabelElement>) {
|
|
34
|
-
let originalProps = props;
|
|
35
|
-
let inputRef = useRef<HTMLInputElement>(null);
|
|
36
|
-
let domRef = useFocusableRef(ref, inputRef);
|
|
37
|
-
|
|
38
|
-
[props, domRef] = useContextProps(props, domRef, CheckboxContext);
|
|
39
|
-
props = useProviderProps(props);
|
|
40
|
-
props = useFormProps(props);
|
|
41
|
-
let {
|
|
42
|
-
isIndeterminate = false,
|
|
43
|
-
isEmphasized = false,
|
|
44
|
-
autoFocus,
|
|
45
|
-
children,
|
|
46
|
-
...otherProps
|
|
47
|
-
} = props;
|
|
48
|
-
let {styleProps} = useStyleProps(otherProps);
|
|
49
|
-
|
|
50
|
-
// Swap hooks depending on whether this checkbox is inside a CheckboxGroup.
|
|
51
|
-
// This is a bit unorthodox. Typically, hooks cannot be called in a conditional,
|
|
52
|
-
// but since the checkbox won't move in and out of a group, it should be safe.
|
|
53
|
-
let groupState = useContext(CheckboxGroupContext);
|
|
54
|
-
let {inputProps, isInvalid, isDisabled} = groupState
|
|
55
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
56
|
-
? useCheckboxGroupItem({
|
|
57
|
-
...props,
|
|
58
|
-
// Value is optional for standalone checkboxes, but required for CheckboxGroup items;
|
|
59
|
-
// it's passed explicitly here to avoid typescript error (requires ignore).
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
value: props.value,
|
|
62
|
-
// Only pass isRequired and validationState to react-aria if they came from
|
|
63
|
-
// the props for this individual checkbox, and not from the group via context.
|
|
64
|
-
isRequired: originalProps.isRequired,
|
|
65
|
-
validationState: originalProps.validationState,
|
|
66
|
-
isInvalid: originalProps.isInvalid
|
|
67
|
-
}, groupState, inputRef)
|
|
68
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
69
|
-
: useCheckbox(props, useToggleState(props), inputRef);
|
|
70
|
-
|
|
71
|
-
let {hoverProps, isHovered} = useHover({isDisabled});
|
|
72
|
-
|
|
73
|
-
let markIcon = isIndeterminate
|
|
74
|
-
? <DashSmall UNSAFE_className={classNames(styles, 'spectrum-Checkbox-partialCheckmark')} />
|
|
75
|
-
: <CheckmarkSmall UNSAFE_className={classNames(styles, 'spectrum-Checkbox-checkmark')} />;
|
|
76
|
-
|
|
77
|
-
if (groupState && process.env.NODE_ENV !== 'production') {
|
|
78
|
-
for (let key of ['isSelected', 'defaultSelected', 'isEmphasized']) {
|
|
79
|
-
if (originalProps[key] != null) {
|
|
80
|
-
console.warn(`${key} is unsupported on individual <Checkbox> elements within a <CheckboxGroup>. Please apply these props to the group instead.`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (props.value == null) {
|
|
84
|
-
console.warn('A <Checkbox> element within a <CheckboxGroup> requires a `value` property.');
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<label
|
|
90
|
-
{...styleProps}
|
|
91
|
-
{...hoverProps}
|
|
92
|
-
ref={domRef}
|
|
93
|
-
className={
|
|
94
|
-
classNames(
|
|
95
|
-
styles,
|
|
96
|
-
'spectrum-Checkbox',
|
|
97
|
-
{
|
|
98
|
-
'is-checked': inputProps.checked,
|
|
99
|
-
'is-indeterminate': isIndeterminate,
|
|
100
|
-
'spectrum-Checkbox--quiet': !isEmphasized,
|
|
101
|
-
'is-invalid': isInvalid,
|
|
102
|
-
'is-disabled': isDisabled,
|
|
103
|
-
'is-hovered': isHovered
|
|
104
|
-
},
|
|
105
|
-
styleProps.className
|
|
106
|
-
)
|
|
107
|
-
}>
|
|
108
|
-
<FocusRing focusRingClass={classNames(styles, 'focus-ring')} autoFocus={autoFocus}>
|
|
109
|
-
<input
|
|
110
|
-
{...inputProps}
|
|
111
|
-
ref={inputRef}
|
|
112
|
-
className={classNames(styles, 'spectrum-Checkbox-input')} />
|
|
113
|
-
</FocusRing>
|
|
114
|
-
<span className={classNames(styles, 'spectrum-Checkbox-box')}>{markIcon}</span>
|
|
115
|
-
{children && (
|
|
116
|
-
<span className={classNames(styles, 'spectrum-Checkbox-label')}>
|
|
117
|
-
{children}
|
|
118
|
-
</span>
|
|
119
|
-
)}
|
|
120
|
-
</label>
|
|
121
|
-
);
|
|
122
|
-
});
|
package/src/CheckboxGroup.tsx
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {CheckboxGroupContext} from './context';
|
|
14
|
-
import {classNames, useDOMRef} from '@react-spectrum/utils';
|
|
15
|
-
import {DOMRef} from '@react-types/shared';
|
|
16
|
-
import {Field} from '@react-spectrum/label';
|
|
17
|
-
import {Provider, useProviderProps} from '@react-spectrum/provider';
|
|
18
|
-
import React from 'react';
|
|
19
|
-
import {SpectrumCheckboxGroupProps} from '@react-types/checkbox';
|
|
20
|
-
import styles from '@adobe/spectrum-css-temp/components/fieldgroup/vars.css';
|
|
21
|
-
import {useCheckboxGroup} from '@react-aria/checkbox';
|
|
22
|
-
import {useCheckboxGroupState} from '@react-stately/checkbox';
|
|
23
|
-
import {useFormProps} from '@react-spectrum/form';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A CheckboxGroup allows users to select one or more items from a list of choices.
|
|
27
|
-
*/
|
|
28
|
-
export const CheckboxGroup = React.forwardRef(function CheckboxGroup(props: SpectrumCheckboxGroupProps, ref: DOMRef<HTMLDivElement>) {
|
|
29
|
-
props = useProviderProps(props);
|
|
30
|
-
props = useFormProps(props);
|
|
31
|
-
let {
|
|
32
|
-
isEmphasized,
|
|
33
|
-
children,
|
|
34
|
-
orientation = 'vertical'
|
|
35
|
-
} = props;
|
|
36
|
-
let domRef = useDOMRef(ref);
|
|
37
|
-
let state = useCheckboxGroupState(props);
|
|
38
|
-
let {groupProps, ...otherProps} = useCheckboxGroup(props, state);
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<Field
|
|
42
|
-
{...props}
|
|
43
|
-
{...otherProps}
|
|
44
|
-
ref={domRef}
|
|
45
|
-
wrapperClassName={classNames(styles, 'spectrum-FieldGroup')}
|
|
46
|
-
elementType="span"
|
|
47
|
-
includeNecessityIndicatorInAccessibilityName>
|
|
48
|
-
<div
|
|
49
|
-
{...groupProps}
|
|
50
|
-
className={
|
|
51
|
-
classNames(
|
|
52
|
-
styles,
|
|
53
|
-
'spectrum-FieldGroup-group',
|
|
54
|
-
{
|
|
55
|
-
'spectrum-FieldGroup-group--horizontal': orientation === 'horizontal'
|
|
56
|
-
}
|
|
57
|
-
)
|
|
58
|
-
}>
|
|
59
|
-
<Provider isEmphasized={isEmphasized}>
|
|
60
|
-
<CheckboxGroupContext.Provider value={state}>
|
|
61
|
-
{children}
|
|
62
|
-
</CheckboxGroupContext.Provider>
|
|
63
|
-
</Provider>
|
|
64
|
-
</div>
|
|
65
|
-
</Field>
|
|
66
|
-
);
|
|
67
|
-
});
|
package/src/context.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {CheckboxGroupState} from '@react-stately/checkbox';
|
|
14
|
-
import React from 'react';
|
|
15
|
-
|
|
16
|
-
export const CheckboxGroupContext = React.createContext<CheckboxGroupState | null>(null);
|