1- import { component$ , useContext , useTask$ } from '@builder.io/qwik' ;
1+ import { component$ , useContext , useSignal , useTask$ } from '@builder.io/qwik' ;
22import {
33 SfButton ,
44 SfButtonSize ,
@@ -7,12 +7,27 @@ import {
77 SfIconSearch ,
88} from 'qwik-storefront-ui' ;
99import { ComponentExample } from '../../../components/utils/ComponentExample' ;
10+ import { createControlsOptions } from '../../../components/utils/ControlsOptions' ;
1011import { ControlsType } from '../../../components/utils/types' ;
1112import { EXAMPLES_STATE } from '../layout' ;
1213
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+
1324export default component$ ( ( ) => {
25+ const selectPrefix = useSignal < boolean > ( )
26+ const selectSuffix = useSignal < boolean > ( )
27+
1428 const examplesState = useContext ( EXAMPLES_STATE ) ;
1529
30+
1631 useTask$ ( ( ) => {
1732 examplesState . data = {
1833 controls : [
@@ -21,6 +36,19 @@ export default component$(() => {
2136 modelName : 'slot' ,
2237 description : 'Only for demonstration purposes. Default slot' ,
2338 } ,
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+ } ,
2452 {
2553 type : 'text' ,
2654 modelName : 'as' ,
@@ -52,14 +80,31 @@ export default component$(() => {
5280 disabled : undefined ,
5381 variant : SfButtonVariant . primary ,
5482 size : SfButtonSize . base ,
83+ slotPrefix : false ,
84+ slotSuffix : false ,
5585 square : undefined ,
5686 } ,
5787 } ;
5888 } ) ;
5989
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+
60102 return (
61103 < 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]" >
63108 < div q :slot = "prefix" >
64109 < SfIconSearch />
65110 </ div >
0 commit comments