summaryrefslogtreecommitdiffstats
path: root/src/ui/objects/ActionButton.tsx
blob: 76f859fa3d0eeec80675fb585952b2d29e4766e7 (plain) (blame)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import type { HTMLTag, Polymorphic } from "corvos/plugins/jsx.ts";

export type Props<Tag extends HTMLTag> = Polymorphic<{
	"as"?: Tag;
	"label-as"?: string;
	"pill"?: boolean;
	"icon"?: JSX.Element;
	"pre"?: JSX.Element;
	"post"?: JSX.Element;
	"highlighted"?: boolean;
	"selected"?: boolean;
	"wide"?: boolean;
	"justify"?: boolean;
	"align-block"?: boolean;
	"level"?: "button" | "badge" | "quiet";
	"variant"?: "accent" | "positive" | "negative" | "warning" | "static-black" | "static-white";
	"size"?: "xs" | "sm" | "lg" | "xl";
	"children"?: JSX.Element;
}>;

export const ActionButton = <T extends HTMLTag = "a">({
	children,
	as: Tag = "a" as T,
	"label-as": Label = "span",
	pill,
	pre,
	post,
	wide,
	justify,
	icon,
	"align-block": alignBlock,
	highlighted,
	selected,
	level,
	variant,
	size,
	class: cls,
	...props
}: Props<T>) => (
	<Tag
		class:list={[
			"o-button",
			{
				"o-button--pill": pill,
				"o-button--wide": wide,
				"o-button--justify": justify,
				"o-button--icon": icon,
				"o-button--align-block": alignBlock,
				"is-highlighted": highlighted,
				"is-selected": selected,
				[`o-button--${level}`]: level && level !== "button",
				[`o-button--${variant}`]: variant,
				[`o-button--${size}`]: size,
			},
			cls,
		]}
		{...props}
	>
		{pre} {icon ?? <Label class="o-button__label">{children}</Label>} {post}
	</Tag>
);