Skip to content

Commit a722b77

Browse files
committed
feat: update combobox demo
1 parent 4a1659f commit a722b77

File tree

8 files changed

+119
-111
lines changed

8 files changed

+119
-111
lines changed

packages/ui/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
"main": "./dist/index.js",
1212
"module": "./dist/index.js",
1313
"types": "./dist/index.d.ts",
14-
"files": [
15-
"dist"
16-
],
14+
"files": ["dist"],
1715
"scripts": {
1816
"build": "pnpm run pgk:prod && pnpm run build:components && pnpm run registry",
1917
"build:components": "tsdown",

packages/ui/src/components/combobox/Combobox.tsx

Lines changed: 0 additions & 56 deletions
This file was deleted.

packages/ui/src/components/combobox/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/ui/src/components/combobox/types.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/ui/src/components/popover/PopoverUI.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Close, Portal, Root, Trigger } from '@radix-ui/react-popover';
33
import type { ComponentRef } from 'react';
44
import { forwardRef } from 'react';
55

6+
import PopoverAnchor from './PopoverAnchor';
67
import PopoverArrow from './PopoverArrow';
78
import PopoverContent from './PopoverContent';
89
import type { PopoverProps } from './types';
@@ -34,7 +35,9 @@ const PopoverUI = forwardRef<ComponentRef<typeof Content>, PopoverProps>((props,
3435
open={open}
3536
onOpenChange={onOpenChange}
3637
>
37-
<Trigger asChild>{trigger}</Trigger>
38+
<PopoverAnchor>
39+
<Trigger asChild>{trigger}</Trigger>
40+
</PopoverAnchor>
3841

3942
<Portal
4043
container={container}

packages/ui/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export * from './components/chip';
2424

2525
export * from './components/collapsible';
2626

27-
export * from './components/combobox';
28-
2927
export * from './components/command';
3028

3129
export * from './components/config-provider';
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
'use client';
2+
3+
import { Check, ChevronsUpDown } from 'lucide-react';
4+
import { useState } from 'react';
5+
import { Button, Card, Command, Popover, cn } from 'soybean-react-ui';
6+
7+
const ComboboxDemo = () => {
8+
const [value, setValue] = useState('');
9+
10+
const frameworks = [
11+
{
12+
label: (
13+
<div className="flex items-center gap-2">
14+
<span>Vue</span>
15+
<Check className={cn('ml-auto', value === 'vue' ? 'opacity-100' : 'opacity-0')} />
16+
</div>
17+
),
18+
value: 'vue'
19+
},
20+
{
21+
label: (
22+
<div className="flex items-center gap-2">
23+
<span>React</span>
24+
<Check className={cn('ml-auto', value === 'react' ? 'opacity-100' : 'opacity-0')} />
25+
</div>
26+
),
27+
value: 'react'
28+
},
29+
{
30+
label: (
31+
<div className="flex items-center gap-2">
32+
<span>Next.js</span>
33+
<Check className={cn('ml-auto', value === 'nextjs' ? 'opacity-100' : 'opacity-0')} />
34+
</div>
35+
),
36+
value: 'nextjs'
37+
},
38+
{
39+
label: (
40+
<div className="flex items-center gap-2">
41+
<span>SvelteKit</span>
42+
<Check className={cn('ml-auto', value === 'sveltekit' ? 'opacity-100' : 'opacity-0')} />
43+
</div>
44+
),
45+
value: 'sveltekit'
46+
},
47+
{
48+
label: (
49+
<div className="flex items-center gap-2">
50+
<span>Nuxt</span>
51+
<Check className={cn('ml-auto', value === 'nuxt' ? 'opacity-100' : 'opacity-0')} />
52+
</div>
53+
),
54+
value: 'nuxt'
55+
},
56+
{
57+
label: (
58+
<div className="flex items-center gap-2">
59+
<span>Remix</span>
60+
<Check className={cn('ml-auto', value === 'remix' ? 'opacity-100' : 'opacity-0')} />
61+
</div>
62+
),
63+
value: 'remix'
64+
},
65+
{
66+
label: (
67+
<div className="flex items-center gap-2">
68+
<span>Astro</span>
69+
<Check className={cn('ml-auto', value === 'astro' ? 'opacity-100' : 'opacity-0')} />
70+
</div>
71+
),
72+
value: 'astro'
73+
}
74+
];
75+
76+
return (
77+
<Card
78+
split
79+
classNames={{ content: 'w-60' }}
80+
title="Combobox Size"
81+
>
82+
<Popover
83+
classNames={{ content: 'p-0' }}
84+
trigger={
85+
<Button
86+
className="w-full justify-between md:max-w-[200px]"
87+
role="combobox"
88+
variant="pure"
89+
>
90+
{value ? frameworks.find(item => item.value === value)?.label : 'Select framework...'}
91+
<ChevronsUpDown className="text-muted-foreground" />
92+
</Button>
93+
}
94+
>
95+
<Command
96+
items={frameworks}
97+
inputProps={{
98+
onValueChange(search) {
99+
setValue(search);
100+
}
101+
}}
102+
/>
103+
</Popover>
104+
</Card>
105+
);
106+
};
107+
108+
export default ComboboxDemo;
Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,11 @@
1-
'use client';
2-
3-
import { ChevronsUpDown } from 'lucide-react';
4-
import { useState } from 'react';
5-
import { Button, Card, Combobox } from 'soybean-react-ui';
6-
7-
const frameworks = [
8-
{ label: 'Vue', value: '0' },
9-
{ label: 'React', value: '1' },
10-
{ label: 'Next.js', value: '2' },
11-
{ label: 'SvelteKit', value: '3' },
12-
{ label: 'Nuxt', value: '4' },
13-
{ label: 'Remix', value: '5' },
14-
{ label: 'Astro', value: '6' }
15-
];
16-
17-
const ComboboxDemo = () => {
18-
const [open, setOpen] = useState(false);
19-
const [value, setValue] = useState('');
1+
import ComboboxDemo from './modules/ComboboxDemo';
202

3+
const ComboboxPage = () => {
214
return (
22-
<Card
23-
split
24-
title="Combobox Size"
25-
>
26-
<Combobox
27-
items={frameworks}
28-
trigger={
29-
<Button
30-
aria-expanded={open}
31-
className="w-full justify-between md:max-w-[200px]"
32-
role="combobox"
33-
variant="pure"
34-
>
35-
{value ? frameworks.find(framework => framework.value === value)?.label : 'Select framework...'}
36-
<ChevronsUpDown className="text-muted-foreground" />
37-
</Button>
38-
}
39-
/>
40-
</Card>
5+
<div className="flex-c gap-4">
6+
<ComboboxDemo />
7+
</div>
418
);
429
};
4310

44-
export default ComboboxDemo;
11+
export default ComboboxPage;

0 commit comments

Comments
 (0)