Skip to content

Commit 0ee32dc

Browse files
bomberfishvelzie
authored andcommitted
add button component
1 parent e534a9a commit 0ee32dc

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { type Component, css } from "dreamland/core";
2+
3+
export const Button: Component<{
4+
class?: string;
5+
"on:click"?: (e: any) => void;
6+
disabled?: boolean;
7+
variant?: "primary" | "secondary" | "icon";
8+
children: any;
9+
}> = function (cx) {
10+
return (
11+
<button
12+
class={`${this.variant} ${this.class}`}
13+
disabled={use(this.disabled)}
14+
on:click={this["on:click"] || (() => {})}
15+
>
16+
{cx.children}
17+
</button>
18+
);
19+
};
20+
21+
Button.style = css`
22+
:scope:not(.icon) {
23+
background: var(--bg02);
24+
border: 1px solid var(--fg4);
25+
border-radius: 4px;
26+
padding: 0.5em 1em;
27+
font-size: 0.9em;
28+
cursor: pointer;
29+
color: var(--fg);
30+
}
31+
:scope:not(.icon):hover {
32+
background: var(--bg03);
33+
}
34+
:scope.primary {
35+
background: var(--accent);
36+
color: white;
37+
border-color: var(--accent);
38+
}
39+
:scope.primary:hover {
40+
background: var(--accent-hover, var(--accent));
41+
}
42+
43+
:scope:disabled,
44+
:scope[disabled] {
45+
opacity: 0.6;
46+
cursor: not-allowed;
47+
pointer-events: none;
48+
background: var(--bg02);
49+
color: var(--fg4);
50+
border-color: var(--fg4);
51+
}
52+
:scope:disabled:hover,
53+
:scope[disabled]:hover {
54+
background: var(--bg02);
55+
}
56+
57+
:scope.icon {
58+
display: flex;
59+
align-items: center;
60+
font-size: 1em;
61+
position: relative;
62+
}
63+
:scope.icon:hover::before {
64+
content: "";
65+
z-index: -1;
66+
position: absolute;
67+
width: 150%;
68+
height: 150%;
69+
top: 50%;
70+
left: 50%;
71+
transform: translate(-50%, -50%);
72+
background: var(--bg20);
73+
border-radius: 50%;
74+
}
75+
`;

0 commit comments

Comments
 (0)