Skip to content

Commit 2365d5d

Browse files
committed
docs(styled select): add docs
1 parent 099c5cc commit 2365d5d

File tree

2 files changed

+145
-2
lines changed

2 files changed

+145
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { component$ } from '@builder.io/qwik';
2+
import { Select } from '~/components/ui';
3+
4+
export default component$(() => {
5+
const users = ['Tim', 'Ryan', 'Jim', 'Jessie', 'Abby'];
6+
7+
return (
8+
<Select.Root>
9+
<Select.Label>Logged in users</Select.Label>
10+
<Select.Trigger>
11+
<Select.DisplayText placeholder="Select an option" />
12+
</Select.Trigger>
13+
<Select.Popover>
14+
<Select.Listbox>
15+
{users.map((user) => (
16+
<Select.Item key={user}>{user}</Select.Item>
17+
))}
18+
</Select.Listbox>
19+
</Select.Popover>
20+
</Select.Root>
21+
);
22+
});

apps/website/src/routes/docs/styled/select/index.mdx

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,129 @@ title: Qwik UI | Styled Select Component
44

55
import { statusByComponent } from '~/_state/component-statuses';
66

7+
<StatusBanner status={statusByComponent.styled.Select} />
8+
79
# Select
810

9-
With a gentle click, you unveil a buffet of options; the Qwik UI Styled select is where your choice is the guest of honor, awaiting its moment to shine
11+
Displays a list of options for the user to pick from — triggered by a button.
1012

11-
<StatusBanner status={statusByComponent.styled.Select} />
13+
{/* <Showcase name="hero" /> */}
14+
15+
## Installation
16+
17+
### Run the following cli command or copy/paste the component code into your project
18+
19+
```sh
20+
qwik-ui add select
21+
```
22+
23+
```tsx
24+
import { PropsOf, Slot, component$ } from '@builder.io/qwik';
25+
import { Select as HeadlessSelect } from '@qwik-ui/headless';
26+
import { cn } from '@qwik-ui/utils';
27+
import { LuCheck, LuFilter } from '@qwikest/icons/lucide';
28+
29+
const Root = HeadlessSelect.Root;
30+
31+
const Label = component$<PropsOf<typeof HeadlessSelect.Label>>(({ ...props }) => {
32+
return (
33+
<>
34+
<HeadlessSelect.Label
35+
class={cn('px-2 py-1.5 text-sm font-semibold', props.class)}
36+
{...props}
37+
>
38+
<Slot />
39+
</HeadlessSelect.Label>
40+
</>
41+
);
42+
});
43+
44+
const Trigger = component$<PropsOf<typeof HeadlessSelect.Trigger>>(({ ...props }) => {
45+
return (
46+
<>
47+
<HeadlessSelect.Trigger
48+
class={cn(
49+
'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+
props.class,
51+
{ ...props },
52+
)}
53+
>
54+
<Slot />
55+
<LuFilter class="h-4 w-4 opacity-50" />
56+
</HeadlessSelect.Trigger>
57+
</>
58+
);
59+
});
60+
61+
const DisplayText = HeadlessSelect.DisplayText;
62+
63+
const Popover = component$<PropsOf<typeof HeadlessSelect.Popover>>(({ ...props }) => {
64+
return (
65+
<>
66+
<HeadlessSelect.Popover
67+
class={cn(
68+
'w-full max-w-[15rem]',
69+
// 'overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md',
70+
props.class,
71+
)}
72+
{...props}
73+
>
74+
<Slot />
75+
</HeadlessSelect.Popover>
76+
</>
77+
);
78+
});
79+
80+
type ListboxProps = PropsOf<typeof HeadlessSelect.Listbox>;
81+
const Listbox = component$<ListboxProps>(({ ...props }) => {
82+
return (
83+
<>
84+
<HeadlessSelect.Listbox
85+
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',
87+
props.class,
88+
)}
89+
{...props}
90+
>
91+
<Slot />
92+
</HeadlessSelect.Listbox>
93+
</>
94+
);
95+
});
96+
97+
const Group = HeadlessSelect.Group;
98+
99+
const GroupLabel = HeadlessSelect.GroupLabel;
100+
101+
const Item = component$<PropsOf<typeof HeadlessSelect.Item>>(({ ...props }) => {
102+
return (
103+
<HeadlessSelect.Item
104+
class={cn(
105+
'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',
106+
props.class,
107+
)}
108+
>
109+
<span class="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
110+
<HeadlessSelect.ItemIndicator>
111+
<LuCheck class="h-4 w-4" />
112+
</HeadlessSelect.ItemIndicator>
113+
</span>
114+
<HeadlessSelect.ItemLabel>
115+
<Slot />
116+
</HeadlessSelect.ItemLabel>
117+
</HeadlessSelect.Item>
118+
);
119+
});
120+
121+
export const Select = {
122+
Root,
123+
Label,
124+
Trigger,
125+
DisplayText,
126+
Popover,
127+
Listbox,
128+
Group,
129+
GroupLabel,
130+
Item,
131+
};
132+
```

0 commit comments

Comments
 (0)