File size: 7,548 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
  "name": "field",
  "file": "compositions/ui/field",
  "snippet": "import { Field as ChakraField } from \"@chakra-ui/react\"\nimport * as React from \"react\"\n\nexport interface FieldProps extends Omit<ChakraField.RootProps, \"label\"> {\n  label?: React.ReactNode\n  helperText?: React.ReactNode\n  errorText?: React.ReactNode\n  optionalText?: React.ReactNode\n}\n\nexport const Field = React.forwardRef<HTMLDivElement, FieldProps>(\n  function Field(props, ref) {\n    const { label, children, helperText, errorText, optionalText, ...rest } =\n      props\n    return (\n      <ChakraField.Root ref={ref} {...rest}>\n        {label && (\n          <ChakraField.Label>\n            {label}\n            <ChakraField.RequiredIndicator fallback={optionalText} />\n          </ChakraField.Label>\n        )}\n        {children}\n        {helperText && (\n          <ChakraField.HelperText>{helperText}</ChakraField.HelperText>\n        )}\n        {errorText && (\n          <ChakraField.ErrorText>{errorText}</ChakraField.ErrorText>\n        )}\n      </ChakraField.Root>\n    )\n  },\n)\n",
  "examples": [
    {
      "name": "field-basic",
      "content": "export const FieldBasic = () => {\n  return (\n    <Field.Root>\n      <Field.Label>Email</Field.Label>\n      <Input placeholder=\"me@example.com\" />\n    </Field.Root>\n  )\n}\n",
      "hasSnippet": false,
      "importPaths": [
        "import { Field, Input } from \"@chakra-ui/react\""
      ],
      "importPath": "import { Field } from \"@chakra-ui/react\""
    },
    {
      "name": "field-closed-component",
      "content": "export interface FieldProps extends Omit<ChakraField.RootProps, \"label\"> {\n  label?: React.ReactNode\n  helperText?: React.ReactNode\n  errorText?: React.ReactNode\n  optionalText?: React.ReactNode\n}\n\nexport const Field = React.forwardRef<HTMLDivElement, FieldProps>(\n  function Field(props, ref) {\n    const { label, children, helperText, errorText, optionalText, ...rest } =\n      props\n    return (\n      <ChakraField.Root ref={ref} {...rest}>\n        {label && (\n          <ChakraField.Label>\n            {label}\n            <ChakraField.RequiredIndicator fallback={optionalText} />\n          </ChakraField.Label>\n        )}\n        {children}\n        {helperText && (\n          <ChakraField.HelperText>{helperText}</ChakraField.HelperText>\n        )}\n        {errorText && (\n          <ChakraField.ErrorText>{errorText}</ChakraField.ErrorText>\n        )}\n      </ChakraField.Root>\n    )\n  },\n)\n",
      "hasSnippet": false,
      "importPaths": [
        "import { Field as ChakraField } from \"@chakra-ui/react\"",
        "import * as React from \"react\""
      ],
      "importPath": "import { Field } from \"@chakra-ui/react\""
    },
    {
      "name": "field-horizontal",
      "content": "export const FieldHorizontal = () => {\n  return (\n    <Stack gap=\"8\" maxW=\"sm\" css={{ \"--field-label-width\": \"96px\" }}>\n      <Field.Root orientation=\"horizontal\">\n        <Field.Label>Name</Field.Label>\n        <Input placeholder=\"John Doe\" flex=\"1\" />\n      </Field.Root>\n\n      <Field.Root orientation=\"horizontal\">\n        <Field.Label>Email</Field.Label>\n        <Input placeholder=\"me@example.com\" flex=\"1\" />\n      </Field.Root>\n\n      <Field.Root orientation=\"horizontal\">\n        <Field.Label>Hide email</Field.Label>\n        <Switch.Root>\n          <Switch.HiddenInput />\n          <Switch.Control />\n        </Switch.Root>\n      </Field.Root>\n    </Stack>\n  )\n}\n",
      "hasSnippet": false,
      "importPaths": [
        "import { Field, Input, Stack, Switch } from \"@chakra-ui/react\""
      ],
      "importPath": "import { Field } from \"@chakra-ui/react\""
    },
    {
      "name": "field-with-disabled",
      "content": "export const FieldWithDisabled = () => {\n  return (\n    <Field.Root disabled>\n      <Field.Label>Email</Field.Label>\n      <Input placeholder=\"me@example.com\" />\n    </Field.Root>\n  )\n}\n",
      "hasSnippet": false,
      "importPaths": [
        "import { Field, Input } from \"@chakra-ui/react\""
      ],
      "importPath": "import { Field } from \"@chakra-ui/react\""
    },
    {
      "name": "field-with-error-text",
      "content": "export const FieldWithErrorText = () => {\n  return (\n    <Field.Root invalid>\n      <Field.Label>Email</Field.Label>\n      <Input placeholder=\"me@example.com\" />\n      <Field.ErrorText>This is an error text</Field.ErrorText>\n    </Field.Root>\n  )\n}\n",
      "hasSnippet": false,
      "importPaths": [
        "import { Field, Input } from \"@chakra-ui/react\""
      ],
      "importPath": "import { Field } from \"@chakra-ui/react\""
    },
    {
      "name": "field-with-helper-text",
      "content": "export const FieldWithHelperText = () => {\n  return (\n    <Field.Root>\n      <Field.Label>Email</Field.Label>\n      <Input placeholder=\"me@example.com\" />\n      <Field.HelperText>This is a helper text</Field.HelperText>\n    </Field.Root>\n  )\n}\n",
      "hasSnippet": false,
      "importPaths": [
        "import { Field, Input } from \"@chakra-ui/react\""
      ],
      "importPath": "import { Field } from \"@chakra-ui/react\""
    },
    {
      "name": "field-with-native-select",
      "content": "export const FieldWithNativeSelect = () => {\n  return (\n    <Field.Root>\n      <Field.Label>Email</Field.Label>\n      <NativeSelect.Root>\n        <NativeSelect.Field>\n          <option value=\"1\">Option 1</option>\n          <option value=\"2\">Option 2</option>\n          <option value=\"3\">Option 3</option>\n        </NativeSelect.Field>\n        <NativeSelect.Indicator />\n      </NativeSelect.Root>\n    </Field.Root>\n  )\n}\n",
      "hasSnippet": false,
      "importPaths": [
        "import { Field, NativeSelect } from \"@chakra-ui/react\""
      ],
      "importPath": "import { Field } from \"@chakra-ui/react\""
    },
    {
      "name": "field-with-optional",
      "content": "export const FieldWithOptional = () => {\n  return (\n    <Field.Root>\n      <Field.Label>\n        Email\n        <Field.RequiredIndicator\n          fallback={\n            <Badge size=\"xs\" variant=\"surface\">\n              Optional\n            </Badge>\n          }\n        />\n      </Field.Label>\n      <Input placeholder=\"me@example.com\" />\n    </Field.Root>\n  )\n}\n",
      "hasSnippet": false,
      "importPaths": [
        "import { Badge, Field, Input } from \"@chakra-ui/react\""
      ],
      "importPath": "import { Field } from \"@chakra-ui/react\""
    },
    {
      "name": "field-with-required",
      "content": "export const FieldWithRequired = () => {\n  return (\n    <Field.Root required>\n      <Field.Label>\n        Email\n        <Field.RequiredIndicator />\n      </Field.Label>\n      <Input placeholder=\"me@example.com\" />\n    </Field.Root>\n  )\n}\n",
      "hasSnippet": false,
      "importPaths": [
        "import { Field, Input } from \"@chakra-ui/react\""
      ],
      "importPath": "import { Field } from \"@chakra-ui/react\""
    },
    {
      "name": "field-with-textarea",
      "content": "export const FieldWithTextarea = () => {\n  return (\n    <Field.Root>\n      <Field.Label>Email</Field.Label>\n      <Textarea placeholder=\"Email\" />\n    </Field.Root>\n  )\n}\n",
      "hasSnippet": false,
      "importPaths": [
        "import { Field, Textarea } from \"@chakra-ui/react\""
      ],
      "importPath": "import { Field } from \"@chakra-ui/react\""
    }
  ]
}