Skip to content

Commit 0f4895c

Browse files
committed
feat(checkbox): added draft docs
1 parent 659ebab commit 0f4895c

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
2+
import { Checkbox } from '@qwik-ui/headless';
3+
export default component$(() => {
4+
const controlledSig = useSignal(false);
5+
return (
6+
<>
7+
<div class="flex flex-col gap-3">
8+
<Checkbox.Root
9+
checkboxSig={controlledSig}
10+
id="test"
11+
class="flex items-center gap-3 border-2 border-black p-2 "
12+
>
13+
<Checkbox.Indicator class="flex h-[25px] w-[25px] items-center justify-center bg-slate-600">
14+
15+
</Checkbox.Indicator>
16+
Toggle Signal
17+
</Checkbox.Root>
18+
<p>Your signal's value is: {`${controlledSig.value}`}</p>
19+
</div>
20+
</>
21+
);
22+
});

apps/website/src/routes/docs/headless/checkbox/index.mdx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,51 @@ import { statusByComponent } from '~/_state/component-statuses';
1212
Allows users to visually select an option by "checking" it.
1313

1414
<Showcase name="hero" />
15-
<Showcase name="pizza" />
15+
### Anatomy
16+
17+
<AnatomyTable
18+
propDescriptors={[
19+
{
20+
name: 'Checkbox.Root',
21+
description:
22+
'Defines the component boundary and exposes its internal logic; must wrap over all other parts',
23+
},
24+
{
25+
name: 'Checkbox.Indicator',
26+
description: 'Wrapper that automatically handles show & hide logic for you',
27+
},
28+
]}
29+
/>
30+
31+
### API
32+
33+
<AnatomyTable
34+
propDescriptors={[
35+
{
36+
name: 'checkboxSig',
37+
description: 'Defined at the root; binds the value to a boolean signal',
38+
},
39+
{
40+
name: 'checklist',
41+
description:
42+
"Defined at the root; makes the checkbox be treated as a tri-state checkbox AND binds it's value over all other checkboxes inside a checklist",
43+
},
44+
]}
45+
/>
46+
### API examples #### Controlled Checkbox
47+
48+
<Showcase name="controlled" />
49+
50+
This example shows that you can pass down your own signal to handle the boolean logic. Note that the initial value of your signal will affect the initial value of the checkbox.
51+
52+
### Customization & Caveats
53+
54+
The Checkbox is made from the ground up to be as customizable as possible.
55+
56+
You can define your own CSS classes on every part of the component as if it were a normal div element. You can even define any valid HTML as your icon, but keep in mind that any child of the Checkbox Indicator is removed from the accesibilyti tree. This is done to prevent text, or emojis, that are meant to be used as icons from being added to the label of the Checkbox (see [automatic labeling](#automatic-labeling) for more info).
57+
58+
### Automatic Labeling
59+
60+
Due to the implementation of the Checkbox element being a div with the role of checkbox, any text present inside the Checkbox Root is interpreted as the checkbox label.
61+
62+
This also means that any text tag is stripped from its semantic meaning. In other words, passing an h1 tag is treated the same as passing a p tag: they are both treated as if you passed no tag at all. See [this](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/checkbox_role#all_descendants_are_presentational) section of MDN for a more detailed explenation.

packages/kit-headless/src/components/checkbox/checkbox.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { CheckListContext, CheckboxContext } from './context-id';
1414
import { TriBool, getTriBool } from '../checklist/checklist-context-wrapper';
1515
export type MixedStateCheckboxProps = {
16-
checkBoxSig?: Signal<boolean>;
16+
checkboxSig?: Signal<boolean>;
1717
checklist?: boolean;
1818
_useCheckListContext?: boolean;
1919
_overWriteCheckbox?: boolean;
@@ -144,16 +144,16 @@ export const MixedStateCheckbox = component$<MixedStateCheckboxProps>((props) =>
144144
// all the sig stuff should be refactored into a fancy hook
145145
const checklistContext = useContext(CheckListContext);
146146
const childCheckboxes = checklistContext.checkboxes;
147-
const appliedSig = props.checkBoxSig ?? checklistContext.checklistSig;
147+
const appliedSig = props.checkboxSig ?? checklistContext.checklistSig;
148148
const ariaControlsStrg =
149149
checklistContext.idArr.length === 0
150150
? ''
151151
: checklistContext.idArr.reduce((p, c) => p + ' ' + c);
152152
useContextProvider(CheckboxContext, appliedSig);
153153

154154
// im not enterily sure why, but the if statement only runs once
155-
if (props.checkBoxSig !== undefined) {
156-
checklistContext.checklistSig = props.checkBoxSig;
155+
if (props.checkboxSig !== undefined) {
156+
checklistContext.checklistSig = props.checkboxSig;
157157
}
158158

159159
const changeChecklistSig = $(() => {

0 commit comments

Comments
 (0)