@@ -10,7 +10,7 @@ import { statusByComponent } from '~/_state/component-statuses';
10
10
11
11
Displays a list of options for the user to pick from — triggered by a button.
12
12
13
- { /* <Showcase name="hero" /> */ }
13
+ <Showcase name = " hero" />
14
14
15
15
## Installation
16
16
@@ -24,16 +24,23 @@ qwik-ui add select
24
24
import { PropsOf , Slot , component$ } from ' @builder.io/qwik' ;
25
25
import { Select as HeadlessSelect } from ' @qwik-ui/headless' ;
26
26
import { cn } from ' @qwik-ui/utils' ;
27
- import { LuCheck , LuFilter } from ' @qwikest/icons/lucide' ;
27
+ import { LuCheck , LuChevronDown } from ' @qwikest/icons/lucide' ;
28
28
29
- const Root = HeadlessSelect .Root ;
29
+ const Root = (props : PropsOf <typeof HeadlessSelect .Root >) => (
30
+ <HeadlessSelect.Root
31
+ { ... props }
32
+ selectItemComponent = { Item }
33
+ selectItemLabelComponent = { ItemLabel }
34
+ selectLabelComponent = { Label }
35
+ />
36
+ );
30
37
31
38
const Label = component$ <PropsOf <typeof HeadlessSelect .Label >>(({ ... props }) => {
32
39
return (
33
40
<>
34
41
<HeadlessSelect.Label
35
- class = { cn (' px-2 py-1.5 text-sm font-semibold' , props .class )}
36
42
{ ... props }
43
+ class = { cn (' px-2 py-1.5 text-sm font-semibold' , props .class )}
37
44
>
38
45
<Slot />
39
46
</HeadlessSelect.Label >
@@ -45,14 +52,14 @@ const Trigger = component$<PropsOf<typeof HeadlessSelect.Trigger>>(({ ...props }
45
52
return (
46
53
<>
47
54
<HeadlessSelect.Trigger
55
+ { ... props }
48
56
class = { cn (
49
57
' flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1' ,
50
58
props .class ,
51
- { ... props },
52
59
)}
53
60
>
54
61
<Slot />
55
- <LuFilter class = " h-4 w-4 opacity-50" />
62
+ <LuChevronDown class = " h-4 w-4 opacity-50" />
56
63
</HeadlessSelect.Trigger >
57
64
</>
58
65
);
@@ -64,12 +71,12 @@ const Popover = component$<PropsOf<typeof HeadlessSelect.Popover>>(({ ...props }
64
71
return (
65
72
<>
66
73
<HeadlessSelect.Popover
74
+ { ... props }
67
75
class = { cn (
68
- ' w-full max-w-[15rem]' ,
76
+ ' w-full max-w-[15rem] data-[open]:animate-in data-[closing]:animate-out data-[closing]:fade-out-0 data-[open]:fade-in-0 data-[closing]:zoom-out-95 data-[open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ' ,
69
77
// 'overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md',
70
78
props .class ,
71
79
)}
72
- { ... props }
73
80
>
74
81
<Slot />
75
82
</HeadlessSelect.Popover >
@@ -82,11 +89,11 @@ const Listbox = component$<ListboxProps>(({ ...props }) => {
82
89
return (
83
90
<>
84
91
<HeadlessSelect.Listbox
92
+ { ... props }
85
93
class = { cn (
86
- ' relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ' ,
94
+ ' relative z-50 max-h-96 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md' ,
87
95
props .class ,
88
96
)}
89
- { ... props }
90
97
>
91
98
<Slot />
92
99
</HeadlessSelect.Listbox >
@@ -101,20 +108,35 @@ const GroupLabel = HeadlessSelect.GroupLabel;
101
108
const Item = component$ <PropsOf <typeof HeadlessSelect .Item >>(({ ... props }) => {
102
109
return (
103
110
<HeadlessSelect.Item
111
+ { ... props }
104
112
class = { cn (
105
113
' relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50' ,
114
+ ' data-[highlighted]:border-base data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground' ,
106
115
props .class ,
107
116
)}
108
117
>
118
+ <Slot />
119
+ </HeadlessSelect.Item >
120
+ );
121
+ });
122
+
123
+ const ItemIndicator = component$ <PropsOf <typeof HeadlessSelect .ItemIndicator >>(
124
+ ({ ... props }) => {
125
+ return (
109
126
<span class = " absolute right-2 flex h-3.5 w-3.5 items-center justify-center" >
110
- <HeadlessSelect.ItemIndicator >
127
+ <HeadlessSelect.ItemIndicator { ... props } >
111
128
<LuCheck class = " h-4 w-4" />
112
129
</HeadlessSelect.ItemIndicator >
113
130
</span >
114
- <HeadlessSelect.ItemLabel >
115
- <Slot />
116
- </HeadlessSelect.ItemLabel >
117
- </HeadlessSelect.Item >
131
+ );
132
+ },
133
+ );
134
+
135
+ const ItemLabel = component$ <PropsOf <typeof HeadlessSelect .ItemLabel >>(({ ... props }) => {
136
+ return (
137
+ <HeadlessSelect.ItemLabel { ... props } >
138
+ <Slot />
139
+ </HeadlessSelect.ItemLabel >
118
140
);
119
141
});
120
142
@@ -128,5 +150,7 @@ export const Select = {
128
150
Group ,
129
151
GroupLabel ,
130
152
Item ,
153
+ ItemIndicator ,
154
+ ItemLabel ,
131
155
};
132
156
```
0 commit comments