Skip to content

Commit 6e7b7e5

Browse files
committed
fix: migrate select to base-ui
1 parent 97c94f2 commit 6e7b7e5

File tree

2 files changed

+62
-85
lines changed

2 files changed

+62
-85
lines changed

packages/ui-react/src/components/select/select.stories.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Meta, Preview } from "@storybook/react";
2-
import * as Select from "./select.js";
32
import { fn } from "@storybook/test";
3+
import * as Select from "./select.js";
44

55
export default {
66
title: "Components/Select",
@@ -41,14 +41,14 @@ export const WithGroups = {
4141
children: (
4242
<>
4343
<Select.Group>
44-
<Select.Label>Symmetriska knopar</Select.Label>
44+
<Select.GroupLabel>Symmetriska knopar</Select.GroupLabel>
4545
<Select.Item value="option1-1">Råbandsknop</Select.Item>
4646
<Select.Item value="option1-2">Dubbelt halvslag</Select.Item>
4747
<Select.Item value="option1-3">Trumpetstek</Select.Item>
4848
</Select.Group>
4949
<Select.Separator />
5050
<Select.Group>
51-
<Select.Label>Osymmetriska knopar</Select.Label>
51+
<Select.GroupLabel>Osymmetriska knopar</Select.GroupLabel>
5252
<Select.Item value="option2-1">Skotstek</Select.Item>
5353
<Select.Item value="option2-2">Smugglarstek</Select.Item>
5454
<Select.Item value="option2-3">Tältlineknop</Select.Item>
Lines changed: 59 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
import * as SelectPrimitive from "@radix-ui/react-select";
1+
import { Select as SelectPrimitive } from "@base-ui-components/react/select";
22
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react";
3-
import { forwardRef } from "react";
3+
44
import { cn } from "../../lib/utils.js";
55

6-
const Root = ({
6+
const Root = <TValue,>({
77
children,
88
placeholder,
99
...props
10-
}: React.ComponentPropsWithoutRef<typeof SelectPrimitive.Root> & {
10+
}: SelectPrimitive.Root.Props<TValue> & {
1111
placeholder?: string;
1212
}) => (
1313
<SelectPrimitive.Root {...props}>
1414
<Trigger>
1515
<Value placeholder={placeholder} />
1616
</Trigger>
17-
<Content className="text-gray-dark">{children}</Content>
17+
<Positioner className="text-gray-dark">{children}</Positioner>
1818
</SelectPrimitive.Root>
1919
);
20-
Root.displayName = SelectPrimitive.Root.displayName;
2120

2221
const Group = SelectPrimitive.Group;
2322

2423
const Value = SelectPrimitive.Value;
2524

26-
const Trigger = forwardRef<
27-
React.ComponentRef<typeof SelectPrimitive.Trigger>,
28-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
29-
>(({ className, children, ...props }, ref) => (
25+
const Trigger = ({
26+
className,
27+
children,
28+
...props
29+
}: SelectPrimitive.Trigger.Props) => (
3030
<SelectPrimitive.Trigger
31-
ref={ref}
3231
className={cn(
3332
`
3433
flex
@@ -53,91 +52,83 @@ const Trigger = forwardRef<
5352
{...props}
5453
>
5554
{children}
56-
<SelectPrimitive.Icon asChild>
55+
<SelectPrimitive.Icon>
5756
<ChevronDownIcon className="size-4 opacity-50" />
5857
</SelectPrimitive.Icon>
5958
</SelectPrimitive.Trigger>
60-
));
61-
Trigger.displayName = SelectPrimitive.Trigger.displayName;
59+
);
6260

63-
const ScrollUpButton = forwardRef<
64-
React.ComponentRef<typeof SelectPrimitive.ScrollUpButton>,
65-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
66-
>(({ className, ...props }, ref) => (
67-
<SelectPrimitive.ScrollUpButton
68-
ref={ref}
61+
const ScrollUpArrow = ({
62+
className,
63+
...props
64+
}: SelectPrimitive.ScrollUpArrow.Props) => (
65+
<SelectPrimitive.ScrollUpArrow
6966
className={cn(
70-
"flex cursor-default items-center justify-center py-1",
67+
"absolute top-0 inset-x-0 flex cursor-default items-center justify-center py-1 z-10",
7168
className,
7269
)}
7370
{...props}
7471
>
7572
<ChevronUpIcon className="size-4" />
76-
</SelectPrimitive.ScrollUpButton>
77-
));
78-
ScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
73+
</SelectPrimitive.ScrollUpArrow>
74+
);
7975

80-
const ScrollDownButton = forwardRef<
81-
React.ComponentRef<typeof SelectPrimitive.ScrollDownButton>,
82-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
83-
>(({ className, ...props }, ref) => (
84-
<SelectPrimitive.ScrollDownButton
85-
ref={ref}
76+
const ScrollDownArrow = ({
77+
className,
78+
...props
79+
}: SelectPrimitive.ScrollDownArrow.Props) => (
80+
<SelectPrimitive.ScrollDownArrow
8681
className={cn(
87-
"flex cursor-default items-center justify-center py-1",
82+
"absolute bottom-0 inset-x-0 flex cursor-default items-center justify-center py-1",
8883
className,
8984
)}
9085
{...props}
9186
>
9287
<ChevronDownIcon className="size-4" />
93-
</SelectPrimitive.ScrollDownButton>
94-
));
95-
ScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
88+
</SelectPrimitive.ScrollDownArrow>
89+
);
9690

97-
const Content = forwardRef<
98-
React.ComponentRef<typeof SelectPrimitive.Content>,
99-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
100-
>(({ className, children, ...props }, ref) => (
91+
const Positioner = ({
92+
className,
93+
children,
94+
...props
95+
}: SelectPrimitive.Positioner.Props) => (
10196
<SelectPrimitive.Portal>
102-
<SelectPrimitive.Content
103-
ref={ref}
97+
<SelectPrimitive.Positioner
10498
className={cn(
105-
"relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-lg border bg-gray-100 text-popover-foreground shadow-md border-gray-300",
99+
"relative z-50 min-w-[calc(var(--anchor-width)+25px-var(--spacing)*1.5)] overflow-y-auto overflow-x-hidden rounded-lg border bg-gray-100 text-popover-foreground shadow-md border-gray-300",
106100
className,
107101
)}
108102
{...props}
109103
>
110-
<ScrollUpButton />
111-
<SelectPrimitive.Viewport className={cn("p-1.5")}>
104+
<ScrollUpArrow />
105+
<SelectPrimitive.Popup className={cn("p-1.5")}>
112106
{children}
113-
</SelectPrimitive.Viewport>
114-
<ScrollDownButton />
115-
</SelectPrimitive.Content>
107+
</SelectPrimitive.Popup>
108+
<ScrollDownArrow />
109+
</SelectPrimitive.Positioner>
116110
</SelectPrimitive.Portal>
117-
));
118-
Content.displayName = SelectPrimitive.Content.displayName;
111+
);
119112

120-
const Label = forwardRef<
121-
React.ComponentRef<typeof SelectPrimitive.Label>,
122-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
123-
>(({ className, ...props }, ref) => (
124-
<SelectPrimitive.Label
125-
ref={ref}
113+
const GroupLabel = ({
114+
className,
115+
...props
116+
}: SelectPrimitive.GroupLabel.Props) => (
117+
<SelectPrimitive.GroupLabel
126118
className={cn(
127119
"px-[25px] text-sm leading-[25px] font-semibold select-none",
128120
className,
129121
)}
130122
{...props}
131123
/>
132-
));
133-
Label.displayName = SelectPrimitive.Label.displayName;
124+
);
134125

135-
const Item = forwardRef<
136-
React.ComponentRef<typeof SelectPrimitive.Item>,
137-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
138-
>(({ className, children, ...props }, ref) => (
126+
const Item = ({
127+
className,
128+
children,
129+
...props
130+
}: SelectPrimitive.Item.Props) => (
139131
<SelectPrimitive.Item
140-
ref={ref}
141132
className={cn(
142133
"relative flex h-7 select-none items-center rounded-sm pl-[25px] pr-[35px] leading-none data-[disabled]:pointer-events-none data-[highlighted]:bg-blue-100 data-[disabled]:opacity-50 data-[highlighted]:text-blue data-[highlighted]:outline-none",
143134
className,
@@ -149,30 +140,16 @@ const Item = forwardRef<
149140
<CheckIcon />
150141
</SelectPrimitive.ItemIndicator>
151142
</SelectPrimitive.Item>
152-
));
153-
Item.displayName = SelectPrimitive.Item.displayName;
143+
);
154144

155-
const Separator = forwardRef<
156-
React.ComponentRef<typeof SelectPrimitive.Separator>,
157-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
158-
>(({ className, ...props }, ref) => (
145+
const Separator = ({
146+
className,
147+
...props
148+
}: SelectPrimitive.Separator.Props) => (
159149
<SelectPrimitive.Separator
160-
ref={ref}
161150
className={cn("m-[5px] h-px bg-gray-300", className)}
162151
{...props}
163152
/>
164-
));
165-
Separator.displayName = SelectPrimitive.Separator.displayName;
153+
);
166154

167-
export {
168-
Root,
169-
Group,
170-
Value,
171-
Trigger,
172-
Content,
173-
Label,
174-
Item,
175-
Separator,
176-
ScrollUpButton,
177-
ScrollDownButton,
178-
};
155+
export { Root, Group, Value, GroupLabel, Item, Separator };

0 commit comments

Comments
 (0)