Skip to content

Commit 0585d83

Browse files
committed
fix: migrate button to base-ui
1 parent 48aa2da commit 0585d83

File tree

4 files changed

+101
-31
lines changed

4 files changed

+101
-31
lines changed

packages/ui-react/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"author": "",
3131
"license": "MIT",
3232
"dependencies": {
33+
"@base-ui-components/react": "1.0.0-beta.0",
3334
"@radix-ui/react-checkbox": "^1.3.2",
3435
"@radix-ui/react-label": "^2.1.7",
3536
"@radix-ui/react-select": "2.1.7",
@@ -52,6 +53,7 @@
5253
"@storybook/react": "8.6.14",
5354
"@storybook/react-vite": "8.6.14",
5455
"@storybook/test": "8.6.14",
56+
"@tailwindcss/cli": "^4.1.7",
5557
"@types/react": "^19.1.4",
5658
"@vitest/browser": "^3.1.3",
5759
"@vitest/coverage-v8": "^3.1.3",
@@ -61,7 +63,6 @@
6163
"storybook": "8.6.14",
6264
"typescript": "^5.8.3",
6365
"vite": "^6.3.5",
64-
"vitest": "^3.1.3",
65-
"@tailwindcss/cli": "^4.1.7"
66+
"vitest": "^3.1.3"
6667
}
6768
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ export const Small = {
3939
size: "small",
4040
},
4141
};
42+
43+
export const Link = {
44+
args: {
45+
render: (
46+
<a href="https://github.com" target="_blank" rel="noopener noreferrer" />
47+
),
48+
children: "Go to GitHub",
49+
},
50+
};

packages/ui-react/src/components/button/button.tsx

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Slot } from "@radix-ui/react-slot";
2-
import { type VariantProps, cva } from "class-variance-authority";
3-
import { forwardRef } from "react";
1+
import { mergeProps, useRender } from "@base-ui-components/react";
2+
import { cva, type VariantProps } from "class-variance-authority";
43
import { cn } from "../../lib/utils.js";
54

65
const buttonVariants = cva(
@@ -140,33 +139,29 @@ const buttonVariants = cva(
140139
},
141140
);
142141

143-
export type ButtonProps = Omit<
144-
React.ButtonHTMLAttributes<HTMLButtonElement>,
145-
"color"
146-
> &
147-
VariantProps<typeof buttonVariants> & {
148-
asChild?: boolean;
142+
export type ButtonProps = Omit<useRender.ComponentProps<"button">, "color"> &
143+
VariantProps<typeof buttonVariants>;
144+
145+
const Button = (props: ButtonProps) => {
146+
const {
147+
// biome-ignore lint/a11y/useButtonType: We set it further down
148+
render = <button />,
149+
className,
150+
color,
151+
variant,
152+
size,
153+
...otherProps
154+
} = props;
155+
156+
const defaultProps: useRender.ElementProps<"button"> = {
157+
className: cn(buttonVariants({ color, variant, size, className })),
158+
type: "button",
149159
};
150160

151-
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
152-
(
153-
{ className, color, variant, size, children, asChild = false, ...props },
154-
ref,
155-
) => {
156-
const Comp = asChild ? Slot : "button";
157-
return (
158-
<Comp
159-
className={cn(buttonVariants({ color, variant, size, className }))}
160-
ref={ref}
161-
{...props}
162-
>
163-
{/* <span> */}
164-
{children}
165-
{/* </span> */}
166-
</Comp>
167-
);
168-
},
169-
);
170-
Button.displayName = "Button";
161+
return useRender({
162+
render,
163+
props: mergeProps(defaultProps, otherProps),
164+
});
165+
};
171166

172167
export { Button };

pnpm-lock.yaml

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)