The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Added command and ComboBox examples
Jonathan Summers-Muir73d10a041983
diff --git a/packages/ui/.storybook/preview.css b/packages/ui/.storybook/preview.cssindex 28dc3437d32..2850c368505 100644--- a/packages/ui/.storybook/preview.css+++ b/packages/ui/.storybook/preview.css@@ -15,7 +15,7 @@@layer base {:root {--background: var(--theme-variables-background-body); /* --background: 0 0% 100%; */- --foreground: var(--theme-variables-background); /* --foreground: 222.2 47.4% 11.2%; */+ --foreground: var(--text-color-body-default); /* --foreground: 222.2 47.4% 11.2%; */--muted: 210 40% 96.1%;--muted-foreground: 215.4 16.3% 46.9%;@@ -50,7 +50,7 @@.dark {--background: var(--theme-variables-background-body); /* --background: 224 71% 4%; */- --foreground: var(--theme-variables-background); /* --foreground: 213 31% 91%; */+ --foreground: var(--text-color-body-default); /* --foreground: 213 31% 91%; */--muted: var(--background-color-body); /* --muted: 223 47% 11%; */--muted-foreground: 215.4 16.3% 56.9%;diff --git a/packages/ui/src/components/shadcn/command.tsx b/packages/ui/src/components/shadcn/command.tsxnew file mode 100644index 00000000000..8c8940306ac--- /dev/null+++ b/packages/ui/src/components/shadcn/command.tsx@@ -0,0 +1,145 @@+'use client'++import * as React from 'react'+import { DialogProps } from '@radix-ui/react-dialog'+import { Command as CommandPrimitive } from 'cmdk-supabase'+import { Search } from 'lucide-react'++import { cn } from '@ui/lib/utils'+import { Dialog, DialogContent } from '@ui/components/shadcn/dialog'++const Command = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive>+>(({ className, ...props }, ref) => (+ <CommandPrimitive+ ref={ref}+ className={cn(+ 'flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground',+ className+ )}+ {...props}+ />+))+Command.displayName = CommandPrimitive.displayName++interface CommandDialogProps extends DialogProps {}++const CommandDialog = ({ children, ...props }: CommandDialogProps) => {+ return (+ <Dialog {...props}>+ <DialogContent className="overflow-hidden p-0 shadow-2xl">+ <Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">+ {children}+ </Command>+ </DialogContent>+ </Dialog>+ )+}++const CommandInput = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Input>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>+>(({ className, ...props }, ref) => (+ <div className="flex items-center border-b px-3" cmdk-input-wrapper="">+ <Search className="mr-2 h-4 w-4 shrink-0 opacity-50" />+ <CommandPrimitive.Input+ ref={ref}+ className={cn(+ 'placeholder:text-foreground-muted flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none disabled:cursor-not-allowed disabled:opacity-50',+ className+ )}+ {...props}+ />+ </div>+))++CommandInput.displayName = CommandPrimitive.Input.displayName++const CommandList = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.List>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.List+ ref={ref}+ className={cn('max-h-[300px] overflow-y-auto overflow-x-hidden', className)}+ {...props}+ />+))++CommandList.displayName = CommandPrimitive.List.displayName++const CommandEmpty = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Empty>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>+>((props, ref) => (+ <CommandPrimitive.Empty ref={ref} className="py-6 text-center text-sm" {...props} />+))++CommandEmpty.displayName = CommandPrimitive.Empty.displayName++const CommandGroup = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Group>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.Group+ ref={ref}+ className={cn(+ 'overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground',+ className+ )}+ {...props}+ />+))++CommandGroup.displayName = CommandPrimitive.Group.displayName++const CommandSeparator = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Separator>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.Separator+ ref={ref}+ className={cn('-mx-1 h-px bg-border', className)}+ {...props}+ />+))+CommandSeparator.displayName = CommandPrimitive.Separator.displayName++const CommandItem = React.forwardRef<+ React.ElementRef<typeof CommandPrimitive.Item>,+ React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>+>(({ className, ...props }, ref) => (+ <CommandPrimitive.Item+ ref={ref}+ className={cn(+ 'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',+ className+ )}+ {...props}+ />+))++CommandItem.displayName = CommandPrimitive.Item.displayName++const CommandShortcut = ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) => {+ return (+ <span+ className={cn('ml-auto text-xs tracking-widest text-muted-foreground', className)}+ {...props}+ />+ )+}+CommandShortcut.displayName = 'CommandShortcut'++export {+ Command,+ CommandDialog,+ CommandInput,+ CommandList,+ CommandEmpty,+ CommandGroup,+ CommandItem,+ CommandShortcut,+ CommandSeparator,+}diff --git a/packages/ui/src/components/shadcn/dialog.tsx b/packages/ui/src/components/shadcn/dialog.tsxnew file mode 100644index 00000000000..5055e1bdddd--- /dev/null+++ b/packages/ui/src/components/shadcn/dialog.tsx@@ -0,0 +1,106 @@+'use client'++import * as React from 'react'+import * as DialogPrimitive from '@radix-ui/react-dialog'+import { X } from 'lucide-react'++import { cn } from '@ui/lib/utils'++const Dialog = DialogPrimitive.Root++const DialogTrigger = DialogPrimitive.Trigger++const DialogPortal = ({ className, children, ...props }: DialogPrimitive.DialogPortalProps) => (+ <DialogPrimitive.Portal className={cn(className)} {...props}>+ <div className="fixed inset-0 z-50 flex items-start justify-center sm:items-center">+ {children}+ </div>+ </DialogPrimitive.Portal>+)+DialogPortal.displayName = DialogPrimitive.Portal.displayName++const DialogOverlay = React.forwardRef<+ React.ElementRef<typeof DialogPrimitive.Overlay>,+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>+>(({ className, ...props }, ref) => (+ <DialogPrimitive.Overlay+ ref={ref}+ className={cn(+ 'fixed inset-0 z-50 bg-background/80 backdrop-blur-sm transition-all duration-100 data-[state=closed]:animate-out data-[state=closed]:fade-out data-[state=open]:fade-in',+ className+ )}+ {...props}+ />+))+DialogOverlay.displayName = DialogPrimitive.Overlay.displayName++const DialogContent = React.forwardRef<+ React.ElementRef<typeof DialogPrimitive.Content>,+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>+>(({ className, children, ...props }, ref) => (+ <DialogPortal>+ <DialogOverlay />+ <DialogPrimitive.Content+ ref={ref}+ className={cn(+ 'fixed z-50 grid w-full gap-4 rounded-b-lg border bg-background p-6 shadow-lg animate-in data-[state=open]:fade-in-90 data-[state=open]:slide-in-from-bottom-10 sm:max-w-lg sm:rounded-lg sm:zoom-in-90 data-[state=open]:sm:slide-in-from-bottom-0',+ className+ )}+ {...props}+ >+ {children}+ <DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">+ <X className="h-4 w-4" />+ <span className="sr-only">Close</span>+ </DialogPrimitive.Close>+ </DialogPrimitive.Content>+ </DialogPortal>+))+DialogContent.displayName = DialogPrimitive.Content.displayName++const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (+ <div className={cn('flex flex-col space-y-1.5 text-center sm:text-left', className)} {...props} />+)+DialogHeader.displayName = 'DialogHeader'++const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (+ <div+ className={cn('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className)}+ {...props}+ />+)+DialogFooter.displayName = 'DialogFooter'++const DialogTitle = React.forwardRef<+ React.ElementRef<typeof DialogPrimitive.Title>,+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>+>(({ className, ...props }, ref) => (+ <DialogPrimitive.Title+ ref={ref}+ className={cn('text-lg font-semibold leading-none tracking-tight', className)}+ {...props}+ />+))+DialogTitle.displayName = DialogPrimitive.Title.displayName++const DialogDescription = React.forwardRef<+ React.ElementRef<typeof DialogPrimitive.Description>,+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>+>(({ className, ...props }, ref) => (+ <DialogPrimitive.Description+ ref={ref}+ className={cn('text-sm text-muted-foreground', className)}+ {...props}+ />+))+DialogDescription.displayName = DialogPrimitive.Description.displayName++export {+ Dialog,+ DialogTrigger,+ DialogContent,+ DialogHeader,+ DialogFooter,+ DialogTitle,+ DialogDescription,+}diff --git a/packages/ui/src/components/shadcn/stories/ComboBox.stories.tsx b/packages/ui/src/components/shadcn/stories/ComboBox.stories.tsxnew file mode 100644index 00000000000..08d04d8dfbe--- /dev/null+++ b/packages/ui/src/components/shadcn/stories/ComboBox.stories.tsx@@ -0,0 +1,423 @@+import {+ Form,+ FormControl,+ FormDescription,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from '@ui/components/shadcn/form'+import { zodResolver } from '@hookform/resolvers/zod'+import type { Meta } from '@storybook/react'+import { Button } from '@ui/components/shadcn/button'+import {+ Command,+ CommandEmpty,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+} from '@ui/components/shadcn/command'+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuGroup,+ DropdownMenuItem,+ DropdownMenuLabel,+ DropdownMenuSeparator,+ DropdownMenuShortcut,+ DropdownMenuSub,+ DropdownMenuSubContent,+ DropdownMenuSubTrigger,+ DropdownMenuTrigger,+} from '@ui/components/shadcn/dropdown-menu'+import { Popover, PopoverContent, PopoverTrigger } from '@ui/components/shadcn/popover'+import { toast } from '@ui/components/shadcn/use-toast'+import { cn } from '@ui/lib/utils'+import {+ ArrowUpCircle,+ Calendar,+ Check,+ CheckCircle2,+ ChevronsUpDown,+ Circle,+ HelpCircle,+ LucideIcon,+ MoreHorizontal,+ Tags,+ Trash,+ User,+ XCircle,+} from 'lucide-react'+import React from 'react'+import { useForm } from 'react-hook-form'+import * as z from 'zod'++const meta: Meta<typeof DropdownMenu> = {+ /* π 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: 'shadcn/Combobox',+ component: DropdownMenu,+}++export default meta++// type Story = StoryObj<typeof DropdownMenu>++/*+ *π Render functions are a framework specific feature to allow you control on how the component renders.+ * See https://storybook.js.org/docs/react/api/csf+ * to learn how to use render functions.+ */++export const Combobox = {+ args: {},+ render: ({}) => {+ const [open, setOpen] = React.useState(false)+ const [value, setValue] = React.useState('')++ const frameworks = [+ {+ value: 'next.js',+ label: 'Next.js',+ },+ {+ value: 'sveltekit',+ label: 'SvelteKit',+ },+ {+ value: 'nuxt.js',+ label: 'Nuxt.js',+ },+ {+ value: 'remix',+ label: 'Remix',+ },+ {+ value: 'astro',+ label: 'Astro',+ },+ ]++ return (+ <Popover open={open} onOpenChange={setOpen}>+ <PopoverTrigger asChild>+ <Button+ variant="outline"+ role="combobox"+ aria-expanded={open}+ className="w-[200px] justify-between"+ >+ {value+ ? frameworks.find((framework) => framework.value === value)?.label+ : 'Select framework...'}+ <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />+ </Button>+ </PopoverTrigger>+ <PopoverContent className="w-[200px] p-0" align="start" side="right">+ <Command>+ <CommandInput placeholder="Search framework..." className="border-none ring-0" />+ <CommandEmpty>No framework found.</CommandEmpty>+ <CommandGroup>+ {frameworks.map((framework) => (+ <CommandItem+ key={framework.value}+ onSelect={(currentValue) => {+ setValue(currentValue === value ? '' : currentValue)+ setOpen(false)+ }}+ >+ <Check+ className={cn(+ 'mr-2 h-4 w-4',+ value === framework.value ? 'opacity-100' : 'opacity-0'+ )}+ />+ {framework.label}+ </CommandItem>+ ))}+ </CommandGroup>+ </Command>+ </PopoverContent>+ </Popover>+ )+ },+}++export const PopoverExample = {+ args: {},+ render: ({}) => {+ type Status = {+ value: string+ label: string+ icon: LucideIcon+ }++ const statuses: Status[] = [+ {+ value: 'backlog',+ label: 'Backlog',+ icon: HelpCircle,+ },+ {+ value: 'todo',+ label: 'Todo',+ icon: Circle,+ },+ {+ value: 'in progress',+ label: 'In Progress',+ icon: ArrowUpCircle,+ },+ {+ value: 'done',+ label: 'Done',+ icon: CheckCircle2,+ },+ {+ value: 'canceled',+ label: 'Canceled',+ icon: XCircle,+ },+ ]++ const [open, setOpen] = React.useState(false)+ const [selectedStatus, setSelectedStatus] = React.useState<Status | null>(null)++ return (+ <div className="flex items-center space-x-4">+ <p className="text-sm text-muted-foreground">Status</p>+ <Popover open={open} onOpenChange={setOpen}>+ <PopoverTrigger asChild>+ <Button variant="outline" size="sm" className="w-[150px] justify-start">+ {selectedStatus ? (+ <>+ <selectedStatus.icon className="mr-2 h-4 w-4 shrink-0" />+ {selectedStatus.label}+ </>+ ) : (+ <>+ Set status</>+ )}+ </Button>+ </PopoverTrigger>+ <PopoverContent className="p-0" side="right" align="start">+ <Command>+ <CommandInput placeholder="Change status..." />+ <CommandList>+ <CommandEmpty>No results found.</CommandEmpty>+ <CommandGroup>+ {statuses.map((status) => (+ <CommandItem+ key={status.value}+ onSelect={(value) => {+ setSelectedStatus(+ statuses.find((priority) => priority.value === value) || null+ )+ setOpen(false)+ }}+ >+ <status.icon+ className={cn(+ 'mr-2 h-4 w-4',+ status.value === selectedStatus?.value ? 'opacity-100' : 'opacity-40'+ )}+ />+ <span>{status.label}</span>+ </CommandItem>+ ))}+ </CommandGroup>+ </CommandList>+ </Command>+ </PopoverContent>+ </Popover>+ </div>+ )+ },+}++export const DropdownExample = {+ args: {},+ render: ({}) => {+ const [label, setLabel] = React.useState('feature')+ const [open, setOpen] = React.useState(false)++ const labels = [+ 'feature',+ 'bug',+ 'enhancement',+ 'documentation',+ 'design',+ 'question',+ 'maintenance',+ ]+ return (+ <div className="flex w-full flex-col items-start justify-between rounded-md border px-4 py-3 sm:flex-row sm:items-center">+ <p className="text-sm font-medium leading-none">+ <span className="mr-2 rounded-lg bg-primary px-2 py-1 text-xs text-primary-foreground">+ {label}+ </span>+ <span className="text-muted-foreground">Create a new project</span>+ </p>+ <DropdownMenu open={open} onOpenChange={setOpen}>+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" size="sm">+ <MoreHorizontal />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" className="w-[200px]">+ <DropdownMenuLabel>Actions</DropdownMenuLabel>+ <DropdownMenuGroup>+ <DropdownMenuItem>+ <User className="mr-2 h-4 w-4" />+ Assign to...+ </DropdownMenuItem>+ <DropdownMenuItem>+ <Calendar className="mr-2 h-4 w-4" />+ Set due date...+ </DropdownMenuItem>+ <DropdownMenuSeparator />+ <DropdownMenuSub>+ <DropdownMenuSubTrigger>+ <Tags className="mr-2 h-4 w-4" />+ Apply label+ </DropdownMenuSubTrigger>+ <DropdownMenuSubContent className="p-0">+ <Command>+ <CommandInput placeholder="Filter label..." autoFocus={true} />+ <CommandList>+ <CommandEmpty>No label found.</CommandEmpty>+ <CommandGroup>+ {labels.map((label) => (+ <CommandItem+ key={label}+ onSelect={(value) => {+ setLabel(value)+ setOpen(false)+ }}+ >+ {label}+ </CommandItem>+ ))}+ </CommandGroup>+ </CommandList>+ </Command>+ </DropdownMenuSubContent>+ </DropdownMenuSub>+ <DropdownMenuSeparator />+ <DropdownMenuItem className="text-red-600">+ <Trash className="mr-2 h-4 w-4" />+ Delete+ <DropdownMenuShortcut>ββ«</DropdownMenuShortcut>+ </DropdownMenuItem>+ </DropdownMenuGroup>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>+ )+ },+}++export const ReactHookFormDemo = {+ args: {},+ render: ({}) => {+ const languages = [+ { label: 'English', value: 'en' },+ { label: 'French', value: 'fr' },+ { label: 'German', value: 'de' },+ { label: 'Spanish', value: 'es' },+ { label: 'Portuguese', value: 'pt' },+ { label: 'Russian', value: 'ru' },+ { label: 'Japanese', value: 'ja' },+ { label: 'Korean', value: 'ko' },+ { label: 'Chinese', value: 'zh' },+ ] as const++ const FormSchema = z.object({+ language: z.string({+ required_error: 'Please select a language.',+ }),+ })++ 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-6">+ <FormField+ control={form.control}+ name="language"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <FormLabel>Language</FormLabel>+ <Popover>+ <PopoverTrigger asChild>+ <FormControl>+ <Button+ variant="outline"+ role="combobox"+ className={cn(+ 'w-[200px] justify-between',+ !field.value && 'text-muted-foreground'+ )}+ >+ {field.value+ ? languages.find((language) => language.value === field.value)?.label+ : 'Select language'}+ <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />+ </Button>+ </FormControl>+ </PopoverTrigger>+ <PopoverContent className="w-[200px] p-0">+ <Command>+ <CommandInput placeholder="Search framework..." />+ <CommandEmpty>No framework found.</CommandEmpty>+ <CommandGroup>+ {languages.map((language) => (+ <CommandItem+ value={language.value}+ key={language.value}+ onSelect={(value) => {+ form.setValue('language', value)+ }}+ >+ <Check+ className={cn(+ 'mr-2 h-4 w-4',+ language.value === field.value ? 'opacity-100' : 'opacity-0'+ )}+ />+ {language.label}+ </CommandItem>+ ))}+ </CommandGroup>+ </Command>+ </PopoverContent>+ </Popover>+ <FormDescription>+ This is the language that will be used in the dashboard.+ </FormDescription>+ <FormMessage />+ </FormItem>+ )}+ />+ <Button type="submit">Submit</Button>+ </form>+ </Form>+ )+ },+}