mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem We used to have a `_Shadcn_` suffix for all the shadcn form components because we also had `formik` form components. This is not needed anymore. ## Solution - Remove the suffix - Update all usages
109 lines
2.6 KiB
Plaintext
109 lines
2.6 KiB
Plaintext
---
|
|
title: Form Item Layout
|
|
description: A helper component that provides a layout for form items.
|
|
component: true
|
|
fragment: true
|
|
---
|
|
|
|
<ComponentPreview
|
|
name="form-item-layout-demo"
|
|
description="A helper component that provides a layout for form items."
|
|
peekCode
|
|
showDottedGrid
|
|
wide
|
|
/>
|
|
|
|
## Usage
|
|
|
|
This component is to help with the layout of form items. It automatically provides `FormItem`, `FormLabel`, `FormMessage` and `FormDescription`.
|
|
The styling and layout of these components can be customized by passing in the components as props.
|
|
|
|
The components that can be replaced in `react-hook-form` atoms are highlighted below:
|
|
|
|
```tsx showLineNumbers {1-2,6-8}
|
|
<FormItem>
|
|
<FormLabel>Username</FormLabel>
|
|
<FormControl>
|
|
<Input placeholder="shadcn" {...field} />
|
|
</FormControl>
|
|
<FormDescription>This is your public display name.</FormDescription>
|
|
<FormMessage />
|
|
</FormItem>
|
|
```
|
|
|
|
Using `FormItemLayout` it can look like this:
|
|
|
|
```tsx
|
|
<FormItemLayout label="Username" description="This is your public display name">
|
|
<FormControl>
|
|
<Input placeholder="mildtomato" {...field} />
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
```
|
|
|
|
Please note that you must still use `FormControl` to wrap input fields.
|
|
|
|
## Examples
|
|
|
|
## With Select component
|
|
|
|
<ComponentPreview
|
|
name="form-item-layout-with-select"
|
|
description="A helper component that provides a layout for form items."
|
|
showDottedGrid
|
|
/>
|
|
|
|
## Horizontal layout
|
|
|
|
This is useful for forms inside a `<SidePanel/>` / `<Sheet/>` component.
|
|
|
|
<ComponentPreview
|
|
name="form-item-layout-with-horizontal"
|
|
description="A helper component that provides a layout for form items."
|
|
showDottedGrid
|
|
/>
|
|
|
|
## With Switch component
|
|
|
|
<ComponentPreview
|
|
name="form-item-layout-with-switch"
|
|
description="A helper component that provides a layout for form items."
|
|
showDottedGrid
|
|
/>
|
|
|
|
## With Checkbox component
|
|
|
|
<ComponentPreview
|
|
name="form-item-layout-with-checkbox"
|
|
description="A helper component that provides a layout for form items."
|
|
showDottedGrid
|
|
/>
|
|
|
|
## List of items as Checkboxes
|
|
|
|
<ComponentPreview
|
|
name="form-item-layout-with-checkbox-list"
|
|
description="A helper component that provides a layout for form items."
|
|
showDottedGrid
|
|
/>
|
|
|
|
## Before label
|
|
|
|
You can insert any `React.Node` or string before the label using the `beforeLabel` prop.
|
|
|
|
<ComponentPreview
|
|
name="form-item-layout-before-label"
|
|
description="Insert react.node or string before the label."
|
|
showDottedGrid
|
|
/>
|
|
|
|
## After label
|
|
|
|
You can insert any `React.Node` or string after the label using the `afterLabel` prop.
|
|
|
|
<ComponentPreview
|
|
name="form-item-layout-after-label"
|
|
description="Insert react.node or string after the label."
|
|
showDottedGrid
|
|
/>
|