File size: 1,652 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
import type { HTMLChakraProps, RecipeVariantProps } from "@chakra-ui/react"
import { createSlotRecipeContext, defineSlotRecipe } from "@chakra-ui/react"
// 1. Define the recipe
const checkbox = defineSlotRecipe({
className: "checkbox",
slots: ["root", "label", "control"],
base: {
root: {
display: "flex",
alignItems: "center",
gap: "2",
},
label: {
fontWeight: "medium",
},
control: {
width: "4",
height: "4",
borderRadius: "md",
borderWidth: "1px",
borderColor: "gray.300",
backgroundColor: "white",
},
},
variants: {
colored: {
true: {
control: {
accentColor: "pink.500",
},
},
},
},
})
const { withProvider, withContext } = createSlotRecipeContext({
recipe: checkbox,
})
// 2. Create the components
interface CheckboxRootProps
extends HTMLChakraProps<"div", RecipeVariantProps<typeof checkbox>> {}
const CheckboxRoot = withProvider<HTMLDivElement, CheckboxRootProps>(
"div",
"root",
)
interface CheckboxLabelProps extends HTMLChakraProps<"label"> {}
const CheckboxLabel = withContext<HTMLLabelElement, CheckboxLabelProps>(
"label",
"label",
)
interface CheckboxControlProps extends HTMLChakraProps<"input"> {}
const CheckboxControl = withContext<HTMLInputElement, CheckboxControlProps>(
"input",
"control",
)
// 3. Use the components
export const SystemInlineSlotRecipe = () => {
return (
<CheckboxRoot colored>
<CheckboxControl id="checkbox" type="checkbox" defaultChecked />
<CheckboxLabel htmlFor="checkbox">Checkbox</CheckboxLabel>
</CheckboxRoot>
)
}
|