-
Notifications
You must be signed in to change notification settings - Fork 353
Expand file tree
/
Copy pathcard-toolbar-button.component.tsx
More file actions
47 lines (42 loc) · 1.21 KB
/
card-toolbar-button.component.tsx
File metadata and controls
47 lines (42 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, { PropsWithChildren, useRef } from "react";
import styles from "./card-toolbar-button.module.scss";
import { AriaButtonOptions, useButton } from "@react-aria/button";
import { clsx } from "clsx";
import { MonoFont } from "@/libs/theme/fonts";
export interface CardToolbarButtonComponentProps
extends AriaButtonOptions<"span"> {
variant: "standard" | "icon";
tooltipText?: string;
}
export const CardToolbarButtonComponent: React.FC<
PropsWithChildren<CardToolbarButtonComponentProps>
> = (props) => {
const { variant, tooltipText, children } = props;
const ref = useRef<HTMLButtonElement | null>(null);
const { buttonProps } = useButton(
{
...props,
elementType: "span",
preventFocusOnPress: true,
},
ref
);
return (
<div className={styles.button__tooltipContainer}>
<button
{...buttonProps}
type="button"
className={clsx(
variant === "icon" ? styles.button__icon : styles.button__standard,
MonoFont.className
)}
data-style="compact"
>
{children}
</button>
{tooltipText && (
<span className={styles.button__tooltip}>{tooltipText}</span>
)}
</div>
);
};