Skip to content

Commit 7e3d722

Browse files
committed
Add button component
1 parent ff5f93b commit 7e3d722

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import Link from '@docusaurus/Link';
2+
import clsx from 'clsx';
3+
import React, { CSSProperties } from 'react';
4+
5+
import styles from './styles.module.css';
6+
7+
type ButtonProps = {
8+
size?: 'sm' | 'lg' | 'small' | 'medium' | 'large' | null;
9+
outline?: boolean;
10+
variant: 'primary' | 'secondary' | 'danger' | 'warning' | 'success' | 'info' | 'link' | string;
11+
block?: boolean;
12+
disabled?: boolean;
13+
className?: string;
14+
style?: CSSProperties;
15+
link: string;
16+
label: string;
17+
Icon?: React.ComponentType<React.SVGProps<SVGSVGElement>>;
18+
};
19+
20+
export default function Button({
21+
size = null,
22+
outline = false,
23+
variant = 'primary',
24+
block = false,
25+
disabled = false,
26+
className,
27+
style,
28+
link,
29+
label,
30+
Icon,
31+
}: ButtonProps) {
32+
const sizeMap = {
33+
sm: 'sm',
34+
small: 'sm',
35+
lg: 'lg',
36+
large: 'lg',
37+
medium: null,
38+
};
39+
const buttonSize = size ? sizeMap[size] : '';
40+
const sizeClass = buttonSize ? `button--${buttonSize}` : '';
41+
const outlineClass = outline ? 'button--outline' : '';
42+
const variantClass = variant ? `button--${variant}` : '';
43+
const blockClass = block ? 'button--block' : '';
44+
const disabledClass = disabled ? 'disabled' : '';
45+
const destination = disabled ? null : link;
46+
47+
return (
48+
<Link to={destination}>
49+
<button
50+
className={clsx(
51+
'button',
52+
sizeClass,
53+
outlineClass,
54+
variantClass,
55+
blockClass,
56+
disabledClass,
57+
className
58+
)}
59+
style={style}
60+
role="button"
61+
aria-disabled={disabled}
62+
>
63+
{Icon && (
64+
<span className={styles.buttonIcon}>
65+
<Icon />
66+
</span>
67+
)}
68+
{label}
69+
</button>
70+
</Link>
71+
);
72+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
:global(.button) {
2+
display: inline-flex;
3+
align-items: center;
4+
justify-content: center;
5+
6+
--button-icon-size: calc(1.5rem * var(--ifm-button-size-multiplier));
7+
8+
.buttonIcon {
9+
display: inline-flex;
10+
height: var(--button-icon-size);
11+
width: var(--button-icon-size);
12+
margin-right: 1rem;
13+
14+
svg {
15+
height: 100%;
16+
width: 100%;
17+
}
18+
}
19+
}

site/src/theme/MDXComponents.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Button from '@site/src/components/Button';
12
import { LanguageTabs, TabItemCpp, TabItemPython } from '@site/src/components/LanguageTabs';
23
import MDXComponents from '@theme-original/MDXComponents';
34
import TabItem from '@theme/TabItem';
@@ -10,6 +11,7 @@ export default {
1011
Tabs,
1112
TabItem,
1213
// Custom components
14+
Button,
1315
LanguageTabs,
1416
TabItemPython,
1517
TabItemCpp,

0 commit comments

Comments
 (0)