The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Alert updated
Jonathan Summers-Muir4514035a4cf2
diff --git a/packages/ui/.storybook/main.ts b/packages/ui/.storybook/main.tsindex a166e5ddacc..90d3cf7e460 100644--- a/packages/ui/.storybook/main.ts+++ b/packages/ui/.storybook/main.ts@@ -10,7 +10,7 @@ const config: StorybookConfig = {// // After all stories are cleaned, revert to wildcard import.stories: ['../src/components/Accordion/Accordion.stories.tsx',- // '../src/components/Alert/Alert.stories.tsx',+ '../src/components/Alert/Alert.stories.tsx',// '../src/components/Avatar/Avatar.stories.tsx','../src/components/Button/Button.stories.tsx',// '../src/components/Checkbox/Checkbox.stories.tsx',diff --git a/packages/ui/src/components/Alert/Alert-old.stories.tsx b/packages/ui/src/components/Alert/Alert-old.stories.tsxnew file mode 100644index 00000000000..915e408018b--- /dev/null+++ b/packages/ui/src/components/Alert/Alert-old.stories.tsx@@ -0,0 +1,135 @@+import React from 'react'++import Alert, { AlertProps } from './Alert'++export default {+ title: 'Displays/Alerts',+ component: Alert,+}++export const Neutral = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++export const Success = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++export const SuccessWithIcon = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++export const Danger = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++export const DangerWithIcon = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++export const Info = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++export const InfoWithIcon = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++export const Warning = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++export const WarningWithIcon = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++export const Closable = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++export const WithAction = (args: AlertProps) => (+ <Alert {...args}>+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.+ </Alert>+)++Neutral.args = {+ title: 'Success alert with icon',+ withIcon: true,+}++Success.args = {+ title: 'Success alert',+ variant: 'success',+}++SuccessWithIcon.args = {+ title: 'Success alert with icon',+ variant: 'success',+ withIcon: true,+}++Danger.args = {+ title: 'Danger alert',+ variant: 'danger',+}++DangerWithIcon.args = {+ title: 'Danger alert with icon',+ variant: 'danger',+ withIcon: true,+}++Info.args = {+ title: 'Info alert',+ variant: 'info',+}++InfoWithIcon.args = {+ title: 'Info alert with icon',+ variant: 'info',+ withIcon: true,+}++Warning.args = {+ title: 'Warning alert',+ variant: 'warning',+}++WarningWithIcon.args = {+ title: 'Warning alert with icon',+ variant: 'warning',+ withIcon: true,+}++Closable.args = {+ title: 'Closable alert',+ closable: true,+}++WithAction.args = {+ title: 'Alert with action',+ variant: 'warning',+ withIcon: true,+ actions: <div>Hello</div>,+}diff --git a/packages/ui/src/components/Alert/Alert-old.tsx b/packages/ui/src/components/Alert/Alert-old.tsxnew file mode 100644index 00000000000..cf0b96fe810--- /dev/null+++ b/packages/ui/src/components/Alert/Alert-old.tsx@@ -0,0 +1,84 @@+import React, { useState } from 'react'+import { IconAlertTriangle } from '../Icon/icons/IconAlertTriangle'++import { IconInfo } from '../Icon/icons/IconInfo'+import { IconX } from '../Icon/icons/IconX'++import styleHandler from '../../lib/theme/styleHandler'+import { IconAlertOctagon } from '../Icon/icons/IconAlertOctagon'+import { IconCheckCircle } from '../Icon/icons/IconCheckCircle'++export interface AlertProps {+ variant?: 'success' | 'danger' | 'warning' | 'info' | 'neutral'+ className?: string+ title: string | React.ReactNode+ withIcon?: boolean+ closable?: boolean+ children?: React.ReactNode+ icon?: React.ReactNode+ actions?: React.ReactNode+}++const icons: Record<'success' | 'danger' | 'warning' | 'info' | 'neutral', React.ReactElement> = {+ danger: <IconAlertOctagon strokeWidth={1.5} size={18} />,+ success: <IconCheckCircle strokeWidth={1.5} size={18} />,+ warning: <IconAlertTriangle strokeWidth={1.5} size={18} />,+ info: <IconInfo strokeWidth={1.5} size={18} />,+ neutral: <></>,+}++function Alert({+ variant = 'neutral',+ className,+ title,+ withIcon,+ closable,+ children,+ icon,+ actions,+}: AlertProps) {+ let __styles = styleHandler('alert')++ const [visible, setVisible] = useState(true)++ let containerClasses = [__styles.base]+ containerClasses.push(__styles.variant[variant].base)++ if (className) containerClasses.push(className)++ let descriptionClasses = [__styles.description, __styles.variant[variant].description]+ let closeButtonClasses = [__styles.close]++ return (+ <>+ {visible && (+ <div className={containerClasses.join(' ')}>+ {withIcon ? (+ <div className={__styles.variant[variant].icon}>{withIcon && icons[variant]}</div>+ ) : null}+ {icon && icon}+ <div className="flex flex-1 items-center justify-between">+ <div>+ <h3 className={[__styles.variant[variant].header, __styles.header].join(' ')}>+ {title}+ </h3>+ <div className={descriptionClasses.join(' ')}>{children}</div>+ </div>+ {actions}+ </div>+ {closable && (+ <button+ aria-label="Close alert"+ onClick={() => setVisible(false)}+ className={closeButtonClasses.join(' ')}+ >+ <IconX strokeWidth={2} size={16} />+ </button>+ )}+ </div>+ )}+ </>+ )+}++export default Alertdiff --git a/packages/ui/src/components/Alert/Alert.stories.tsx b/packages/ui/src/components/Alert/Alert.stories.tsxindex 915e408018b..de5cf016871 100644--- a/packages/ui/src/components/Alert/Alert.stories.tsx+++ b/packages/ui/src/components/Alert/Alert.stories.tsx@@ -1,135 +1,92 @@-import React from 'react'+// Button.stories.ts|tsx-import Alert, { AlertProps } from './Alert'+import type { Meta, StoryObj } from '@storybook/react'-export default {- title: 'Displays/Alerts',- component: Alert,-}--export const Neutral = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)--export const Success = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)--export const SuccessWithIcon = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)--export const Danger = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)--export const DangerWithIcon = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)--export const Info = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)--export const InfoWithIcon = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)--export const Warning = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)--export const WarningWithIcon = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)--export const Closable = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)+import { Alert, AlertProps } from './Alert'-export const WithAction = (args: AlertProps) => (- <Alert {...args}>- Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur amet labore.- </Alert>-)+import { IconAirplay } from '../Icon/icons/IconAirplay'+import { Terminal } from 'lucide-react'-Neutral.args = {- title: 'Success alert with icon',- withIcon: true,-}--Success.args = {- title: 'Success alert',- variant: 'success',-}--SuccessWithIcon.args = {- title: 'Success alert with icon',- variant: 'success',- withIcon: true,-}--Danger.args = {- title: 'Danger alert',- variant: 'danger',-}--DangerWithIcon.args = {- title: 'Danger alert with icon',- variant: 'danger',- withIcon: true,-}--Info.args = {- title: 'Info alert',- variant: 'info',+const meta: Meta<typeof Alert> = {+ /* π 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: 'General/Alert',+ component: Alert,}-InfoWithIcon.args = {- title: 'Info alert with icon',- variant: 'info',- withIcon: true,+export default meta++type Story = StoryObj<typeof Alert>++/*+ *π 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 Info = {+ args: {+ variant: 'info',+ withIcon: true,+ },+ render: ({ withIcon, variant }: AlertProps) => (+ <Alert variant={variant} withIcon={withIcon}>+ <Alert.Title>Info Alert</Alert.Title>+ <Alert.Description>This is an informative message for your application.</Alert.Description>+ </Alert>+ ),}-Warning.args = {- title: 'Warning alert',- variant: 'warning',+export const Danger = {+ args: {+ variant: 'danger',+ withIcon: true,+ },+ render: ({ withIcon, variant }: AlertProps) => (+ <Alert variant={variant} withIcon={withIcon}>+ <Alert.Title>Danger Alert</Alert.Title>+ <Alert.Description>This is a dangerous warning for your application.</Alert.Description>+ </Alert>+ ),}-WarningWithIcon.args = {- title: 'Warning alert with icon',- variant: 'warning',- withIcon: true,+export const Warning = {+ args: {+ variant: 'warning',+ withIcon: true,+ },+ render: ({ withIcon, variant }: AlertProps) => (+ <Alert variant={variant} withIcon={withIcon}>+ <Alert.Title>Warning Alert</Alert.Title>+ <Alert.Description>This is a warning message for your application.</Alert.Description>+ </Alert>+ ),}-Closable.args = {- title: 'Closable alert',- closable: true,+export const Success = {+ args: {+ variant: 'success',+ withIcon: true,+ },+ render: ({ withIcon, variant }: AlertProps) => (+ <Alert variant={variant} withIcon={withIcon}>+ <Alert.Title>Success Alert</Alert.Title>+ <Alert.Description>This is a successful notification for your application.</Alert.Description>+ </Alert>+ ),}-WithAction.args = {- title: 'Alert with action',- variant: 'warning',- withIcon: true,- actions: <div>Hello</div>,+export const Neutral = {+ args: {+ variant: 'neutral',+ withIcon: true,+ },+ render: ({ withIcon, variant }: AlertProps) => (+ <Alert variant={variant} withIcon={withIcon}>+ <Alert.Title>Neutral Alert</Alert.Title>+ <Alert.Description>This is a neutral message for your application.</Alert.Description>+ </Alert>+ ),}diff --git a/packages/ui/src/components/Alert/Alert.tsx b/packages/ui/src/components/Alert/Alert.tsxindex cf0b96fe810..73f58c95b2b 100644--- a/packages/ui/src/components/Alert/Alert.tsx+++ b/packages/ui/src/components/Alert/Alert.tsx@@ -1,84 +1,145 @@-import React, { useState } from 'react'-import { IconAlertTriangle } from '../Icon/icons/IconAlertTriangle'--import { IconInfo } from '../Icon/icons/IconInfo'-import { IconX } from '../Icon/icons/IconX'--import styleHandler from '../../lib/theme/styleHandler'-import { IconAlertOctagon } from '../Icon/icons/IconAlertOctagon'-import { IconCheckCircle } from '../Icon/icons/IconCheckCircle'--export interface AlertProps {- variant?: 'success' | 'danger' | 'warning' | 'info' | 'neutral'- className?: string- title: string | React.ReactNode- withIcon?: boolean- closable?: boolean- children?: React.ReactNode- icon?: React.ReactNode- actions?: React.ReactNode+import * as React from 'react'+import { VariantProps, cva } from 'class-variance-authority'+import { cn } from '@ui/lib/utils'+import { AlertCircle, AlertOctagon, AlertTriangle, Check, Info } from 'lucide-react'++export type AlertRootVariantsProps = VariantProps<typeof alertRootVariants>+const alertRootVariants = cva(+ `relative w-full+ rounded-lg border+ py-4 px-6+ [&>svg]:absolute [&>svg]:text-foreground [&>svg]:left-4 [&>svg]:top-4 [&>svg+div]:translate-y-[-3px] [&:has(svg)]:pl-11`,+ {+ variants: {+ variant: {+ danger: `bg-red-200 dark:bg-red-100 text-red-1200 border-red-700 [&>svg]:text-red-1200`,+ warning: `bg-amber-200 dark:bg-amber-100 border-amber-700 [&>svg]:text-amber-1200`,+ info: `bg-scale-400 border-scale-500 dark:bg-scale-100 dark:border-scale-300 [&>svg]:text-scale-1200`,+ success: `bg-brand-300 dark:bg-brand-100 border-brand-700 [&>svg]:text-brand-900`,+ neutral: `bg-scale-300 dark:bg-scale-300 border-scale-500 [&>svg]:text-scale-900`,+ },+ },+ defaultVariants: {+ variant: 'info',+ },+ }+)++const alertTitleVariants = cva('mb-1 font-medium leading-none tracking-tight', {+ variants: {+ variant: {+ danger: `text-red-1200`,+ warning: `text-amber-1200`,+ info: `text-scale-1200`,+ success: `text-brand-1200`,+ neutral: `text-scale-1200`,+ },+ defaultVariants: {+ variant: 'info',+ },+ },+})++const alertDescriptionVariants = cva('text-sm [&_p]:leading-relaxed', {+ variants: {+ variant: {+ danger: 'text-red-1100',+ warning: 'text-amber-1100',+ info: 'text-scale-1100',+ success: 'text-brand-1100',+ neutral: 'text-scale-1100',+ },+ defaultVariants: {+ variant: 'info',+ },+ },+})++interface ContextValue {+ variant: AlertRootVariantsProps['variant']}-const icons: Record<'success' | 'danger' | 'warning' | 'info' | 'neutral', React.ReactElement> = {- danger: <IconAlertOctagon strokeWidth={1.5} size={18} />,- success: <IconCheckCircle strokeWidth={1.5} size={18} />,- warning: <IconAlertTriangle strokeWidth={1.5} size={18} />,- info: <IconInfo strokeWidth={1.5} size={18} />,- neutral: <></>,+const AlertContext = React.createContext<ContextValue>({+ variant: undefined,+})++// Define the Alert component+interface AlertProps+ extends React.HTMLAttributes<HTMLDivElement>,+ VariantProps<typeof alertRootVariants> {+ withIcon: boolean}-function Alert({- variant = 'neutral',- className,- title,- withIcon,- closable,- children,- icon,- actions,-}: AlertProps) {- let __styles = styleHandler('alert')-- const [visible, setVisible] = useState(true)-- let containerClasses = [__styles.base]- containerClasses.push(__styles.variant[variant].base)-- if (className) containerClasses.push(className)-- let descriptionClasses = [__styles.description, __styles.variant[variant].description]- let closeButtonClasses = [__styles.close]-- return (- <>- {visible && (- <div className={containerClasses.join(' ')}>- {withIcon ? (- <div className={__styles.variant[variant].icon}>{withIcon && icons[variant]}</div>- ) : null}- {icon && icon}- <div className="flex flex-1 items-center justify-between">- <div>- <h3 className={[__styles.variant[variant].header, __styles.header].join(' ')}>- {title}- </h3>- <div className={descriptionClasses.join(' ')}>{children}</div>- </div>- {actions}- </div>- {closable && (- <button- aria-label="Close alert"- onClick={() => setVisible(false)}- className={closeButtonClasses.join(' ')}- >- <IconX strokeWidth={2} size={16} />- </button>- )}- </div>- )}- </>- )+interface AlertComponent+ extends React.ForwardRefExoticComponent<AlertProps & React.RefAttributes<HTMLDivElement>> {+ Title: typeof AlertTitle+ Description: typeof AlertDescription}-export default Alert+type AlertIconVariant = Exclude<AlertRootVariantsProps['variant'], null | undefined>+const icons: Record<AlertIconVariant, React.ReactElement> = {+ danger: <AlertOctagon strokeWidth={1.5} size={18} />,+ success: <Check strokeWidth={1.5} size={18} />,+ warning: <AlertTriangle strokeWidth={1.5} size={18} />,+ info: <Info strokeWidth={1.5} size={18} />,+ neutral: <></>,+}++const Alert = React.forwardRef<HTMLDivElement, AlertProps>(+ ({ className, withIcon, variant = 'info', children, ...props }, ref) => {+ const contextValue = {+ variant,+ }++ return (+ <div+ ref={ref}+ role="alert"+ className={cn(alertRootVariants({ variant }), className)}+ {...props}+ children={+ <AlertContext.Provider value={{ ...contextValue }}>+ {withIcon && icons[variant as AlertIconVariant]}+ {children}+ </AlertContext.Provider>+ }+ />+ )+ }+) as AlertComponent++Alert.displayName = 'Alert'++// Define the AlertTitle component as a subcomponent of Alert+interface AlertTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {}++const AlertTitle = React.forwardRef<HTMLHeadingElement, AlertTitleProps>(+ ({ className, ...props }, ref) => {+ const { variant } = React.useContext(AlertContext)+ console.log('variant', variant)+ return <h5 ref={ref} className={cn(alertTitleVariants({ variant }), className)} {...props} />+ }+)++AlertTitle.displayName = 'AlertTitle'++// Define the AlertDescription component as a subcomponent of Alert+interface AlertDescriptionProps extends React.HTMLAttributes<HTMLParagraphElement> {}++const AlertDescription = React.forwardRef<HTMLParagraphElement, AlertDescriptionProps>(+ ({ className, ...props }, ref) => {+ const { variant } = React.useContext(AlertContext)+ return (+ <div ref={ref} className={cn(alertDescriptionVariants({ variant }), className)} {...props} />+ )+ }+)++AlertDescription.displayName = 'AlertDescription'++// Attach the subcomponents to the Alert component+Alert.Title = AlertTitle+Alert.Description = AlertDescription++// Export the Alert component+export { Alert }