mirror of
https://github.com/supabase/supabase.git
synced 2026-06-18 05:33:50 +08:00
## Problem Our `<Button>` component breaks the default `button` contract by redefining the `type` prop to set its variant (`primary`, `default`, etc) instead of the button type (`submit`, `button`, etc). This is confusing and forces to write more code when using it with shadcn components that expect/inject the standard button props. ## Solution - rename the `type` prop to `variant` - rename the `htmlType` prop to `type` - propagate the changes where necessary - format code ## How to test As this is just prop renaming, if it builds it's ok --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
97 lines
2.8 KiB
TypeScript
97 lines
2.8 KiB
TypeScript
import { ExternalLink, Maximize2, Minimize2 } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { forwardRef, ReactNode, useState } from 'react'
|
|
import { Button } from 'ui'
|
|
|
|
interface InformationBoxProps {
|
|
icon?: ReactNode
|
|
title: ReactNode | string
|
|
description?: ReactNode | string
|
|
url?: string
|
|
urlLabel?: string
|
|
defaultVisibility?: boolean
|
|
hideCollapse?: boolean
|
|
button?: React.ReactNode
|
|
className?: string
|
|
block?: boolean
|
|
}
|
|
|
|
/** @deprecated Use `Admonition` from 'ui-patterns' instead. */
|
|
|
|
const InformationBox = forwardRef<HTMLDivElement, InformationBoxProps>(
|
|
(
|
|
{
|
|
icon,
|
|
title,
|
|
description,
|
|
url,
|
|
urlLabel = 'Read more',
|
|
defaultVisibility = false,
|
|
hideCollapse = false,
|
|
button,
|
|
className = '',
|
|
block = false,
|
|
},
|
|
ref
|
|
) => {
|
|
const [isExpanded, setIsExpanded] = useState<boolean>(defaultVisibility)
|
|
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
role="alert"
|
|
className={`${block ? 'block w-full' : ''}
|
|
block w-full rounded-md border bg-surface-300/25 py-3 ${className}`}
|
|
>
|
|
<div className="flex flex-col px-4">
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex w-full space-x-3 items-center">
|
|
{icon && <span className="text-foreground-lighter">{icon}</span>}
|
|
<div className="grow">
|
|
<h5 className="text-foreground">{title}</h5>
|
|
</div>
|
|
</div>
|
|
{description && !hideCollapse ? (
|
|
<div
|
|
className="cursor-pointer text-foreground-lighter"
|
|
onClick={() => setIsExpanded(!isExpanded)}
|
|
>
|
|
{isExpanded ? (
|
|
<Minimize2 size={14} strokeWidth={1.5} />
|
|
) : (
|
|
<Maximize2 size={14} strokeWidth={1.5} />
|
|
)}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
{(description || url || button) && (
|
|
<div
|
|
className={`flex flex-col space-y-3 overflow-hidden transition-all ${
|
|
isExpanded ? 'mt-3' : ''
|
|
}`}
|
|
style={{ maxHeight: isExpanded ? 500 : 0 }}
|
|
>
|
|
<div className="text-foreground-light text-sm">{description}</div>
|
|
|
|
{url && (
|
|
<div>
|
|
<Button asChild variant="default" icon={<ExternalLink />}>
|
|
<Link href={url} target="_blank" rel="noreferrer">
|
|
{urlLabel}
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
)}
|
|
|
|
{button && <div>{button}</div>}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
)
|
|
|
|
InformationBox.displayName = 'InformationBox'
|
|
export default InformationBox
|