Files
supabase/apps/studio/components/interfaces/Integrations/CronJobs/CronJobsTab.Header.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

70 lines
1.8 KiB
TypeScript

import { RefreshCw, Search, X } from 'lucide-react'
import type { KeyboardEvent, Ref } from 'react'
import { Button } from 'ui'
import { Input } from 'ui-patterns/DataInputs/Input'
import { onSearchInputEscape } from '@/lib/keyboard'
interface CronJobsTabHeaderProps {
search: string
isRefreshing: boolean
searchInputRef?: Ref<HTMLInputElement>
onSearchChange: (value: string) => void
onSearchSubmit: () => void
onClearSearch: () => void
onRefresh: () => void
onCreateJob: () => void
}
export const CronJobsTabHeader = ({
search,
isRefreshing,
searchInputRef,
onSearchChange,
onSearchSubmit,
onClearSearch,
onRefresh,
onCreateJob,
}: CronJobsTabHeaderProps) => {
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
onSearchInputEscape(search, onClearSearch)(event)
if (event.key === 'Enter' || event.code === 'NumpadEnter') {
onSearchSubmit()
}
}
return (
<div className="bg-surface-200 py-3 px-10 flex items-center justify-between flex-wrap gap-y-2">
<Input
ref={searchInputRef}
size="tiny"
className="w-52"
placeholder="Search for a job"
icon={<Search />}
value={search}
onChange={(e) => onSearchChange(e.target.value)}
onKeyDown={handleKeyDown}
actions={[
search && (
<Button
key="clear-search"
size="tiny"
variant="text"
icon={<X />}
onClick={onClearSearch}
className="p-0 h-5 w-5"
/>
),
]}
/>
<div className="flex items-center gap-x-2">
<Button variant="default" icon={<RefreshCw />} loading={isRefreshing} onClick={onRefresh}>
Refresh
</Button>
<Button onClick={onCreateJob}>Create job</Button>
</div>
</div>
)
}