MCPcopy Create free account
hub / github.com/adobe/react-spectrum / Checkbox

Function Checkbox

starters/hooks/src/Checkbox.tsx:11–56  ·  view source on GitHub ↗
(props: AriaCheckboxProps)

Source from the content-addressed store, hash-verified

9import './Checkbox.css';
10
11export function Checkbox(props: AriaCheckboxProps) {
12 let state = useToggleState(props);
13 let ref = useRef<HTMLInputElement>(null);
14 /*- begin highlight -*/
15 let {labelProps, inputProps, isSelected, isPressed, isDisabled, isReadOnly, isInvalid} =
16 useCheckbox(props, state, ref);
17 /*- end highlight -*/
18 let {hoverProps, isHovered} = useHover({isDisabled: isDisabled || isReadOnly});
19 let {isFocused, isFocusVisible, focusProps} = useFocusRing();
20 let isIndeterminate = props.isIndeterminate || false;
21
22 return (
23 <div className="react-aria-CheckboxField" data-disabled={isDisabled || undefined}>
24 {/* The label wraps a visually hidden native input plus the styled indicator. */}
25 <label
26 {...mergeProps(labelProps, hoverProps)}
27 className="react-aria-CheckboxButton"
28 data-selected={isSelected || undefined}
29 data-indeterminate={isIndeterminate || undefined}
30 data-pressed={isPressed || undefined}
31 data-hovered={isHovered || undefined}
32 data-focused={isFocused || undefined}
33 data-focus-visible={isFocusVisible || undefined}
34 data-disabled={isDisabled || undefined}
35 data-readonly={isReadOnly || undefined}
36 data-invalid={isInvalid || undefined}>
37 <VisuallyHidden elementType="span">
38 <input {...mergeProps(inputProps, focusProps)} ref={ref} />
39 </VisuallyHidden>
40 <div className="indicator">
41 <svg
42 viewBox="0 0 18 18"
43 aria-hidden="true"
44 key={isIndeterminate ? 'indeterminate' : 'check'}>
45 {isIndeterminate ? (
46 <rect x={1} y={7.5} width={16} height={3} />
47 ) : (
48 <polyline points="2 9 7 14 16 4" />
49 )}
50 </svg>
51 </div>
52 {props.children}
53 </label>
54 </div>
55 );
56}

Callers

nothing calls this directly

Calls 5

useToggleStateFunction · 0.90
useCheckboxFunction · 0.90
useHoverFunction · 0.90
useFocusRingFunction · 0.90
mergePropsFunction · 0.90

Tested by

no test coverage detected