Skip to content

Commit d53909b

Browse files
committed
fix(button): support asChild prop broken by previous flex layout fix
1 parent 32f0feb commit d53909b

File tree

7 files changed

+83
-37
lines changed

7 files changed

+83
-37
lines changed

components/ui/8bit/button.tsx

Lines changed: 77 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,51 +47,97 @@ function Button({ children, asChild, ...props }: BitButtonProps) {
4747
<ShadcnButton
4848
{...props}
4949
className={cn(
50-
"rounded-none active:translate-y-1 transition-transform relative inline-flex items-center justify-center",
50+
"rounded-none active:translate-y-1 transition-transform relative inline-flex items-center justify-center gap-1.5",
5151
font !== "normal" && "retro",
5252
className
5353
)}
5454
size={size}
5555
variant={variant}
5656
asChild={asChild}
5757
>
58-
{children}
58+
{asChild ? (
59+
<span className="relative inline-flex items-center justify-center gap-1.5">
60+
{children}
5961

60-
{variant !== "ghost" && variant !== "link" && size !== "icon" && (
61-
<>
62-
{/* Pixelated border */}
63-
<div className="absolute -top-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring" />
64-
<div className="absolute -top-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring" />
65-
<div className="absolute -bottom-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring" />
66-
<div className="absolute -bottom-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring" />
67-
<div className="absolute top-0 left-0 size-1.5 bg-foreground dark:bg-ring" />
68-
<div className="absolute top-0 right-0 size-1.5 bg-foreground dark:bg-ring" />
69-
<div className="absolute bottom-0 left-0 size-1.5 bg-foreground dark:bg-ring" />
70-
<div className="absolute bottom-0 right-0 size-1.5 bg-foreground dark:bg-ring" />
71-
<div className="absolute top-1.5 -left-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring" />
72-
<div className="absolute top-1.5 -right-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring" />
73-
{variant !== "outline" && (
62+
{variant !== "ghost" && variant !== "link" && size !== "icon" && (
7463
<>
75-
{/* Top shadow */}
76-
<div className="absolute top-0 left-0 w-full h-1.5 bg-foreground/20" />
77-
<div className="absolute top-1.5 left-0 w-3 h-1.5 bg-foreground/20" />
64+
{/* Pixelated border */}
65+
<div className="absolute -top-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring" />
66+
<div className="absolute -top-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring" />
67+
<div className="absolute -bottom-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring" />
68+
<div className="absolute -bottom-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring" />
69+
<div className="absolute top-0 left-0 size-1.5 bg-foreground dark:bg-ring" />
70+
<div className="absolute top-0 right-0 size-1.5 bg-foreground dark:bg-ring" />
71+
<div className="absolute bottom-0 left-0 size-1.5 bg-foreground dark:bg-ring" />
72+
<div className="absolute bottom-0 right-0 size-1.5 bg-foreground dark:bg-ring" />
73+
<div className="absolute top-1.5 -left-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring" />
74+
<div className="absolute top-1.5 -right-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring" />
75+
{variant !== "outline" && (
76+
<>
77+
{/* Top shadow */}
78+
<div className="absolute top-0 left-0 w-full h-1.5 bg-foreground/20" />
79+
<div className="absolute top-1.5 left-0 w-3 h-1.5 bg-foreground/20" />
7880

79-
{/* Bottom shadow */}
80-
<div className="absolute bottom-0 left-0 w-full h-1.5 bg-foreground/20" />
81-
<div className="absolute bottom-1.5 right-0 w-3 h-1.5 bg-foreground/20" />
81+
{/* Bottom shadow */}
82+
<div className="absolute bottom-0 left-0 w-full h-1.5 bg-foreground/20" />
83+
<div className="absolute bottom-1.5 right-0 w-3 h-1.5 bg-foreground/20" />
84+
</>
85+
)}
8286
</>
8387
)}
84-
</>
85-
)}
8688

87-
{size === "icon" && (
89+
{size === "icon" && (
90+
<>
91+
<div className="absolute top-0 left-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none" />
92+
<div className="absolute bottom-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none" />
93+
<div className="absolute top-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
94+
<div className="absolute bottom-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
95+
<div className="absolute top-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
96+
<div className="absolute bottom-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
97+
</>
98+
)}
99+
</span>
100+
) : (
88101
<>
89-
<div className="absolute top-0 left-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none" />
90-
<div className="absolute bottom-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none" />
91-
<div className="absolute top-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
92-
<div className="absolute bottom-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
93-
<div className="absolute top-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
94-
<div className="absolute bottom-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
102+
{children}
103+
104+
{variant !== "ghost" && variant !== "link" && size !== "icon" && (
105+
<>
106+
{/* Pixelated border */}
107+
<div className="absolute -top-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring" />
108+
<div className="absolute -top-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring" />
109+
<div className="absolute -bottom-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring" />
110+
<div className="absolute -bottom-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring" />
111+
<div className="absolute top-0 left-0 size-1.5 bg-foreground dark:bg-ring" />
112+
<div className="absolute top-0 right-0 size-1.5 bg-foreground dark:bg-ring" />
113+
<div className="absolute bottom-0 left-0 size-1.5 bg-foreground dark:bg-ring" />
114+
<div className="absolute bottom-0 right-0 size-1.5 bg-foreground dark:bg-ring" />
115+
<div className="absolute top-1.5 -left-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring" />
116+
<div className="absolute top-1.5 -right-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring" />
117+
{variant !== "outline" && (
118+
<>
119+
{/* Top shadow */}
120+
<div className="absolute top-0 left-0 w-full h-1.5 bg-foreground/20" />
121+
<div className="absolute top-1.5 left-0 w-3 h-1.5 bg-foreground/20" />
122+
123+
{/* Bottom shadow */}
124+
<div className="absolute bottom-0 left-0 w-full h-1.5 bg-foreground/20" />
125+
<div className="absolute bottom-1.5 right-0 w-3 h-1.5 bg-foreground/20" />
126+
</>
127+
)}
128+
</>
129+
)}
130+
131+
{size === "icon" && (
132+
<>
133+
<div className="absolute top-0 left-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none" />
134+
<div className="absolute bottom-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none" />
135+
<div className="absolute top-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
136+
<div className="absolute bottom-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
137+
<div className="absolute top-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
138+
<div className="absolute bottom-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none" />
139+
</>
140+
)}
95141
</>
96142
)}
97143
</ShadcnButton>

public/r/8bit-button.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"files": [
1111
{
1212
"path": "components/ui/8bit/button.tsx",
13-
"content": "import { type VariantProps, cva } from \"class-variance-authority\";\n\nimport { cn } from \"@/lib/utils\";\n\nimport { Button as ShadcnButton } from \"@/components/ui/button\";\n\nimport \"./styles/retro.css\";\n\nexport const buttonVariants = cva(\"\", {\n variants: {\n font: {\n normal: \"\",\n retro: \"retro\",\n },\n variant: {\n default: \"bg-foreground\",\n destructive: \"bg-foreground\",\n outline: \"bg-foreground\",\n secondary: \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n ghost: \"hover:bg-accent hover:text-accent-foreground\",\n link: \"text-primary underline-offset-4 hover:underline\",\n },\n size: {\n default: \"h-9 px-4 py-2 has-[>svg]:px-3\",\n sm: \"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5\",\n lg: \"h-10 rounded-md px-6 has-[>svg]:px-4\",\n icon: \"size-9\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n size: \"default\",\n },\n});\n\nexport interface BitButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n VariantProps<typeof buttonVariants> {\n asChild?: boolean;\n ref?: React.Ref<HTMLButtonElement>;\n}\n\nfunction Button({ children, asChild, ...props }: BitButtonProps) {\n const { variant, size, className, font } = props;\n\n return (\n <ShadcnButton\n {...props}\n className={cn(\n \"rounded-none active:translate-y-1 transition-transform relative inline-flex items-center justify-center\",\n font !== \"normal\" && \"retro\",\n className\n )}\n size={size}\n variant={variant}\n asChild={asChild}\n >\n {children}\n\n {variant !== \"ghost\" && variant !== \"link\" && size !== \"icon\" && (\n <>\n {/* Pixelated border */}\n <div className=\"absolute -top-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute -top-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute -bottom-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute -bottom-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-0 left-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-0 right-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute bottom-0 left-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute bottom-0 right-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-1.5 -left-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-1.5 -right-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring\" />\n {variant !== \"outline\" && (\n <>\n {/* Top shadow */}\n <div className=\"absolute top-0 left-0 w-full h-1.5 bg-foreground/20\" />\n <div className=\"absolute top-1.5 left-0 w-3 h-1.5 bg-foreground/20\" />\n\n {/* Bottom shadow */}\n <div className=\"absolute bottom-0 left-0 w-full h-1.5 bg-foreground/20\" />\n <div className=\"absolute bottom-1.5 right-0 w-3 h-1.5 bg-foreground/20\" />\n </>\n )}\n </>\n )}\n\n {size === \"icon\" && (\n <>\n <div className=\"absolute top-0 left-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute bottom-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute top-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute bottom-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute top-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute bottom-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n </>\n )}\n </ShadcnButton>\n );\n}\n\nexport { Button };\n",
13+
"content": "import { type VariantProps, cva } from \"class-variance-authority\";\n\nimport { cn } from \"@/lib/utils\";\n\nimport { Button as ShadcnButton } from \"@/components/ui/button\";\n\nimport \"./styles/retro.css\";\n\nexport const buttonVariants = cva(\"\", {\n variants: {\n font: {\n normal: \"\",\n retro: \"retro\",\n },\n variant: {\n default: \"bg-foreground\",\n destructive: \"bg-foreground\",\n outline: \"bg-foreground\",\n secondary: \"bg-secondary text-secondary-foreground hover:bg-secondary/80\",\n ghost: \"hover:bg-accent hover:text-accent-foreground\",\n link: \"text-primary underline-offset-4 hover:underline\",\n },\n size: {\n default: \"h-9 px-4 py-2 has-[>svg]:px-3\",\n sm: \"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5\",\n lg: \"h-10 rounded-md px-6 has-[>svg]:px-4\",\n icon: \"size-9\",\n },\n },\n defaultVariants: {\n variant: \"default\",\n size: \"default\",\n },\n});\n\nexport interface BitButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement>,\n VariantProps<typeof buttonVariants> {\n asChild?: boolean;\n ref?: React.Ref<HTMLButtonElement>;\n}\n\nfunction Button({ children, asChild, ...props }: BitButtonProps) {\n const { variant, size, className, font } = props;\n\n return (\n <ShadcnButton\n {...props}\n className={cn(\n \"rounded-none active:translate-y-1 transition-transform relative inline-flex items-center justify-center gap-1.5\",\n font !== \"normal\" && \"retro\",\n className\n )}\n size={size}\n variant={variant}\n asChild={asChild}\n >\n {asChild ? (\n <span className=\"relative inline-flex items-center justify-center gap-1.5\">\n {children}\n\n {variant !== \"ghost\" && variant !== \"link\" && size !== \"icon\" && (\n <>\n {/* Pixelated border */}\n <div className=\"absolute -top-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute -top-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute -bottom-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute -bottom-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-0 left-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-0 right-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute bottom-0 left-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute bottom-0 right-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-1.5 -left-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-1.5 -right-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring\" />\n {variant !== \"outline\" && (\n <>\n {/* Top shadow */}\n <div className=\"absolute top-0 left-0 w-full h-1.5 bg-foreground/20\" />\n <div className=\"absolute top-1.5 left-0 w-3 h-1.5 bg-foreground/20\" />\n\n {/* Bottom shadow */}\n <div className=\"absolute bottom-0 left-0 w-full h-1.5 bg-foreground/20\" />\n <div className=\"absolute bottom-1.5 right-0 w-3 h-1.5 bg-foreground/20\" />\n </>\n )}\n </>\n )}\n\n {size === \"icon\" && (\n <>\n <div className=\"absolute top-0 left-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute bottom-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute top-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute bottom-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute top-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute bottom-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n </>\n )}\n </span>\n ) : (\n <>\n {children}\n\n {variant !== \"ghost\" && variant !== \"link\" && size !== \"icon\" && (\n <>\n {/* Pixelated border */}\n <div className=\"absolute -top-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute -top-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute -bottom-1.5 w-1/2 left-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute -bottom-1.5 w-1/2 right-1.5 h-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-0 left-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-0 right-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute bottom-0 left-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute bottom-0 right-0 size-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-1.5 -left-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring\" />\n <div className=\"absolute top-1.5 -right-1.5 h-2/3 w-1.5 bg-foreground dark:bg-ring\" />\n {variant !== \"outline\" && (\n <>\n {/* Top shadow */}\n <div className=\"absolute top-0 left-0 w-full h-1.5 bg-foreground/20\" />\n <div className=\"absolute top-1.5 left-0 w-3 h-1.5 bg-foreground/20\" />\n\n {/* Bottom shadow */}\n <div className=\"absolute bottom-0 left-0 w-full h-1.5 bg-foreground/20\" />\n <div className=\"absolute bottom-1.5 right-0 w-3 h-1.5 bg-foreground/20\" />\n </>\n )}\n </>\n )}\n\n {size === \"icon\" && (\n <>\n <div className=\"absolute top-0 left-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute bottom-0 w-full h-[5px] md:h-1.5 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute top-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute bottom-1 -left-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute top-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n <div className=\"absolute bottom-1 -right-1 w-[5px] md:w-1.5 h-1/2 bg-foreground dark:bg-ring pointer-events-none\" />\n </>\n )}\n </>\n )}\n </ShadcnButton>\n );\n}\n\nexport { Button };\n",
1414
"type": "registry:component",
1515
"target": "components/ui/8bit/button.tsx"
1616
},

0 commit comments

Comments
 (0)