File size: 1,014 Bytes
5e0e982
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/** Primary action button with press-scale feedback. */

import type { ComponentChildren, JSX } from "preact";
import { Pressable } from "./Pressable";

type Variant = "primary" | "secondary" | "destructive" | "plain";

type ButtonProps = {
  children: ComponentChildren;
  variant?: Variant;
  disabled?: boolean;
  type?: "button" | "submit";
  onClick?: JSX.MouseEventHandler<HTMLElement>;
  className?: string;
  ariaLabel?: string;
};

const variantClass: Record<Variant, string> = {
  primary: "btn btn-primary",
  secondary: "btn btn-secondary",
  destructive: "btn btn-destructive",
  plain: "btn btn-plain",
};

export function Button({
  children,
  variant = "primary",
  disabled = false,
  type = "button",
  onClick,
  className = "",
  ariaLabel,
}: ButtonProps) {
  return (
    <Pressable
      type={type}
      disabled={disabled}
      onClick={onClick}
      ariaLabel={ariaLabel}
      className={`${variantClass[variant]} ${className}`.trim()}
    >
      {children}
    </Pressable>
  );
}