Skip to content

Commit ed09dae

Browse files
committed
refactor(checbox&checklist): replaces checkboxSig for bind:checked
API is now fully up to date
1 parent 36df07a commit ed09dae

File tree

11 files changed

+29
-29
lines changed

11 files changed

+29
-29
lines changed

apps/website/src/routes/docs/headless/checkbox/examples/controlled.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default component$(() => {
66
<>
77
<div class="flex flex-col gap-3">
88
<Checkbox.Root
9-
checkboxSig={controlledSig}
9+
bind:checked={controlledSig}
1010
id="test"
1111
class="flex items-center gap-3 border-2 border-black p-2 "
1212
>

apps/website/src/routes/docs/headless/checkbox/examples/test-controlled-list-false.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default component$(() => {
1111
<Checkbox.Root
1212
class="flex items-center gap-3 bg-slate-900 text-white"
1313
checklist={true}
14-
checkboxSig={checklistSig}
14+
bind:checked={checklistSig}
1515
id="checklist"
1616
>
1717
<Checklist.Indicator class="w-fit">

apps/website/src/routes/docs/headless/checkbox/examples/test-controlled-list-falses.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export default component$(() => {
1717
<p>Controlls all</p>
1818
</Checkbox.Root>
1919
<Checkbox.Root
20-
checkboxSig={firstUserSig}
20+
bind:checked={firstUserSig}
2121
class="flex items-center gap-3 bg-slate-900 pr-2 text-white"
2222
>
2323
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
2424
<p>No other stuff is needed here</p>
2525
</Checkbox.Root>
2626

27-
<Checkbox.Root checkboxSig={secondUserSig} class="bg-slate-900 text-white">
27+
<Checkbox.Root bind:checked={secondUserSig} class="bg-slate-900 text-white">
2828
<div class="flex items-center gap-3">
2929
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
3030
<p>No other stuff is needed here</p>

apps/website/src/routes/docs/headless/checkbox/examples/test-controlled-list-mixed.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ export default component$(() => {
2222
<p>Controlls all</p>
2323
</Checkbox.Root>
2424
<Checkbox.Root
25-
checkboxSig={firstUserSig}
25+
bind:checked={firstUserSig}
2626
class="flex items-center gap-3 bg-slate-900 pr-2 text-white"
2727
>
2828
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
2929
<p>No other stuff is needed here</p>
3030
</Checkbox.Root>
3131

32-
<Checkbox.Root checkboxSig={secondUserSig} class="bg-slate-900 text-white">
32+
<Checkbox.Root bind:checked={secondUserSig} class="bg-slate-900 text-white">
3333
<div class="flex items-center gap-3">
3434
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
3535
<p>No other stuff is needed here</p>

apps/website/src/routes/docs/headless/checkbox/examples/test-controlled-list-true.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default component$(() => {
1010
<Checkbox.Root
1111
class="flex items-center gap-3 bg-slate-900 text-white"
1212
checklist={true}
13-
checkboxSig={checklistSig}
13+
bind:checked={checklistSig}
1414
id="checklist"
1515
>
1616
<Checklist.Indicator class="w-fit">

apps/website/src/routes/docs/headless/checkbox/examples/test-controlled-list-trues.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export default component$(() => {
1717
<p>Controlls all</p>
1818
</Checkbox.Root>
1919
<Checkbox.Root
20-
checkboxSig={firstUserSig}
20+
bind:checked={firstUserSig}
2121
class="flex items-center gap-3 bg-slate-900 pr-2 text-white"
2222
>
2323
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
2424
<p>No other stuff is needed here</p>
2525
</Checkbox.Root>
2626

27-
<Checkbox.Root checkboxSig={secondUserSig} class="bg-slate-900 text-white">
27+
<Checkbox.Root bind:checked={secondUserSig} class="bg-slate-900 text-white">
2828
<div class="flex items-center gap-3">
2929
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
3030
<p>No other stuff is needed here</p>

apps/website/src/routes/docs/headless/checkbox/examples/test-controlled-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default component$(() => {
1717
<p>Controlls all</p>
1818
</Checkbox.Root>
1919
<Checkbox.Root
20-
checkboxSig={firstUserSig}
20+
bind:checked={firstUserSig}
2121
class="flex items-center gap-3 bg-slate-900 pr-2 text-white"
2222
>
2323
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>

apps/website/src/routes/docs/headless/checkbox/examples/test-hero.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default component$(() => {
55
const userSig = useSignal(true);
66
return (
77
<>
8-
<Checkbox.Root class="bg-slate-900 text-white" checkboxSig={userSig}>
8+
<Checkbox.Root class="bg-slate-900 text-white" bind:checked={userSig}>
99
<div class="flex items-center gap-3">
1010
<Checkbox.Indicator class="w-fit bg-slate-600">
1111
<p id="indicator"></p>

apps/website/src/routes/docs/headless/checkbox/examples/test-props-ids-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default component$(() => {
1919
</Checkbox.Root>
2020
<Checkbox.Root
2121
id="child-1"
22-
checkboxSig={firstUserSig}
22+
bind:checked={firstUserSig}
2323
class="flex items-center gap-3 bg-slate-900 pr-2 text-white"
2424
>
2525
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ 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+
'bind:checked'?: Signal<boolean>;
1717
checklist?: boolean;
1818
_useCheckListContext?: boolean;
1919
_overWriteCheckbox?: boolean;
2020
} & PropsOf<'div'>;
2121
export type TwoStateCheckboxProps = {
22-
checkboxSig?: Signal<boolean>;
22+
'bind:checked'?: Signal<boolean>;
2323
_useCheckListContext?: boolean;
2424
_overWriteCheckbox?: boolean;
2525
} & PropsOf<'div'>;
@@ -28,7 +28,7 @@ type TwoStateCheckboxBehaviorProps = {
2828
checkboxSig: Signal<boolean>;
2929
} & PropsOf<'div'>;
3030
export type ChecklistTwoStateCheckboxProps = {
31-
checkboxSig?: Signal<boolean>;
31+
'bind:checked'?: Signal<boolean>;
3232
_useCheckListContext?: boolean;
3333
_overWriteCheckbox?: boolean;
3434
} & PropsOf<'div'>;
@@ -65,12 +65,12 @@ function getAriaChecked(triBool: TriBool): 'mixed' | 'true' | 'false' {
6565
export const TwoStateCheckbox = component$<TwoStateCheckboxProps>((props) => {
6666
// all the sig stuff should be refactored into a fancy hook
6767
const defaultSig = useSignal(false);
68-
const appliedSig = props.checkboxSig ?? defaultSig;
68+
const appliedSig = props['bind:checked'] ?? defaultSig;
6969
const checklistID = useSignal<string | undefined>(props.id);
7070
useContextProvider(CheckboxContext, appliedSig);
7171
return (
7272
<TwoStateCheckboxBehavior
73-
checkboxSig={appliedSig}
73+
bind:checked={appliedSig}
7474
tabIndex={0}
7575
role="checkbox"
7676
aria-checked={getAriaChecked(appliedSig.value)}
@@ -89,7 +89,7 @@ export const ChecklistTwoStateCheckbox = component$<ChecklistTwoStateCheckboxPro
8989
// making this a wrapper over the simpler component or using hooks
9090
const checklistContext = useContext(CheckListContext);
9191
const defaultSig = useSignal(false);
92-
const appliedSig = props.checkboxSig ?? defaultSig;
92+
const appliedSig = props['bind:checked'] ?? defaultSig;
9393
const checklistID = useSignal<string | undefined>(props.id);
9494
// makes sure that the checklist's value is the same as its child
9595
const syncToChecklist = useSignal<undefined | boolean>(props._overWriteCheckbox);
@@ -130,7 +130,7 @@ export const ChecklistTwoStateCheckbox = component$<ChecklistTwoStateCheckboxPro
130130
role="checkbox"
131131
aria-checked={getAriaChecked(appliedSig.value)}
132132
id={checklistID.value}
133-
checkboxSig={appliedSig}
133+
bind:checked={appliedSig}
134134
>
135135
<Slot />
136136
</TwoStateCheckboxBehavior>
@@ -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['bind:checked'] ?? 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['bind:checked'] !== undefined) {
156+
checklistContext.checklistSig = props['bind:checked'];
157157
}
158158

159159
const changeChecklistSig = $(() => {
@@ -202,19 +202,19 @@ const TwoStateCheckboxBehavior = component$<TwoStateCheckboxBehaviorProps>((prop
202202
});
203203
// this logic is duplicared thrice, make into hook pls
204204
const handleClick = $(() => {
205-
props.checkboxSig.value = !props.checkboxSig.value;
205+
props['bind:checked'].value = !props['bind:checked'].value;
206206
});
207207
const handleKeyDown$ = $((e: KeyboardEvent) => {
208208
if (e.key === ' ') {
209-
props.checkboxSig.value = !props.checkboxSig.value;
209+
props['bind:checked'].value = !props['bind:checked'].value;
210210
}
211211
});
212212
// TODO: refactor to usetask code into fancy hook thingy
213213
return (
214214
<div
215215
tabIndex={0}
216216
role="checkbox"
217-
aria-checked={getAriaChecked(props.checkboxSig.value)}
217+
aria-checked={getAriaChecked(props['bind:checked'].value)}
218218
{...props}
219219
onKeyDown$={[handleKeyDownSync$, handleKeyDown$]}
220220
onClick$={handleClick}

0 commit comments

Comments
 (0)