mirror of
https://github.com/supabase/supabase.git
synced 2026-07-03 14:13:42 -04:00
96d43099bb
## 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>
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
import { Plug } from 'lucide-react'
|
|
import { parseAsBoolean, useQueryState } from 'nuqs'
|
|
import { ComponentProps } from 'react'
|
|
import { Button, cn } from 'ui'
|
|
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { PROJECT_STATUS } from '@/lib/constants'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
|
|
interface ConnectButtonProps {
|
|
buttonVariant?: ComponentProps<typeof Button>['variant']
|
|
className?: string
|
|
iconOnly?: boolean
|
|
}
|
|
|
|
export const ConnectButton = ({
|
|
buttonVariant = 'default',
|
|
className,
|
|
iconOnly = false,
|
|
}: ConnectButtonProps) => {
|
|
const { data: selectedProject } = useSelectedProjectQuery()
|
|
const { setConnectSheetSource } = useAppStateSnapshot()
|
|
const isActiveHealthy = selectedProject?.status === PROJECT_STATUS.ACTIVE_HEALTHY
|
|
const track = useTrack()
|
|
|
|
const [showConnect, setShowConnect] = useQueryState(
|
|
'showConnect',
|
|
parseAsBoolean.withDefault(false)
|
|
)
|
|
|
|
if (isActiveHealthy) {
|
|
return (
|
|
<ShortcutTooltip
|
|
shortcutId={SHORTCUT_IDS.CONNECT_OPEN_SHEET}
|
|
side="bottom"
|
|
open={showConnect ? false : undefined}
|
|
>
|
|
<Button
|
|
variant={buttonVariant}
|
|
disabled={!isActiveHealthy}
|
|
className={cn('rounded-full', className)}
|
|
icon={<Plug className="rotate-90" />}
|
|
onClick={() => {
|
|
track('header_connect_button_clicked')
|
|
setConnectSheetSource('header_button')
|
|
setShowConnect(true)
|
|
}}
|
|
>
|
|
<span className={cn({ 'sr-only': iconOnly })}>Connect</span>
|
|
</Button>
|
|
</ShortcutTooltip>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<ButtonTooltip
|
|
variant={buttonVariant}
|
|
disabled
|
|
className={cn('rounded-full', className)}
|
|
icon={<Plug className="rotate-90" />}
|
|
onClick={() => {
|
|
track('header_connect_button_clicked')
|
|
setConnectSheetSource('header_button')
|
|
setShowConnect(true)
|
|
}}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: 'Project is currently not active and cannot be connected',
|
|
},
|
|
}}
|
|
>
|
|
<span className={cn({ 'sr-only': iconOnly })}>Connect</span>
|
|
</ButtonTooltip>
|
|
)
|
|
}
|