File tree Expand file tree Collapse file tree 3 files changed +35
-5
lines changed
apps/website/src/routes/docs/styled/toggle Expand file tree Collapse file tree 3 files changed +35
-5
lines changed Original file line number Diff line number Diff line change 1+ import { component$ , useComputed$ , useSignal } from '@builder.io/qwik' ;
2+ import { Toggle } from '~/components/ui' ;
3+
4+ export default component$ ( ( ) => {
5+ const pressedState = useSignal ( true ) ;
6+
7+ const text = useComputed$ ( ( ) => {
8+ return pressedState . value ? 'You pressed me' : 'You unpressed me' ;
9+ } ) ;
10+
11+ return (
12+ < div class = "flex flex-col items-center justify-center" >
13+ < Toggle bind :pressed = { pressedState } class = "shrink-0" >
14+ Hello
15+ </ Toggle >
16+
17+ < span > { text . value } </ span >
18+ < button
19+ style = { { border : '1px solid black' , padding : '10px' } }
20+ onClick$ = { ( ) => ( pressedState . value = true ) }
21+ >
22+ I can only press
23+ </ button >
24+ </ div >
25+ ) ;
26+ } ) ;
File renamed without changes.
Original file line number Diff line number Diff line change @@ -76,16 +76,20 @@ import { Toggle } from '~/components/ui';
7676
7777### Initial Value (Uncontrolled)
7878
79- An initial, uncontrolled value can be provided using the `defaultPressed ` prop.
79+ An initial, uncontrolled value can be provided using the `pressed ` prop.
8080
81- <Showcase name = " defaultPressed" />
81+ <Showcase name = " initialPressed" />
82+
83+ If you want to have some control when the toggle is pressed, like making some side effect you can use
84+ the `onPressedChange$`. The event is fired when the user toggle the button, and receives the new value.
85+
86+ <Showcase name = " pressed" />
8287
8388### Reactive Value (Controlled)
8489
85- Pass the `pressed` prop to make the pressed state controlled.
86- The `onPressedChange$` event is fired when the user toggle the button, and receives the new value.
90+ Pass a signal to `bind:value` prop to make the pressed state controlled (binding the value with a signal).
8791
88- <Showcase name = " pressed" />
92+ <Showcase name = " bind- pressed" />
8993
9094### Disabled
9195
You can’t perform that action at this time.
0 commit comments