Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/components/elements/button/Button.tsx
10263 views
1
import React, { forwardRef } from 'react';
2
import classNames from 'classnames';
3
import { ButtonProps, Options } from '@/components/elements/button/types';
4
import styles from './style.module.css';
5
6
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
7
({ children, shape, size, variant, className, ...rest }, ref) => {
8
return (
9
<button
10
ref={ref}
11
className={classNames(
12
styles.button,
13
styles.primary,
14
{
15
[styles.secondary]: variant === Options.Variant.Secondary,
16
[styles.square]: shape === Options.Shape.IconSquare,
17
[styles.small]: size === Options.Size.Small,
18
[styles.large]: size === Options.Size.Large,
19
},
20
className
21
)}
22
{...rest}
23
>
24
{children}
25
</button>
26
);
27
}
28
);
29
30
const TextButton = forwardRef<HTMLButtonElement, ButtonProps>(({ className, ...props }, ref) => (
31
// @ts-expect-error not sure how to get this correct
32
<Button ref={ref} className={classNames(styles.text, className)} {...props} />
33
));
34
35
const DangerButton = forwardRef<HTMLButtonElement, ButtonProps>(({ className, ...props }, ref) => (
36
// @ts-expect-error not sure how to get this correct
37
<Button ref={ref} className={classNames(styles.danger, className)} {...props} />
38
));
39
40
const _Button = Object.assign(Button, {
41
Sizes: Options.Size,
42
Shapes: Options.Shape,
43
Variants: Options.Variant,
44
Text: TextButton,
45
Danger: DangerButton,
46
});
47
48
export default _Button;
49
50