Skip to content

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

adding calendar and form example

Jonathan Summers-Muir9b4047218f7f
diff --git a/package-lock.json b/package-lock.json
index 9914a9fcb9d..c55cecd9c09 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -41775,9 +41775,9 @@
}
},
"node_modules/tailwind-merge": {
- "version": "1.11.0",
- "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-1.11.0.tgz",
- "integrity": "sha512-oG3/328Y7LrfPMfkgMNxoqEk1ZQdXBxdphf9FFrreo8q0EtVIHt3bQf2IyFhQuVt8puB57lCRBNbazGhYAyz9w==",
+ "version": "1.12.0",
+ "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-1.12.0.tgz",
+ "integrity": "sha512-Y17eDp7FtN1+JJ4OY0Bqv9OA41O+MS8c1Iyr3T6JFLnOgLg3EvcyMKZAnQ8AGyvB5Nxm3t9Xb5Mhe139m8QT/g==",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/dcastil"
@@ -41824,6 +41824,14 @@
"postcss": "^8.0.9"
}
},
+ "node_modules/tailwindcss-animate": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/tailwindcss-animate/-/tailwindcss-animate-1.0.5.tgz",
+ "integrity": "sha512-UU3qrOJ4lFQABY+MVADmBm+0KW3xZyhMdRvejwtXqYOL7YjHYxmuREFAZdmVG5LPe5E9CAst846SLC4j5I3dcw==",
+ "peerDependencies": {
+ "tailwindcss": ">=3.0.0 || insiders"
+ }
+ },
"node_modules/tailwindcss-radix": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/tailwindcss-radix/-/tailwindcss-radix-1.6.0.tgz",
@@ -45627,6 +45635,7 @@
"color": "^4.2.3",
"colorjs.io": "^0.4.3",
"common-tags": "^1.8.2",
+ "date-fns": "^2.30.0",
"formik": "^2.2.9",
"lodash": "^4.17.20",
"lucide-react": "^0.124.0",
@@ -45635,14 +45644,16 @@
"prop-types": "^15.7.2",
"react-copy-to-clipboard": "^5.1.0",
"react-countdown": "^2.3.5",
+ "react-day-picker": "^8.7.1",
"react-feather": "^2.0.10",
"react-hook-form": "^7.43.9",
"react-markdown": "^8.0.3",
"react-syntax-highlighter": "^15.5.0",
"remark-gfm": "^3.0.1",
"sse.js": "^0.6.1",
- "tailwind-merge": "^1.10.0",
+ "tailwind-merge": "^1.12.0",
"tailwindcss": "^3.0.15",
+ "tailwindcss-animate": "^1.0.5",
"tailwindcss-radix": "^1.6.0",
"zod": "^3.21.4"
},
@@ -46046,11 +46057,27 @@
},
"packages/ui/node_modules/clsx": {
"version": "1.2.1",
- "license": "MIT",
+ "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz",
+ "integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==",
"engines": {
"node": ">=6"
}
},
+ "packages/ui/node_modules/date-fns": {
+ "version": "2.30.0",
+ "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz",
+ "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==",
+ "dependencies": {
+ "@babel/runtime": "^7.21.0"
+ },
+ "engines": {
+ "node": ">=0.11"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/date-fns"
+ }
+ },
"packages/ui/node_modules/dotenv-expand": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz",
@@ -46169,6 +46196,19 @@
"node": ">=4"
}
},
+ "packages/ui/node_modules/react-day-picker": {
+ "version": "8.7.1",
+ "resolved": "https://registry.npmjs.org/react-day-picker/-/react-day-picker-8.7.1.tgz",
+ "integrity": "sha512-Gv426AW8b151CZfh3aP5RUGztLwHB/EyJgWZ5iMgtzbFBkjHfG6Y66CIQFMWGLnYjsQ9DYSJRmJ5S0Pg5HWKjA==",
+ "funding": {
+ "type": "individual",
+ "url": "https://github.com/sponsors/gpbl"
+ },
+ "peerDependencies": {
+ "date-fns": "^2.28.0",
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
+ }
+ },
"packages/ui/node_modules/react-element-to-jsx-string": {
"version": "15.0.0",
"resolved": "https://registry.npmjs.org/react-element-to-jsx-string/-/react-element-to-jsx-string-15.0.0.tgz",
@@ -79169,9 +79209,9 @@
}
},
"tailwind-merge": {
- "version": "1.11.0",
- "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-1.11.0.tgz",
- "integrity": "sha512-oG3/328Y7LrfPMfkgMNxoqEk1ZQdXBxdphf9FFrreo8q0EtVIHt3bQf2IyFhQuVt8puB57lCRBNbazGhYAyz9w=="
+ "version": "1.12.0",
+ "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-1.12.0.tgz",
+ "integrity": "sha512-Y17eDp7FtN1+JJ4OY0Bqv9OA41O+MS8c1Iyr3T6JFLnOgLg3EvcyMKZAnQ8AGyvB5Nxm3t9Xb5Mhe139m8QT/g=="
},
"tailwindcss": {
"version": "3.3.1",
@@ -79204,6 +79244,12 @@
"sucrase": "^3.29.0"
}
},
+ "tailwindcss-animate": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/tailwindcss-animate/-/tailwindcss-animate-1.0.5.tgz",
+ "integrity": "sha512-UU3qrOJ4lFQABY+MVADmBm+0KW3xZyhMdRvejwtXqYOL7YjHYxmuREFAZdmVG5LPe5E9CAst846SLC4j5I3dcw==",
+ "requires": {}
+ },
"tailwindcss-radix": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/tailwindcss-radix/-/tailwindcss-radix-1.6.0.tgz",
@@ -80212,6 +80258,7 @@
"common-tags": "^1.8.2",
"config": "*",
"copyfiles": "^2.4.1",
+ "date-fns": "^2.30.0",
"formik": "^2.2.9",
"glob": "^8.1.0",
"lodash": "^4.17.20",
@@ -80221,6 +80268,7 @@
"prop-types": "^15.7.2",
"react-copy-to-clipboard": "^5.1.0",
"react-countdown": "^2.3.5",
+ "react-day-picker": "^8.7.1",
"react-feather": "^2.0.10",
"react-hook-form": "^7.43.9",
"react-markdown": "^8.0.3",
@@ -80233,6 +80281,7 @@
"style-dictionary": "^3.7.1",
"tailwind-merge": "^1.10.0",
"tailwindcss": "^3.0.15",
+ "tailwindcss-animate": "*",
"tailwindcss-radix": "^1.6.0",
"tsconfig-paths-webpack-plugin": "^4.0.1",
"typescript": "4.3.4",
@@ -80499,7 +80548,17 @@
}
},
"clsx": {
- "version": "1.2.1"
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz",
+ "integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg=="
+ },
+ "date-fns": {
+ "version": "2.30.0",
+ "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz",
+ "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==",
+ "requires": {
+ "@babel/runtime": "^7.21.0"
+ }
},
"dotenv-expand": {
"version": "10.0.0",
@@ -80585,6 +80644,12 @@
"util-deprecate": "^1.0.2"
}
},
+ "react-day-picker": {
+ "version": "8.7.1",
+ "resolved": "https://registry.npmjs.org/react-day-picker/-/react-day-picker-8.7.1.tgz",
+ "integrity": "sha512-Gv426AW8b151CZfh3aP5RUGztLwHB/EyJgWZ5iMgtzbFBkjHfG6Y66CIQFMWGLnYjsQ9DYSJRmJ5S0Pg5HWKjA==",
+ "requires": {}
+ },
"react-element-to-jsx-string": {
"version": "15.0.0",
"resolved": "https://registry.npmjs.org/react-element-to-jsx-string/-/react-element-to-jsx-string-15.0.0.tgz",
diff --git a/packages/ui/.storybook/preview.css b/packages/ui/.storybook/preview.css
index 7c9bdb31cb7..e03c2e1e6f7 100644
--- a/packages/ui/.storybook/preview.css
+++ b/packages/ui/.storybook/preview.css
@@ -5,10 +5,94 @@
@import './../build/css/themes/dark.css';
@import './../build/css/themes/light.css';
/* @import './../build/css/themes/darker-dark.css'; */
-
+/*
.dark,
.light,
.light .docs-story,
.dark .docs-story {
@apply bg-body;
+} */
+@layer base {
+ :root {
+ --background: 0 0% 100%;
+ --foreground: 222.2 47.4% 11.2%;
+
+ --muted: 210 40% 96.1%;
+ --muted-foreground: 215.4 16.3% 46.9%;
+
+ --popover: 0 0% 100%;
+ --popover-foreground: 222.2 47.4% 11.2%;
+
+ --card: 0 0% 100%;
+ --card-foreground: 222.2 47.4% 11.2%;
+
+ --border: 214.3 31.8% 91.4%;
+ --input: 214.3 31.8% 91.4%;
+
+ --primary: 222.2 47.4% 11.2%;
+ --primary-foreground: 210 40% 98%;
+
+ --secondary: 210 40% 96.1%;
+ --secondary-foreground: 222.2 47.4% 11.2%;
+
+ --accent: 210 40% 96.1%;
+ --accent-foreground: 222.2 47.4% 11.2%;
+
+ --destructive: 0 100% 50%;
+ --destructive-foreground: 210 40% 98%;
+
+ --ring: 215 20.2% 65.1%;
+
+ --radius: 0.5rem;
+ }
+
+ .dark {
+ --background: 224 71% 4%;
+ --foreground: 213 31% 91%;
+
+ --muted: 223 47% 11%;
+ --muted-foreground: 215.4 16.3% 56.9%;
+
+ --popover: 224 71% 4%;
+ --popover-foreground: 215 20.2% 65.1%;
+
+ --card: 224 71% 4%;
+ --card-foreground: 213 31% 91%;
+
+ --border: 216 34% 17%;
+ --input: 216 34% 17%;
+
+ --primary: 210 40% 98%;
+ --primary-foreground: 222.2 47.4% 1.2%;
+
+ --secondary: 222.2 47.4% 11.2%;
+ --secondary-foreground: 210 40% 98%;
+
+ --accent: 216 34% 17%;
+ --accent-foreground: 210 40% 98%;
+
+ --destructive: 0 63% 31%;
+ --destructive-foreground: 210 40% 98%;
+
+ --ring: 216 34% 17%;
+
+ --radius: 0.5rem;
+ }
+}
+
+@layer base {
+ * {
+ @apply border-border;
+ }
+ body {
+ @apply bg-background text-foreground;
+ font-feature-settings: 'rlig' 1, 'calt' 1;
+ }
+}
+
+.dark,
+.light,
+.light .docs-story,
+.dark .docs-story {
+ @apply bg-background text-foreground;
}
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 221d6ee632d..97661ec88e8 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -39,6 +39,7 @@
"color": "^4.2.3",
"colorjs.io": "^0.4.3",
"common-tags": "^1.8.2",
+ "date-fns": "^2.30.0",
"formik": "^2.2.9",
"lodash": "^4.17.20",
"lucide-react": "^0.124.0",
@@ -47,14 +48,16 @@
"prop-types": "^15.7.2",
"react-copy-to-clipboard": "^5.1.0",
"react-countdown": "^2.3.5",
+ "react-day-picker": "^8.7.1",
"react-feather": "^2.0.10",
"react-hook-form": "^7.43.9",
"react-markdown": "^8.0.3",
"react-syntax-highlighter": "^15.5.0",
"remark-gfm": "^3.0.1",
"sse.js": "^0.6.1",
- "tailwind-merge": "^1.10.0",
+ "tailwind-merge": "^1.12.0",
"tailwindcss": "^3.0.15",
+ "tailwindcss-animate": "^1.0.5",
"tailwindcss-radix": "^1.6.0",
"zod": "^3.21.4"
},
diff --git a/packages/ui/src/components/Button/Button.tsx b/packages/ui/src/components/Button/Button.tsx
index a70c9b393c1..24546fb28e6 100644
--- a/packages/ui/src/components/Button/Button.tsx
+++ b/packages/ui/src/components/Button/Button.tsx
@@ -8,8 +8,8 @@ import { IconLoader } from './../Icon/icons/IconLoader'
import { cn } from '@ui/lib/utils'
import { sizes } from '@ui/lib/commonCva'
-export type ButtonVariantProps = VariantProps<typeof buttonVariantsNew>
-const buttonVariantsNew = cva(
+export type ButtonVariantProps = VariantProps<typeof buttonVariants>
+const buttonVariants = cva(
`relative
cursor-pointer
inline-flex
@@ -176,7 +176,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
return (
<Comp
- className={cn(buttonVariantsNew({ type, size, disabled, className }))}
+ className={cn(buttonVariants({ type, size, disabled }), className)}
ref={ref}
type={props.htmlType}
{...props}
@@ -189,4 +189,4 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
Button.displayName = 'Button'
-export { Button, buttonVariantsNew }
+export { Button, buttonVariants }
diff --git a/packages/ui/src/components/shadcn/button.tsx b/packages/ui/src/components/shadcn/button.tsx
new file mode 100644
index 00000000000..f44e27e7212
--- /dev/null
+++ b/packages/ui/src/components/shadcn/button.tsx
@@ -0,0 +1,48 @@
+import * as React from 'react'
+import { Slot } from '@radix-ui/react-slot'
+import { VariantProps, cva } from 'class-variance-authority'
+
+import { cn } from '@ui/lib/utils'
+
+const buttonVariants = cva(
+ 'inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background',
+ {
+ variants: {
+ variant: {
+ default: 'bg-primary text-primary-foreground hover:bg-primary/90',
+ destructive: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',
+ outline: 'border border-input hover:bg-accent hover:text-accent-foreground',
+ secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
+ ghost: 'hover:bg-accent hover:text-accent-foreground',
+ link: 'underline-offset-4 hover:underline text-primary',
+ },
+ size: {
+ default: 'h-10 py-2 px-4',
+ sm: 'h-9 px-3 rounded-md',
+ lg: 'h-11 px-8 rounded-md',
+ },
+ },
+ defaultVariants: {
+ variant: 'default',
+ size: 'default',
+ },
+ }
+)
+
+export interface ButtonProps
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
+ VariantProps<typeof buttonVariants> {
+ asChild?: boolean
+}
+
+const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
+ const Comp = asChild ? Slot : 'button'
+ return (
+ <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
+ )
+ }
+)
+Button.displayName = 'Button'
+
+export { Button, buttonVariants }
diff --git a/packages/ui/src/components/shadcn/calendar.tsx b/packages/ui/src/components/shadcn/calendar.tsx
new file mode 100644
index 00000000000..ef9bb2493fe
--- /dev/null
+++ b/packages/ui/src/components/shadcn/calendar.tsx
@@ -0,0 +1,57 @@
+'use client'
+
+import * as React from 'react'
+import { ChevronLeft, ChevronRight } from 'lucide-react'
+import { DayPicker } from 'react-day-picker'
+
+import { cn } from '@ui/lib/utils'
+import { buttonVariants } from '@ui/components/shadcn/button'
+
+export type CalendarProps = React.ComponentProps<typeof DayPicker>
+
+function Calendar({ className, classNames, showOutsideDays = true, ...props }: CalendarProps) {
+ return (
+ <DayPicker
+ showOutsideDays={showOutsideDays}
+ className={cn('p-3', className)}
+ classNames={{
+ months: 'flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0',
+ month: 'space-y-4',
+ caption: 'flex justify-center pt-1 relative items-center',
+ caption_label: 'text-sm font-medium',
+ nav: 'space-x-1 flex items-center',
+ nav_button: cn(
+ buttonVariants({ variant: 'outline' }),
+ 'h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100'
+ ),
+ nav_button_previous: 'absolute left-1',
+ nav_button_next: 'absolute right-1',
+ table: 'w-full border-collapse space-y-1',
+ head_row: 'flex',
+ head_cell: 'text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]',
+ row: 'flex w-full mt-2',
+ cell: 'text-center text-sm p-0 relative [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20',
+ day: cn(
+ buttonVariants({ variant: 'ghost' }),
+ 'h-9 w-9 p-0 font-normal aria-selected:opacity-100'
+ ),
+ day_selected:
+ 'bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground',
+ day_today: 'bg-accent text-accent-foreground',
+ day_outside: 'text-muted-foreground opacity-50',
+ day_disabled: 'text-muted-foreground opacity-50',
+ day_range_middle: 'aria-selected:bg-accent aria-selected:text-accent-foreground',
+ day_hidden: 'invisible',
+ ...classNames,
+ }}
+ components={{
+ IconLeft: ({ ...props }) => <ChevronLeft className="h-4 w-4" />,
+ IconRight: ({ ...props }) => <ChevronRight className="h-4 w-4" />,
+ }}
+ {...props}
+ />
+ )
+}
+Calendar.displayName = 'Calendar'
+
+export { Calendar }
diff --git a/packages/ui/src/components/shadcn/form/Form.stories.tsx b/packages/ui/src/components/shadcn/form/Form.stories.tsx
index 7560d88ccd3..edbeed4af12 100644
--- a/packages/ui/src/components/shadcn/form/Form.stories.tsx
+++ b/packages/ui/src/components/shadcn/form/Form.stories.tsx
@@ -1,32 +1,35 @@
// Button.stories.ts|tsx
+import { zodResolver } from '@hookform/resolvers/zod'
+import { IdProvider } from '@radix-ui/react-id'
import type { Meta, StoryObj } from '@storybook/react'
+import { Button } from './../button'
+import { cn } from '@ui/lib/utils'
+import { format } from 'date-fns'
+import { CalendarIcon } from 'lucide-react'
import { useForm } from 'react-hook-form'
-
-import { IdProvider } from '@radix-ui/react-id'
-
-import { zodResolver } from '@hookform/resolvers/zod'
import * as z from 'zod'
-
+import { Calendar } from '../calendar'
+import { Popover, PopoverContent, PopoverTrigger } from '../popover'
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../select'
+import { toast } from '../use-toast'
import {
Form,
+ FormControl,
+ FormDescription,
FormField,
FormItem,
FormLabel,
- FormControl,
- FormDescription,
FormMessage,
} from './../form'
-
import { Input } from './../input'
-import { Button } from '@ui/components/Button'
const meta: Meta<typeof Form> = {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/react/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
- title: 'Forms/Form',
+ title: 'Shadcn/Form',
component: Form,
}
@@ -47,6 +50,9 @@ export const Primary = {
username: z.string().min(2, {
message: 'Username must be at least 2 characters.',
}),
+ job: z.string().min(2, {
+ message: 'Username must be at least 2 characters.',
+ }),
})
// 1. Define your form.
@@ -68,21 +74,119 @@ export const Primary = {
<FormField
control={form.control}
name="username"
+ render={({ field }) => (
+ <>
+ <FormItem>
+ <FormLabel>Username</FormLabel>
+ <FormControl>
+ <Input placeholder="shadcn" {...field} />
+ </FormControl>
+ <FormDescription>This is your public display name.</FormDescription>
+ <FormMessage />
+ </FormItem>
+ </>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="job"
render={({ field }) => (
<FormItem>
- <FormLabel>Username</FormLabel>
- <FormControl>
- <Input placeholder="shadcn" {...field} />
- </FormControl>
- <FormDescription>This is your public display name.</FormDescription>
+ <FormLabel>Email</FormLabel>
+ <Select onValueChange={field.onChange} defaultValue={field.value}>
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="Select a verified email to display" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ <SelectItem value="[email protected]">[email protected]</SelectItem>
+ <SelectItem value="[email protected]">[email protected]</SelectItem>
+ <SelectItem value="[email protected]">[email protected]</SelectItem>
+ </SelectContent>
+ </Select>
+ <FormDescription>
+ You can manage email addresses in your{' '}
+ <a href="/examples/forms">email settings</a>.
+ </FormDescription>
<FormMessage />
</FormItem>
)}
/>
- <Button htmlType="submit">Submit</Button>
+ <Button type="submit">Submit</Button>
</form>
</Form>
</IdProvider>
)
},
}
+
+export const CalendarExample = {
+ args: {},
+ render: ({}: any) => {
+ 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),
+ })
+
+ function onSubmit(data: z.infer<typeof FormSchema>) {
+ toast({
+ title: 'You submitted the following values:',
+ description: (
+ <pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4">
+ <code className="text-white">{JSON.stringify(data, null, 2)}</code>
+ </pre>
+ ),
+ })
+ }
+
+ return (
+ <Form {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
+ <FormField
+ control={form.control}
+ name="dob"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Date of birth</FormLabel>
+ <Popover>
+ <PopoverTrigger asChild>
+ <FormControl>
+ <Button
+ variant={'outline'}
+ className={cn(
+ 'w-[240px] pl-3 text-left font-normal',
+ !field.value && 'text-muted-foreground'
+ )}
+ >
+ {field.value ? format(field.value, 'PPP') : <span>Pick a date</span>}
+ <CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
+ </Button>
+ </FormControl>
+ </PopoverTrigger>
+ <PopoverContent 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>
+ </Popover>
+ <FormDescription>Your date of birth is used to calculate your age.</FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <Button type="submit">Submit</Button>
+ </form>
+ </Form>
+ )
+ },
+}
diff --git a/packages/ui/src/components/shadcn/input.tsx b/packages/ui/src/components/shadcn/input.tsx
index 16a52c8bf59..97902149ee0 100644
--- a/packages/ui/src/components/shadcn/input.tsx
+++ b/packages/ui/src/components/shadcn/input.tsx
@@ -10,13 +10,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
<input
type={type}
className={cn(
- `flex h-10 w-full rounded-md
- border border-scale-700 bg-transparent px-3 py-2
- text-sm text-scale-1200 ring-offset-background
- file:border-0 file:bg-transparent file:text-sm file:font-medium
- placeholder:text-scale-700
- focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring
- focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,
+ 'flex h-10 w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
className
)}
ref={ref}
diff --git a/packages/ui/src/components/shadcn/popover.tsx b/packages/ui/src/components/shadcn/popover.tsx
new file mode 100644
index 00000000000..831f03e5fba
--- /dev/null
+++ b/packages/ui/src/components/shadcn/popover.tsx
@@ -0,0 +1,29 @@
+import * as React from 'react'
+import * as PopoverPrimitive from '@radix-ui/react-popover'
+
+import { cn } from '@ui/lib/utils'
+
+const Popover = PopoverPrimitive.Root
+
+const PopoverTrigger = PopoverPrimitive.Trigger
+
+const PopoverContent = React.forwardRef<
+ React.ElementRef<typeof PopoverPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
+>(({ className, align = 'center', sideOffset = 4, ...props }, ref) => (
+ <PopoverPrimitive.Portal>
+ <PopoverPrimitive.Content
+ ref={ref}
+ align={align}
+ sideOffset={sideOffset}
+ className={cn(
+ 'z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none animate-in data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
+ className
+ )}
+ {...props}
+ />
+ </PopoverPrimitive.Portal>
+))
+PopoverContent.displayName = PopoverPrimitive.Content.displayName
+
+export { Popover, PopoverTrigger, PopoverContent }
diff --git a/packages/ui/src/components/shadcn/select.tsx b/packages/ui/src/components/shadcn/select.tsx
new file mode 100644
index 00000000000..917c7cf6bc0
--- /dev/null
+++ b/packages/ui/src/components/shadcn/select.tsx
@@ -0,0 +1,118 @@
+import * as React from 'react'
+import * as SelectPrimitive from '@radix-ui/react-select'
+import { Check, ChevronDown } from 'lucide-react'
+
+import { cn } from '@ui/lib/utils'
+
+const Select = SelectPrimitive.Root
+
+const SelectGroup = SelectPrimitive.Group
+
+const SelectValue = SelectPrimitive.Value
+
+const SelectTrigger = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Trigger>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
+>(({ className, children, ...props }, ref) => (
+ <SelectPrimitive.Trigger
+ ref={ref}
+ className={cn(
+ 'flex h-10 w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
+ className
+ )}
+ {...props}
+ >
+ {children}
+ <SelectPrimitive.Icon asChild>
+ <ChevronDown className="h-4 w-4 opacity-50" />
+ </SelectPrimitive.Icon>
+ </SelectPrimitive.Trigger>
+))
+SelectTrigger.displayName = SelectPrimitive.Trigger.displayName
+
+const SelectContent = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
+>(({ className, children, position = 'popper', ...props }, ref) => (
+ <SelectPrimitive.Portal>
+ <SelectPrimitive.Content
+ ref={ref}
+ className={cn(
+ 'relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md animate-in fade-in-80',
+ position === 'popper' && 'translate-y-1',
+ className
+ )}
+ position={position}
+ {...props}
+ >
+ <SelectPrimitive.Viewport
+ className={cn(
+ 'p-1',
+ position === 'popper' &&
+ 'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'
+ )}
+ >
+ {children}
+ </SelectPrimitive.Viewport>
+ </SelectPrimitive.Content>
+ </SelectPrimitive.Portal>
+))
+SelectContent.displayName = SelectPrimitive.Content.displayName
+
+const SelectLabel = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Label>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
+>(({ className, ...props }, ref) => (
+ <SelectPrimitive.Label
+ ref={ref}
+ className={cn('py-1.5 pl-8 pr-2 text-sm font-semibold', className)}
+ {...props}
+ />
+))
+SelectLabel.displayName = SelectPrimitive.Label.displayName
+
+const SelectItem = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Item>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
+>(({ className, children, ...props }, ref) => (
+ <SelectPrimitive.Item
+ ref={ref}
+ className={cn(
+ 'relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
+ className
+ )}
+ {...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>
+ </span>
+
+ <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
+ </SelectPrimitive.Item>
+))
+SelectItem.displayName = SelectPrimitive.Item.displayName
+
+const SelectSeparator = React.forwardRef<
+ React.ElementRef<typeof SelectPrimitive.Separator>,
+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
+>(({ className, ...props }, ref) => (
+ <SelectPrimitive.Separator
+ ref={ref}
+ className={cn('-mx-1 my-1 h-px bg-muted', className)}
+ {...props}
+ />
+))
+SelectSeparator.displayName = SelectPrimitive.Separator.displayName
+
+export {
+ Select,
+ SelectGroup,
+ SelectValue,
+ SelectTrigger,
+ SelectContent,
+ SelectLabel,
+ SelectItem,
+ SelectSeparator,
+}
diff --git a/packages/ui/src/components/shadcn/toast.tsx b/packages/ui/src/components/shadcn/toast.tsx
new file mode 100644
index 00000000000..0596ac420ff
--- /dev/null
+++ b/packages/ui/src/components/shadcn/toast.tsx
@@ -0,0 +1,122 @@
+import * as React from 'react'
+import * as ToastPrimitives from '@radix-ui/react-toast'
+import { VariantProps, cva } from 'class-variance-authority'
+import { X } from 'lucide-react'
+
+import { cn } from '@ui/lib/utils'
+
+const ToastProvider = ToastPrimitives.Provider
+
+const ToastViewport = React.forwardRef<
+ React.ElementRef<typeof ToastPrimitives.Viewport>,
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
+>(({ className, ...props }, ref) => (
+ <ToastPrimitives.Viewport
+ ref={ref}
+ className={cn(
+ 'fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]',
+ className
+ )}
+ {...props}
+ />
+))
+ToastViewport.displayName = ToastPrimitives.Viewport.displayName
+
+const toastVariants = cva(
+ 'data-[swipe=move]:transition-none group relative pointer-events-auto flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full data-[state=closed]:slide-out-to-right-full',
+ {
+ variants: {
+ variant: {
+ default: 'bg-background border',
+ destructive:
+ 'group destructive border-destructive bg-destructive text-destructive-foreground',
+ },
+ },
+ defaultVariants: {
+ variant: 'default',
+ },
+ }
+)
+
+const Toast = React.forwardRef<
+ React.ElementRef<typeof ToastPrimitives.Root>,
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> & VariantProps<typeof toastVariants>
+>(({ className, variant, ...props }, ref) => {
+ return (
+ <ToastPrimitives.Root
+ ref={ref}
+ className={cn(toastVariants({ variant }), className)}
+ {...props}
+ />
+ )
+})
+Toast.displayName = ToastPrimitives.Root.displayName
+
+const ToastAction = React.forwardRef<
+ React.ElementRef<typeof ToastPrimitives.Action>,
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
+>(({ className, ...props }, ref) => (
+ <ToastPrimitives.Action
+ ref={ref}
+ className={cn(
+ 'inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-destructive/30 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive',
+ className
+ )}
+ {...props}
+ />
+))
+ToastAction.displayName = ToastPrimitives.Action.displayName
+
+const ToastClose = React.forwardRef<
+ React.ElementRef<typeof ToastPrimitives.Close>,
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
+>(({ className, ...props }, ref) => (
+ <ToastPrimitives.Close
+ ref={ref}
+ className={cn(
+ 'absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600',
+ className
+ )}
+ toast-close=""
+ {...props}
+ >
+ <X className="h-4 w-4" />
+ </ToastPrimitives.Close>
+))
+ToastClose.displayName = ToastPrimitives.Close.displayName
+
+const ToastTitle = React.forwardRef<
+ React.ElementRef<typeof ToastPrimitives.Title>,
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
+>(({ className, ...props }, ref) => (
+ <ToastPrimitives.Title ref={ref} className={cn('text-sm font-semibold', className)} {...props} />
+))
+ToastTitle.displayName = ToastPrimitives.Title.displayName
+
+const ToastDescription = React.forwardRef<
+ React.ElementRef<typeof ToastPrimitives.Description>,
+ React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
+>(({ className, ...props }, ref) => (
+ <ToastPrimitives.Description
+ ref={ref}
+ className={cn('text-sm opacity-90', className)}
+ {...props}
+ />
+))
+ToastDescription.displayName = ToastPrimitives.Description.displayName
+
+type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
+
+type ToastActionElement = React.ReactElement<typeof ToastAction>
+
+export {
+ type ToastProps,
+ type ToastActionElement,
+ ToastProvider,
+ ToastViewport,
+ Toast,
+ ToastTitle,
+ ToastDescription,
+ ToastClose,
+ ToastAction,
+}
diff --git a/packages/ui/src/components/shadcn/use-toast.tsx b/packages/ui/src/components/shadcn/use-toast.tsx
new file mode 100644
index 00000000000..c4cbb92e510
--- /dev/null
+++ b/packages/ui/src/components/shadcn/use-toast.tsx
@@ -0,0 +1,187 @@
+// Inspired by react-hot-toast library
+import * as React from 'react'
+
+import { ToastActionElement, type ToastProps } from '@ui/components/shadcn/toast'
+
+const TOAST_LIMIT = 1
+const TOAST_REMOVE_DELAY = 1000000
+
+type ToasterToast = ToastProps & {
+ id: string
+ title?: React.ReactNode
+ description?: React.ReactNode
+ action?: ToastActionElement
+}
+
+const actionTypes = {
+ ADD_TOAST: 'ADD_TOAST',
+ UPDATE_TOAST: 'UPDATE_TOAST',
+ DISMISS_TOAST: 'DISMISS_TOAST',
+ REMOVE_TOAST: 'REMOVE_TOAST',
+} as const
+
+let count = 0
+
+function genId() {
+ count = (count + 1) % Number.MAX_VALUE
+ return count.toString()
+}
+
+type ActionType = typeof actionTypes
+
+type Action =
+ | {
+ type: ActionType['ADD_TOAST']
+ toast: ToasterToast
+ }
+ | {
+ type: ActionType['UPDATE_TOAST']
+ toast: Partial<ToasterToast>
+ }
+ | {
+ type: ActionType['DISMISS_TOAST']
+ toastId?: ToasterToast['id']
+ }
+ | {
+ type: ActionType['REMOVE_TOAST']
+ toastId?: ToasterToast['id']
+ }
+
+interface State {
+ toasts: ToasterToast[]
+}
+
+const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
+
+const addToRemoveQueue = (toastId: string) => {
+ if (toastTimeouts.has(toastId)) {
+ return
+ }
+
+ const timeout = setTimeout(() => {
+ toastTimeouts.delete(toastId)
+ dispatch({
+ type: 'REMOVE_TOAST',
+ toastId: toastId,
+ })
+ }, TOAST_REMOVE_DELAY)
+
+ toastTimeouts.set(toastId, timeout)
+}
+
+export const reducer = (state: State, action: Action): State => {
+ switch (action.type) {
+ case 'ADD_TOAST':
+ return {
+ ...state,
+ toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
+ }
+
+ case 'UPDATE_TOAST':
+ return {
+ ...state,
+ toasts: state.toasts.map((t) => (t.id === action.toast.id ? { ...t, ...action.toast } : t)),
+ }
+
+ case 'DISMISS_TOAST': {
+ const { toastId } = action
+
+ // ! Side effects ! - This could be extracted into a dismissToast() action,
+ // but I'll keep it here for simplicity
+ if (toastId) {
+ addToRemoveQueue(toastId)
+ } else {
+ state.toasts.forEach((toast) => {
+ addToRemoveQueue(toast.id)
+ })
+ }
+
+ return {
+ ...state,
+ toasts: state.toasts.map((t) =>
+ t.id === toastId || toastId === undefined
+ ? {
+ ...t,
+ open: false,
+ }
+ : t
+ ),
+ }
+ }
+ case 'REMOVE_TOAST':
+ if (action.toastId === undefined) {
+ return {
+ ...state,
+ toasts: [],
+ }
+ }
+ return {
+ ...state,
+ toasts: state.toasts.filter((t) => t.id !== action.toastId),
+ }
+ }
+}
+
+const listeners: Array<(state: State) => void> = []
+
+let memoryState: State = { toasts: [] }
+
+function dispatch(action: Action) {
+ memoryState = reducer(memoryState, action)
+ listeners.forEach((listener) => {
+ listener(memoryState)
+ })
+}
+
+interface Toast extends Omit<ToasterToast, 'id'> {}
+
+function toast({ ...props }: Toast) {
+ const id = genId()
+
+ const update = (props: ToasterToast) =>
+ dispatch({
+ type: 'UPDATE_TOAST',
+ toast: { ...props, id },
+ })
+ const dismiss = () => dispatch({ type: 'DISMISS_TOAST', toastId: id })
+
+ dispatch({
+ type: 'ADD_TOAST',
+ toast: {
+ ...props,
+ id,
+ open: true,
+ onOpenChange: (open) => {
+ if (!open) dismiss()
+ },
+ },
+ })
+
+ return {
+ id: id,
+ dismiss,
+ update,
+ }
+}
+
+function useToast() {
+ const [state, setState] = React.useState<State>(memoryState)
+
+ React.useEffect(() => {
+ listeners.push(setState)
+ return () => {
+ const index = listeners.indexOf(setState)
+ if (index > -1) {
+ listeners.splice(index, 1)
+ }
+ }
+ }, [state])
+
+ return {
+ ...state,
+ toast,
+ dismiss: (toastId?: string) => dispatch({ type: 'DISMISS_TOAST', toastId }),
+ }
+}
+
+export { useToast, toast }
diff --git a/packages/ui/tailwind.config.js b/packages/ui/tailwind.config.js
index 1dff83a81f0..d717c4d8d49 100644
--- a/packages/ui/tailwind.config.js
+++ b/packages/ui/tailwind.config.js
@@ -1,4 +1,5 @@
const config = require('config/tailwind.config')
+const { fontFamily } = require('tailwindcss/defaultTheme')
module.exports = config({
content: [
@@ -11,6 +12,13 @@ module.exports = config({
'./_blog/*.mdx',
],
theme: {
+ container: {
+ center: true,
+ padding: '2rem',
+ screens: {
+ '2xl': '1400px',
+ },
+ },
extend: {
keyframes: {
'flash-code': {
@@ -22,8 +30,63 @@ module.exports = config({
'flash-code': 'flash-code 1s forwards',
'flash-code-slow': 'flash-code 2s forwards',
},
+ colors: {
+ border: 'hsl(var(--border))',
+ input: 'hsl(var(--input))',
+ ring: 'hsl(var(--ring))',
+ background: 'hsl(var(--background))',
+ foreground: 'hsl(var(--foreground))',
+ primary: {
+ DEFAULT: 'hsl(var(--primary))',
+ foreground: 'hsl(var(--primary-foreground))',
+ },
+ secondary: {
+ DEFAULT: 'hsl(var(--secondary))',
+ foreground: 'hsl(var(--secondary-foreground))',
+ },
+ destructive: {
+ DEFAULT: 'hsl(var(--destructive))',
+ foreground: 'hsl(var(--destructive-foreground))',
+ },
+ muted: {
+ DEFAULT: 'hsl(var(--muted))',
+ foreground: 'hsl(var(--muted-foreground))',
+ },
+ accent: {
+ DEFAULT: 'hsl(var(--accent))',
+ foreground: 'hsl(var(--accent-foreground))',
+ },
+ popover: {
+ DEFAULT: 'hsl(var(--popover))',
+ foreground: 'hsl(var(--popover-foreground))',
+ },
+ card: {
+ DEFAULT: 'hsl(var(--card))',
+ foreground: 'hsl(var(--card-foreground))',
+ },
+ },
+ borderRadius: {
+ lg: `var(--radius)`,
+ md: `calc(var(--radius) - 2px)`,
+ sm: 'calc(var(--radius) - 4px)',
+ },
+ fontFamily: {
+ sans: ['var(--font-sans)', ...fontFamily.sans],
+ },
+ keyframes: {
+ 'accordion-down': {
+ from: { height: 0 },
+ to: { height: 'var(--radix-accordion-content-height)' },
+ },
+ 'accordion-up': {
+ from: { height: 'var(--radix-accordion-content-height)' },
+ to: { height: 0 },
+ },
+ },
+ animation: {
+ 'accordion-down': 'accordion-down 0.2s ease-out',
+ 'accordion-up': 'accordion-up 0.2s ease-out',
+ },
},
},
})
-
-// module.exports = require('config/tailwind.config')