1
- import { component$ , useContext , useTask$ } from '@builder.io/qwik' ;
1
+ import { component$ , useContext , useSignal , useTask$ } from '@builder.io/qwik' ;
2
2
import {
3
3
SfButton ,
4
4
SfButtonSize ,
@@ -7,12 +7,27 @@ import {
7
7
SfIconSearch ,
8
8
} from 'qwik-storefront-ui' ;
9
9
import { ComponentExample } from '../../../components/utils/ComponentExample' ;
10
+ import { createControlsOptions } from '../../../components/utils/ControlsOptions' ;
10
11
import { ControlsType } from '../../../components/utils/types' ;
11
12
import { EXAMPLES_STATE } from '../layout' ;
12
13
14
+
15
+ const prefixSlotOptions = createControlsOptions ( {
16
+ none : undefined ,
17
+ 'Search icon' : < SfIconSearch /> ,
18
+ } ) ;
19
+ const suffixSlotOptions = createControlsOptions ( {
20
+ none : undefined ,
21
+ 'Lock icon' : < SfIconLock /> ,
22
+ } ) ;
23
+
13
24
export default component$ ( ( ) => {
25
+ const selectPrefix = useSignal < boolean > ( )
26
+ const selectSuffix = useSignal < boolean > ( )
27
+
14
28
const examplesState = useContext ( EXAMPLES_STATE ) ;
15
29
30
+
16
31
useTask$ ( ( ) => {
17
32
examplesState . data = {
18
33
controls : [
@@ -21,6 +36,19 @@ export default component$(() => {
21
36
modelName : 'slot' ,
22
37
description : 'Only for demonstration purposes. Default slot' ,
23
38
} ,
39
+ {
40
+ type : 'select' ,
41
+ modelName : 'slotPrefix' ,
42
+ description : 'slotPrefix' ,
43
+ options : prefixSlotOptions . controlsOptions ,
44
+
45
+ } ,
46
+ {
47
+ type : 'select' ,
48
+ modelName : 'slotSuffix' ,
49
+ description : 'slotSuffix' ,
50
+ options : suffixSlotOptions . controlsOptions ,
51
+ } ,
24
52
{
25
53
type : 'text' ,
26
54
modelName : 'as' ,
@@ -52,14 +80,31 @@ export default component$(() => {
52
80
disabled : undefined ,
53
81
variant : SfButtonVariant . primary ,
54
82
size : SfButtonSize . base ,
83
+ slotPrefix : false ,
84
+ slotSuffix : false ,
55
85
square : undefined ,
56
86
} ,
57
87
} ;
58
88
} ) ;
59
89
90
+ useTask$ ( ( { track } ) => {
91
+ track ( ( ) => examplesState . data . state ) ;
92
+ if ( selectPrefix . value === null ) return ;
93
+ selectPrefix . value = prefixSlotOptions . getValue ( examplesState . data . state . slotPrefix )
94
+ } ) ;
95
+
96
+ useTask$ ( ( { track } ) => {
97
+ track ( ( ) => examplesState . data . state ) ;
98
+ if ( selectSuffix . value === null ) return ;
99
+ selectSuffix . value = suffixSlotOptions . getValue ( examplesState . data . state . slotSuffix )
100
+ } ) ;
101
+
60
102
return (
61
103
< ComponentExample componentContainerClass = "space-x-2" >
62
- < SfButton { ...examplesState . data . state } class = "max-w-[200px]" >
104
+ < SfButton
105
+ slotPrefix = { selectPrefix . value }
106
+ slotSuffix = { selectSuffix . value }
107
+ { ...examplesState . data . state } class = "max-w-[200px]" >
63
108
< div q :slot = "prefix" >
64
109
< SfIconSearch />
65
110
</ div >
0 commit comments