-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFormButtons.tsx
43 lines (42 loc) · 1.05 KB
/
FormButtons.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { FormState } from '@/hooks/useFormState'
import { Button } from '@stacklok/ui-kit'
import { FlipBackward } from '@untitled-ui/icons-react'
type Props<T> = {
canSubmit: boolean
formErrorMessage?: string
formSideNote?: string
formState: FormState<T>
children?: React.ReactNode
isPending: boolean
}
export function FormButtons<T>({
formErrorMessage,
formState,
canSubmit,
isPending,
children,
formSideNote,
}: Props<T>) {
return (
<div className="flex items-center gap-2">
{formSideNote && <div className="p-1 text-secondary">{formSideNote}</div>}
{formErrorMessage && (
<div className="p-1 text-red-700">{formErrorMessage}</div>
)}
{formState.isDirty && (
<Button variant="tertiary" onPress={formState.resetForm}>
<FlipBackward />
Revert changes
</Button>
)}
{children}
<Button
isPending={isPending}
isDisabled={!canSubmit || !formState.isDirty || isPending}
type="submit"
>
Save
</Button>
</div>
)
}