2024-02-04 13:56:25 +05:30
|
|
|
import { useState } from "react"
|
|
|
|
|
|
|
|
|
|
type Props = {
|
2024-02-25 00:12:46 +05:30
|
|
|
onClick?: () => void
|
2024-02-04 13:56:25 +05:30
|
|
|
disabled?: boolean
|
|
|
|
|
className?: string
|
|
|
|
|
text?: string
|
|
|
|
|
textOnSave?: string
|
2024-02-25 00:12:46 +05:30
|
|
|
btnType?: "button" | "submit" | "reset"
|
2024-02-04 13:56:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const SaveButton = ({
|
|
|
|
|
onClick,
|
|
|
|
|
disabled,
|
|
|
|
|
className,
|
|
|
|
|
text = "Save",
|
2024-02-25 00:12:46 +05:30
|
|
|
textOnSave = "Saved",
|
|
|
|
|
btnType = "button"
|
2024-02-04 13:56:25 +05:30
|
|
|
}: Props) => {
|
|
|
|
|
const [clickedSave, setClickedSave] = useState(false)
|
|
|
|
|
return (
|
|
|
|
|
<button
|
2024-02-25 00:12:46 +05:30
|
|
|
type={btnType}
|
2024-02-04 13:56:25 +05:30
|
|
|
onClick={() => {
|
|
|
|
|
setClickedSave(true)
|
|
|
|
|
onClick()
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
setClickedSave(false)
|
|
|
|
|
}, 1000)
|
|
|
|
|
}}
|
|
|
|
|
disabled={disabled}
|
2024-02-15 00:26:13 +05:30
|
|
|
className={`inline-flex mt-4 items-center rounded-md border border-transparent bg-black px-2 py-2 text-sm font-medium leading-4 text-white shadow-sm dark:bg-white dark:text-gray-800 disabled:opacity-50 ${className}`}>
|
2024-02-04 13:56:25 +05:30
|
|
|
{clickedSave ? textOnSave : text}
|
|
|
|
|
</button>
|
|
|
|
|
)
|
|
|
|
|
}
|