Skip to content

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

Chore/add first pattern docs (#21741)

Jonathan Summers-Muir9104cbc35936
diff --git a/apps/storybook/.storybook/main.js b/apps/storybook/.storybook/main.js
index 210cbfea196..b339652d95f 100644
--- a/apps/storybook/.storybook/main.js
+++ b/apps/storybook/.storybook/main.js
@@ -11,14 +11,16 @@ function getAbsolutePath(value) {
/** @type { import('@storybook/nextjs').StorybookConfig } */
const config = {
stories: [
+ // package based stories
+ '../../../packages/ui-patterns/**/*.stories.@(js|jsx|mjs|ts|tsx)',
+ // primitives
+ '../../../packages/ui/src/components/shadcn/**/*.stories.@(js|jsx|mjs|ts|tsx)',
+ //
// local stories
'../stories/**/*.mdx',
'../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)',
// app based stories
// -- add app based stories here
- // package based stories
- '../../../packages/ui/src/components/shadcn/**/*.stories.@(js|jsx|mjs|ts|tsx)',
- '../../../packages/ui-patterns/**/*.stories.@(js|jsx|mjs|ts|tsx)',
],
addons: [
getAbsolutePath('@storybook/addon-links'),
diff --git a/apps/storybook/.storybook/preview.css b/apps/storybook/.storybook/preview.css
index 7b163aac313..4695f453f0e 100644
--- a/apps/storybook/.storybook/preview.css
+++ b/apps/storybook/.storybook/preview.css
@@ -3,10 +3,30 @@
@tailwind utilities;
@import './../../../packages/ui/build/css/source/global.css';
-@import './../../../packages/ui/build/css/themes/deep-dark.css';
@import './../../../packages/ui/build/css/themes/dark.css';
+@import './../../../packages/ui/build/css/themes/deep-dark.css';
@import './../../../packages/ui/build/css/themes/light.css';
+@font-face {
+ font-family: 'custom-font';
+ src:
+ url(../../../packages/common/assets/fonts/CustomFont-Book.woff2) format('woff2'),
+ url(../../../packages/common/assets/fonts/CustomFont-Book.woff) format('woff');
+ font-weight: 400;
+ font-style: normal;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: 'custom-font';
+ src:
+ url(../../../packages/common/assets/fonts/CustomFont-Medium.woff2) format('woff2'),
+ url(../../../packages/common/assets/fonts/CustomFont-Medium.woff) format('woff');
+ font-weight: 500;
+ font-style: normal;
+ font-display: swap;
+}
+
@layer base {
:root {
/* --background: 0 0% 100%;
@@ -73,10 +93,15 @@
}
}
-html {
- @apply bg text font-[400];
- font-feature-settings:
- 'rlig' 1,
- 'calt' 1;
- font-family: 'Circular std';
+html,
+body,
+#__next,
+.main {
+ @apply bg-studio;
+ @apply text-foreground;
+ height: 100%;
+ padding: 0;
+ margin: 0;
+ -moz-osx-font-smoothing: grayscale;
+ -webkit-font-smoothing: antialiased;
}
diff --git a/apps/storybook/.storybook/preview.js b/apps/storybook/.storybook/preview.js
index 2075734049b..929a04a191d 100644
--- a/apps/storybook/.storybook/preview.js
+++ b/apps/storybook/.storybook/preview.js
@@ -1,4 +1,4 @@
-import { withThemeByClassName } from '@storybook/addon-themes'
+import { withThemeByClassName, withThemeByDataAttribute } from '@storybook/addon-themes'
import './preview.css'
export const decorators = [
@@ -10,4 +10,12 @@ export const decorators = [
},
defaultTheme: 'dark',
}),
+ withThemeByDataAttribute({
+ themes: {
+ light: 'light',
+ dark: 'dark',
+ 'deep-dark': 'dark',
+ },
+ defaultTheme: 'dark',
+ }),
]
diff --git a/apps/storybook/tailwind.config.js b/apps/storybook/tailwind.config.js
index bcf8e6d9c94..43c0da26c12 100644
--- a/apps/storybook/tailwind.config.js
+++ b/apps/storybook/tailwind.config.js
@@ -1,5 +1,5 @@
const config = require('config/tailwind.config')
-const { fontFamily } = require('tailwindcss/defaultTheme')
+// const { fontFamily } = require('tailwindcss/defaultTheme')
module.exports = config({
content: [
@@ -9,60 +9,6 @@ module.exports = config({
'./../../packages/ui-patterns/**/*.*.{tsx,ts,js}',
],
// Toggle dark-mode based on .dark class or data-mode="dark"
- // darkMode: ['class', '[data-mode="dark"]'],
- theme: {
- container: {
- center: true,
- padding: '2rem',
- screens: {
- '2xl': '1400px',
- },
- },
- // extend: {
- // colors: {
- // border: 'hsl(var(--border-overlay))',
- // input: 'hsl(var(--border-control))',
- // ring: 'hsl(var(--ring))',
- // background: 'hsl(var(--background-default))',
- // foreground: 'hsl(var(--foreground-default))',
- // primary: {
- // DEFAULT: 'hsl(var(--foreground-default))',
- // foreground: 'hsl(var(--background-default))',
- // },
- // secondary: {
- // DEFAULT: 'hsl(var(--secondary))',
- // foreground: 'hsl(var(--secondary-foreground))',
- // },
- // destructive: {
- // DEFAULT: 'hsl(var(--destructive-default))',
- // foreground: 'hsl(var(--foreground-default))',
- // },
- // muted: {
- // DEFAULT: 'hsl(var(--border-overlay))',
- // foreground: 'hsl(var(--foreground-lighter))',
- // },
- // accent: {
- // DEFAULT: 'hsl(var(--background-overlay))',
- // foreground: 'hsl(var(--foreground-lighter))',
- // },
- // popover: {
- // DEFAULT: 'hsl(var(--background-overlay))',
- // foreground: 'hsl(var(--foreground-default))',
- // },
- // card: {
- // DEFAULT: 'hsl(var(--background-overlay))',
- // foreground: 'hsl(var(--foreground-default))',
- // },
- // },
- // borderRadius: {
- // lg: `var(--radius)`,
- // md: `calc(var(--radius) - 2px)`,
- // sm: 'calc(var(--radius) - 4px)',
- // },
- // fontFamily: {
- // sans: ['var(--font-sans)', ...fontFamily.sans],
- // },
- // },
- },
+ // darkMode: ['class', '[data-mode="dark"]']
plugins: [require('tailwindcss-animate')],
})
diff --git a/apps/storybook/tsconfig.json b/apps/storybook/tsconfig.json
new file mode 100644
index 00000000000..2af4d072e21
--- /dev/null
+++ b/apps/storybook/tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "compilerOptions": {
+ "baseUrl": ".",
+ "paths": {
+ "@ui/*": ["./../../packages/ui/src/*"] // handle ui package paths
+ }
+ },
+ "include": ["**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
+ "exclude": ["node_modules"]
+}
diff --git a/apps/studio/components/interfaces/BranchManagement/BranchManagement.tsx b/apps/studio/components/interfaces/BranchManagement/BranchManagement.tsx
index f8b8733614e..cfc761e5ed3 100644
--- a/apps/studio/components/interfaces/BranchManagement/BranchManagement.tsx
+++ b/apps/studio/components/interfaces/BranchManagement/BranchManagement.tsx
@@ -349,7 +349,7 @@ const BranchManagement = () => {
</ScaffoldContainer>
<TextConfirmModal
- size="medium"
+ variant={'warning'}
visible={selectedBranchToDelete !== undefined}
onCancel={() => setSelectedBranchToDelete(undefined)}
onConfirm={() => onConfirmDeleteBranch()}
@@ -358,8 +358,13 @@ const BranchManagement = () => {
confirmLabel="Delete branch"
confirmPlaceholder="Type in name of branch"
confirmString={selectedBranchToDelete?.name ?? ''}
- text={`This will delete your database preview branch "${selectedBranchToDelete?.name}"`}
- alert="You cannot recover this branch once it is deleted!"
+ alert={{ title: 'You cannot recover this branch once deleted' }}
+ text={
+ <>
+ This will delete your database preview branch
+ <span className="text-bold text-foreground">{selectedBranchToDelete?.name}</span>.
+ </>
+ }
/>
<ConfirmationModal
diff --git a/apps/studio/components/interfaces/Database/Functions/DeleteFunction.tsx b/apps/studio/components/interfaces/Database/Functions/DeleteFunction.tsx
index 2da5bec798f..8b15c1e5c9d 100644
--- a/apps/studio/components/interfaces/Database/Functions/DeleteFunction.tsx
+++ b/apps/studio/components/interfaces/Database/Functions/DeleteFunction.tsx
@@ -35,6 +35,7 @@ const DeleteFunction = ({ func, visible, setVisible }: DeleteFunctionProps) => {
return (
<>
<TextConfirmModal
+ variant={'warning'}
visible={visible}
onCancel={() => setVisible(!visible)}
onConfirm={handleDelete}
@@ -43,8 +44,14 @@ const DeleteFunction = ({ func, visible, setVisible }: DeleteFunctionProps) => {
confirmLabel={`Delete function ${name}`}
confirmPlaceholder="Type in name of function"
confirmString={name}
- text={`This will delete your function called ${name} of schema ${schema}.`}
- alert="You cannot recover this function once it is deleted!"
+ text={
+ <>
+ This will delete the function
+ <span className="text-bold text-foreground">{name}</span> from the schema
+ <span className="text-bold text-foreground">{schema}</span>
+ </>
+ }
+ alert={{ title: 'You cannot recover this function once deleted.' }}
/>
</>
)
diff --git a/apps/studio/components/interfaces/Database/Hooks/DeleteHookModal.tsx b/apps/studio/components/interfaces/Database/Hooks/DeleteHookModal.tsx
index 31768e8066d..cfbc125fdef 100644
--- a/apps/studio/components/interfaces/Database/Hooks/DeleteHookModal.tsx
+++ b/apps/studio/components/interfaces/Database/Hooks/DeleteHookModal.tsx
@@ -42,6 +42,7 @@ const DeleteHookModal = ({ selectedHook, visible, onClose }: DeleteHookModalProp
return (
<TextConfirmModal
+ variant={'warning'}
visible={visible}
size="medium"
onCancel={() => onClose()}
@@ -51,8 +52,14 @@ const DeleteHookModal = ({ selectedHook, visible, onClose }: DeleteHookModalProp
confirmLabel={`Delete ${name}`}
confirmPlaceholder="Type in name of webhook"
confirmString={name || ''}
- text={`This will delete the webhook "${name}" from the schema "${schema}".`}
- alert="You cannot recover this webhook once it is deleted!"
+ text={
+ <>
+ This will delete the webhook
+ <span className="text-bold text-foreground">{name}</span> rom the schema
+ <span className="text-bold text-foreground">{schema}</span>
+ </>
+ }
+ alert={{ title: 'You cannot recover this webhook once deleted.' }}
/>
)
}
diff --git a/apps/studio/components/interfaces/Database/Triggers/DeleteTrigger.tsx b/apps/studio/components/interfaces/Database/Triggers/DeleteTrigger.tsx
index 60b60d3ec45..80da310e632 100644
--- a/apps/studio/components/interfaces/Database/Triggers/DeleteTrigger.tsx
+++ b/apps/studio/components/interfaces/Database/Triggers/DeleteTrigger.tsx
@@ -37,6 +37,7 @@ const DeleteTrigger = ({ trigger, visible, setVisible }: DeleteTriggerProps) =>
return (
<TextConfirmModal
+ variant={'warning'}
visible={visible}
onCancel={() => setVisible(!visible)}
onConfirm={handleDelete}
@@ -45,8 +46,16 @@ const DeleteTrigger = ({ trigger, visible, setVisible }: DeleteTriggerProps) =>
confirmLabel={`Delete trigger ${name}`}
confirmPlaceholder="Type in name of trigger"
confirmString={name}
- text={`This will delete your trigger called ${name} of schema ${schema}.`}
- alert="You cannot recover this trigger once it is deleted!"
+ text={
+ <>
+ This will delete your trigger called{' '}
+ <span className="text-bold text-foreground">{name}</span> of schema{' '}
+ <span className="text-bold text-foreground">{schema}</span>
+ </>
+ }
+ alert={{
+ title: 'You cannot recover this trigger once deleted.',
+ }}
/>
)
}
diff --git a/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsx b/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsx
index 03a1b68cc14..caf5bcf3a32 100644
--- a/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsx
+++ b/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectButton.tsx
@@ -3,14 +3,15 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import { Button, Input } from 'ui'
+import toast from 'react-hot-toast'
+import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'
import { CANCELLATION_REASONS } from 'components/interfaces/Billing/Billing.constants'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
-import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'
import { useSendDowngradeFeedbackMutation } from 'data/feedback/exit-survey-send'
import { useProjectDeleteMutation } from 'data/projects/project-delete-mutation'
-import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
+import { useCheckPermissions, useSelectedOrganization } from 'hooks'
export interface DeleteProjectButtonProps {
type?: 'danger' | 'default'
@@ -18,7 +19,6 @@ export interface DeleteProjectButtonProps {
const DeleteProjectButton = ({ type = 'danger' }: DeleteProjectButtonProps) => {
const router = useRouter()
- const { ui } = useStore()
const { project } = useProjectContext()
const organization = useSelectedOrganization()
@@ -66,11 +66,7 @@ const DeleteProjectButton = ({ type = 'danger' }: DeleteProjectButtonProps) => {
if (project === undefined) return
if (!isFree && selectedReasons.length === 0) {
- return ui.setNotification({
- category: 'error',
- duration: 4000,
- message: 'Please select at least one reason for deleting your project',
- })
+ return toast.error('Please select at least one reason for deleting your project')
}
try {
@@ -85,7 +81,7 @@ const DeleteProjectButton = ({ type = 'danger' }: DeleteProjectButtonProps) => {
})
}
- ui.setNotification({ category: 'success', message: `Successfully deleted ${project.name}` })
+ toast.success(`Successfully deleted ${project.name}`)
router.push(`/projects`)
} finally {
}
@@ -120,13 +116,15 @@ const DeleteProjectButton = ({ type = 'danger' }: DeleteProjectButtonProps) => {
<TextConfirmModal
visible={isOpen}
loading={isSubmitting}
- size={isFree ? 'small' : 'xlarge'}
+ size={isFree ? 'small' : 'medium'}
title={`Confirm deletion of ${project?.name}`}
- alert={
- isFree
+ variant="destructive"
+ alert={{
+ title: isFree
? 'This action cannot be undone.'
- : `This will permanently delete the ${project?.name} project and all of its data, and cannot be undone`
- }
+ : `This will permanently delete the ${project?.name}`,
+ description: !isFree ? `All project data will be lost, and cannot be undone` : '',
+ }}
text={
isFree
? `This will permanently delete the ${project?.name} project and all of its data.`
diff --git a/apps/studio/components/to-be-cleaned/Storage/DeleteBucketModal.tsx b/apps/studio/components/to-be-cleaned/Storage/DeleteBucketModal.tsx
index 4bf0b55ae7e..969b924b20b 100644
--- a/apps/studio/components/to-be-cleaned/Storage/DeleteBucketModal.tsx
+++ b/apps/studio/components/to-be-cleaned/Storage/DeleteBucketModal.tsx
@@ -71,6 +71,7 @@ const DeleteBucketModal = ({ visible = false, bucket, onClose }: DeleteBucketMod
return (
<TextConfirmModal
+ variant={'destructive'}
visible={visible}
title={`Confirm deletion of ${bucket?.name}`}
confirmPlaceholder="Type in name of bucket"
@@ -80,11 +81,14 @@ const DeleteBucketModal = ({ visible = false, bucket, onClose }: DeleteBucketMod
loading={isDeleting}
text={
<>
- Your bucket <span className="font-bold">{bucket?.name}</span> and all its contents will be
- permanently deleted.
+ Your bucket <span className="font-bold text-foreground">{bucket?.name}</span> and all its
+ contents will be permanently deleted.
</>
}
- alert="You cannot recover this bucket once it is deleted."
+ alert={{
+ title: 'You cannot recover this bucket once deleted.',
+ description: 'All bucket data will be lost.',
+ }}
confirmLabel={`Delete bucket ${bucket?.name}`}
/>
)
diff --git a/packages/ui-patterns/Dialogs/TextConfirmModal.stories.tsx b/packages/ui-patterns/Dialogs/TextConfirmModal.stories.tsx
new file mode 100644
index 00000000000..7bc83779149
--- /dev/null
+++ b/packages/ui-patterns/Dialogs/TextConfirmModal.stories.tsx
@@ -0,0 +1,295 @@
+import { useArgs } from '@storybook/preview-api'
+import { StoryObj } from '@storybook/react'
+import { Button, IconUserPlus } from 'ui'
+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',
+ component: TextConfirmModal,
+ parameters: {
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
+ layout: 'centered',
+ },
+ // 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: {
+ title: { control: 'text' },
+ cancelLabel: { control: 'text' },
+ confirmLabel: { control: 'text' },
+ },
+}
+
+// export default meta
+
+// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
+// export const Primary = {
+// args: {
+// size: 'small',
+// // visible: true,
+// },
+// }
+
+type Story = StoryObj<typeof TextConfirmModal>
+
+export const Primary: Story = {
+ args: {
+ confirmString: 'project name',
+ visible: false,
+ title: 'Are you sure you want to delete?',
+ size: 'small',
+ // label: 'Try Me!',
+ },
+ /**
+ * πŸ‘‡ To avoid linting issues, it is recommended to use a function with a capitalized name.
+ * If you are not concerned with linting, you may use an arrow function.
+ */
+ render: function Render(args) {
+ const [{ visible }, updateArgs] = useArgs()
+
+ function onVisibleChange() {
+ updateArgs({ visible: !visible })
+ }
+
+ return (
+ <>
+ <Button type="default" onClick={() => onVisibleChange()}>
+ Open text confirm dialog
+ </Button>
+ <TextConfirmModal
+ // visible={visible}
+ key="primary"
+ {...args}
+ onCancel={() => onVisibleChange()}
+ // onChange={onChange}
+
+ // isChecked={isChecked}
+ />
+ </>
+ )
+ },
+}
+
+export const withInfoAlert: Story = {
+ args: {
+ confirmString: 'project name',
+ visible: false,
+ variant: 'default',
+ title: 'Are you sure you want to move?',
+ alert: {
+ title: 'This is a reminder banner',
+ description: 'This should not be used for important CRUD events.',
+ },
+ },
+ /**
+ * πŸ‘‡ To avoid linting issues, it is recommended to use a function with a capitalized name.
+ * If you are not concerned with linting, you may use an arrow function.
+ */
+ render: function Render(args) {
+ const [{ visible }, updateArgs] = useArgs()
+ // const [visible, setVisibleState] = useState(args.visible)
+
+ function onVisibleChange() {
+ updateArgs({ visible: !visible })
+ }
+
+ return (
+ <>
+ <Button type="default" onClick={() => onVisibleChange()}>
+ Open warning text confirm dialog
+ </Button>
+ <TextConfirmModal key="withWarningAlert" {...args} onCancel={() => onVisibleChange()} />
+ </>
+ )
+ },
+}
+
+export const withWarningAlert: Story = {
+ args: {
+ confirmString: 'project name',
+ visible: false,
+ variant: 'warning',
+ title: 'Are you sure you want to delete?',
+ alert: {
+ title: 'This is a warning',
+ description: 'You are about to delete this item. This action cannot be undone.',
+ },
+ },
+ /**
+ * πŸ‘‡ To avoid linting issues, it is recommended to use a function with a capitalized name.
+ * If you are not concerned with linting, you may use an arrow function.
+ */
+ render: function Render(args) {
+ const [{ visible }, updateArgs] = useArgs()
+ // const [visible, setVisibleState] = useState(args.visible)
+
+ function onVisibleChange() {
+ updateArgs({ visible: !visible })
+ }
+
+ return (
+ <>
+ <Button type="default" onClick={() => onVisibleChange()}>
+ Open warning text confirm dialog
+ </Button>
+ <TextConfirmModal key="withWarningAlert" {...args} onCancel={() => onVisibleChange()} />
+ </>
+ )
+ },
+}
+
+export const withDestructiveAlert: Story = {
+ args: {
+ confirmString: 'project name',
+ visible: false,
+ variant: 'destructive',
+ title: 'Are you sure you want to delete?',
+ alert: {
+ title: 'This is a warning',
+ description: 'You are about to delete this item. This action cannot be undone.',
+ },
+ // label: 'Try Me!',
+ },
+ /**
+ * πŸ‘‡ To avoid linting issues, it is recommended to use a function with a capitalized name.
+ * If you are not concerned with linting, you may use an arrow function.
+ */
+ render: function Render(args) {
+ const [{ visible }, updateArgs] = useArgs()
+ // const [visible, setVisibleState] = useState(args.visible)
+
+ function onVisibleChange() {
+ updateArgs({ visible: !visible })
+ }
+
+ return (
+ <>
+ <Button type="default" onClick={() => onVisibleChange()}>
+ Open warning text confirm dialog
+ </Button>
+ <TextConfirmModal key="withWarningAlert" {...args} onCancel={() => onVisibleChange()} />
+ </>
+ )
+ },
+}
+
+export const withCancelButton: Story = {
+ args: {
+ confirmString: 'project name',
+ visible: false,
+ variant: 'destructive',
+ title: 'Are you sure you want to delete?',
+ blockDeleteButton: false,
+ // label: 'Try Me!',
+ },
+ /**
+ * πŸ‘‡ To avoid linting issues, it is recommended to use a function with a capitalized name.
+ * If you are not concerned with linting, you may use an arrow function.
+ */
+ render: function Render(args) {
+ const [{ visible }, updateArgs] = useArgs()
+ // const [visible, setVisibleState] = useState(args.visible)
+
+ function onVisibleChange() {
+ updateArgs({ visible: !visible })
+ }
+
+ return (
+ <>
+ <Button type="default" onClick={() => onVisibleChange()}>
+ Open warning text confirm dialog
+ </Button>
+ <TextConfirmModal key="withWarningAlert" {...args} onCancel={() => onVisibleChange()} />
+ </>
+ )
+ },
+}
+
+export const withChildren: Story = {
+ args: {
+ confirmString: 'project name',
+ visible: false,
+ variant: 'destructive',
+ title: 'Are you sure you want to delete?',
+ },
+ /**
+ * πŸ‘‡ To avoid linting issues, it is recommended to use a function with a capitalized name.
+ * If you are not concerned with linting, you may use an arrow function.
+ */
+ render: function Render(args) {
+ const [{ visible }, updateArgs] = useArgs()
+
+ function onVisibleChange() {
+ updateArgs({ visible: !visible })
+ }
+
+ return (
+ <>
+ <Button type="default" onClick={() => onVisibleChange()}>
+ Open warning text confirm dialog
+ </Button>
+ <TextConfirmModal
+ key="withWarningAlert"
+ // visible={visible}
+ {...args}
+ onCancel={() => onVisibleChange()}
+ // onChange={onChange}
+
+ // isChecked={isChecked}
+ >
+ <div className="flex flex-col gap-3 text-sm">
+ <div className="flex gap-3 items-center">
+ <IconUserPlus className="text-foreground-lighter" />
+ <p>
+ This is a paragraph <strong>with some bold text</strong>
+ </p>
+ </div>
+ <div className="flex gap-3 items-center">
+ <IconUserPlus className="text-foreground-lighter" />
+ <p>
+ This is a paragraph <strong>with some bold text</strong>
+ </p>
+ </div>
+ <div className="flex gap-3 items-center">
+ <IconUserPlus className="text-foreground-lighter" />
+ <p>
+ This is a paragraph <strong>with some bold text</strong>
+ </p>
+ </div>
+ </div>
+ </TextConfirmModal>
+ </>
+ )
+ },
+}
+
+export const withSize: Story = {
+ args: {
+ confirmString: 'project name',
+ visible: false,
+ size: 'xlarge',
+ variant: 'destructive',
+ title: 'Are you sure you want to delete?',
+ },
+ /**
+ * πŸ‘‡ To avoid linting issues, it is recommended to use a function with a capitalized name.
+ * If you are not concerned with linting, you may use an arrow function.
+ */
+ render: function Render(args) {
+ const [{ visible }, updateArgs] = useArgs()
+
+ function onVisibleChange() {
+ updateArgs({ visible: !visible })
+ }
+
+ return (
+ <>
+ <Button type="default" onClick={() => onVisibleChange()}>
+ Open warning text confirm dialog
+ </Button>
+ <TextConfirmModal key="withWarningAlert" {...args} onCancel={() => onVisibleChange()} />
+ </>
+ )
+ },
+}
diff --git a/packages/ui-patterns/Dialogs/TextConfirmModal.tsx b/packages/ui-patterns/Dialogs/TextConfirmModal.tsx
index 5ee814a43ee..fc8961e4067 100644
--- a/packages/ui-patterns/Dialogs/TextConfirmModal.tsx
+++ b/packages/ui-patterns/Dialogs/TextConfirmModal.tsx
@@ -1,108 +1,200 @@
-import { PropsWithChildren, ReactNode } from 'react'
-import { Alert, Button, Form, Input, Modal } from 'ui'
+'use client'
-interface TextConfirmModalProps {
+import { zodResolver } from '@hookform/resolvers/zod'
+import { ReactNode, forwardRef } from 'react'
+import { useForm } from 'react-hook-form'
+import {
+ Admonition,
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ DialogContent_Shadcn_,
+ DialogSectionSeparator_Shadcn_,
+ DialogSection_Shadcn_,
+ DialogTitle_Shadcn_,
+ Dialog_Shadcn_,
+ FormControl_Shadcn_,
+ FormDescription_Shadcn_,
+ FormField_Shadcn_,
+ FormItem_Shadcn_,
+ FormLabel_Shadcn_,
+ FormMessage_Shadcn_,
+ Form_Shadcn_,
+ IconAlertCircle,
+ Input_Shadcn_,
+ cn,
+} from 'ui'
+import {
+ DIALOG_PADDING_X_SMALL,
+ DIALOG_PADDING_Y_SMALL,
+ DialogHeader,
+} from 'ui/src/components/shadcn/ui/dialog'
+import { z } from 'zod'
+
+export interface TextConfirmModalProps {
loading: boolean
visible: boolean
title: string
- size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge'
- confirmLabel: string
+ size?: React.ComponentProps<typeof DialogContent_Shadcn_>['size']
+ cancelLabel?: string
+ confirmLabel?: string
confirmPlaceholder: string
confirmString: string
- alert?: string
text?: string | ReactNode
onConfirm: () => void
onCancel: () => void
+ variant: React.ComponentProps<typeof Alert_Shadcn_>['variant']
+ alert?: {
+ base?: React.ComponentProps<typeof Alert_Shadcn_>
+ title?: string
+ description?: string
+ }
+ input?: React.ComponentProps<typeof Input_Shadcn_>
+ label?: React.ComponentProps<typeof FormLabel_Shadcn_>
+ formMessage?: React.ComponentProps<typeof FormMessage_Shadcn_>
+ description?: React.ComponentProps<typeof FormDescription_Shadcn_>
+ blockDeleteButton?: boolean
}
-const TextConfirmModal = ({
- title,
- size = 'small',
- onConfirm,
- visible,
- onCancel,
- loading,
- confirmLabel,
- confirmPlaceholder,
- confirmString,
- alert,
- text,
- children,
-}: PropsWithChildren<TextConfirmModalProps>) => {
- // [Joshen] Have to keep the loading prop here as this component itself doesn't
- // directly trigger any potential async job that follows onConfirm. It only triggers
- // the onConfirm callback function, and hence if anything fails in the callback,
- // have to depend on loading prop to unfreeze the UI state
+const TextConfirmModal = forwardRef<
+ React.ElementRef<typeof DialogContent_Shadcn_>,
+ React.ComponentPropsWithoutRef<typeof Dialog_Shadcn_> & TextConfirmModalProps
+>(
+ (
+ {
+ title,
+ size = 'small',
+ onConfirm,
+ visible,
+ onCancel,
+ loading,
+ cancelLabel = 'Cancel',
+ confirmLabel = 'Submit',
+ confirmPlaceholder,
+ confirmString,
+ alert,
+ input,
+ label,
+ description,
+ formMessage,
+ text,
+ children,
+ blockDeleteButton = true,
+ variant = 'default',
+ ...props
+ },
+ ref
+ ) => {
+ const formSchema = z.object({
+ confirmValue: z.literal(confirmString, {
+ required_error: 'Value entered does not match.',
+ }),
+ })
+
+ // 1. Define your form.
+ const form = useForm<z.infer<typeof formSchema>>({
+ resolver: zodResolver(formSchema),
+ defaultValues: {
+ confirmValue: '',
+ },
+ })
- const validate = (values: any) => {
- const errors: any = {}
- if (values.confirmValue.length === 0) {
- errors.confirmValue = 'Enter the required value.'
- } else if (values.confirmValue !== confirmString) {
- errors.confirmValue = 'Value entered does not match.'
+ // 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.
+ onConfirm()
}
- return errors
- }
- return (
- <Modal hideFooter closable size={size} visible={visible} header={title} onCancel={onCancel}>
- <Form
- validateOnBlur
- initialValues={{ confirmValue: '' }}
- validate={validate}
- onSubmit={onConfirm}
+ return (
+ <Dialog_Shadcn_
+ open={visible}
+ {...props}
+ onOpenChange={() => {
+ if (visible) {
+ onCancel()
+ }
+ }}
>
- {() => (
- <div className="w-full py-4">
- <div className="space-y-4">
- {children && (
- <>
- <Modal.Content>{children}</Modal.Content>
- <Modal.Separator />
- </>
- )}
- {alert && (
- <Modal.Content>
- <Alert variant="warning" withIcon title={alert} />
- </Modal.Content>
- )}
- {text !== undefined && (
- <Modal.Content>
- <p className="mb-2 block text-sm break-all">{text}</p>
- </Modal.Content>
- )}
- <Modal.Separator />
- <Modal.Content>
- <Input
- id="confirmValue"
- label={
- <span>
+ <DialogContent_Shadcn_ ref={ref} className="p-0 gap-0 pb-5" size={size}>
+ <DialogHeader className={cn('border-b')} padding={'small'}>
+ <DialogTitle_Shadcn_ className="">{title}</DialogTitle_Shadcn_>
+ </DialogHeader>
+ {alert && (
+ <Admonition
+ type={variant as 'default' | 'destructive' | 'warning'}
+ label={alert.title}
+ description={alert.description}
+ className="border-r-0 border-l-0 rounded-none -mt-px [&_svg]:ml-0.5 mb-0"
+ {...alert?.base}
+ />
+ )}
+ {children && (
+ <>
+ <DialogSection_Shadcn_ padding={'small'}>{children}</DialogSection_Shadcn_>
+ <DialogSectionSeparator_Shadcn_ />
+ </>
+ )}
+ {/* // older prop from before refactor */}
+ {text !== undefined && (
+ <>
+ <DialogSection_Shadcn_ className="p-5" padding={'small'}>
+ <p className="text-foreground-light text-sm">{text}</p>
+ </DialogSection_Shadcn_>
+ <DialogSectionSeparator_Shadcn_ />
+ </>
+ )}
+ <Form_Shadcn_ {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)} className="px-5 flex flex-col gap-2 pt-3">
+ <FormField_Shadcn_
+ control={form.control}
+ name="confirmValue"
+ render={({ field }) => (
+ <FormItem_Shadcn_>
+ <FormLabel_Shadcn_ {...label}>
Type <span className="text-foreground break-all">{confirmString}</span> to
confirm.
- </span>
- }
- placeholder={confirmPlaceholder}
- />
- </Modal.Content>
- <Modal.Separator />
- <Modal.Content>
+ </FormLabel_Shadcn_>
+ <FormControl_Shadcn_>
+ <Input_Shadcn_ placeholder={confirmPlaceholder} {...input} {...field} />
+ </FormControl_Shadcn_>
+ <FormDescription_Shadcn_ {...description} />
+ <FormMessage_Shadcn_ {...formMessage} />
+ </FormItem_Shadcn_>
+ )}
+ />
+ <div className="flex justify-end gap-2">
+ {!blockDeleteButton && (
+ <Button size="medium" block type="default" disabled={loading}>
+ {cancelLabel}
+ </Button>
+ )}
<Button
- block
- type="danger"
size="medium"
+ type={
+ variant === 'destructive'
+ ? 'danger'
+ : variant === 'warning'
+ ? 'warning'
+ : 'primary'
+ }
htmlType="submit"
+ block
loading={loading}
disabled={loading}
>
{confirmLabel}
</Button>
- </Modal.Content>
- </div>
- </div>
- )}
- </Form>
- </Modal>
- )
-}
+ </div>
+ </form>
+ </Form_Shadcn_>
+ </DialogContent_Shadcn_>
+ </Dialog_Shadcn_>
+ )
+ }
+)
+
+TextConfirmModal.displayName = 'TextConfirmModal'
export default TextConfirmModal
diff --git a/packages/ui/index.tsx b/packages/ui/index.tsx
index 253134b4330..d6c92f6e803 100644
--- a/packages/ui/index.tsx
+++ b/packages/ui/index.tsx
@@ -107,6 +107,7 @@ export {
DialogTitle as DialogTitle_Shadcn_,
DialogDescription as DialogDescription_Shadcn_,
DialogSection as DialogSection_Shadcn_,
+ DialogSectionSeparator as DialogSectionSeparator_Shadcn_,
DIALOG_PADDING_X as DIALOG_PADDING_X_Shadcn_,
DIALOG_PADDING_Y as DIALOG_PADDING_Y_Shadcn_,
} from './src/components/shadcn/ui/dialog'
diff --git a/packages/ui/src/components/Admonition/index.tsx b/packages/ui/src/components/Admonition/index.tsx
index c63662caec7..9b9e9d9b311 100644
--- a/packages/ui/src/components/Admonition/index.tsx
+++ b/packages/ui/src/components/Admonition/index.tsx
@@ -1,12 +1,21 @@
import { cva } from 'class-variance-authority'
-import { PropsWithChildren } from 'react'
-
+import { forwardRef } from 'react'
import { cn } from '../../lib/utils/cn'
import { Alert, AlertDescription, AlertTitle } from './../shadcn/ui/alert'
export interface AdmonitionProps {
- type: 'note' | 'tip' | 'caution' | 'danger' | 'deprecation'
+ type:
+ | 'note'
+ | 'tip'
+ | 'caution'
+ | 'danger'
+ | 'deprecation'
+ | 'default'
+ | 'destructive'
+ | 'warning'
label?: string
+ title?: string
+ description?: string
}
const admonitionToAlertMapping: Record<
@@ -18,6 +27,9 @@ const admonitionToAlertMapping: Record<
caution: 'warning',
danger: 'destructive',
deprecation: 'warning',
+ default: 'default',
+ warning: 'warning',
+ destructive: 'destructive',
}
const InfoIcon = () => (
@@ -70,24 +82,26 @@ const admonitionBase = cva('', {
},
})
-export const Admonition = ({
- type = 'note',
- label,
- children,
-}: PropsWithChildren<AdmonitionProps>) => {
+export const Admonition = forwardRef<
+ React.ElementRef<typeof Alert>,
+ React.ComponentPropsWithoutRef<typeof Alert> & AdmonitionProps
+>(({ type = 'note', label, title, description, children, ...props }, ref) => {
const typeMapped = admonitionToAlertMapping[type]
return (
<Alert
+ ref={ref}
+ variant={typeMapped}
+ {...props}
className={cn(
'mb-2',
admonitionSVG({ type: typeMapped }),
- admonitionBase({ type: typeMapped })
+ admonitionBase({ type: typeMapped }),
+ props.className
)}
- variant={typeMapped}
>
{typeMapped === 'warning' || typeMapped === 'destructive' ? <WarningIcon /> : <InfoIcon />}
- {label ? (
+ {label || title ? (
<>
<AlertTitle
className={cn(
@@ -95,8 +109,10 @@ export const Admonition = ({
!label && 'flex-col'
)}
>
- {label}
+ {label || title}
</AlertTitle>
+ {description && <AlertDescription>{description}</AlertDescription>}
+ {/* // children is to handle Docs and MDX issues with children and <p> elements */}
{children && (
<AlertDescription className="mt-3 [&_p]:mb-1.5 [&_p]:mt-0">{children}</AlertDescription>
)}
@@ -108,4 +124,4 @@ export const Admonition = ({
)}
</Alert>
)
-}
+})
diff --git a/packages/ui/src/components/shadcn/stories/Dialog.stories.tsx b/packages/ui/src/components/shadcn/stories/Dialog.stories.tsx
index 584f575ac9e..461d967f265 100644
--- a/packages/ui/src/components/shadcn/stories/Dialog.stories.tsx
+++ b/packages/ui/src/components/shadcn/stories/Dialog.stories.tsx
@@ -1,55 +1,119 @@
-import { Meta } from '@storybook/react'
+import { useArgs } from '@storybook/preview-api'
+import { Meta, StoryObj } from '@storybook/react'
+import React from 'react'
import { Button } from '../ui/button'
import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogSection,
+ DialogTitle,
+ DialogTrigger,
} from '../ui/dialog'
import { Input } from '../ui/input'
import { Label } from '../ui/label'
-const meta: Meta = {
+const meta: Meta<typeof Dialog> = {
title: 'shadcn/Dialog',
component: Dialog,
+ subcomponents: {
+ DialogContent,
+ },
+ parameters: {
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
+ layout: 'centered',
+ },
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
+ tags: ['autodocs'],
}
-export function Default() {
- return (
- <Dialog>
- <DialogTrigger asChild>
- <Button variant="outline">Edit Profile</Button>
- </DialogTrigger>
- <DialogContent className="sm:max-w-[425px]">
- <DialogHeader>
- <DialogTitle>Edit profile</DialogTitle>
- <DialogDescription>
- Make changes to your profile here. Click save when you're done.
- </DialogDescription>
- </DialogHeader>
- <div className="grid gap-4 py-4">
- <div className="grid grid-cols-4 items-center gap-4">
- <Label htmlFor="name" className="text-right">
- Name
- </Label>
- <Input id="name" value="Pedro Duarte" className="col-span-3" />
- </div>
- <div className="grid grid-cols-4 items-center gap-4">
- <Label htmlFor="username" className="text-right">
- Username
- </Label>
- <Input id="username" value="@peduarte" className="col-span-3" />
+export default meta
+
+type Story = StoryObj<typeof Dialog>
+
+export const Default: Story = {
+ args: {},
+
+ render: function Render(args) {
+ return (
+ <Dialog {...args}>
+ <DialogTrigger asChild>
+ <Button variant="outline">Edit Profile</Button>
+ </DialogTrigger>
+ <DialogContent className="sm:max-w-[425px]">
+ <DialogHeader>
+ <DialogTitle>Edit profile</DialogTitle>
+ <DialogDescription>
+ Make changes to your profile here. Click save when you're done.
+ </DialogDescription>
+ </DialogHeader>
+ <div className="grid gap-4 py-4">
+ <div className="grid grid-cols-4 items-center gap-4">
+ <Label htmlFor="name" className="text-right">
+ Name
+ </Label>
+ <Input id="name" value="Pedro Duarte" className="col-span-3" />
+ </div>
+ <div className="grid grid-cols-4 items-center gap-4">
+ <Label htmlFor="username" className="text-right">
+ Username
+ </Label>
+ <Input id="username" value="@peduarte" className="col-span-3" />
+ </div>
</div>
- </div>
- <DialogFooter>
- <Button type="submit">Save changes</Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- )
+ <DialogFooter>
+ <Button type="submit">Save changes</Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+ },
}
-export default meta
+export const withSize: Story = {
+ args: {},
+ /**
+ * πŸ‘‡ To avoid linting issues, it is recommended to use a function with a capitalized name.
+ * If you are not concerned with linting, you may use an arrow function.
+ */
+ render: function Render(args) {
+ return (
+ <>
+ <Dialog {...args}>
+ <DialogTrigger asChild>
+ <Button variant="outline">Edit Profile</Button>
+ </DialogTrigger>
+ <DialogContent size="xlarge">
+ <DialogHeader>
+ <DialogTitle>Edit profile</DialogTitle>
+ <DialogDescription>
+ Make changes to your profile here. Click save when you're done.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogSection>
+ <div className="grid gap-4 py-4">
+ <div className="grid grid-cols-4 items-center gap-4">
+ <Label htmlFor="name" className="text-right">
+ Name
+ </Label>
+ <Input id="name" value="Pedro Duarte" className="col-span-3" />
+ </div>
+ <div className="grid grid-cols-4 items-center gap-4">
+ <Label htmlFor="username" className="text-right">
+ Username
+ </Label>
+ <Input id="username" value="@peduarte" className="col-span-3" />
+ </div>
+ </div>
+ </DialogSection>
+ <DialogFooter>
+ <Button type="submit">Save changes</Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ </>
+ )
+ },
+}
diff --git a/packages/ui/src/components/shadcn/ui/dialog.tsx b/packages/ui/src/components/shadcn/ui/dialog.tsx
index f20af5f8a30..584a625de6c 100644
--- a/packages/ui/src/components/shadcn/ui/dialog.tsx
+++ b/packages/ui/src/components/shadcn/ui/dialog.tsx
@@ -5,10 +5,26 @@ import { X } from 'lucide-react'
import * as React from 'react'
import { cn } from '../../../lib/utils/cn'
+import { VariantProps, cva } from 'class-variance-authority'
+
+export const DIALOG_PADDING_Y_SMALL = 'py-4'
+export const DIALOG_PADDING_X_SMALL = 'px-5'
export const DIALOG_PADDING_Y = 'py-6'
export const DIALOG_PADDING_X = 'px-7'
+const DialogPaddingVariants = cva('', {
+ variants: {
+ padding: {
+ default: `${DIALOG_PADDING_Y} ${DIALOG_PADDING_X}`,
+ small: `${DIALOG_PADDING_Y_SMALL} ${DIALOG_PADDING_X_SMALL}`,
+ },
+ },
+ defaultVariants: {
+ padding: 'default',
+ },
+})
+
const Dialog = DialogPrimitive.Root
const DialogTrigger = DialogPrimitive.Trigger
@@ -25,7 +41,10 @@ const DialogOverlay = React.forwardRef<
<DialogPrimitive.Overlay
ref={ref}
className={cn(
- 'fixed inset-0 z-50 bg-background/90 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
+ // 'z-50 fixed h-full w-full left-0 top-0',
+ // 'bg-alternative/90 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
+ 'bg-alternative/90 backdrop-blur-sm',
+ 'z-50 fixed inset-0 grid place-items-center overflow-y-auto data-open:animate-overlay-show data-closed:animate-overlay-hide',
className
)}
{...props}
@@ -33,59 +52,103 @@ const DialogOverlay = React.forwardRef<
))
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
+const DialogContentVariants = cva(
+ cn(
+ 'my-8',
+ 'relative z-50 grid w-full gap-4 border shadow-md dark:shadow-sm duration-200',
+ 'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
+ 'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
+ 'data-[state=closed]:slide-out-to-left-[0%] data-[state=closed]:slide-out-to-top-[0%',
+ 'data-[state=open]:slide-in-from-left-[0%] data-[state=open]:slide-in-from-top-[0%]',
+ 'sm:rounded-lg md:w-full',
+ 'bg-overlay'
+ ),
+ {
+ variants: {
+ size: {
+ tiny: `sm:align-middle sm:w-full sm:max-w-xs`,
+ small: `sm:align-middle sm:w-full sm:max-w-sm`,
+ medium: `sm:align-middle sm:w-full sm:max-w-lg`,
+ large: `sm:align-middle sm:w-full max-w-xl`,
+ xlarge: `sm:align-middle sm:w-full max-w-3xl`,
+ xxlarge: `sm:align-middle sm:w-full max-w-6xl`,
+ xxxlarge: `sm:align-middle sm:w-full max-w-7xl`,
+ },
+ },
+ defaultVariants: {
+ size: 'medium',
+ },
+ }
+)
+
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
- React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
->(({ className, children, ...props }, ref) => (
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> &
+ VariantProps<typeof DialogContentVariants>
+>(({ className, children, size, ...props }, ref) => (
<DialogPortal>
- <DialogOverlay />
- <DialogPrimitive.Content
- ref={ref}
- className={cn(
- 'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg md:w-full',
- 'bg border-overlay',
- 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-foreground-muted">
- <X className="h-4 w-4" />
- <span className="sr-only">Close</span>
- </DialogPrimitive.Close>
- </DialogPrimitive.Content>
+ <DialogOverlay>
+ <DialogPrimitive.Content
+ ref={ref}
+ className={cn(DialogContentVariants({ size }), 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-foreground-muted">
+ <X className="h-4 w-4" />
+ <span className="sr-only">Close</span>
+ </DialogPrimitive.Close>
+ </DialogPrimitive.Content>
+ </DialogOverlay>
</DialogPortal>
))
DialogContent.displayName = DialogPrimitive.Content.displayName
-const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
+const DialogHeader = React.forwardRef<
+ HTMLDivElement,
+ React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof DialogPaddingVariants>
+>(({ className, padding = 'default', ...props }, ref) => (
<div
+ ref={ref}
+ {...props}
className={cn(
- 'flex flex-col space-y-1.5 text-center sm:text-left',
- DIALOG_PADDING_X,
- DIALOG_PADDING_Y,
+ 'flex flex-col gap-1.5 text-center sm:text-left',
+ DialogPaddingVariants({ padding }),
className
)}
- {...props}
/>
-)
+))
+
DialogHeader.displayName = 'DialogHeader'
-const DialogFooter = ({ className, children, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
+const DialogFooter = React.forwardRef<
+ HTMLDivElement,
+ React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof DialogPaddingVariants>
+>(({ className, children, padding, ...props }, ref) => (
<div
- className={cn('flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', className)}
+ ref={ref}
+ className={cn(
+ 'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2',
+ 'border-t',
+ DialogPaddingVariants({ padding }),
+ className
+ )}
{...props}
>
{children}
</div>
-)
+))
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 leading-none', className)} {...props} />
+ <DialogPrimitive.Title
+ ref={ref}
+ className={cn('text-base leading-none font-normal', className)}
+ {...props}
+ />
))
DialogTitle.displayName = DialogPrimitive.Title.displayName
@@ -118,15 +181,28 @@ const DialogClose = React.forwardRef<
))
DialogClose.displayName = DialogPrimitive.Close.displayName
-const DialogSection = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
- ({ className, children, ...props }, ref) => (
- <div ref={ref} {...props} className={cn('px-5 py-3', className)}>
- {children}
- </div>
- )
-)
+const DialogSection = React.forwardRef<
+ HTMLDivElement,
+ React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof DialogPaddingVariants>
+>(({ className, children, padding, ...props }, ref) => (
+ <div
+ ref={ref}
+ {...props}
+ className={cn('px-5 py-3', DialogPaddingVariants({ padding }), className)}
+ >
+ {children}
+ </div>
+))
DialogSection.displayName = 'DialogSection'
+const DialogSectionSeparator = React.forwardRef<
+ HTMLDivElement,
+ React.HTMLAttributes<HTMLDivElement>
+>(({ className, children, ...props }, ref) => (
+ <div ref={ref} {...props} className={cn('w-full h-px bg-border-overlay', className)} />
+))
+DialogSectionSeparator.displayName = 'DialogSectionSeparator'
+
export {
Dialog,
DialogContent,
@@ -137,4 +213,5 @@ export {
DialogTitle,
DialogTrigger,
DialogSection,
+ DialogSectionSeparator,
}
diff --git a/packages/ui/src/components/shadcn/ui/form.tsx b/packages/ui/src/components/shadcn/ui/form.tsx
index ca367dc7f8b..4c13213c227 100644
--- a/packages/ui/src/components/shadcn/ui/form.tsx
+++ b/packages/ui/src/components/shadcn/ui/form.tsx
@@ -17,7 +17,7 @@ const Form = FormProvider
type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
- TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> = {
name: TName
}
@@ -26,7 +26,7 @@ const FormFieldContext = React.createContext<FormFieldContextValue>({} as FormFi
const FormField = <
TFieldValues extends FieldValues = FieldValues,
- TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
+ TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>({
...props
}: ControllerProps<TFieldValues, TName>) => {
@@ -88,7 +88,13 @@ const FormLabel = React.forwardRef<
return (
<Label
ref={ref}
- className={cn(error && 'text-destructive', className, 'leading-normal')}
+ className={cn(
+ 'text-foreground-light',
+ 'transition-colors',
+ error && 'text-destructive',
+ className,
+ 'leading-normal'
+ )}
htmlFor={formItemId}
{...props}
/>