Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox Implementation #54

Merged
merged 28 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c12b68f
Co-authored-by: Jack Shelton <[email protected]>
jay-kunaico Aug 27, 2024
329b704
Updated tests
jay-kunaico Aug 27, 2024
051578a
all tests passing
jay-kunaico Aug 27, 2024
653174b
Added hero tests
jay-kunaico Aug 27, 2024
f985c82
changed for loop to for of
jay-kunaico Aug 27, 2024
8c27d19
Fix Biome suggestions
jay-kunaico Aug 27, 2024
61bbf93
updated checklist and indicator
jay-kunaico Aug 27, 2024
88852cd
create outline for checkbox components
jay-kunaico Aug 27, 2024
a18c0e0
New Checkbox and files
jay-kunaico Aug 28, 2024
599677b
All tests pass for Checkbox
jay-kunaico Aug 28, 2024
98ba169
Add Checklist components
jay-kunaico Aug 28, 2024
693bce0
Checklist and updated checkbox tests
jay-kunaico Aug 29, 2024
dae75b2
updated property and data-hidden for checkbox
jay-kunaico Aug 30, 2024
d3bbb8f
Update checklistitem, checklistindicator and checkbox root
jay-kunaico Aug 30, 2024
9ee8c48
Polymorphism
jay-kunaico Sep 3, 2024
876b793
update selectAll
jay-kunaico Sep 3, 2024
d15e1ac
Update checklistItem, update checkbox tests
jay-kunaico Sep 4, 2024
e9c113e
Interim changes for index
jay-kunaico Sep 5, 2024
53994af
Interim changes for index
jay-kunaico Sep 5, 2024
f93b920
Inline ChecklistRoot
jay-kunaico Sep 6, 2024
70dbbdc
Co-authored-by: Aleksandr Zainetdinov <[email protected]>
jay-kunaico Sep 9, 2024
9e5dc1e
Update state management
jay-kunaico Sep 9, 2024
252372c
all checkboxes check and uncheck
jay-kunaico Sep 9, 2024
dc2533b
Updated tests for selecting checkboxes
jay-kunaico Sep 9, 2024
443801a
made function simpler
jay-kunaico Sep 9, 2024
c985fcd
Troubleshoot children checkboxes
jay-kunaico Sep 10, 2024
455f20c
Clean up tests for preview
jay-kunaico Sep 10, 2024
17274a9
Merge branch 'main' into DS-77
jay-kunaico Sep 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/component-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
},
"engines-annotation": "Mostly required by sharp which needs a Node-API v9 compatible runtime",
"private": true,
"trustedDependencies": ["sharp"],
"trustedDependencies": [
"sharp"
],
"trustedDependencies-annotation": "Needed for bun to allow running install scripts",
"type": "module",
"scripts": {
Expand All @@ -15,7 +17,7 @@
"build.preview": "vite build --ssr src/entry.preview.tsx",
"build.types": "tsc --incremental --noEmit",
"deploy": "echo 'Run \"npm run qwik add\" to install a server adapter'",
"dev": "vite --mode ssr",
"dev": "vite --mode ssr --host",
"dev.debug": "node --inspect-brk ./node_modules/vite/bin/vite.js --mode ssr --force",
"fmt": "prettier --write .",
"fmt.check": "prettier --check .",
Expand Down
23 changes: 16 additions & 7 deletions apps/component-tests/src/entry.ssr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@
* - npm run build
*
*/
import { type RenderToStreamOptions, renderToStream } from "@builder.io/qwik/server";
import { manifest } from "@qwik-client-manifest";
import Root from "./root";
import {
type RenderToStreamOptions,
renderToStream,
} from '@builder.io/qwik/server';
import { manifest } from '@qwik-client-manifest';
import Root from './root';

export default function (opts: RenderToStreamOptions) {
return renderToStream(<Root />, {
manifest,
...opts,
// Use container attributes to set attributes on the html tag.
containerAttributes: {
lang: "en-us",
...opts.containerAttributes
lang: 'en-us',
...opts.containerAttributes,
},
serverData: {
...opts.serverData
}
...opts.serverData,
},
prefetchStrategy: {
implementation: {
linkInsert: 'html-append',
linkRel: 'modulepreload',
},
},
});
}
28 changes: 28 additions & 0 deletions apps/docs/src/routes/checkbox/examples/checklist.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { component$ } from '@builder.io/qwik';

import { Checklist } from '@kunai-consulting/qwik-components';

export default component$(() => {
return (
<Checklist.Root initialStates={[false, 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>

{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>
);
});
42 changes: 42 additions & 0 deletions apps/docs/src/routes/checkbox/examples/controlled-values.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox } from '@kunai-consulting/qwik-components';
export default component$(() => {
const initialVal1 = false;
const controlledSig1 = useSignal(initialVal1);
const initialVal2 = true;
const controlledSig2 = useSignal(initialVal2);
return (
<>
<div class="flex gap-8">
<div class="flex flex-col gap-3">
<Checkbox.Root
bind:checked={controlledSig1}
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>
Toggle Value
</Checkbox.Root>
<p>The initial value was: {`${initialVal1}`}</p>
<p>The current value is: {`${controlledSig1.value}`}</p>
</div>
<div class="flex flex-col gap-3">
<Checkbox.Root
bind:checked={controlledSig2}
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>
Toggle Value
</Checkbox.Root>
<p>The initial value was: {`${initialVal2}`}</p>
<p>The current value is: {`${controlledSig2.value}`}</p>
</div>
</div>
</>
);
});
24 changes: 24 additions & 0 deletions apps/docs/src/routes/checkbox/examples/controlled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { component$, useSignal } from '@builder.io/qwik';
import { Checkbox } from '@kunai-consulting/qwik-components';
export default component$(() => {
const initialVal1 = false;
const controlledSig1 = useSignal(initialVal1);
return (
<>
<div class="flex gap-8">
<div class="flex flex-col gap-3">
<Checkbox.Root
bind:checked={controlledSig1}
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>
Toggle Value
</Checkbox.Root>
</div>
</div>
</>
);
});
18 changes: 18 additions & 0 deletions apps/docs/src/routes/checkbox/examples/hero.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox } from '@kunai-consulting/qwik-components';
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>
);
});
42 changes: 42 additions & 0 deletions apps/docs/src/routes/checkbox/examples/pizza.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
// import { Checkbox, Checklist } from '@kunai-consulting/qwik-components';
// 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>

// {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>
// </>
// );
// });
27 changes: 27 additions & 0 deletions apps/docs/src/routes/checkbox/examples/reactive.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox } from '@kunai-consulting/qwik-components';
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
@@ -0,0 +1,49 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox, Checklist } from '@kunai-consulting/qwik-components';
// 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
export default component$(() => {
const checklistSig = useSignal(false);
return (
<>
<h3 id="test123">Pick a cat</h3>
<Checklist.Root initialStates={[false, false, false]}>
<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>
</>
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { component$ } from '@builder.io/qwik';

import { Checklist } from '@kunai-consulting/qwik-components';

export default component$(() => {
return (
<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>

{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
@@ -0,0 +1,46 @@
// import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
// import { Checkbox, Checklist } from '@kunai-consulting/qwik-components';
// 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>
// </>
// );
// });
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Checkbox, Checklist } from '@kunai-consulting/qwik-components';
// this test basically ensures that the sig passed to the checklist controlls trumps all its children
export default component$(() => {
// const checklistSig = useSignal(true);
return (
<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