mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-12-05 17:09:04 +01:00
e8d23f6bcb
Port 11a63b2db6
to glitch-soc
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renaud Chaput <renchap@gmail.com>
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
62 lines
1.2 KiB
TypeScript
62 lines
1.2 KiB
TypeScript
import type { PropsWithChildren, JSX } from 'react';
|
|
import { useCallback } from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
interface BaseProps
|
|
extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'children'> {
|
|
block?: boolean;
|
|
secondary?: boolean;
|
|
dangerous?: boolean;
|
|
}
|
|
|
|
interface PropsChildren extends PropsWithChildren<BaseProps> {
|
|
text?: undefined;
|
|
}
|
|
|
|
interface PropsWithText extends BaseProps {
|
|
text: JSX.Element | string;
|
|
children?: undefined;
|
|
}
|
|
|
|
type Props = PropsWithText | PropsChildren;
|
|
|
|
export const Button: React.FC<Props> = ({
|
|
type = 'button',
|
|
onClick,
|
|
disabled,
|
|
block,
|
|
secondary,
|
|
dangerous,
|
|
className,
|
|
title,
|
|
text,
|
|
children,
|
|
...props
|
|
}) => {
|
|
const handleClick = useCallback<React.MouseEventHandler<HTMLButtonElement>>(
|
|
(e) => {
|
|
if (!disabled && onClick) {
|
|
onClick(e);
|
|
}
|
|
},
|
|
[disabled, onClick],
|
|
);
|
|
|
|
return (
|
|
<button
|
|
className={classNames('button', className, {
|
|
'button-secondary': secondary,
|
|
'button--block': block,
|
|
'button--dangerous': dangerous,
|
|
})}
|
|
disabled={disabled}
|
|
onClick={handleClick}
|
|
title={title}
|
|
type={type}
|
|
{...props}
|
|
>
|
|
{text ?? children}
|
|
</button>
|
|
);
|
|
};
|