Skip to content

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

feat(ui-patterns): add CollapsibleCardSection component (#46250)

Danny White55ee3e0f2c56
diff --git a/apps/design-system/__registry__/index.tsx b/apps/design-system/__registry__/index.tsx
index 772b0471f45..9d5f52779c0 100644
--- a/apps/design-system/__registry__/index.tsx
+++ b/apps/design-system/__registry__/index.tsx
@@ -5,6 +5,17 @@ import * as React from "react"
export const Index: Record<string, any> = {
"default": {
+ "CollapsibleCardSection": {
+ name: "CollapsibleCardSection",
+ type: "components:fragment",
+ registryDependencies: undefined,
+ component: React.lazy(() => import("@/../../packages/ui-patterns/src/CollapsibleCardSection")),
+ source: "",
+ files: ["registry/default//CollapsibleCardSection.tsx"],
+ category: "undefined",
+ subcategory: "undefined",
+ chunks: []
+ },
"ConfirmationModal": {
name: "ConfirmationModal",
type: "components:fragment",
@@ -225,6 +236,17 @@ export const Index: Record<string, any> = {
subcategory: "undefined",
chunks: []
},
+ "collapsible-card-section-demo": {
+ name: "collapsible-card-section-demo",
+ type: "components:example",
+ registryDependencies: ["collapsible-card-section"],
+ component: React.lazy(() => import("@/registry/default/example/collapsible-card-section-demo")),
+ source: "",
+ files: ["registry/default/example/collapsible-card-section-demo.tsx"],
+ category: "undefined",
+ subcategory: "undefined",
+ chunks: []
+ },
"alert-dialog-demo": {
name: "alert-dialog-demo",
type: "components:example",
diff --git a/apps/design-system/config/docs.ts b/apps/design-system/config/docs.ts
index a74316e46d3..748ccee8bfc 100644
--- a/apps/design-system/config/docs.ts
+++ b/apps/design-system/config/docs.ts
@@ -122,6 +122,11 @@ export const docsConfig: DocsConfig = {
href: '/docs/fragments/collapsible-alert',
items: [],
},
+ {
+ title: 'Collapsible Card Section',
+ href: '/docs/fragments/collapsible-card-section',
+ items: [],
+ },
{
title: 'Assistant Chat',
href: '/docs/fragments/assistant-chat',
diff --git a/apps/design-system/content/docs/fragments/collapsible-card-section.mdx b/apps/design-system/content/docs/fragments/collapsible-card-section.mdx
new file mode 100644
index 00000000000..825505b4433
--- /dev/null
+++ b/apps/design-system/content/docs/fragments/collapsible-card-section.mdx
@@ -0,0 +1,40 @@
+---
+title: Collapsible Card Section
+description: A mono-uppercase collapsible trigger for hiding optional or advanced settings inside a card or panel.
+fragment: true
+---
+
+Use `CollapsibleCardSection` to progressively disclose optional or advanced fields inside a card or panel form. The trigger is styled mono-uppercase to blend with card section headings; content animates in and out on toggle.
+
+<ComponentPreview name="collapsible-card-section-demo" peekCode wide />
+
+## Usage
+
+```tsx
+import { CollapsibleCardSection } from 'ui-patterns/CollapsibleCardSection'
+```
+
+```tsx
+<CollapsibleCardSection title="Advanced settings">{/* form fields */}</CollapsibleCardSection>
+```
+
+### With description
+
+Use `description` to add a short qualifier below the title, only when the content needs context that the title alone doesn't provide.
+
+```tsx
+<CollapsibleCardSection
+ title="Advanced settings"
+ description="These settings cannot be changed after creation"
+>
+ {/* form fields */}
+</CollapsibleCardSection>
+```
+
+### Default open
+
+```tsx
+<CollapsibleCardSection title="Advanced settings" defaultOpen>
+ {/* form fields */}
+</CollapsibleCardSection>
+```
diff --git a/apps/design-system/registry/default/example/collapsible-card-section-demo.tsx b/apps/design-system/registry/default/example/collapsible-card-section-demo.tsx
new file mode 100644
index 00000000000..c388d47c2cd
--- /dev/null
+++ b/apps/design-system/registry/default/example/collapsible-card-section-demo.tsx
@@ -0,0 +1,23 @@
+import { Input } from 'ui'
+import { CollapsibleCardSection } from 'ui-patterns/CollapsibleCardSection'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+
+export default function CollapsibleCardSectionDemo() {
+ return (
+ <div className="border rounded-lg px-6 py-4 w-full max-w-lg">
+ <CollapsibleCardSection
+ title="Advanced settings"
+ description="These settings cannot be changed after creation"
+ >
+ <FormItemLayout
+ isReactForm={false}
+ layout="flex-row-reverse"
+ label="OIDC Issuer"
+ description="The OIDC issuer URL of your identity provider."
+ >
+ <Input placeholder="https://your-org.okta.com" />
+ </FormItemLayout>
+ </CollapsibleCardSection>
+ </div>
+ )
+}
diff --git a/apps/design-system/registry/examples.ts b/apps/design-system/registry/examples.ts
index aba1bc622a6..85097c15a08 100644
--- a/apps/design-system/registry/examples.ts
+++ b/apps/design-system/registry/examples.ts
@@ -67,6 +67,12 @@ export const examples: Registry = [
registryDependencies: ['collapsible-alert'],
files: ['example/collapsible-alert-demo.tsx'],
},
+ {
+ name: 'collapsible-card-section-demo',
+ type: 'components:example',
+ registryDependencies: ['collapsible-card-section'],
+ files: ['example/collapsible-card-section-demo.tsx'],
+ },
{
name: 'alert-dialog-demo',
type: 'components:example',
diff --git a/apps/design-system/registry/fragments.ts b/apps/design-system/registry/fragments.ts
index 2c5137e2678..2372986ea8f 100644
--- a/apps/design-system/registry/fragments.ts
+++ b/apps/design-system/registry/fragments.ts
@@ -1,6 +1,12 @@
import { Registry } from '@/registry/schema'
export const fragments: Registry = [
+ {
+ name: 'CollapsibleCardSection',
+ type: 'components:fragment',
+ files: ['/CollapsibleCardSection.tsx'],
+ optionalPath: '',
+ },
{
name: 'ConfirmationModal',
type: 'components:fragment',
diff --git a/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx b/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx
index 52edab624ce..f73e4778acc 100644
--- a/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/AdvancedConfiguration.tsx
@@ -1,12 +1,10 @@
import { useFlag } from 'common'
-import { ChevronRight } from 'lucide-react'
import { UseFormReturn } from 'react-hook-form'
import {
Badge,
+ Card,
+ CardContent,
cn,
- Collapsible,
- CollapsibleContent,
- CollapsibleTrigger,
FormControl,
FormField,
FormItem,
@@ -17,11 +15,11 @@ import {
TooltipTrigger,
} from 'ui'
import { Admonition } from 'ui-patterns'
+import { CollapsibleCardSection } from 'ui-patterns/CollapsibleCardSection'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { CreateProjectForm } from './ProjectCreation.schema'
import { DocsButton } from '@/components/ui/DocsButton'
-import Panel from '@/components/ui/Panel'
import { DOCS_URL } from '@/lib/constants'
interface AdvancedConfigurationProps {
@@ -32,24 +30,12 @@ export const AdvancedConfiguration = ({ form }: AdvancedConfigurationProps) => {
const disableOrioleProjectCreation = useFlag('disableOrioleProjectCreation')
return (
- <Panel.Content>
- <Collapsible>
- <CollapsibleTrigger className="group/advanced-trigger font-mono uppercase tracking-widest text-xs flex items-center gap-1 text-foreground-lighter/75 hover:text-foreground-light transition data-open:text-foreground-light">
- Advanced Configuration
- <ChevronRight
- size={16}
- strokeWidth={1}
- className="mr-2 group-data-open/advanced-trigger:rotate-90 group-hover/advanced-trigger:text-foreground-light transition"
- />
- </CollapsibleTrigger>
- <CollapsibleContent
- className={cn(
- 'pt-2 data-closed:animate-collapsible-up data-open:animate-collapsible-down'
- )}
+ <Card className="border-0 border-b rounded-none">
+ <CardContent>
+ <CollapsibleCardSection
+ title="Advanced Configuration"
+ description="These settings cannot be changed after the project is created"
>
- <p className="text-xs text-foreground-lighter mb-6">
- These settings cannot be changed after the project is created
- </p>
<FormField
name="useOrioleDb"
control={form.control}
@@ -129,8 +115,8 @@ export const AdvancedConfiguration = ({ form }: AdvancedConfigurationProps) => {
</>
)}
/>
- </CollapsibleContent>
- </Collapsible>
- </Panel.Content>
+ </CollapsibleCardSection>
+ </CardContent>
+ </Card>
)
}
diff --git a/apps/studio/components/interfaces/ProjectCreation/InternalOnlyConfiguration.tsx b/apps/studio/components/interfaces/ProjectCreation/InternalOnlyConfiguration.tsx
index e9cac41b78d..3737650ec10 100644
--- a/apps/studio/components/interfaces/ProjectCreation/InternalOnlyConfiguration.tsx
+++ b/apps/studio/components/interfaces/ProjectCreation/InternalOnlyConfiguration.tsx
@@ -1,22 +1,14 @@
import { useParams } from 'common'
-import { ChevronRight } from 'lucide-react'
import { UseFormReturn } from 'react-hook-form'
import { type CloudProvider } from 'shared-data'
-import {
- Collapsible,
- CollapsibleContent,
- CollapsibleTrigger,
- FormControl,
- FormField,
- Input,
-} from 'ui'
+import { Card, CardContent, FormControl, FormField, Input } from 'ui'
+import { CollapsibleCardSection } from 'ui-patterns/CollapsibleCardSection'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { CloudProviderSelector } from './CloudProviderSelector'
import { HighAvailabilityInput } from './HighAvailabilityInput'
import { PostgresVersionSelector } from './PostgresVersionSelector'
import { CreateProjectForm } from './ProjectCreation.schema'
-import Panel from '@/components/ui/Panel'
interface InternalOnlyConfigurationProps {
form: UseFormReturn<CreateProjectForm>
@@ -27,21 +19,13 @@ export const InternalOnlyConfiguration = ({ form }: InternalOnlyConfigurationPro
const showNonProdFields = process.env.NEXT_PUBLIC_ENVIRONMENT !== 'prod'
return (
- <Panel.Content>
- <Collapsible>
- <CollapsibleTrigger className="group/advanced-trigger font-mono uppercase tracking-widest text-xs flex items-center gap-1 text-foreground-lighter/75 hover:text-foreground-light transition data-open:text-foreground-light">
- Internal-only Configuration
- <ChevronRight
- size={16}
- strokeWidth={1}
- className="mr-2 group-data-open/advanced-trigger:rotate-90 group-hover/advanced-trigger:text-foreground-light transition"
- />
- </CollapsibleTrigger>
- <CollapsibleContent className="pt-2 data-closed:animate-collapsible-up data-open:animate-collapsible-down flex flex-col gap-y-6">
- <div>
- <p className="text-xs text-foreground-lighter mb-6">
- These settings are only visible to internal staff
- </p>
+ <Card className="border-0 border-b rounded-none">
+ <CardContent>
+ <CollapsibleCardSection
+ title="Internal-only Configuration"
+ description="These settings are only visible to internal staff"
+ >
+ <div className="flex flex-col gap-y-6">
<div className="flex flex-col gap-y-4">
<FormField
control={form.control}
@@ -59,52 +43,52 @@ export const InternalOnlyConfiguration = ({ form }: InternalOnlyConfigurationPro
<HighAvailabilityInput form={form} />
</div>
- </div>
- {showNonProdFields && (
- <div>
- <p className="text-xs text-foreground-lighter mb-6">
- The settings below are only applicable for local/staging projects
- </p>
- <div className="flex flex-col gap-y-4">
- <CloudProviderSelector form={form} />
+ {showNonProdFields && (
+ <div>
+ <p className="text-xs text-foreground-lighter mb-6">
+ The settings below are only applicable for local/staging projects
+ </p>
+ <div className="flex flex-col gap-y-4">
+ <CloudProviderSelector form={form} />
- <FormField
- control={form.control}
- name="postgresVersion"
- render={({ field }) => (
- <FormItemLayout
- label="Custom Postgres version"
- layout="horizontal"
- description="Specify a custom version of Postgres (defaults to the latest)."
- >
- <FormControl>
- <Input placeholder="e.g 17.6.1.104" {...field} autoComplete="off" />
- </FormControl>
- </FormItemLayout>
- )}
- />
+ <FormField
+ control={form.control}
+ name="postgresVersion"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Custom Postgres version"
+ layout="horizontal"
+ description="Specify a custom version of Postgres (defaults to the latest)."
+ >
+ <FormControl>
+ <Input placeholder="e.g 17.6.1.104" {...field} autoComplete="off" />
+ </FormControl>
+ </FormItemLayout>
+ )}
+ />
- <FormField
- control={form.control}
- name="instanceType"
- render={({ field }) => (
- <FormItemLayout
- label="Custom instance type"
- layout="horizontal"
- description="Specify a custom instance type."
- >
- <FormControl>
- <Input placeholder="e.g t3.nano" {...field} autoComplete="off" />
- </FormControl>
- </FormItemLayout>
- )}
- />
+ <FormField
+ control={form.control}
+ name="instanceType"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Custom instance type"
+ layout="horizontal"
+ description="Specify a custom instance type."
+ >
+ <FormControl>
+ <Input placeholder="e.g t3.nano" {...field} autoComplete="off" />
+ </FormControl>
+ </FormItemLayout>
+ )}
+ />
+ </div>
</div>
- </div>
- )}
- </CollapsibleContent>
- </Collapsible>
- </Panel.Content>
+ )}
+ </div>
+ </CollapsibleCardSection>
+ </CardContent>
+ </Card>
)
}
diff --git a/packages/ui-patterns/package.json b/packages/ui-patterns/package.json
index bc5431f4097..093c476cd4d 100644
--- a/packages/ui-patterns/package.json
+++ b/packages/ui-patterns/package.json
@@ -78,6 +78,10 @@
"import": "./src/CodeBlock/index.tsx",
"types": "./src/CodeBlock/index.tsx"
},
+ "./CollapsibleCardSection": {
+ "import": "./src/CollapsibleCardSection.tsx",
+ "types": "./src/CollapsibleCardSection.tsx"
+ },
"./CommandMenu/api/Badges": {
"import": "./src/CommandMenu/api/Badges.tsx",
"types": "./src/CommandMenu/api/Badges.tsx"
diff --git a/packages/ui-patterns/src/CollapsibleCardSection.tsx b/packages/ui-patterns/src/CollapsibleCardSection.tsx
new file mode 100644
index 00000000000..17e3268a76a
--- /dev/null
+++ b/packages/ui-patterns/src/CollapsibleCardSection.tsx
@@ -0,0 +1,35 @@
+import { ChevronRight } from 'lucide-react'
+import type { PropsWithChildren, ReactNode } from 'react'
+import { cn, Collapsible, CollapsibleContent, CollapsibleTrigger } from 'ui'
+
+type CollapsibleCardSectionProps = PropsWithChildren<{
+ title: string
+ description?: ReactNode
+ defaultOpen?: boolean
+}>
+
+export const CollapsibleCardSection = ({
+ title,
+ description,
+ defaultOpen = false,
+ children,
+}: CollapsibleCardSectionProps) => (
+ <Collapsible defaultOpen={defaultOpen}>
+ <CollapsibleTrigger className="group/trigger font-mono uppercase tracking-widest text-xs flex items-center gap-1 text-foreground-lighter/75 hover:text-foreground-light transition data-open:text-foreground-light">
+ {title}
+ <ChevronRight
+ size={16}
+ strokeWidth={1}
+ className="mr-2 group-data-open/trigger:rotate-90 group-hover/trigger:text-foreground-light transition"
+ />
+ </CollapsibleTrigger>
+ <CollapsibleContent
+ className={cn(
+ '[overflow-y:clip] pt-2 data-closed:animate-collapsible-up data-open:animate-collapsible-down'
+ )}
+ >
+ {description && <p className="text-xs text-foreground-lighter mb-6">{description}</p>}
+ {children}
+ </CollapsibleContent>
+ </Collapsible>
+)