Files
supabase/apps/studio/components/ui/DataTable/RefreshButton.tsx
Gildas Garcia 96d43099bb chore: refactor Button API so that it can be used a standard button (#46880)
## 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>
2026-06-16 23:59:58 +02:00

59 lines
1.5 KiB
TypeScript

import { LoaderCircle, RefreshCcw } from 'lucide-react'
import { Button } from 'ui'
import { ButtonTooltip } from '../ButtonTooltip'
import { Shortcut } from '@/components/ui/Shortcut'
import type { ShortcutId } from '@/state/shortcuts/registry'
interface RefreshButtonProps {
isLoading: boolean
onRefresh: () => void
/**
* When provided, the button binds this registered shortcut (hotkey + a
* tooltip that surfaces the keybind). Otherwise it falls back to a plain
* "Refresh logs" tooltip with no keybind.
*/
shortcutId?: ShortcutId
}
export const RefreshButton = ({ isLoading, onRefresh, shortcutId }: RefreshButtonProps) => {
const icon = isLoading ? (
<LoaderCircle className="text-foreground animate-spin" />
) : (
<RefreshCcw className="text-foreground" />
)
if (shortcutId) {
return (
<Shortcut
id={shortcutId}
onTrigger={onRefresh}
options={{ enabled: !isLoading, registerInCommandMenu: true }}
side="bottom"
>
<Button
size="tiny"
variant="default"
disabled={isLoading}
onClick={onRefresh}
className="w-[26px]"
icon={icon}
aria-label="Refresh logs"
/>
</Shortcut>
)
}
return (
<ButtonTooltip
size="tiny"
variant="default"
disabled={isLoading}
onClick={onRefresh}
className="w-[26px]"
icon={icon}
tooltip={{ content: { side: 'bottom', text: 'Refresh logs' } }}
/>
)
}