Files
page-assist/src/components/Common/SaveButton.tsx

40 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-02-04 13:56:25 +05:30
import { useState } from "react"
import { CheckIcon } from "lucide-react"
2024-02-04 13:56:25 +05:30
type Props = {
onClick?: () => void
2024-02-04 13:56:25 +05:30
disabled?: boolean
className?: string
text?: string
textOnSave?: string
btnType?: "button" | "submit" | "reset"
2024-02-04 13:56:25 +05:30
}
export const SaveButton = ({
onClick,
disabled,
className,
text = "Save",
textOnSave = "Saved",
btnType = "button"
2024-02-04 13:56:25 +05:30
}: Props) => {
const [clickedSave, setClickedSave] = useState(false)
return (
<button
type={btnType}
2024-02-04 13:56:25 +05:30
onClick={() => {
setClickedSave(true)
if (onClick) {
onClick()
}
2024-02-04 13:56:25 +05:30
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}`}>
{clickedSave ? <CheckIcon className="w-4 h-4 mr-2" /> : null}
2024-02-04 13:56:25 +05:30
{clickedSave ? textOnSave : text}
</button>
)
}