1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00
vault-frontend/src/components/input/Toggle/index.tsx
2022-01-02 20:59:52 +07:00

38 lines
852 B
TypeScript

import React, { FC, useCallback } from 'react';
import styles from './styles.module.scss';
import classNames from 'classnames';
import { ButtonProps } from '~/utils/types';
type ToggleColor = 'primary' | 'secondary' | 'lab' | 'danger' | 'white';
type IProps = Omit<ButtonProps, 'value' | 'color'> & {
value?: boolean;
handler?: (val: boolean) => void;
color?: ToggleColor;
};
const Toggle: FC<IProps> = ({ value, handler, color = 'primary', ...rest }) => {
const onClick = useCallback(() => {
if (!handler) {
return;
}
handler(!value);
}, [value, handler]);
return (
<button
{...rest}
type="button"
className={classNames(
styles.toggle,
{ [styles.active]: value },
styles[color],
rest.className
)}
onClick={onClick}
/>
);
};
export { Toggle };