Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Feat/form item layout (#21835)

Jonathan Summers-Muird5765e712733
diff --git a/apps/storybook/.storybook/preview.css b/apps/storybook/.storybook/preview.css
index 4695f453f0e..04db23e32fc 100644
--- a/apps/storybook/.storybook/preview.css
+++ b/apps/storybook/.storybook/preview.css
@@ -96,7 +96,8 @@
html,
body,
#__next,
-.main {
+.main,
+.docs-story {
@apply bg-studio;
@apply text-foreground;
height: 100%;
diff --git a/packages/ui-patterns/DataInputs/Input.stories.tsx b/packages/ui-patterns/DataInputs/Input.stories.tsx
new file mode 100644
index 00000000000..1d98477c4e4
--- /dev/null
+++ b/packages/ui-patterns/DataInputs/Input.stories.tsx
@@ -0,0 +1,69 @@
+import { StoryObj } from '@storybook/react'
+import { Input } from './Input'
+import { User } from 'lucide-react'
+
+// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
+export default {
+ title: 'Data Inputs/Input',
+ component: Input,
+ parameters: {
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
+ layout: 'centered',
+ },
+ decorators: [
+ (Story: any) => {
+ return (
+ <div className="w-80">
+ <Story />
+ </div>
+ )
+ },
+ ],
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
+ tags: ['autodocs'],
+ // More on argTypes: https://storybook.js.org/docs/api/argtypes
+ // argTypes: {},
+}
+
+// export default meta
+
+type Story = StoryObj<typeof Input>
+
+export const Primary: Story = {
+ render: function Render(args) {
+ return <Input {...args} />
+ },
+ args: {
+ placeholder: 'mildtomato',
+ },
+}
+
+export const withIcon: Story = {
+ render: function Render(args) {
+ return <Input {...args} />
+ },
+ args: {
+ placeholder: 'mildtomato',
+ icon: <User className="text-foreground-muted" strokeWidth={1.5} size={21} />,
+ },
+}
+
+export const withCopy: Story = {
+ render: function Render(args) {
+ return <Input {...args} />
+ },
+ args: {
+ placeholder: 'mildtomato',
+ copy: true,
+ },
+}
+
+export const size: Story = {
+ render: function Render(args) {
+ return <Input {...args} />
+ },
+ args: {
+ placeholder: 'mildtomato',
+ size: 'small',
+ },
+}
diff --git a/packages/ui-patterns/DataInputs/Input.tsx b/packages/ui-patterns/DataInputs/Input.tsx
new file mode 100644
index 00000000000..bc0fec74765
--- /dev/null
+++ b/packages/ui-patterns/DataInputs/Input.tsx
@@ -0,0 +1,277 @@
+import { Copy } from 'lucide-react'
+import React, {
+ ComponentProps,
+ ComponentPropsWithoutRef,
+ ElementRef,
+ forwardRef,
+ useState,
+} from 'react'
+import { Button, Input_Shadcn_, cn } from 'ui'
+import styleHandler from 'ui/src/lib/theme/styleHandler'
+import InputIconContainer from '../form/Layout/InputIconContainer'
+
+export const HIDDEN_PLACEHOLDER = '**** **** **** ****'
+
+export interface Props extends Omit<ComponentProps<typeof Input_Shadcn_>, 'size' | 'onCopy'> {
+ copy?: boolean
+ onCopy?: () => void
+ icon?: any
+ reveal?: boolean
+ actions?: React.ReactNode
+ iconContainerClassName?: string
+ containerClassName?: string
+}
+
+const Input = forwardRef<
+ ElementRef<typeof Input_Shadcn_>,
+ ComponentPropsWithoutRef<typeof Input_Shadcn_> & Props
+>(
+ (
+ {
+ copy,
+ icon,
+ reveal = false,
+ actions,
+ onCopy,
+ iconContainerClassName,
+ containerClassName,
+ ...props
+ }: Props,
+ ref
+ ) => {
+ const [copyLabel, setCopyLabel] = useState('Copy')
+ const [hidden, setHidden] = useState(true)
+
+ const __styles = styleHandler('input')
+
+ function _onCopy(value: any) {
+ navigator.clipboard.writeText(value)?.then(
+ function () {
+ /* clipboard successfully set */
+ setCopyLabel('Copied')
+ setTimeout(function () {
+ setCopyLabel('Copy')
+ }, 3000)
+ onCopy?.()
+ },
+ function () {
+ /* clipboard write failed */
+ setCopyLabel('Failed to copy')
+ }
+ )
+ }
+
+ function onReveal() {
+ setHidden(false)
+ }
+
+ let inputClasses = []
+ if (icon) inputClasses.push(__styles.with_icon)
+
+ return (
+ <div className={cn('relative', containerClassName)}>
+ <Input_Shadcn_
+ ref={ref}
+ {...props}
+ onCopy={onCopy}
+ value={reveal && hidden ? HIDDEN_PLACEHOLDER : props.value}
+ className={cn(...inputClasses, props.className)}
+ />
+ {icon && <InputIconContainer icon={icon} className={iconContainerClassName} />}
+ {copy || actions ? (
+ <div className={__styles.actions_container}>
+ {/* {error && <InputErrorIcon size={size} />} */}
+ {copy && !(reveal && hidden) ? (
+ <Button
+ size="tiny"
+ type="default"
+ icon={<Copy size={16} className="text-foreground-muted" />}
+ onClick={() => _onCopy(props.value)}
+ >
+ {copyLabel}
+ </Button>
+ ) : null}
+ {reveal && hidden ? (
+ <Button size="tiny" type="default" onClick={onReveal}>
+ Reveal
+ </Button>
+ ) : null}
+ {actions && actions}
+ </div>
+ ) : null}
+ </div>
+ )
+ }
+)
+
+export { Input }
+
+// export interface TextAreaProps
+// extends Omit<React.InputHTMLAttributes<HTMLTextAreaElement>, 'size' | 'onCopy'> {
+// textAreaClassName?: string
+// descriptionText?: string | React.ReactNode | undefined
+// error?: string
+// icon?: any
+// label?: string | React.ReactNode
+// afterLabel?: string
+// beforeLabel?: string
+// labelOptional?: string | React.ReactNode
+// layout?: 'horizontal' | 'vertical'
+// rows?: number
+// limit?: number
+// size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge'
+// borderless?: boolean
+// validation?: (x: any) => void
+// copy?: boolean
+// onCopy?: () => void
+// actions?: React.ReactNode
+// }
+
+// function TextArea({
+// className,
+// textAreaClassName,
+// descriptionText,
+// disabled,
+// error,
+// icon,
+// id = '',
+// name = '',
+// label,
+// afterLabel,
+// beforeLabel,
+// labelOptional,
+// layout,
+// onChange,
+// onBlur,
+// placeholder,
+// value,
+// style,
+// rows = 4,
+// limit,
+// size,
+// borderless = false,
+// validation,
+// copy = false,
+// onCopy,
+// actions,
+// ...props
+// }: TextAreaProps) {
+// const [charLength, setCharLength] = useState(0)
+// const [copyLabel, setCopyLabel] = useState('Copy')
+
+// function _onCopy(value: any) {
+// navigator.clipboard.writeText(value).then(
+// function () {
+// /* clipboard successfully set */
+// setCopyLabel('Copied')
+// setTimeout(function () {
+// setCopyLabel('Copy')
+// }, 3000)
+// onCopy?.()
+// },
+// function () {
+// /* clipboard write failed */
+// setCopyLabel('Failed to copy')
+// }
+// )
+// }
+
+// const { formContextOnChange, values, errors, handleBlur, touched, fieldLevelValidation } =
+// useFormContext()
+
+// if (values && !value) value = values[id || name]
+
+// function handleBlurEvent(e: React.FocusEvent<HTMLTextAreaElement>) {
+// if (handleBlur) {
+// setTimeout(() => {
+// handleBlur(e)
+// }, 100)
+// }
+// if (onBlur) onBlur(e)
+// }
+
+// if (!error) {
+// if (errors && !error) error = errors[id || name]
+// error = touched && touched[id || name] ? error : undefined
+// }
+
+// function onInputChange(e: React.ChangeEvent<HTMLTextAreaElement>) {
+// setCharLength(e.target.value.length)
+// if (onChange) onChange(e)
+// // update form
+// if (formContextOnChange) formContextOnChange(e)
+// // run field level validation
+// if (validation) fieldLevelValidation(id, validation(e.target.value))
+// }
+
+// useEffect(() => {
+// if (validation) fieldLevelValidation(id, validation(value))
+// }, [])
+
+// const __styles = styleHandler('input')
+
+// let classes = [__styles.base]
+
+// if (error) classes.push(__styles.variants.error)
+// if (!error) classes.push(__styles.variants.standard)
+// if (icon) classes.push(__styles.with_icon)
+// if (size) classes.push(__styles.size[size])
+// if (disabled) classes.push(__styles.disabled)
+// if (textAreaClassName) classes.push(textAreaClassName)
+
+// return (
+// <FormLayout
+// className={className}
+// label={label}
+// afterLabel={afterLabel}
+// beforeLabel={beforeLabel}
+// labelOptional={labelOptional}
+// layout={layout}
+// id={id}
+// error={error}
+// descriptionText={descriptionText}
+// style={style}
+// size={size}
+// >
+// <div className={__styles.container}>
+// <textarea
+// disabled={disabled}
+// id={id}
+// name={name}
+// rows={rows}
+// cols={100}
+// placeholder={placeholder}
+// onChange={onInputChange}
+// onBlur={handleBlurEvent}
+// onCopy={onCopy}
+// value={value}
+// className={classes.join(' ')}
+// maxLength={limit}
+// {...props}
+// />
+// {copy || error || actions ? (
+// <div className={__styles['textarea_actions_container']}>
+// <div className={__styles['textarea_actions_container_items']}>
+// {error && <InputErrorIcon size={size} />}
+// {copy && (
+// <Button
+// size="tiny"
+// type="default"
+// onClick={() => _onCopy(value)}
+// icon={<IconCopy />}
+// >
+// {copyLabel}
+// </Button>
+// )}
+// {actions && actions}
+// </div>
+// </div>
+// ) : null}
+// </div>
+// </FormLayout>
+// )
+// }
+
+// Input.TextArea = TextArea
+
+// export default Input
diff --git a/packages/ui-patterns/Dialogs/TextConfirmModal.stories.tsx b/packages/ui-patterns/Dialogs/TextConfirmModal.stories.tsx
index 7bc83779149..fa44e42f131 100644
--- a/packages/ui-patterns/Dialogs/TextConfirmModal.stories.tsx
+++ b/packages/ui-patterns/Dialogs/TextConfirmModal.stories.tsx
@@ -5,7 +5,7 @@ import TextConfirmModal from './TextConfirmModal'
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
export default {
- title: 'Dialog Patterns/TextConfirmModal',
+ title: 'Dialogs/TextConfirmModal',
component: TextConfirmModal,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
diff --git a/packages/ui-patterns/InfoTooltip/InfoTooltip.tsx b/packages/ui-patterns/InfoTooltip/InfoTooltip.tsx
new file mode 100644
index 00000000000..a712a069192
--- /dev/null
+++ b/packages/ui-patterns/InfoTooltip/InfoTooltip.tsx
@@ -0,0 +1,34 @@
+import { ElementRef, forwardRef } from 'react'
+import { TooltipContent_Shadcn_, TooltipTrigger_Shadcn_, Tooltip_Shadcn_ } from 'ui'
+
+const SVG = forwardRef<SVGSVGElement, React.SVGProps<SVGSVGElement>>((props, ref) => (
+ <svg
+ ref={ref}
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 16 16"
+ fill="currentColor"
+ {...props}
+ >
+ <path
+ fill-rule="evenodd"
+ d="M15 8A7 7 0 1 1 1 8a7 7 0 0 1 14 0ZM9 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0ZM6.75 8a.75.75 0 0 0 0 1.5h.75v1.75a.75.75 0 0 0 1.5 0v-2.5A.75.75 0 0 0 8.25 8h-1.5Z"
+ clip-rule="evenodd"
+ />
+ </svg>
+))
+
+const InfoTooltip = forwardRef<
+ ElementRef<typeof TooltipContent_Shadcn_>,
+ React.ComponentPropsWithoutRef<typeof TooltipContent_Shadcn_>
+>(({ ...props }, ref) => {
+ return (
+ <Tooltip_Shadcn_>
+ <TooltipTrigger_Shadcn_ className="flex [&_svg]:data-[state=delayed-open]:fill-foreground-lighter [&_svg]:data-[state=instant-open]:fill-foreground-lighter">
+ <SVG strokeWidth={2} className="transition-colors fill-foreground-muted w-4 h-4" />
+ </TooltipTrigger_Shadcn_>
+ <TooltipContent_Shadcn_ {...props} />
+ </Tooltip_Shadcn_>
+ )
+})
+
+export { InfoTooltip }
diff --git a/packages/ui-patterns/InnerSideMenu/index.tsx b/packages/ui-patterns/InnerSideMenu/index.tsx
index 1fbbe7f89a8..07958e3352f 100644
--- a/packages/ui-patterns/InnerSideMenu/index.tsx
+++ b/packages/ui-patterns/InnerSideMenu/index.tsx
@@ -106,7 +106,7 @@ const InnerSideBarFilters = forwardRef<HTMLDivElement, React.ComponentPropsWitho
const InnerSideBarFilterSearchInput = forwardRef<
HTMLInputElement,
- React.ComponentPropsWithoutRef<'input'> & { 'aria-labelledby': string; name: string }
+ React.ComponentPropsWithoutRef<typeof Input_Shadcn_> & { 'aria-labelledby': string; name: string }
>(({ children, ...props }, ref) => {
return (
<label htmlFor={props.name} className="relative w-full">
diff --git a/packages/ui-patterns/form/FormItemLayout/FormItemLayout.stories.tsx b/packages/ui-patterns/form/FormItemLayout/FormItemLayout.stories.tsx
new file mode 100644
index 00000000000..ec47d60ea55
--- /dev/null
+++ b/packages/ui-patterns/form/FormItemLayout/FormItemLayout.stories.tsx
@@ -0,0 +1,295 @@
+import { zodResolver } from '@hookform/resolvers/zod'
+import { StoryContext, StoryObj } from '@storybook/react'
+import { useForm } from 'react-hook-form'
+import {
+ Button,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ FormItem_Shadcn_,
+ Form_Shadcn_,
+ PopoverContent_Shadcn_,
+ PopoverTrigger_Shadcn_,
+ Popover_Shadcn_,
+ SelectContent_Shadcn_,
+ SelectItem_Shadcn_,
+ SelectTrigger_Shadcn_,
+ SelectValue_Shadcn_,
+ Select_Shadcn_,
+ Calendar,
+ cn,
+} from 'ui'
+import { z } from 'zod'
+import { transformSourceForm } from '../../lib/transformSource'
+import { FormItemLayout } from './FormItemLayout'
+import { Input } from '../../DataInputs/Input'
+import { Calendar as CalendarIcon } from 'lucide-react'
+import { format } from 'date-fns'
+
+// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
+export default {
+ title: 'Form/FormItemLayout',
+ component: FormItemLayout,
+ decorators: [
+ (Story: any) => {
+ return <Story />
+ },
+ ],
+ parameters: {
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
+ layout: 'centered',
+ docs: {
+ // controls: { exclude: ['style'] },
+ source: {
+ language: 'tsx',
+ transform: (code: string, StoryContext: StoryContext) =>
+ transformSourceForm(code, StoryContext).replace('_c', 'FormInput'),
+ },
+ },
+ },
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
+ tags: ['autodocs'],
+ // More on argTypes: https://storybook.js.org/docs/api/argtypes
+ // argTypes: {},
+}
+
+type Story = StoryObj<typeof FormItemLayout>
+
+export const Primary: Story = {
+ render: function Render(args) {
+ const formSchema = z.object({
+ username: z.string().min(2, {
+ message: 'Username must be at least 2 characters.',
+ }),
+ })
+
+ // 1. Define your form.
+ const form = useForm<z.infer<typeof formSchema>>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ username: '',
+ },
+ })
+
+ // 2. Define a submit handler.
+ function onSubmit(values: z.infer<typeof formSchema>) {
+ // Do something with the form values.
+ // ✅ This will be type-safe and validated.
+ console.log(values)
+ // action('form form.handleSubmit(onSubmit)')(values)
+ }
+ return (
+ <Form_Shadcn_ {...form}>
+ <form className="w-96 flex flex-col gap-3" onSubmit={form.handleSubmit(onSubmit)}>
+ <FormField_Shadcn_
+ name="username"
+ control={form.control}
+ render={({ field }) => (
+ <FormItem_Shadcn_>
+ <FormItemLayout {...args}>
+ <FormControl_Shadcn_>
+ <Input placeholder="mildtomato" {...field} />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ </FormItem_Shadcn_>
+ )}
+ />
+ <Button size="small" type="primary" htmlType="submit">
+ Submit
+ </Button>
+ </form>
+ </Form_Shadcn_>
+ )
+ },
+ args: {
+ label: 'Username',
+ description: 'this is the description',
+ labelOptional: 'optional',
+ placeholder: 'shadcn',
+ },
+}
+
+export const withSelect: Story = {
+ render: function Render(args) {
+ const FormSchema = z.object({
+ email: z
+ .string({
+ required_error: 'Please select an email to display.',
+ })
+ .email(),
+ })
+
+ const form = useForm<z.infer<typeof FormSchema>>({
+ resolver: zodResolver(FormSchema),
+ })
+
+ // 2. Define a submit handler.
+ function onSubmit(values: z.infer<typeof FormSchema>) {
+ // Do something with the form values.
+ // ✅ This will be type-safe and validated.
+ console.log(values)
+ // action('form form.handleSubmit(onSubmit)')(values)
+ }
+
+ return (
+ <Form_Shadcn_ {...form}>
+ <form className="w-96 flex flex-col gap-3" onSubmit={form.handleSubmit(onSubmit)}>
+ <FormField_Shadcn_
+ name="email"
+ control={form.control}
+ render={({ field }) => (
+ <FormItemLayout {...args}>
+ <FormItem_Shadcn_>
+ <Select_Shadcn_ onValueChange={field.onChange} defaultValue={field.value}>
+ <FormControl_Shadcn_>
+ <SelectTrigger_Shadcn_>
+ <SelectValue_Shadcn_ placeholder="Select a verified email to display" />
+ </SelectTrigger_Shadcn_>
+ </FormControl_Shadcn_>
+ <SelectContent_Shadcn_>
+ <SelectItem_Shadcn_ value="[email protected]">[email protected]</SelectItem_Shadcn_>
+ <SelectItem_Shadcn_ value="[email protected]">[email protected]</SelectItem_Shadcn_>
+ <SelectItem_Shadcn_ value="[email protected]">[email protected]</SelectItem_Shadcn_>
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ </FormItem_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ <Button size="small" type="primary" htmlType="submit">
+ Submit
+ </Button>
+ </form>
+ </Form_Shadcn_>
+ )
+ },
+ args: {
+ label: 'Username',
+ description: 'this is the description',
+ labelOptional: 'optional',
+ placeholder: 'shadcn',
+ },
+}
+
+export const withLayoutChange: Story = {
+ render: function Render(args) {
+ const formSchema = z.object({
+ username: z.string().min(2, {
+ message: 'Username must be at least 2 characters.',
+ }),
+ })
+
+ // 1. Define your form.
+ const form = useForm<z.infer<typeof formSchema>>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ username: '',
+ },
+ })
+
+ // 2. Define a submit handler.
+ function onSubmit(values: z.infer<typeof formSchema>) {
+ // Do something with the form values.
+ // ✅ This will be type-safe and validated.
+ console.log(values)
+ // action('form form.handleSubmit(onSubmit)')(values)
+ }
+ return (
+ <Form_Shadcn_ {...form}>
+ <form className="w-[520px] flex flex-col gap-8" onSubmit={form.handleSubmit(onSubmit)}>
+ <FormField_Shadcn_
+ name="username"
+ control={form.control}
+ render={({ field }) => (
+ <FormItemLayout {...args}>
+ <FormItem_Shadcn_>
+ <FormControl_Shadcn_>
+ <Input placeholder="mildtomato" {...field} />
+ </FormControl_Shadcn_>
+ </FormItem_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ <Button size="small" type="primary" htmlType="submit">
+ Submit
+ </Button>
+ </form>
+ </Form_Shadcn_>
+ )
+ },
+ args: {
+ layout: 'horizontal',
+ label: 'Username',
+ description: 'this is the description',
+ labelOptional: 'optional',
+ placeholder: 'shadcn',
+ },
+}
+
+export const withCalendar: Story = {
+ render: function Render(args) {
+ const FormSchema = z.object({
+ dob: z.date({
+ required_error: 'A date of birth is required.',
+ }),
+ })
+
+ const form = useForm<z.infer<typeof FormSchema>>({
+ resolver: zodResolver(FormSchema),
+ })
+ // 2. Define a submit handler.
+ function onSubmit(values: z.infer<typeof FormSchema>) {
+ // Do something with the form values.
+ // ✅ This will be type-safe and validated.
+ console.log(values)
+ // action('form form.handleSubmit(onSubmit)')(values)
+ }
+ return (
+ <Form_Shadcn_ {...form}>
+ <form className="w-[280px] flex flex-col gap-8" onSubmit={form.handleSubmit(onSubmit)}>
+ <FormField_Shadcn_
+ name="dob"
+ control={form.control}
+ render={({ field }) => (
+ <FormItemLayout {...args}>
+ <FormItem_Shadcn_ className="flex flex-col">
+ <Popover_Shadcn_>
+ <PopoverTrigger_Shadcn_ asChild>
+ <FormControl_Shadcn_>
+ <Button
+ icon={<CalendarIcon className="text-foreground-muted" size={16} />}
+ type={'default'}
+ className={cn(!field.value && 'text-muted-foreground', 'justify-start')}
+ >
+ {field.value ? format(field.value, 'PPP') : <span>Pick a date</span>}
+ </Button>
+ </FormControl_Shadcn_>
+ </PopoverTrigger_Shadcn_>
+ <PopoverContent_Shadcn_ className="w-auto p-0" align="start">
+ <Calendar
+ mode="single"
+ selected={field.value}
+ onSelect={field.onChange}
+ disabled={(date) => date > new Date() || date < new Date('1900-01-01')}
+ initialFocus
+ />
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
+ </FormItem_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ <Button size="small" type="primary" htmlType="submit">
+ Submit
+ </Button>
+ </form>
+ </Form_Shadcn_>
+ )
+ },
+ args: {
+ layout: 'vertical',
+ label: 'Date of birth',
+ description: 'Your date of birth is used to calculate your age.',
+ labelOptional: 'optional',
+ placeholder: 'shadcn',
+ },
+}
diff --git a/packages/ui-patterns/form/FormItemLayout/FormItemLayout.tsx b/packages/ui-patterns/form/FormItemLayout/FormItemLayout.tsx
new file mode 100644
index 00000000000..908c7d60aac
--- /dev/null
+++ b/packages/ui-patterns/form/FormItemLayout/FormItemLayout.tsx
@@ -0,0 +1,20 @@
+import { ElementRef, forwardRef } from 'react'
+import { FormItem_Shadcn_ } from 'ui'
+import { FormLayout } from '../Layout/FormLayout'
+
+const FormItemLayout = forwardRef<
+ ElementRef<typeof FormLayout>,
+ React.ComponentPropsWithoutRef<typeof FormLayout> // Use any as placeholder types
+>(({ ...props }, ref) => {
+ return (
+ <FormItem_Shadcn_>
+ <FormLayout ref={ref} isReactForm {...props}>
+ {props.children}
+ </FormLayout>
+ </FormItem_Shadcn_>
+ )
+})
+
+FormItemLayout.displayName = 'FormItemLayout'
+
+export { FormItemLayout }
diff --git a/packages/ui-patterns/form/FormLayout.tsx b/packages/ui-patterns/form/FormLayout.tsx
new file mode 100644
index 00000000000..15f37d21eac
--- /dev/null
+++ b/packages/ui-patterns/form/FormLayout.tsx
@@ -0,0 +1,358 @@
+import { zodResolver } from '@hookform/resolvers/zod'
+import { Box, FileWarning } from 'lucide-react'
+import { useForm } from 'react-hook-form'
+import {
+ Badge_Shadcn_,
+ Button,
+ Checkbox_Shadcn_,
+ Form_Shadcn_,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ RadioGroup_Shadcn_,
+ RadioGroupItem_Shadcn_,
+ Select_Shadcn_,
+ SelectContent_Shadcn_,
+ SelectItem_Shadcn_,
+ SelectTrigger_Shadcn_,
+ SelectValue_Shadcn_,
+ Separator,
+ Switch,
+} from 'ui'
+import { z } from 'zod'
+import { Input } from '../DataInputs/Input'
+import { InfoTooltip } from '../InfoTooltip/InfoTooltip'
+import { FormItemLayout } from './FormItemLayout/FormItemLayout'
+
+const items = [
+ {
+ id: 'recents',
+ label: 'Recents',
+ },
+ {
+ id: 'home',
+ label: 'Home',
+ },
+ {
+ id: 'applications',
+ label: 'Applications',
+ },
+ {
+ id: 'desktop',
+ label: 'Desktop',
+ },
+ {
+ id: 'downloads',
+ label: 'Downloads',
+ },
+ {
+ id: 'documents',
+ label: 'Documents',
+ },
+] as const
+
+export const Page = () => {
+ const FormSchema = z.object({
+ username: z.string().min(2, {
+ message: 'Username must be at least 2 characters.',
+ }),
+ kevins_input: z.string().min(6, {
+ message: 'Username must be at least 6 characters.',
+ }),
+ email: z
+ .string({
+ required_error: 'Please select an email to display.',
+ })
+ .email(),
+ consistent_settings: z.boolean().default(false).optional(),
+ switch_option: z.boolean().default(false).optional(),
+ items: z.array(z.string()).refine((value) => value.some((item) => item), {
+ message: 'You have to select at least one item.',
+ }),
+ type: z.enum(['all', 'mentions', 'none'], {
+ required_error: 'You need to select a notification type.',
+ }),
+ })
+
+ const form = useForm<z.infer<typeof FormSchema>>({
+ resolver: zodResolver(FormSchema),
+ defaultValues: {
+ username: '',
+ items: ['recents', 'home'],
+ },
+ })
+
+ function onSubmit(data: z.infer<typeof FormSchema>) {
+ console.log(data)
+ }
+
+ const UserIcon = () => {
+ return (
+ <div>
+ <img
+ className="relative h-4 w-4 rounded-full"
+ src="https://avatars.githubusercontent.com/u/8291514?v=4"
+ />
+ </div>
+ )
+ }
+
+ return (
+ <Form_Shadcn_ {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)} className="w-[420px] flex flex-col gap-8">
+ <div>
+ <h1 className="text-foreground">Welcome</h1>
+ <p className="text-foreground-light">Please fill in the following</p>
+ </div>
+
+ <Separator />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="username"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Function name"
+ description="This is your public display name."
+ layout="horizontal"
+ labelOptional="Optional"
+ afterLabel={<InfoTooltip side="right">You can also rename this later.</InfoTooltip>}
+ >
+ <FormControl_Shadcn_>
+ <Input
+ icon={<Box strokeWidth={1.5} size={16} />}
+ placeholder="mildtomato"
+ {...field}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <Separator />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="switch_option"
+ render={({ field }) => (
+ <FormItemLayout
+ afterLabel="Switch"
+ label="Use ./supabase directory for everything"
+ description="This is an explanation."
+ layout="flex"
+ >
+ <FormControl_Shadcn_>
+ <Switch
+ placeholder="mildtomato"
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <Separator />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="email"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Choose user"
+ description="This is your public display name."
+ layout="horizontal"
+ >
+ <Select_Shadcn_ onValueChange={field.onChange} defaultValue={field.value}>
+ <FormControl_Shadcn_ className="w-full">
+ <SelectTrigger_Shadcn_ className="w-full">
+ <SelectValue_Shadcn_
+ placeholder="Select a verified email"
+ className="flex gap-2"
+ />
+ </SelectTrigger_Shadcn_>
+ </FormControl_Shadcn_>
+ <SelectContent_Shadcn_>
+ <SelectItem_Shadcn_ value="[email protected]">
+ <div className="flex gap-2 items-center">
+ <UserIcon />
+ <span>[email protected]</span>
+ </div>
+ </SelectItem_Shadcn_>
+ <SelectItem_Shadcn_ value="[email protected]" className="flex gap-2">
+ <div className="flex gap-2 items-center">
+ <UserIcon />
+ </div>
+ </SelectItem_Shadcn_>
+ <SelectItem_Shadcn_ value="[email protected]" className="flex gap-2">
+ <div className="flex gap-2 items-center">
+ <UserIcon />
+ </div>
+ </SelectItem_Shadcn_>
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <Separator />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="kevins_input"
+ render={({ field }) => (
+ <FormItemLayout
+ afterLabel="Kevins input"
+ label="Kevins input"
+ description="This is your public display name."
+ layout="vertical"
+ labelOptional="Optional"
+ >
+ <FormControl_Shadcn_>
+ <Input
+ icon={<Box strokeWidth={1.5} size={16} />}
+ placeholder="Needs to be 6 long"
+ {...field}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <Separator />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="consistent_settings"
+ render={({ field }) => (
+ <FormItemLayout
+ afterLabel={
+ <Badge_Shadcn_ variant={'destructive'} className="flex gap-1">
+ <FileWarning size={14} strokeWidth={1.5} className="text-destructive-500" />
+ Danger zone!
+ </Badge_Shadcn_>
+ }
+ label="Use consistent settings"
+ description="This is your public display name."
+ layout="flex"
+ >
+ <FormControl_Shadcn_>
+ <Checkbox_Shadcn_ checked={field.value} onCheckedChange={field.onChange} />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <Separator />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="items"
+ render={() => (
+ <FormItemLayout
+ label="Sidebar"
+ description="Select the items you want to display in the sidebar."
+ layout="horizontal"
+ afterLabel={<InfoTooltip side="right">Please give me info</InfoTooltip>}
+ >
+ {/* <div className="mb-4">
+ <FormLabel className="text-base">Sidebar</FormLabel>
+ <FormDescription>
+ Select the items you want to display in the sidebar.
+ </FormDescription>
+ </div> */}
+ {items.map((item) => (
+ <FormField_Shadcn_
+ key={item.id}
+ control={form.control}
+ name="items"
+ render={({ field }) => {
+ return (
+ <FormItemLayout
+ key={item.id}
+ className="flex flex-row items-start space-x-3 space-y-0"
+ label={item.label}
+ layout="flex"
+ hideMessage
+ >
+ <FormControl_Shadcn_>
+ <Checkbox_Shadcn_
+ checked={field.value?.includes(item.id)}
+ onCheckedChange={(checked) => {
+ return checked
+ ? field.onChange([...field.value, item.id])
+ : field.onChange(field.value?.filter((value) => value !== item.id))
+ }}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )
+ }}
+ />
+ ))}
+ {/* <FormMessage /> */}
+ </FormItemLayout>
+ )}
+ />
+
+ <FormField_Shadcn_
+ control={form.control}
+ name="type"
+ render={({ field }) => (
+ <FormItemLayout
+ className="space-y-3"
+ label="Notify me about..."
+ description="I am descript"
+ layout="horizontal"
+ >
+ <FormControl_Shadcn_>
+ <RadioGroup_Shadcn_
+ onValueChange={field.onChange}
+ defaultValue={field.value}
+ className="flex flex-col space-y-1"
+ >
+ <FormItemLayout
+ className="flex items-center space-x-3 space-y-0"
+ label="All new messages"
+ layout="flex"
+ hideMessage
+ >
+ <FormControl_Shadcn_>
+ <RadioGroupItem_Shadcn_ value="all" />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ <FormItemLayout
+ className="flex items-center space-x-3 space-y-0"
+ label="Direct messages and mentions"
+ layout="flex"
+ hideMessage
+ >
+ <FormControl_Shadcn_>
+ <RadioGroupItem_Shadcn_ value="mentions" />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ <FormItemLayout
+ className="flex items-center space-x-3 space-y-0"
+ label="Nothing"
+ layout="flex"
+ hideMessage
+ >
+ <FormControl_Shadcn_>
+ <RadioGroupItem_Shadcn_ value="none" />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ </RadioGroup_Shadcn_>
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <Separator />
+ <div className="flex flex-row w-full justify-end">
+ <Button htmlType="submit">Submit</Button>
+ </div>
+ </form>
+ </Form_Shadcn_>
+ )
+}
diff --git a/packages/ui-patterns/form/Layout/FormLayout.tsx b/packages/ui-patterns/form/Layout/FormLayout.tsx
new file mode 100644
index 00000000000..2805b481748
--- /dev/null
+++ b/packages/ui-patterns/form/Layout/FormLayout.tsx
@@ -0,0 +1,401 @@
+import { cva } from 'class-variance-authority'
+import React from 'react'
+import {
+ FormDescription_Shadcn_,
+ FormLabel_Shadcn_,
+ FormMessage_Shadcn_,
+ Label_Shadcn_,
+ cn,
+} from 'ui'
+import { SIZE } from 'ui/src/lib/constants'
+
+type Props = {
+ align?: 'left' | 'right'
+ description?: string | React.ReactNode
+ error?: string | React.ReactNode
+ label?: string | React.ReactNode
+ labelOptional?: string | React.ReactNode
+ layout?: 'horizontal' | 'vertical' | 'flex'
+ size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge'
+ beforeLabel?: string | React.ReactNode
+ afterLabel?: string | React.ReactNode
+ nonBoxInput?: boolean
+ labelLayout?: 'horizontal' | 'vertical'
+ isReactForm?: boolean
+ hideMessage?: boolean
+ name?: string
+}
+
+const ContainerVariants = cva('grid gap-2', {
+ variants: {
+ size: {
+ tiny: 'text-xs',
+ small: 'text-sm leading-4',
+ medium: 'text-sm',
+ large: 'text-base',
+ xlarge: 'text-base',
+ },
+ align: { left: '', right: '' },
+ responsive: {
+ true: '',
+ false: '',
+ },
+ layout: {
+ horizontal: 'flex flex-row gap-6 justify-between',
+ vertical: 'flex flex-col gap-3',
+ flex: 'flex flex-row gap-3',
+ },
+ flex: {
+ true: '',
+ false: '',
+ },
+ },
+ compoundVariants: [
+ {
+ layout: 'flex',
+ align: 'right',
+ className: 'justify-between',
+ },
+ ],
+ defaultVariants: {},
+})
+
+const LabelContainerVariants = cva('', {
+ variants: {
+ flex: {
+ true: '',
+ false: '',
+ },
+ align: {
+ left: '',
+ right: '',
+ },
+ layout: {
+ horizontal: 'flex flex-col gap-2',
+ vertical: 'flex flex-row gap-2 justify-between',
+ flex: 'flex flex-col gap-0',
+ },
+ labelLayout: {
+ horizontal: '',
+ vertical: '',
+ ['']: '',
+ },
+ },
+ compoundVariants: [
+ {
+ flex: true,
+ align: 'left',
+ className: 'order-2',
+ },
+ {
+ flex: true,
+ align: 'right',
+ className: 'order-1',
+ },
+ {
+ layout: 'vertical' || 'flex',
+ labelLayout: undefined,
+ flex: false,
+ className: 'flex flex-row gap-2 justify-between',
+ },
+
+ {
+ layout: 'horizontal',
+ className: 'flex flex-col gap-2',
+ },
+ ],
+ defaultVariants: {},
+})
+
+const DataContainerVariants = cva('', {
+ variants: {
+ flex: {
+ true: '',
+ false: '',
+ },
+ align: {
+ left: 'order-1',
+ right: 'order-2',
+ },
+ layout: {
+ horizontal: '',
+ vertical: '',
+ flex: '',
+ },
+ },
+ compoundVariants: [
+ {
+ flex: true,
+ align: 'left',
+ className: 'order-1',
+ },
+ {
+ flex: true,
+ align: 'right',
+ className: 'order-2',
+ },
+ {
+ layout: 'vertical' || 'flex',
+ className: 'col-span-12',
+ },
+ {
+ layout: 'horizontal',
+ align: 'left',
+ className: 'col-span-8',
+ },
+ {
+ layout: 'horizontal',
+ align: 'right',
+ className: 'text-right',
+ },
+ ],
+ defaultVariants: {},
+})
+
+const DescriptionVariants = cva('text-foreground-lighter leading-normal', {
+ variants: {
+ size: {
+ ...SIZE.text,
+ },
+ layout: {
+ vertical: 'mt-2',
+ horizontal: 'mt-2',
+ flex: '',
+ },
+ },
+ defaultVariants: {},
+})
+
+const LabelBeforeVariants = cva('text-foreground-muted', {
+ variants: {
+ size: {
+ ...SIZE.text,
+ },
+ },
+ defaultVariants: {},
+})
+
+const LabelAfterVariants = cva('text-foreground-muted', {
+ variants: {
+ size: {
+ ...SIZE.text,
+ },
+ },
+ defaultVariants: {},
+})
+
+const LabelOptionalVariants = cva('text-foreground-muted', {
+ variants: {
+ size: {
+ ...SIZE.text,
+ },
+ },
+ defaultVariants: {},
+})
+
+const FlexContainer = cva('', {
+ variants: {
+ flex: {
+ true: '',
+ false: '',
+ },
+ align: {
+ left: '',
+ right: '',
+ },
+ },
+ compoundVariants: [
+ {
+ flex: true,
+ align: 'left',
+ className: '',
+ },
+ {
+ flex: true,
+ align: 'right',
+ className: 'order-last',
+ },
+ ],
+})
+
+const NonBoxInputContainer = cva('', {
+ variants: {
+ nonBoxInput: {
+ true: '',
+ false: '',
+ },
+ label: {
+ true: '',
+ false: '',
+ },
+ layout: {
+ vertical: '',
+ horizontal: '',
+ },
+ },
+ compoundVariants: [
+ {
+ nonBoxInput: true,
+ label: true,
+ layout: 'vertical',
+ className: 'my-3',
+ },
+ {
+ nonBoxInput: true,
+ label: true,
+ layout: 'horizontal',
+ className: 'my-3 md:mt-0 mb-3',
+ },
+ ],
+ defaultVariants: {},
+})
+
+export const FormLayout = React.forwardRef<
+ HTMLDivElement,
+ React.ComponentPropsWithoutRef<'div'> & Props
+>(
+ (
+ {
+ align = 'left',
+ className,
+ description,
+ id,
+ label,
+ labelOptional,
+ layout = 'vertical',
+ style,
+ labelLayout,
+ size = 'medium',
+ beforeLabel,
+ afterLabel,
+ nonBoxInput = label ? false : true,
+ hideMessage = false,
+ isReactForm,
+ ...props
+ },
+ ref
+ ) => {
+ const flex = layout === 'flex'
+ const hasLabel = Boolean(label || beforeLabel || afterLabel)
+ const renderError = isReactForm && !hideMessage && (
+ <FormMessage_Shadcn_ className="mt-2" data-formlayout-id={'message'} />
+ )
+
+ const renderDescription =
+ description && isReactForm ? (
+ <FormDescription_Shadcn_
+ className={cn(DescriptionVariants({ size, layout }))}
+ data-formlayout-id={'description'}
+ id={id + '-description'}
+ >
+ {description}
+ </FormDescription_Shadcn_>
+ ) : (
+ <p
+ className={cn(DescriptionVariants({ size, layout }), 'text-sm text-foreground-light')}
+ data-formlayout-id={'description'}
+ >
+ {description}
+ </p>
+ )
+
+ const LabelContents = () => (
+ <>
+ {beforeLabel && (
+ <span
+ className={cn(LabelBeforeVariants({ size }))}
+ id={id + '-before'}
+ data-formlayout-id={'beforeLabel'}
+ >
+ {beforeLabel}
+ </span>
+ )}
+ {label}
+ {afterLabel && (
+ <span
+ className={cn(LabelAfterVariants({ size }))}
+ id={id + '-after'}
+ data-formlayout-id={'afterLabel'}
+ >
+ {afterLabel}
+ </span>
+ )}
+ </>
+ )
+
+ return (
+ <div
+ ref={ref}
+ {...props}
+ className={cn(ContainerVariants({ size, flex, align, layout }), className)}
+ >
+ {flex && <div className={cn(FlexContainer({ flex, align }))}>{props.children}</div>}
+ {hasLabel || labelOptional || layout === 'horizontal' ? (
+ <>
+ <div
+ className={cn(LabelContainerVariants({ align, labelLayout, flex, layout }))}
+ data-formlayout-id={'labelContainer'}
+ >
+ {hasLabel && isReactForm ? (
+ <FormLabel_Shadcn_
+ className="flex gap-2 items-center"
+ data-formlayout-id={'formLabel'}
+ >
+ <LabelContents />
+ </FormLabel_Shadcn_>
+ ) : (
+ <Label_Shadcn_
+ htmlFor={props.name}
+ data-formlayout-id={'label'}
+ className="flex gap-2 items-center"
+ >
+ <LabelContents />
+ </Label_Shadcn_>
+ )}
+ {labelOptional && (
+ <span
+ className={cn(LabelOptionalVariants({ size }))}
+ id={id + '-optional'}
+ data-formlayout-id={'labelOptional'}
+ >
+ {labelOptional}
+ </span>
+ )}
+ {flex && (
+ <>
+ {renderDescription}
+ {renderError}
+ </>
+ )}
+ </div>
+ </>
+ ) : null}
+ {!flex && (
+ <div
+ className={cn(DataContainerVariants({ align, layout }))}
+ style={style}
+ data-formlayout-id={'dataContainer'}
+ >
+ <>
+ <div
+ className={cn(
+ NonBoxInputContainer({
+ nonBoxInput,
+ // @ts-expect-error
+ label,
+ layout,
+ })
+ )}
+ data-formlayout-id={'nonBoxInputContainer'}
+ >
+ {props.children}
+ </div>
+ {renderError}
+ {renderDescription}
+ </>
+ </div>
+ )}
+ </div>
+ )
+ }
+)
diff --git a/packages/ui-patterns/form/Layout/InputIconContainer.module.css b/packages/ui-patterns/form/Layout/InputIconContainer.module.css
new file mode 100644
index 00000000000..4b0df33466a
--- /dev/null
+++ b/packages/ui-patterns/form/Layout/InputIconContainer.module.css
@@ -0,0 +1,6 @@
+.sbui-input-icon-container {
+ @apply absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none;
+ /* set the default color of the icon */
+ @apply text-gray-600;
+ @apply dark:text-white;
+}
diff --git a/packages/ui-patterns/form/Layout/InputIconContainer.tsx b/packages/ui-patterns/form/Layout/InputIconContainer.tsx
new file mode 100644
index 00000000000..6ab29b6260d
--- /dev/null
+++ b/packages/ui-patterns/form/Layout/InputIconContainer.tsx
@@ -0,0 +1,14 @@
+import { cn } from 'ui'
+
+export default function InputIconContainer({ icon, className }: any) {
+ return (
+ <div
+ className={cn(
+ 'absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none text-foreground-light',
+ className
+ )}
+ >
+ {icon}
+ </div>
+ )
+}
diff --git a/packages/ui-patterns/form/Page.stories.tsx b/packages/ui-patterns/form/Page.stories.tsx
new file mode 100644
index 00000000000..345c32effb3
--- /dev/null
+++ b/packages/ui-patterns/form/Page.stories.tsx
@@ -0,0 +1,37 @@
+// import { within, userEvent, expect } from '@storybook/test'
+import { TooltipProvider_Shadcn_ } from 'ui'
+import { Page } from './FormLayout'
+
+export default {
+ title: 'Form Examples/One',
+ component: Page,
+ parameters: {
+ // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
+ layout: 'centered',
+ },
+ decorators: [
+ (Story: any) => {
+ return (
+ <TooltipProvider_Shadcn_>
+ <Story />
+ </TooltipProvider_Shadcn_>
+ )
+ },
+ ],
+}
+
+export const StateOne = {}
+
+// More on interaction testing: https://storybook.js.org/docs/writing-tests/interaction-testing
+// export const LoggedIn = {
+// play: async ({ canvasElement }) => {
+// const canvas = within(canvasElement)
+// const loginButton = canvas.getByRole('button', { name: /Log in/i })
+// await expect(loginButton).toBeInTheDocument()
+// await userEvent.click(loginButton)
+// await expect(loginButton).not.toBeInTheDocument()
+
+// const logoutButton = canvas.getByRole('button', { name: /Log out/i })
+// await expect(logoutButton).toBeInTheDocument()
+// },
+// }
diff --git a/packages/ui-patterns/form/utils.tsx b/packages/ui-patterns/form/utils.tsx
new file mode 100644
index 00000000000..0782551b239
--- /dev/null
+++ b/packages/ui-patterns/form/utils.tsx
@@ -0,0 +1,29 @@
+import React, { ComponentPropsWithoutRef, ElementRef, forwardRef } from 'react'
+import { ControllerRenderProps, FieldPath, FieldValues } from 'react-hook-form'
+import { FormControl_Shadcn_, FormField_Shadcn_, FormItem_Shadcn_ } from 'ui'
+
+/**
+ * Handles react-hook-form field type for FormItem<name> components
+ */
+export interface FormItemProps<
+ TFieldValues extends FieldValues,
+ TName extends FieldPath<TFieldValues>,
+> {
+ field?: ControllerRenderProps<TFieldValues, TName>
+}
+
+/**
+ * Repeatable wrapper for FormItem<name> components
+ */
+const FormItemWrapper = forwardRef<
+ ElementRef<typeof FormItem_Shadcn_>,
+ ComponentPropsWithoutRef<typeof FormItem_Shadcn_> // Use any as placeholder types
+>(({ ...props }, ref) => (
+ <FormItem_Shadcn_ ref={ref} {...props}>
+ <FormControl_Shadcn_>{props.children}</FormControl_Shadcn_>
+ </FormItem_Shadcn_>
+))
+
+FormItemWrapper.displayName = 'FormItemWrapper'
+
+export { FormItemWrapper }
diff --git a/packages/ui-patterns/lib/transformSource.tsx b/packages/ui-patterns/lib/transformSource.tsx
new file mode 100644
index 00000000000..fa3034c44ae
--- /dev/null
+++ b/packages/ui-patterns/lib/transformSource.tsx
@@ -0,0 +1,210 @@
+import { StoryContext } from '@storybook/react'
+
+export function transformSourceForm(code: string, StoryContext: StoryContext) {
+ let _code = code
+ // _code = _code.replace('<FormProvider', '<Form')
+ _code = _code.replace(
+ `<FormProvider
+ clearErrors={() => {}}
+ control={{
+ _defaultValues: {
+ username: ''
+ },
+ _executeSchema: () => {},
+ _fields: {},
+ _formState: {
+ dirtyFields: {},
+ errors: {},
+ isDirty: false,
+ isLoading: false,
+ isSubmitSuccessful: false,
+ isSubmitted: false,
+ isSubmitting: false,
+ isValid: false,
+ isValidating: false,
+ submitCount: 0,
+ touchedFields: {}
+ },
+ _formValues: {
+ username: ''
+ },
+ _getDirty: () => {},
+ _getFieldArray: () => {},
+ _getWatch: () => {},
+ _names: {
+ array: {},
+ mount: {},
+ unMount: {},
+ watch: {}
+ },
+ _options: {
+ defaultValues: {
+ username: ''
+ },
+ mode: 'onSubmit',
+ reValidateMode: 'onChange',
+ resolver: () => {},
+ shouldFocusError: true
+ },
+ _proxyFormState: {
+ dirtyFields: false,
+ errors: false,
+ isDirty: false,
+ isValid: false,
+ isValidating: false,
+ touchedFields: false
+ },
+ _removeUnmounted: () => {},
+ _reset: () => {},
+ _resetDefaultValues: () => {},
+ _state: {
+ action: false,
+ mount: false,
+ watch: false
+ },
+ _subjects: {
+ array: {
+ next: () => {},
+ observers: [],
+ subscribe: () => {},
+ unsubscribe: () => {}
+ },
+ state: {
+ next: () => {},
+ observers: [],
+ subscribe: () => {},
+ unsubscribe: () => {}
+ },
+ values: {
+ next: () => {},
+ observers: [],
+ subscribe: () => {},
+ unsubscribe: () => {}
+ }
+ },
+ _updateDisabledField: () => {},
+ _updateFieldArray: () => {},
+ _updateFormState: () => {},
+ _updateValid: () => {},
+ getFieldState: () => {},
+ handleSubmit: () => {},
+ register: () => {},
+ setError: () => {},
+ unregister: () => {}
+ }}
+ formState={{
+ defaultValues: {
+ username: ''
+ }
+ }}
+ getFieldState={() => {}}
+ getValues={() => {}}
+ handleSubmit={() => {}}
+ register={() => {}}
+ reset={() => {}}
+ resetField={() => {}}
+ setError={() => {}}
+ setFocus={() => {}}
+ setValue={() => {}}
+ trigger={() => {}}
+ unregister={() => {}}
+ watch={() => {}}
+>`,
+ `<Form_shadcn_ {...form}>`
+ )
+ _code = _code.replace(
+ `
+ control={{
+ _defaultValues: {
+ username: ''
+ },
+ _executeSchema: () => {},
+ _fields: {},
+ _formState: {
+ dirtyFields: {},
+ errors: {},
+ isDirty: false,
+ isLoading: false,
+ isSubmitSuccessful: false,
+ isSubmitted: false,
+ isSubmitting: false,
+ isValid: false,
+ isValidating: false,
+ submitCount: 0,
+ touchedFields: {}
+ },
+ _formValues: {
+ username: ''
+ },
+ _getDirty: () => {},
+ _getFieldArray: () => {},
+ _getWatch: () => {},
+ _names: {
+ array: {},
+ mount: {},
+ unMount: {},
+ watch: {}
+ },
+ _options: {
+ defaultValues: {
+ username: ''
+ },
+ mode: 'onSubmit',
+ reValidateMode: 'onChange',
+ resolver: () => {},
+ shouldFocusError: true
+ },
+ _proxyFormState: {
+ defaultValues: 'all',
+ dirtyFields: false,
+ errors: false,
+ isDirty: false,
+ isValid: false,
+ isValidating: false,
+ touchedFields: false
+ },
+ _removeUnmounted: () => {},
+ _reset: () => {},
+ _resetDefaultValues: () => {},
+ _state: {
+ action: false,
+ mount: false,
+ watch: false
+ },
+ _subjects: {
+ array: {
+ next: () => {},
+ observers: [],
+ subscribe: () => {},
+ unsubscribe: () => {}
+ },
+ state: {
+ next: () => {},
+ observers: [],
+ subscribe: () => {},
+ unsubscribe: () => {}
+ },
+ values: {
+ next: () => {},
+ observers: [],
+ subscribe: () => {},
+ unsubscribe: () => {}
+ }
+ },
+ _updateDisabledField: () => {},
+ _updateFieldArray: () => {},
+ _updateFormState: () => {},
+ _updateValid: () => {},
+ getFieldState: () => {},
+ handleSubmit: () => {},
+ register: () => {},
+ setError: () => {},
+ unregister: () => {}
+ }}`,
+ `
+ control={form.control}`
+ )
+
+ _code = _code.replace('</FormProvider>', '</Form_Shadcn_>')
+ return _code
+}
diff --git a/packages/ui/.storybook/preview.css b/packages/ui/.storybook/preview.css
index b7e455bded3..ea12bf939f4 100644
--- a/packages/ui/.storybook/preview.css
+++ b/packages/ui/.storybook/preview.css
@@ -103,7 +103,9 @@
@layer base {
body {
@apply bg text;
- font-feature-settings: 'rlig' 1, 'calt' 1;
+ font-feature-settings:
+ 'rlig' 1,
+ 'calt' 1;
font-family: 'Circular std';
}
}
@@ -113,6 +115,12 @@
.light .docs-story,
.dark .docs-story {
@apply bg text font-[400];
- font-feature-settings: 'rlig' 1, 'calt' 1;
+ font-feature-settings:
+ 'rlig' 1,
+ 'calt' 1;
font-family: 'Circular std';
}
+
+html {
+ @apply bg text font-[400];
+}
diff --git a/packages/ui/index.tsx b/packages/ui/index.tsx
index ad320595e23..602aa743a0f 100644
--- a/packages/ui/index.tsx
+++ b/packages/ui/index.tsx
@@ -87,6 +87,8 @@ export * from './src/components/shadcn/ui/toaster'
export { Badge as Badge_Shadcn_ } from './src/components/shadcn/ui/badge'
+export * from './src/components/shadcn/ui/separator'
+
export {
Command as Command_Shadcn_,
CommandDialog as CommandDialog_Shadcn_,
@@ -216,6 +218,8 @@ export {
HoverCardContent as HoverCardContent_Shadcn_,
} from './src/components/shadcn/ui/hover-card'
+export * from './src/components/shadcn/ui/calendar'
+
export { Toggle as Toggle_Shadcn } from './src/components/shadcn/ui/toggle'
export { ScrollArea, ScrollBar } from './src/components/shadcn/ui/scroll-area'
diff --git a/packages/ui/src/components/shadcn/stories/Badge.stories.tsx b/packages/ui/src/components/shadcn/stories/Badge.stories.tsx
index 8f05b26a20e..6e49f63a6f5 100644
--- a/packages/ui/src/components/shadcn/stories/Badge.stories.tsx
+++ b/packages/ui/src/components/shadcn/stories/Badge.stories.tsx
@@ -1,3 +1,4 @@
+import React from 'react'
import { Meta } from '@storybook/react'
import { Badge, BadgeProps } from '../ui/badge'
@@ -16,16 +17,24 @@ export const Brand = () => <Badge variant="brand">Brand</Badge>
Brand.storyName = 'Brand'
-export const Secondary = () => <Badge variant="secondary">Secondary</Badge>
+export const Warning = () => <Badge variant={'warning'}>Warning</Badge>
-Secondary.storyName = 'Secondary'
+Warning.storyName = 'Warning'
-export const Outline = () => <Badge variant="outline">Outline</Badge>
+export const Success = () => <Badge variant="success">Success</Badge>
-Outline.storyName = 'Outline'
+Success.storyName = 'Success'
export const Destructive = () => <Badge variant="destructive">Destructive</Badge>
Destructive.storyName = 'Destructive'
+export const Secondary = () => <Badge variant="secondary">Secondary</Badge>
+
+Secondary.storyName = 'Secondary'
+
+export const Outline = () => <Badge variant="outline">Outline</Badge>
+
+Outline.storyName = 'Outline'
+
export default meta
diff --git a/packages/ui/src/components/shadcn/stories/Select.stories.tsx b/packages/ui/src/components/shadcn/stories/Select.stories.tsx
index a136a32451d..1cb8896eb3f 100644
--- a/packages/ui/src/components/shadcn/stories/Select.stories.tsx
+++ b/packages/ui/src/components/shadcn/stories/Select.stories.tsx
@@ -1,23 +1,24 @@
+import React from 'react'
import { zodResolver } from '@hookform/resolvers/zod'
import { Meta } from '@storybook/react'
import { Button } from '../ui/button'
import {
- Form,
- FormControl,
- FormDescription,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
+ Form,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
} from '../ui/form'
import {
- Select,
- SelectContent,
- SelectGroup,
- SelectItem,
- SelectLabel,
- SelectTrigger,
- SelectValue,
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectLabel,
+ SelectTrigger,
+ SelectValue,
} from '../ui/select'
import { toast } from '../ui/use-toast'
// import Link from 'next/link'
diff --git a/packages/ui/src/components/shadcn/ui/form.tsx b/packages/ui/src/components/shadcn/ui/form.tsx
index 4c13213c227..068ed96cfaa 100644
--- a/packages/ui/src/components/shadcn/ui/form.tsx
+++ b/packages/ui/src/components/shadcn/ui/form.tsx
@@ -91,7 +91,7 @@ const FormLabel = React.forwardRef<
className={cn(
'text-foreground-light',
'transition-colors',
- error && 'text-destructive',
+ error && '!text-destructive',
className,
'leading-normal'
)}
diff --git a/packages/ui/src/components/shadcn/ui/input.tsx b/packages/ui/src/components/shadcn/ui/input.tsx
index e9010f2bca9..b53165d962a 100644
--- a/packages/ui/src/components/shadcn/ui/input.tsx
+++ b/packages/ui/src/components/shadcn/ui/input.tsx
@@ -1,24 +1,37 @@
+import { VariantProps, cva } from 'class-variance-authority'
import * as React from 'react'
-
+import { SIZE_VARIANTS, SIZE_VARIANTS_DEFAULT } from '../../../lib/constants'
import { cn } from '../../../lib/utils/cn'
-export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
+export interface InputProps
+ extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'>,
+ VariantProps<typeof InputVariants> {}
-const customClasses = ['bg-control']
+const InputVariants = cva('aria-[]', {
+ variants: {
+ size: {
+ ...SIZE_VARIANTS,
+ },
+ },
+ defaultVariants: {
+ size: SIZE_VARIANTS_DEFAULT,
+ },
+})
const Input = React.forwardRef<HTMLInputElement, InputProps>(
- ({ className, type, ...props }, ref) => {
+ ({ className, type, size = 'medium', ...props }, ref) => {
return (
<input
type={type}
+ ref={ref}
+ {...props}
className={cn(
- 'flex h-10 w-full rounded-md border border-control bg-control px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-foreground-muted',
+ 'flex h-10 w-full rounded-md border border-control bg-foreground/[.026] px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-foreground-muted',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-background-control focus-visible:ring-offset-2 focus-visible:ring-offset-foreground-muted disabled:cursor-not-allowed disabled:opacity-50',
- ...customClasses,
+ 'aria-[invalid=true]:bg-destructive-200 aria-[invalid=true]:border-destructive-400 aria-[invalid=true]:focus:border-destructive aria-[invalid=true]:focus-visible:border-destructive',
+ InputVariants({ size }),
className
)}
- ref={ref}
- {...props}
/>
)
}
diff --git a/packages/ui/src/components/shadcn/ui/select.tsx b/packages/ui/src/components/shadcn/ui/select.tsx
index 488f3c1bf70..ca1d90bed06 100644
--- a/packages/ui/src/components/shadcn/ui/select.tsx
+++ b/packages/ui/src/components/shadcn/ui/select.tsx
@@ -5,6 +5,8 @@ import { Check, ChevronDown } from 'lucide-react'
import * as React from 'react'
import { cn } from '../../../lib/utils/cn'
+import { VariantProps, cva } from 'class-variance-authority'
+import { SIZE_VARIANTS, SIZE_VARIANTS_DEFAULT } from '../../../lib/constants'
const Select = SelectPrimitive.Root
@@ -12,14 +14,27 @@ const SelectGroup = SelectPrimitive.Group
const SelectValue = SelectPrimitive.Value
+const SelectTriggerVariants = cva('', {
+ variants: {
+ size: {
+ ...SIZE_VARIANTS,
+ },
+ },
+ defaultVariants: {
+ size: SIZE_VARIANTS_DEFAULT,
+ },
+})
+
const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
- React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
->(({ className, children, ...props }, ref) => (
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> &
+ VariantProps<typeof SelectTriggerVariants>
+>(({ className, children, size, ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
className={cn(
- 'flex h-8 w-full items-center justify-between rounded-md border border-control bg-control px-3 py-2 text-xs ring-offset-background-control placeholder:text-foreground-muted focus:outline-none ring-border-control focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
+ 'flex w-full items-center justify-between rounded-md border border-control bg-control text-xs ring-offset-background-control placeholder:text-foreground-muted focus:outline-none ring-border-control focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
+ SelectTriggerVariants({ size }),
className
)}
{...props}
@@ -86,8 +101,8 @@ const SelectItem = React.forwardRef<
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
- <SelectPrimitive.ItemIndicator>
- <Check className="h-4 w-4" />
+ <SelectPrimitive.ItemIndicator className="h-3.5 w-3.5 bg-foreground rounded-full flex justify-center items-center">
+ <Check className="h-2 w-2 text-background-overlay" strokeWidth={6} />
</SelectPrimitive.ItemIndicator>
</span>
diff --git a/packages/ui/src/lib/constants.ts b/packages/ui/src/lib/constants.ts
index 024516efe04..67b00e06dca 100644
--- a/packages/ui/src/lib/constants.ts
+++ b/packages/ui/src/lib/constants.ts
@@ -41,3 +41,37 @@ export type AvailableColors =
| 'gold'
| 'gray'
| 'slate'
+
+export const SIZE = {
+ text: {
+ tiny: 'text-xs',
+ small: 'text-sm leading-4',
+ medium: 'text-sm',
+ large: 'text-base',
+ xlarge: 'text-base',
+ },
+ padding: {
+ tiny: 'px-2.5 py-1',
+ small: 'px-3 py-2',
+ medium: 'px-4 py-2',
+ large: 'px-4 py-2',
+ xlarge: 'px-6 py-3',
+ },
+ height: {
+ tiny: 'h-[26px]',
+ small: 'h-[34px]',
+ medium: 'h-[38px]',
+ large: 'h-[42px]',
+ xlarge: 'h-[50px]',
+ },
+}
+
+export const SIZE_VARIANTS = {
+ tiny: `${SIZE.text['tiny']} ${SIZE.padding['tiny']} ${SIZE.height['tiny']}`,
+ small: `${SIZE.text['small']} ${SIZE.padding['small']} ${SIZE.height['small']}`,
+ medium: `${SIZE.text['medium']} ${SIZE.padding['medium']} ${SIZE.height['medium']}`,
+ large: `${SIZE.text['large']} ${SIZE.padding['large']} ${SIZE.height['large']}`,
+ xlarge: `${SIZE.text['xlarge']} ${SIZE.padding['xlarge']} ${SIZE.height['xlarge']}`,
+}
+
+export const SIZE_VARIANTS_DEFAULT = 'small'