mirror of
https://github.com/xitanggg/open-resume.git
synced 2023-07-20 23:08:37 +03:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { cx } from "lib/cx";
|
|
import { Tooltip } from "components/Tooltip";
|
|
|
|
type ReactButtonProps = React.ComponentProps<"button">;
|
|
type ReactAnchorProps = React.ComponentProps<"a">;
|
|
type ButtonProps = ReactButtonProps | ReactAnchorProps;
|
|
|
|
const isAnchor = (props: ButtonProps): props is ReactAnchorProps => {
|
|
return "href" in props;
|
|
};
|
|
|
|
export const Button = (props: ButtonProps) => {
|
|
if (isAnchor(props)) {
|
|
return <a {...props} />;
|
|
} else {
|
|
return <button type="button" {...props} />;
|
|
}
|
|
};
|
|
|
|
export const PrimaryButton = ({ className, ...props }: ButtonProps) => (
|
|
<Button className={cx("btn-primary", className)} {...props} />
|
|
);
|
|
|
|
type IconButtonProps = ButtonProps & {
|
|
size?: "small" | "medium";
|
|
tooltipText: string;
|
|
};
|
|
|
|
export const IconButton = ({
|
|
className,
|
|
size = "medium",
|
|
tooltipText,
|
|
...props
|
|
}: IconButtonProps) => (
|
|
<Tooltip text={tooltipText}>
|
|
<Button
|
|
type="button"
|
|
className={cx(
|
|
"rounded-full outline-none hover:bg-gray-100 focus-visible:bg-gray-100",
|
|
size === "medium" ? "p-1.5" : "p-1",
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
</Tooltip>
|
|
);
|