import { createStyledContext, styled, withSlots } from "better-styled";
// Define shared variants
const ButtonContext = createStyledContext({
size: ["sm", "md", "lg"],
variant: ["primary", "secondary"],
});
// Parent: the button itself
const ButtonRoot = styled("button", {
context: ButtonContext,
base: { className: "inline-flex items-center gap-2 font-medium rounded-lg" },
variants: {
variant: {
primary: { className: "bg-blue-600 text-white" },
secondary: { className: "bg-gray-200 text-gray-900" },
},
size: {
sm: { className: "px-3 py-1.5" },
md: { className: "px-4 py-2" },
lg: { className: "px-6 py-3" },
},
},
});
// Child: inherits size from parent automatically
const ButtonLabel = styled("span", {
context: ButtonContext,
variants: {
size: {
sm: { className: "text-sm" },
md: { className: "text-base" },
lg: { className: "text-lg" },
},
},
});
// Combine into compound component
export const Button = withSlots(ButtonRoot, {
Label: ButtonLabel,
});