-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.tsx
More file actions
87 lines (85 loc) · 2.4 KB
/
Button.tsx
File metadata and controls
87 lines (85 loc) · 2.4 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { createComponent } from "../../src/functions/createComponent";
import {
mixAddClass,
mixFunction,
mixRemoveClass,
} from "../../src/functions/mixFunctions";
type ButtonProps = {
size: "tiny" | "small" | "medium" | "large";
variant?: "none" | "outline" | "filled";
rounded?: boolean;
anotherOption?: "on" | "off";
dynamicOptions?: number;
} & Partial<{
// alias:
round: ButtonProps["rounded"];
v: ButtonProps["variant"];
}>;
export const Button = createComponent<ButtonProps, "button">(
"button",
{
base: ["btn", { hover: ["btn-hover", "text-bold"] }, () => "btn-base"],
mix: [
mixAddClass(["size.tiny", "variant.outline"], "size-tiny-outline-mix"),
mixRemoveClass(
["size.tiny", "variant.filled"],
["btn-base", { hover: "btn-hover" }, "hover:text-bold"]
),
mixRemoveClass(["data-something.a"], ["btn-base"]),
mixFunction(["anotherOption.*", "disabled.true"], (css) =>
css.add("any-anotherOptions-disabled-true")
),
{ when: ["type.reset"], run: (css) => css.add("btn-reset") },
{
when: ["formNoValidate.true"],
run: (css) => css.add("form-no-validate"),
},
],
alias: {
v: "variant", // v="outline" is interpreted as variant="outline"
round: "rounded",
},
options: {
size: {
tiny: "padding-tiny margin-tiny", // you can use string
small: [
"padding-medium",
"margin-medium",
["text-medium", "font-something"],
],
medium: () => `medium-stuff class-returned-by-function`,
large: {
large: ["text", "font", "padding"],
key: { abc: ["a", "b", "c"], num: ["n1", "n2", "n3"] },
},
},
$type: {
submit: "btn-submit",
},
variant: {
none: "",
outline: "bg-white-500 text-black border border-gray-400",
filled: "bg-teal-200 text-white",
},
anotherOption: {
on: "option-on",
off: "options-off",
},
dynamicOptions: (value) => {
if (value < 50) return "less-than-50";
if (value > 50) return "more-than-50";
return ["value-is-50", "dynamic-options-50"];
},
rounded: "rounded-2xl",
$disabled: "btn-disabled",
$$title: "btn-has-title",
"data-something": {
a: "something-a",
b: "something-b",
},
},
},
{
variant: "none",
}
);