mirror of
https://github.com/supabase/supabase.git
synced 2026-05-21 12:57:15 +08:00
## Problem The `_Shadcn_` suffix isn't needed anymore on Accordion components ## Solution - Remove the `_Shadcn_` suffix - Simplify UI package exports - Apply prettier <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Updated accordion component exports and imports to use unified naming conventions across the codebase, improving consistency for developers using the UI library. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46107?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
80 lines
1.9 KiB
TypeScript
80 lines
1.9 KiB
TypeScript
'use client'
|
|
|
|
import React, { ComponentProps, useState } from 'react'
|
|
import {
|
|
AccordionContent,
|
|
AccordionTrigger,
|
|
Accordion as BaseAccordion,
|
|
AccordionItem as BaseAccordionItem,
|
|
cn,
|
|
} from 'ui'
|
|
|
|
type Type = 'default' | 'bordered'
|
|
type Align = 'left' | 'right'
|
|
|
|
type BaseAccordionProps = ComponentProps<typeof Accordion>
|
|
|
|
export interface AccordionProps {
|
|
children?: React.ReactNode
|
|
className?: string
|
|
defaultActiveId?: (string | number)[]
|
|
onChange?: (item: string | string[]) => void
|
|
openBehaviour: 'single' | 'multiple'
|
|
type?: Type
|
|
defaultValue?: string | string[] | undefined
|
|
justified?: Boolean
|
|
chevronAlign?: Align
|
|
}
|
|
|
|
export function Accordion({
|
|
children,
|
|
className,
|
|
onChange,
|
|
openBehaviour = 'multiple',
|
|
defaultValue = undefined,
|
|
// All props below are ignored but kept to avoid impacting all docs pages
|
|
type = 'default',
|
|
justified = false,
|
|
chevronAlign = 'right',
|
|
}: AccordionProps) {
|
|
return (
|
|
// @ts-expect-error: This is because the Radix component has 2 interfaces discriminated by its type prop. Safe to ignore
|
|
<BaseAccordion
|
|
type={openBehaviour}
|
|
onValueChange={onChange}
|
|
defaultValue={defaultValue}
|
|
className={className}
|
|
>
|
|
{children}
|
|
</BaseAccordion>
|
|
)
|
|
}
|
|
|
|
interface ItemProps {
|
|
children?: React.ReactNode
|
|
className?: string
|
|
header: React.ReactNode
|
|
id: string
|
|
icon?: React.ReactNode
|
|
disabled?: boolean
|
|
}
|
|
|
|
export function AccordionItem({ children, className, header, id, disabled }: ItemProps) {
|
|
const [open, setOpen] = useState(false)
|
|
|
|
return (
|
|
<BaseAccordionItem
|
|
value={id}
|
|
// my-0 is required to avoid issues with the prose classes
|
|
className={cn('*:my-0', className)}
|
|
disabled={disabled}
|
|
onClick={() => {
|
|
setOpen(!open)
|
|
}}
|
|
>
|
|
<AccordionTrigger className="text-sm">{header}</AccordionTrigger>
|
|
<AccordionContent>{children}</AccordionContent>
|
|
</BaseAccordionItem>
|
|
)
|
|
}
|