-
Notifications
You must be signed in to change notification settings - Fork 146
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
feat: add a new switch component #960
Open
JerryWu1234
wants to merge
66
commits into
qwikifiers:main
Choose a base branch
from
JerryWu1234:add_component_switch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,532
−536
Open
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
dbe9fc4
feat: add a new switch component
JerryWu1234 40c8fba
Merge branch 'main' into add_component_switch
JerryWu1234 a219d8f
init debug
JerryWu1234 df815cf
Merge branch 'main' into add_component_switch
JerryWu1234 7a5f627
switch is developing
JerryWu1234 5850f72
headless Switch
JerryWu1234 61e5eb4
add css style
JerryWu1234 5d18929
Merge branch 'main' into add_component_switch
JerryWu1234 e167210
Merge branch 'main' into add_component_switch
JerryWu1234 fa4d78d
Merge branch 'main' into add_component_switch
JerryWu1234 75b226e
switch function
JerryWu1234 6da7f8f
Merge branch 'add_component_switch' of https://github.com/JerryWu1234…
JerryWu1234 6c112bb
add more properties
JerryWu1234 80a69b0
Merge branch 'main' into add_component_switch
JerryWu1234 924a6a7
fix bug
JerryWu1234 d30ee27
fix conflict
JerryWu1234 4aeca25
add test
JerryWu1234 9cc504c
add switch component in headless
JerryWu1234 db01981
Merge branch 'main' into add_component_switch
JerryWu1234 2839aa6
fix switch
JerryWu1234 c62ddda
fix switch
JerryWu1234 521c3b0
developing styled
JerryWu1234 2f54039
developing styled
JerryWu1234 a132016
css
JerryWu1234 b51919a
css
JerryWu1234 e78c0c4
add css
JerryWu1234 1d7562a
Merge branch 'main' into add_component_switch
JerryWu1234 8aae55d
test
JerryWu1234 32cf8bc
Merge branch 'add_component_switch' of https://github.com/JerryWu1234…
JerryWu1234 eb3f351
test
JerryWu1234 2324120
Merge branch 'main' into add_component_switch
JerryWu1234 482d258
fix css
JerryWu1234 89bddb5
Merge branch 'main' into add_component_switch
JerryWu1234 4ae9b4e
fix
JerryWu1234 28bbe12
Merge branch 'add_component_switch' of https://github.com/JerryWu1234…
JerryWu1234 d58521e
fix
JerryWu1234 d2eb94a
fix
JerryWu1234 db37e73
switch
JerryWu1234 b176836
switch
JerryWu1234 a10ddbb
Merge branch 'main' into add_component_switch
JerryWu1234 c02a82e
Merge branch 'main' into add_component_switch
JerryWu1234 4220133
Merge branch 'main' into add_component_switch
JerryWu1234 d499152
Merge branch 'main' into add_component_switch
JerryWu1234 0fa6cfe
fix
JerryWu1234 ff96a9a
Merge branch 'main' into add_component_switch
JerryWu1234 258ff6e
swich
JerryWu1234 e7e5a94
Merge branch 'add_component_switch' of https://github.com/JerryWu1234…
JerryWu1234 e6969b1
fix
JerryWu1234 ae47c83
Merge branch 'main' into add_component_switch
JerryWu1234 296de86
fix Clicking outside the thumb
JerryWu1234 0a7e6d0
Merge branch 'main' into add_component_switch
JerryWu1234 c8b9525
fix default value
JerryWu1234 4fb3eee
add more test and fix ts error
JerryWu1234 e6835c4
fix bug
JerryWu1234 eda1332
add more test, enhance demo
JerryWu1234 799de9a
fix
JerryWu1234 ce19f13
css
JerryWu1234 e3d5dd8
fix
JerryWu1234 c511e7d
fix by comment
JerryWu1234 efbbbc9
Merge branch 'add_component_switch' of https://github.com/JerryWu1234…
JerryWu1234 7cee977
add useBoundSignal
JerryWu1234 979d0c0
fix name
JerryWu1234 8c08e38
fix filename
JerryWu1234 e701143
Merge branch 'main' into add_component_switch
JerryWu1234 adac7ed
feat: optimize it according to comment
JerryWu1234 52b9c9c
Merge branch 'add_component_switch' of https://github.com/JerryWu1234…
JerryWu1234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading status checks…
headless Switch
- Loading branch information
commit 5850f72027c7f45ac1a05c3b0cb6767b9b3f6bdd
There are no files selected for viewing
29 changes: 6 additions & 23 deletions
29
apps/website/src/routes/docs/headless/switch/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 |
---|---|---|
@@ -1,31 +1,14 @@ | ||
import { component$, useStyles$ } from '@builder.io/qwik'; | ||
import { Select } from '@qwik-ui/headless'; | ||
import { component$ } from '@builder.io/qwik'; | ||
import { Switch } from '@qwik-ui/headless'; | ||
|
||
export default component$(() => { | ||
useStyles$(styles); | ||
const users = ['Tim', 'Ryan', 'Jim', 'Jessie', 'Abby']; | ||
|
||
return ( | ||
<Select.Root class="select"> | ||
<Select.Label>Logged in users</Select.Label> | ||
<Select.Trigger class="select-trigger"> | ||
<Select.DisplayValue placeholder="Select an option" /> | ||
</Select.Trigger> | ||
<Select.Popover class="select-popover"> | ||
{users.map((user) => ( | ||
<Select.Item class="select-item" key={user}> | ||
<Select.ItemLabel>{user}</Select.ItemLabel> | ||
<Select.ItemIndicator> | ||
<LuCheck /> | ||
</Select.ItemIndicator> | ||
</Select.Item> | ||
))} | ||
</Select.Popover> | ||
</Select.Root> | ||
<Switch.Root> | ||
<Switch.Label>sdsds</Switch.Label> | ||
<Switch.Input/> | ||
</Switch.Root> | ||
); | ||
}); | ||
|
||
// internal | ||
import styles from '../snippets/select.css?inline'; | ||
import { LuCheck } from '@qwikest/icons/lucide'; | ||
|
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export {} | ||
export { SwitchRoot as Root } from './switch-root' | ||
export { SwitchInput as Input } from './switch-input' | ||
export { SwitchLable as Label } from './switch-lable' |
12 changes: 6 additions & 6 deletions
12
packages/kit-headless/src/components/switch/switch-context.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { createContextId, type Signal } from '@builder.io/qwik'; | ||
import { createContextId, QRL, type Signal } from '@builder.io/qwik'; | ||
|
||
export interface SwitchState { | ||
'bind:checked': Signal<boolean>; | ||
defaultChecked: boolean; | ||
disabled: boolean; | ||
label: string; | ||
'bind:checked'?: Signal<boolean>; | ||
defaultChecked?: boolean; | ||
disabled?: boolean; | ||
onChange$?: QRL<() => void> | ||
} | ||
// | ||
export type SwitchContextState = Omit<SwitchState, 'bind:checked'> & { bindChecked: Signal<boolean> } | ||
export type SwitchContextState = Omit<SwitchState, 'bind:checked'> & { bindChecked?: Signal<boolean> } | ||
|
||
export const SwitchContext = createContextId<SwitchContextState>('SwitchContext'); |
14 changes: 14 additions & 0 deletions
14
packages/kit-headless/src/components/switch/switch-input.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,14 @@ | ||
|
||
import { component$, PropsOf, useContext } from '@builder.io/qwik'; | ||
import { SwitchContext } from './switch-context'; | ||
export const SwitchInput = component$<PropsOf<'input'>>(() => { | ||
const context = useContext(SwitchContext) | ||
return ( | ||
<input | ||
type="checkbox" | ||
role="switch" | ||
onChange$={context.onChange$} | ||
/> | ||
); | ||
}, | ||
); |
10 changes: 10 additions & 0 deletions
10
packages/kit-headless/src/components/switch/switch-lable.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,10 @@ | ||
|
||
import { component$, PropsOf, Slot } from '@builder.io/qwik'; | ||
export const SwitchLable = component$<PropsOf<'lable'>>(() => { | ||
return ( | ||
<label> | ||
<Slot></Slot> | ||
</label> | ||
); | ||
}, | ||
); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the input here as the interaction point defeats the purpose of the headless component. We are trying to avoid the limitations of the native input element.
You can have a visually hidden input with thise role called
Switch.Input
, orSwitch.HiddenInput
but the purpose there would be for native form support.I think you want a button, as it naturally calls the onClick$ function on the enter and spacebar keys.