{ "name": "checkbox", "file": "compositions/ui/checkbox", "snippet": "import { Checkbox as ChakraCheckbox } from \"@chakra-ui/react\"\nimport * as React from \"react\"\n\nexport interface CheckboxProps extends ChakraCheckbox.RootProps {\n icon?: React.ReactNode\n inputProps?: React.InputHTMLAttributes\n rootRef?: React.RefObject\n}\n\nexport const Checkbox = React.forwardRef(\n function Checkbox(props, ref) {\n const { icon, children, inputProps, rootRef, ...rest } = props\n return (\n \n \n \n {icon || }\n \n {children != null && (\n {children}\n )}\n \n )\n },\n)\n", "examples": [ { "name": "checkbox-basic", "content": "export const CheckboxBasic = () => {\n return (\n \n \n \n Accept terms and conditions\n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-closed-component", "content": "export interface CheckboxProps extends ChakraCheckbox.RootProps {\n icon?: React.ReactNode\n inputProps?: React.InputHTMLAttributes\n rootRef?: React.RefObject\n}\n\nexport const Checkbox = React.forwardRef(\n function Checkbox(props, ref) {\n const { icon, children, inputProps, rootRef, ...rest } = props\n return (\n \n \n \n {icon || }\n \n {children != null && (\n {children}\n )}\n \n )\n },\n)\n", "hasSnippet": false, "importPaths": [ "import { Checkbox as ChakraCheckbox } from \"@chakra-ui/react\"", "import * as React from \"react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-controlled", "content": "\"use client\"\nexport const CheckboxControlled = () => {\n const [checked, setChecked] = useState(false)\n return (\n setChecked(!!e.checked)}\n >\n \n \n Accept terms and conditions\n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox } from \"@chakra-ui/react\"", "import { useState } from \"react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-indeterminate", "content": "\"use client\"\nconst initialValues = [\n { label: \"Monday\", checked: false, value: \"monday\" },\n { label: \"Tuesday\", checked: false, value: \"tuesday\" },\n { label: \"Wednesday\", checked: false, value: \"wednesday\" },\n { label: \"Thursday\", checked: false, value: \"thursday\" },\n]\n\nexport const CheckboxIndeterminate = () => {\n const [values, setValues] = useState(initialValues)\n\n const allChecked = values.every((value) => value.checked)\n const indeterminate = values.some((value) => value.checked) && !allChecked\n\n const items = values.map((item, index) => (\n {\n setValues((current) => {\n const newValues = [...current]\n newValues[index] = { ...newValues[index], checked: !!e.checked }\n return newValues\n })\n }}\n >\n \n \n {item.label}\n \n ))\n\n return (\n \n {\n setValues((current) =>\n current.map((value) => ({ ...value, checked: !!e.checked })),\n )\n }}\n >\n \n \n \n \n Weekdays\n \n {items}\n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox, Stack } from \"@chakra-ui/react\"", "import { useState } from \"react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-colors", "content": "export const CheckboxWithColors = () => {\n return (\n \n {colorPalettes.map((colorPalette) => (\n \n {colorPalette}\n \n {(variant) => (\n \n \n \n \n Checkbox\n \n\n \n \n \n Checkbox\n \n \n )}\n \n \n ))}\n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox, For, Stack, Text } from \"@chakra-ui/react\"", "import { colorPalettes } from \"compositions/lib/color-palettes\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-custom-icon", "content": "export const CheckboxWithCustomIcon = () => {\n return (\n \n \n \n \n \n With Custom Icon\n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox } from \"@chakra-ui/react\"", "import { HiOutlinePlus } from \"react-icons/hi\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"", "npmDependencies": [ "react-icons" ] }, { "name": "checkbox-with-description", "content": "export const CheckboxWithDescription = () => {\n return (\n \n \n \n \n I agree to the terms and conditions\n \n By clicking this, you agree to our Terms and Privacy Policy.\n \n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Box, Checkbox, Stack } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-form", "content": "\"use client\"\nexport const CheckboxWithForm = () => {\n return (\n {\n e.preventDefault()\n console.log(e.currentTarget.elements)\n }}\n >\n \n \n Username\n \n \n \n Password\n \n \n\n \n \n \n Remember me\n \n\n \n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Button, Checkbox, Field, Input, Stack } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-group-hook-form", "content": "\"use client\"\nconst formSchema = z.object({\n framework: z.array(z.string()).min(1, {\n message: \"You must select at least one framework.\",\n }),\n})\n\ntype FormData = z.infer\n\nconst items = [\n { label: \"React\", value: \"react\" },\n { label: \"Svelte\", value: \"svelte\" },\n { label: \"Vue\", value: \"vue\" },\n { label: \"Angular\", value: \"angular\" },\n]\n\nexport const CheckboxWithGroupHookForm = () => {\n const {\n handleSubmit,\n control,\n formState: { errors },\n } = useForm({\n resolver: zodResolver(formSchema),\n })\n\n const framework = useController({\n control,\n name: \"framework\",\n defaultValue: [],\n })\n\n const invalid = !!errors.framework\n\n return (\n
console.log(data))}>\n \n Select your framework\n \n \n {items.map((item) => (\n \n \n \n {item.label}\n \n ))}\n \n \n\n {errors.framework && (\n {errors.framework.message}\n )}\n\n \n\n Values: {JSON.stringify(framework.field.value, null, 2)}\n \n
\n )\n}\n", "hasSnippet": false, "importPaths": [ "import {\n Button,\n Checkbox,\n CheckboxGroup,\n Code,\n Fieldset,\n} from \"@chakra-ui/react\"", "import { zodResolver } from \"@hookform/resolvers/zod\"", "import { useController, useForm } from \"react-hook-form\"", "import { z } from \"zod\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"", "npmDependencies": [ "@hookform/resolvers", "react-hook-form", "zod" ] }, { "name": "checkbox-with-group", "content": "export const CheckboxWithGroup = () => {\n return (\n \n \n \n Select framework\n \n \n \n {(value) => (\n \n \n \n {value}\n \n )}\n \n \n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox, CheckboxGroup, Fieldset, For } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-hook-form", "content": "\"use client\"\nconst formSchema = z.object({\n enabled: z.boolean(),\n})\n\ntype FormData = z.infer\n\nexport const CheckboxWithHookForm = () => {\n const form = useForm({\n resolver: zodResolver(formSchema),\n defaultValues: { enabled: false },\n })\n\n const enabled = useController({\n control: form.control,\n name: \"enabled\",\n })\n\n const invalid = !!form.formState.errors.enabled\n\n return (\n
console.log(data))}>\n \n (\n \n field.onChange(checked)}\n >\n \n \n Checkbox\n \n \n {form.formState.errors.enabled?.message}\n \n \n )}\n />\n\n \n form.setValue(\"enabled\", !enabled.field.value)}\n >\n Toggle\n \n \n \n\n \n\n Checked: {JSON.stringify(enabled.field.value, null, 2)}\n \n
\n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Button, Checkbox, Code, Field, HStack, Stack } from \"@chakra-ui/react\"", "import { zodResolver } from \"@hookform/resolvers/zod\"", "import { Controller, useController, useForm } from \"react-hook-form\"", "import { z } from \"zod\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"", "npmDependencies": [ "@hookform/resolvers", "react-hook-form", "zod" ] }, { "name": "checkbox-with-indeterminate", "content": "export const CheckboxWithIndeterminate = () => {\n return (\n \n \n {(variant) => (\n \n \n \n {variant}\n \n )}\n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox, For, Stack } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-label-position", "content": "export const CheckboxWithLabelPosition = () => {\n return (\n \n \n Accept terms and conditions\n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-link", "content": "export const CheckboxWithLink = () => {\n return (\n \n \n \n \n I agree to the{\" \"}\n \n terms and conditions\n \n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox, Link } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-sizes", "content": "export const CheckboxWithSizes = () => {\n return (\n \n \n {(size) => (\n \n \n \n Checkbox\n \n )}\n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox, For, Stack } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-states", "content": "export const CheckboxWithStates = () => {\n return (\n \n \n \n \n Disabled\n \n\n \n \n \n Disabled\n \n\n \n \n \n Readonly\n \n\n \n \n \n Invalid\n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox, Stack } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-store", "content": "\"use client\"\nexport const CheckboxWithStore = () => {\n const checkbox = useCheckbox()\n return (\n \n \n \n \n Accept terms and conditions\n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox, useCheckbox } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" }, { "name": "checkbox-with-variants", "content": "export const CheckboxWithVariants = () => {\n return (\n \n \n {(variant) => (\n \n {variant}\n \n \n \n Checkbox\n \n \n )}\n \n \n )\n}\n", "hasSnippet": false, "importPaths": [ "import { Checkbox, For, HStack, Stack, Text } from \"@chakra-ui/react\"" ], "importPath": "import { Checkbox } from \"@chakra-ui/react\"" } ] }