Skip to content

Commit

Permalink
Updated checkbox (qwikifiers#969)
Browse files Browse the repository at this point in the history
* initial tests

* updated checkbox
  • Loading branch information
thejackshelton authored Sep 20, 2024
1 parent 6fcd472 commit c818eec
Show file tree
Hide file tree
Showing 38 changed files with 921 additions and 928 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { component$ } from '@builder.io/qwik';

import { Checklist } from '@qwik-ui/headless';

export default component$(() => {
return (
<Checklist.Root initialStates={[false, false, false]}>
<Checklist.SelectAll class="flex items-center justify-center border-2 p-2">
<div class="flex items-center justify-center border-2 p-2">
<Checklist.ItemIndicator></Checklist.ItemIndicator>
</div>{' '}
Select All
</Checklist.SelectAll>

{Array.from({ length: 2 }, (_, index) => {
const uniqueKey = `cl-${index}-${Date.now()}`;
return (
<Checklist.Item key={uniqueKey} _index={index}>
<div class="flex items-center justify-center border-2 p-2">
<Checklist.ItemIndicator></Checklist.ItemIndicator>
</div>
{`item ${index}`}
</Checklist.Item>
);
})}
</Checklist.Root>
);
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { component$, useSignal } from '@builder.io/qwik';
import { Checkbox } from '@qwik-ui/headless';
export default component$(() => {
const initialVal1 = false;
Expand Down
22 changes: 13 additions & 9 deletions apps/website/src/routes/docs/headless/checkbox/examples/hero.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { component$, useSignal } from '@builder.io/qwik';
import { Checkbox } from '@qwik-ui/headless';
export default component$(() => {
const isCheckedSig = useSignal(false);

return (
<>
<Checkbox.Root id="test" class="flex items-center gap-3 border-2 border-black p-2 ">
<Checkbox.Indicator class="flex h-[25px] w-[25px] items-center justify-center bg-slate-600">
</Checkbox.Indicator>
I have read the README
</Checkbox.Root>
</>
<Checkbox.Root
bind:checked={isCheckedSig}
id="test"
class="flex items-center gap-3 border-2 border-black p-2"
>
<div class="flex h-[25px] w-[25px] items-center justify-center bg-slate-600">
<Checkbox.Indicator></Checkbox.Indicator>
</div>
<p> I have read the README</p>
</Checkbox.Root>
);
});
77 changes: 40 additions & 37 deletions apps/website/src/routes/docs/headless/checkbox/examples/pizza.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox, Checklist } from '@qwik-ui/headless';
const toppingNames = ['hot peppers', 'ham', 'pineaple', 'mushroom'];
const toppingImages = ['🌶️', '🍗', '🍍', '🍄'];
export default component$(() => {
return (
<>
<h3 id="pizza-toppings">Pizza toppings</h3>
<Checklist.Root ariaLabeledBy="pizza-toppings" class="flex flex-col gap-4">
<Checkbox.Root
class="flex items-center gap-3 border-2 border-black p-2"
checklist={true}
>
<Checklist.Indicator class="flex h-[25px] w-[25px] items-center justify-center bg-slate-600">
<div q:slot="true" id="true-img">
🍕
</div>
// import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
// import { Checkbox, Checklist } from '@qwik-ui/headless';
// const toppingNames = ['hot peppers', 'ham', 'pineaple', 'mushroom'];
// const toppingImages = ['🌶️', '🍗', '🍍', '🍄'];
// export default component$(() => {
// return (
// <>
// <h3 id="pizza-toppings">Pizza toppings</h3>
// <Checklist.Root
// ariaLabeledBy="pizza-toppings"
// class="flex flex-col gap-4"
// >
// <Checkbox.Root
// class="flex items-center gap-3 border-2 border-black p-2"
// checklist={true}
// >
// <Checklist.Indicator class="flex h-[25px] w-[25px] items-center justify-center bg-slate-600">
// <div q:slot="true" id="true-img">
// 🍕
// </div>

<div q:slot="mixed" id="mixed-img">
</div>
</Checklist.Indicator>
Pick all toppings
</Checkbox.Root>
// <div q:slot="mixed" id="mixed-img">
//
// </div>
// </Checklist.Indicator>
// Pick all toppings
// </Checkbox.Root>

{toppingNames.map((name, i) => {
return (
<Checkbox.Root class="ml-8 flex items-center gap-3 border-2 border-black p-2">
<Checkbox.Indicator class="flex h-[25px] w-[25px] items-center justify-center bg-slate-600">
{toppingImages[i]}
</Checkbox.Indicator>
{name}
</Checkbox.Root>
);
})}
</Checklist.Root>
</>
);
});
// {toppingNames.map((name, i) => {
// return (
// <Checkbox.Root class="ml-8 flex items-center gap-3 border-2 border-black p-2">
// <Checkbox.Indicator class="flex h-[25px] w-[25px] items-center justify-center bg-slate-600">
// {toppingImages[i]}
// </Checkbox.Indicator>
// {name}
// </Checkbox.Root>
// );
// })}
// </Checklist.Root>
// </>
// );
// });
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { component$, useSignal } from '@builder.io/qwik';
import { Checkbox } from '@qwik-ui/headless';
export default component$(() => {
const isCheckedSig = useSignal(false);

return (
<>
<Checkbox.Root
bind:checked={isCheckedSig}
id="test"
class="flex items-center gap-3 border-2 border-black p-2"
>
<div class="flex h-[25px] w-[25px] items-center justify-center bg-slate-600">
<Checkbox.Indicator></Checkbox.Indicator>
</div>
<p> I have read the README</p>
</Checkbox.Root>
<button
type="button"
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
onClick$={() => (isCheckedSig.value = !isCheckedSig.value)}
>
Check the checkbox above
</button>
</>
);
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { component$, useSignal } from '@builder.io/qwik';
import { Checkbox, Checklist } from '@qwik-ui/headless';
// TODO: add logic to handle user passed sigs with trues
// this test basically ensures that the sig passed to the checklist controlls trumps all its children
Expand All @@ -7,10 +7,10 @@ export default component$(() => {
return (
<>
<h3 id="test123">Pick a cat</h3>
<Checklist.Root class="flex flex-col gap-3" ariaLabeledBy="test123">
<Checklist.Root initialStates={[false, false, false]}>
<Checkbox.Root
class="flex items-center gap-3 bg-slate-900 text-white"
checklist={true}
// checklist={true}
bind:checked={checklistSig}
id="checklist"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox, Checklist } from '@qwik-ui/headless';
import { component$ } from '@builder.io/qwik';

import { Checklist } from '@qwik-ui/headless';

export default component$(() => {
const firstUserSig = useSignal(false);
const secondUserSig = useSignal(false);
return (
<>
<h3 id="test123">Pick a cat</h3>
<Checklist.Root class="flex flex-col gap-3" ariaLabeledBy="test123">
<Checkbox.Root
class="flex items-center gap-3 bg-slate-900 p-2 text-white"
checklist={true}
>
<Checkbox.Indicator class=" flex w-[80px] justify-center bg-white p-3">
</Checkbox.Indicator>
<p>Controlls all</p>
</Checkbox.Root>
<Checkbox.Root
bind:checked={firstUserSig}
class="flex items-center gap-3 bg-slate-900 pr-2 text-white"
>
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
<p>No other stuff is needed here</p>
</Checkbox.Root>
<Checklist.Root initialStates={[true, false, false]}>
<Checklist.SelectAll class="flex h-[25px] w-[25px] items-center justify-center border-2 border-black p-2">
<div class="flex h-[25px] w-[25px] items-center justify-center border-2 border-black p-2">
<Checklist.ItemIndicator></Checklist.ItemIndicator>
</div>{' '}
Select All
</Checklist.SelectAll>

<Checkbox.Root bind:checked={secondUserSig} class="bg-slate-900 text-white">
<div class="flex items-center gap-3">
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
<p>No other stuff is needed here</p>
</div>
</Checkbox.Root>
</Checklist.Root>
</>
{Array.from({ length: 2 }, (_, index) => {
const uniqueKey = `cl-${index}-${Date.now()}`;
return (
<Checklist.Item key={uniqueKey} _index={index}>
<div class="flex h-[25px] w-[25px] items-center justify-center border-2 border-black p-2">
<Checklist.ItemIndicator></Checklist.ItemIndicator>
</div>
{`item ${index}`}
</Checklist.Item>
);
})}
</Checklist.Root>
);
});
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox, Checklist } from '@qwik-ui/headless';
export default component$(() => {
const firstUserSig = useSignal(false);
const secondUserSig = useSignal(true);
return (
<>
<h3 id="test123">Pick a cat</h3>
<Checklist.Root class="flex flex-col gap-3" ariaLabeledBy="test123">
<Checkbox.Root
class="flex items-center gap-3 bg-slate-900 p-2 text-white"
checklist={true}
>
<Checklist.Indicator class="w-fit">
<div q:slot="true" id="true-img">
</div>
<div q:slot="mixed" id="mixed-img">
</div>
</Checklist.Indicator>
<p>Controlls all</p>
</Checkbox.Root>
<Checkbox.Root
bind:checked={firstUserSig}
class="flex items-center gap-3 bg-slate-900 pr-2 text-white"
>
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
<p>No other stuff is needed here</p>
</Checkbox.Root>
// import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
// import { Checkbox, Checklist } from '@qwik-ui/headless';
// export default component$(() => {
// const firstUserSig = useSignal(false);
// const secondUserSig = useSignal(true);
// return (
// <>
// <h3 id="test123">Pick a cat</h3>
// <Checklist.Root class="flex flex-col gap-3" ariaLabeledBy="test123">
// <Checkbox.Root
// class="flex items-center gap-3 bg-slate-900 p-2 text-white"
// checklist={true}
// >
// <Checklist.Indicator class="w-fit">
// <div q:slot="true" id="true-img">
//
// </div>
// <div q:slot="mixed" id="mixed-img">
//
// </div>
// </Checklist.Indicator>
// <p>Controlls all</p>
// </Checkbox.Root>
// <Checkbox.Root
// bind:checked={firstUserSig}
// class="flex items-center gap-3 bg-slate-900 pr-2 text-white"
// >
// <Checkbox.Indicator class="w-fit bg-slate-600">✅</Checkbox.Indicator>
// <p>No other stuff is needed here</p>
// </Checkbox.Root>

<Checkbox.Root bind:checked={secondUserSig} class="bg-slate-900 text-white">
<div class="flex items-center gap-3">
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
<p>No other stuff is needed here</p>
</div>
</Checkbox.Root>
</Checklist.Root>
</>
);
});
// <Checkbox.Root
// bind:checked={secondUserSig}
// class="bg-slate-900 text-white"
// >
// <div class="flex items-center gap-3">
// <Checkbox.Indicator class="w-fit bg-slate-600">
// ✅
// </Checkbox.Indicator>
// <p>No other stuff is needed here</p>
// </div>
// </Checkbox.Root>
// </Checklist.Root>
// </>
// );
// });
Original file line number Diff line number Diff line change
@@ -1,46 +1,19 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox, Checklist } from '@qwik-ui/headless';
import { component$ } from '@builder.io/qwik';
import { Checklist } from '@qwik-ui/headless';
// this test basically ensures that the sig passed to the checklist controlls trumps all its children
export default component$(() => {
const checklistSig = useSignal(true);
// const checklistSig = useSignal(true);
return (
<>
<h3 id="test123">Pick a cat</h3>
<Checklist.Root class="flex flex-col gap-3" ariaLabeledBy="test123">
<Checkbox.Root
class="flex items-center gap-3 bg-slate-900 text-white"
checklist={true}
bind:checked={checklistSig}
id="checklist"
>
<Checklist.Indicator class="w-fit">
<div q:slot="true" id="true-img">
</div>

<div q:slot="mixed" id="mixed-img">
</div>
</Checklist.Indicator>
<p>Controlls all</p>
</Checkbox.Root>
<Checkbox.Root
id="child-1"
class="flex items-center gap-3 bg-slate-900 pr-2 text-white"
>
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
<p>No other stuff is needed here</p>
</Checkbox.Root>

<Checkbox.Root id="child-2" class="bg-slate-900 text-white">
<div class="flex items-center gap-3">
<Checkbox.Indicator class="w-fit bg-slate-600"></Checkbox.Indicator>
<p>Im a true.tsx</p>
</div>
</Checkbox.Root>
</Checklist.Root>
<p>You signal is: </p>
<p id="signal-to-text">{`${checklistSig.value}`}</p>
</>
<Checklist.Root initialStates={[true, true]}>
<Checklist.SelectAll>
<Checklist.Indicator></Checklist.Indicator>
</Checklist.SelectAll>
<Checklist.Item>
<Checklist.ItemIndicator></Checklist.ItemIndicator> first item
</Checklist.Item>
<Checklist.Item>
<Checklist.ItemIndicator></Checklist.ItemIndicator> second item
</Checklist.Item>
</Checklist.Root>
);
});
Loading

0 comments on commit c818eec

Please sign in to comment.