-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add toggle and togglegroup headless and styled components (#957)
* feat: toggle * feat: toggle fix * feat: toggle examples and more tests * feat: toggle group * feat: add toggle & toggle group to menu * fix: toggle item correctly updates based on each individual toggle * chore: clean toggle-group-item * chore: clean toggle and togglegroup * add changeset * refactor: toggle-group, remove defaultValue and update docs for toggle and toggle-group * docs: remove default from styled toggle * chore: rename onValueChange to onChange --------- Co-authored-by: thejackshelton <[email protected]>
- Loading branch information
1 parent
26c1788
commit 18f6543
Showing
79 changed files
with
4,514 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@qwik-ui/headless': minor | ||
'@qwik-ui/styled': minor | ||
--- | ||
|
||
feat: toggle and togglegroup headless and styled components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
apps/website/src/routes/docs/headless/toggle-group/examples/disabled.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
|
||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
return ( | ||
<div class="toggle-container"> | ||
<ToggleGroup.Root disabled> | ||
<ToggleGroup.Item value="left" aria-label="Left aligned" class="toggle"> | ||
Left | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="center" aria-label="Center aligned" class="toggle"> | ||
Center | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="right" aria-label="Right aligned" class="toggle"> | ||
Right | ||
</ToggleGroup.Item> | ||
</ToggleGroup.Root> | ||
</div> | ||
); | ||
}); |
22 changes: 22 additions & 0 deletions
22
apps/website/src/routes/docs/headless/toggle-group/examples/hero.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
return ( | ||
<div class="toggle-container"> | ||
<ToggleGroup.Root> | ||
<ToggleGroup.Item value="left" aria-label="Left aligned" class="toggle"> | ||
Left | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="center" aria-label="Center aligned" class="toggle"> | ||
Center | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="right" aria-label="Right aligned" class="toggle"> | ||
Right | ||
</ToggleGroup.Item> | ||
</ToggleGroup.Root> | ||
</div> | ||
); | ||
}); |
23 changes: 23 additions & 0 deletions
23
apps/website/src/routes/docs/headless/toggle-group/examples/horizontal-rtl.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
|
||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
return ( | ||
<div class="toggle-container"> | ||
<ToggleGroup.Root orientation={'horizontal'} direction={'rtl'}> | ||
<ToggleGroup.Item value="left" aria-label="Left aligned" class="toggle"> | ||
Left | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="center" aria-label="Center aligned" class="toggle"> | ||
Center | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="right" aria-label="Right aligned" class="toggle"> | ||
Right | ||
</ToggleGroup.Item> | ||
</ToggleGroup.Root> | ||
</div> | ||
); | ||
}); |
23 changes: 23 additions & 0 deletions
23
apps/website/src/routes/docs/headless/toggle-group/examples/initialValue.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
|
||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
return ( | ||
<div class="toggle-container"> | ||
<ToggleGroup.Root value={'left'}> | ||
<ToggleGroup.Item value="left" aria-label="Left aligned" class="toggle"> | ||
Left | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="center" aria-label="Center aligned" class="toggle"> | ||
Center | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="right" aria-label="Right aligned" class="toggle"> | ||
Right | ||
</ToggleGroup.Item> | ||
</ToggleGroup.Root> | ||
</div> | ||
); | ||
}); |
28 changes: 28 additions & 0 deletions
28
apps/website/src/routes/docs/headless/toggle-group/examples/item-disabled-center.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
|
||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
return ( | ||
<div class="toggle-container"> | ||
<ToggleGroup.Root> | ||
<ToggleGroup.Item value="left" aria-label="Left aligned" class="toggle"> | ||
Left | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item | ||
disabled | ||
value="center" | ||
aria-label="Center aligned" | ||
class="toggle" | ||
> | ||
Center | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="right" aria-label="Right aligned" class="toggle"> | ||
Right | ||
</ToggleGroup.Item> | ||
</ToggleGroup.Root> | ||
</div> | ||
); | ||
}); |
23 changes: 23 additions & 0 deletions
23
apps/website/src/routes/docs/headless/toggle-group/examples/loop-item-disabled.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
|
||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
return ( | ||
<div class="toggle-container"> | ||
<ToggleGroup.Root loop> | ||
<ToggleGroup.Item disabled value="left" aria-label="Left aligned" class="toggle"> | ||
Left | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="center" aria-label="Center aligned" class="toggle"> | ||
Center | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="right" aria-label="Right aligned" class="toggle"> | ||
Right | ||
</ToggleGroup.Item> | ||
</ToggleGroup.Root> | ||
</div> | ||
); | ||
}); |
23 changes: 23 additions & 0 deletions
23
apps/website/src/routes/docs/headless/toggle-group/examples/loop.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
|
||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
return ( | ||
<div class="toggle-container"> | ||
<ToggleGroup.Root loop> | ||
<ToggleGroup.Item value="left" aria-label="Left aligned" class="toggle"> | ||
Left | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="center" aria-label="Center aligned" class="toggle"> | ||
Center | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="right" aria-label="Right aligned" class="toggle"> | ||
Right | ||
</ToggleGroup.Item> | ||
</ToggleGroup.Root> | ||
</div> | ||
); | ||
}); |
23 changes: 23 additions & 0 deletions
23
apps/website/src/routes/docs/headless/toggle-group/examples/multiple.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
|
||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
return ( | ||
<div class="toggle-container"> | ||
<ToggleGroup.Root multiple> | ||
<ToggleGroup.Item value="left" aria-label="Left aligned" class="toggle"> | ||
Left | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="center" aria-label="Center aligned" class="toggle"> | ||
Center | ||
</ToggleGroup.Item> | ||
<ToggleGroup.Item value="right" aria-label="Right aligned" class="toggle"> | ||
Right | ||
</ToggleGroup.Item> | ||
</ToggleGroup.Root> | ||
</div> | ||
); | ||
}); |
42 changes: 42 additions & 0 deletions
42
apps/website/src/routes/docs/headless/toggle-group/examples/test-csr-order-multiple-bind.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
import { useSignal } from '@builder.io/qwik'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
const items = ['left', 'center', 'right']; | ||
const isItemsRenderedSig = useSignal(false); | ||
const valueSelected = useSignal<string[]>(['left', 'center']); | ||
|
||
return ( | ||
<div> | ||
<button onClick$={() => (isItemsRenderedSig.value = true)}> | ||
render on the client | ||
</button> | ||
{isItemsRenderedSig.value && ( | ||
<div class="toggle-container"> | ||
<ToggleGroup.Root multiple bind:value={valueSelected}> | ||
{items.map((item, index) => ( | ||
<ToggleGroup.Item | ||
key={index} | ||
value={item} | ||
aria-label={`${item} item`} | ||
class="toggle" | ||
> | ||
{item} | ||
</ToggleGroup.Item> | ||
))} | ||
</ToggleGroup.Root> | ||
<span test-data-bounded-span>You selected: {valueSelected.value}</span> | ||
<button | ||
style={{ border: '1px solid black', padding: '10px' }} | ||
onClick$={() => (valueSelected.value = ['right'])} | ||
> | ||
I can only press 'right' | ||
</button> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}); |
32 changes: 32 additions & 0 deletions
32
apps/website/src/routes/docs/headless/toggle-group/examples/test-csr-order-multiple.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
import { useSignal } from '@builder.io/qwik'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
const items = ['left', 'center', 'right']; | ||
const isItemsRenderedSig = useSignal(false); | ||
|
||
return ( | ||
<div> | ||
<button onClick$={() => (isItemsRenderedSig.value = true)}> | ||
render on the client | ||
</button> | ||
{isItemsRenderedSig.value && ( | ||
<ToggleGroup.Root multiple> | ||
{items.map((item, index) => ( | ||
<ToggleGroup.Item | ||
key={index} | ||
value={item} | ||
aria-label={`${item} item`} | ||
class="toggle" | ||
> | ||
{item} | ||
</ToggleGroup.Item> | ||
))} | ||
</ToggleGroup.Root> | ||
)} | ||
</div> | ||
); | ||
}); |
42 changes: 42 additions & 0 deletions
42
...site/src/routes/docs/headless/toggle-group/examples/test-csr-order-single-bind-center.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import styles from '../snippets/toggle.css?inline'; | ||
import { ToggleGroup } from '@qwik-ui/headless'; | ||
import { useSignal } from '@builder.io/qwik'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
const items = ['left', 'center', 'right']; | ||
const isItemsRenderedSig = useSignal(false); | ||
const valueSelected = useSignal<string>('center'); | ||
|
||
return ( | ||
<div> | ||
<button onClick$={() => (isItemsRenderedSig.value = true)}> | ||
render on the client | ||
</button> | ||
{isItemsRenderedSig.value && ( | ||
<div class="toggle-container"> | ||
<ToggleGroup.Root bind:value={valueSelected}> | ||
{items.map((item, index) => ( | ||
<ToggleGroup.Item | ||
key={index} | ||
value={item} | ||
aria-label={`${item} item`} | ||
class="toggle" | ||
> | ||
{item} | ||
</ToggleGroup.Item> | ||
))} | ||
</ToggleGroup.Root> | ||
<span test-data-bounded-span>You selected: {valueSelected.value}</span> | ||
<button | ||
style={{ border: '1px solid black', padding: '10px' }} | ||
onClick$={() => (valueSelected.value = 'right')} | ||
> | ||
I can only press 'right' | ||
</button> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}); |
Oops, something went wrong.