-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyCap.tsx
37 lines (33 loc) · 983 Bytes
/
KeyCap.tsx
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
import cx from 'classnames';
import { HTMLAttributes, MouseEventHandler } from "react";
import Link from 'next/link';
import { UrlObject } from 'url';
export type Props = HTMLAttributes<HTMLButtonElement> & {
keyCode: string;
href?: string | UrlObject;
} & ({
href: string | UrlObject
} | {
onClick: MouseEventHandler<HTMLButtonElement>
});
export const KeyCap = ({ keyCode, className, onClick, href }: Props) => {
const classes = cx(
'flex items-center justify-center capitalize border border-gray-600 bg-gray-400 rounded px-2 cursor-pointer shadow-md focus:outline-none',
keyCode.length <= 1 && 'text-base',
keyCode.length == 2 && 'text-sm',
keyCode.length >= 3 && 'text-xs',
className,
);
return href ? (
<Link href={href}>
<a className={classes}>{keyCode}</a>
</Link>
) : (
<button
onClick={onClick}
className={classes}
>
<div>{keyCode}</div>
</button>
);
}