Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/v4/registry/bases/radix/ui/button.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from "react"
import { renderToStaticMarkup } from "react-dom/server"
import { describe, expect, it } from "vitest"

import { Button } from "./button"

describe("radix button", () => {
it("is a forwardRef component", () => {
expect(Button.$$typeof).toBe(Symbol.for("react.forward_ref"))
})

it("renders an asChild child without wrapping", () => {
const html = renderToStaticMarkup(
<Button asChild>
<span>Action</span>
</Button>
)

expect(html).toMatch(/^<span\b[^>]*>Action<\/span>$/)
expect(html).not.toContain("<button")
})
})
26 changes: 17 additions & 9 deletions apps/v4/registry/bases/radix/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,35 @@ const buttonVariants = cva(
}
)

function Button({
className,
variant = "default",
size = "default",
asChild = false,
...props
}: React.ComponentProps<"button"> &
type ButtonProps = React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Button(
{
className,
variant = "default",
size = "default",
asChild = false,
...props
},
ref
) {
const Comp = asChild ? Slot.Root : "button"

return (
<Comp
ref={ref}
data-slot="button"
data-variant={variant}
data-size={size}
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
)
}
})

Button.displayName = "Button"

export { Button, buttonVariants }
22 changes: 22 additions & 0 deletions apps/v4/registry/new-york-v4/ui/button.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from "react"
import { renderToStaticMarkup } from "react-dom/server"
import { describe, expect, it } from "vitest"

import { Button } from "./button"

describe("new-york Button", () => {
it("is a forwardRef component", () => {
expect(Button.$$typeof).toBe(Symbol.for("react.forward_ref"))
})

it("renders an asChild child without wrapping", () => {
const html = renderToStaticMarkup(
<Button asChild>
<span>Action</span>
</Button>
)

expect(html).toMatch(/^<span\b[^>]*>Action<\/span>$/)
expect(html).not.toContain("<button")
})
})
26 changes: 17 additions & 9 deletions apps/v4/registry/new-york-v4/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,35 @@ const buttonVariants = cva(
}
)

function Button({
className,
variant = "default",
size = "default",
asChild = false,
...props
}: React.ComponentProps<"button"> &
type ButtonProps = React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(function Button(
{
className,
variant = "default",
size = "default",
asChild = false,
...props
},
ref
) {
const Comp = asChild ? Slot.Root : "button"

return (
<Comp
ref={ref}
data-slot="button"
data-variant={variant}
data-size={size}
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
)
}
})

Button.displayName = "Button"

export { Button, buttonVariants }
Loading