-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckbox.tsx
59 lines (53 loc) · 1.75 KB
/
checkbox.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { JSXChildren, Slot, component$, useStyles$ } from "@builder.io/qwik";
import { BaseCheckAll, BaseCheckItem, BaseCheckList, BaseCheckbox, BaseCheckItemProps, BaseCheckboxProps, BaseCheckListProps } from "./base";
import { mergeProps } from "../../utils/attributes";
import { InputAttributes } from "../types";
import { isNodeType } from "../../utils/jsx";
import styles from './checkbox.scss?inline';
export const CheckSymbol = () => (
<svg focusable="false" viewBox="0 0 24 24" aria-hidden="true">
<path fill="none"></path>
</svg>
);
type CheckListProps = BaseCheckListProps & {
children: JSXChildren;
}
export function CheckList(props: CheckListProps) {
const { children, ...rest } = props;
const childrenArray = Array.isArray(children) ? children : [children];
const merged = mergeProps<'div'>(rest, {
role: 'group',
class: 'he-check-list'
});
const allValues = childrenArray.filter(isNodeType(CheckItem)).map(node => node.props.value);
return <BaseCheckList {...merged} allValues={allValues}>
{children}
</BaseCheckList>
}
export const CheckAll = component$<InputAttributes>((props) => {
useStyles$(styles);
return <div class="he-check-all">
<BaseCheckAll {...props} intermediateClass="he-check-indeterminate">
<CheckSymbol />
<Slot/>
</BaseCheckAll>
</div>
});
export const CheckItem = component$<BaseCheckItemProps>((props) => {
useStyles$(styles);
return <div class="he-check-item">
<BaseCheckItem {...props}>
<CheckSymbol />
<Slot/>
</BaseCheckItem>
</div>
});
export const Checkbox = component$<BaseCheckboxProps>((props) => {
useStyles$(styles);
return <div class="he-checkbox">
<BaseCheckbox {...props}>
<CheckSymbol />
<Slot/>
</BaseCheckbox>
</div>
});