mars-v2-frontend/src/components/Button/EscButton.tsx
Linkie Link cfd7fb3073
Pre migration adjustments (#506)
* fix: added close button to accountDetails

* fix: fixed the AccountList to load async

* fix: fixed the heart size on the AccountStats

* fix: added AccountDetails loading state

* feat: added migration banner

* fix: fixed tests
2023-09-25 20:17:43 +02:00

46 lines
1.0 KiB
TypeScript

import { useCallback, useEffect } from 'react'
import Button from 'components/Button'
import { Cross } from 'components/Icons'
import Text from 'components/Text'
interface Props {
enableKeyPress?: boolean
hideText?: boolean
className?: string
onClick: () => void
}
export default function EscButton(props: Props) {
const handleEscKey = useCallback(
(event: KeyboardEvent) => {
if (event.code === 'Escape') {
props.onClick()
}
},
[props],
)
useEffect(() => {
if (props.enableKeyPress) {
document.addEventListener('keydown', handleEscKey)
}
return () => {
document.removeEventListener('keydown', handleEscKey)
}
}, [props.onClick, props.enableKeyPress, handleEscKey])
return (
<Button
onClick={props.onClick}
leftIcon={<Cross />}
iconClassName='w-3'
color='tertiary'
className={props.className ? props.className : 'h-3 w-13'}
size='xs'
>
{!props.hideText && <Text size='2xs'>ESC</Text>}
</Button>
)
}