Skip to content

Commit 53e1786

Browse files
committed
♻️ make color optional
1 parent e3b5ad8 commit 53e1786

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

index.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
declare module '@eliancodes/brutal-ui' {
22
type ButtonProps = {
33
href: string;
4-
target: '_blank' | '_self';
5-
color: string;
6-
string: string;
4+
target?: '_blank' | '_self';
5+
color?: string;
76
}
87

98
export function Button(props: ButtonProps): any;

src/components/Button.astro

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
---
22
interface Props {
33
href: string;
4-
target: '_blank' | '_self';
5-
color: string;
6-
string: string;
4+
target?: '_blank' | '_self';
5+
color?: string;
76
}
87
9-
const colors = await Astro.glob('../config/colors.json')
8+
import colors from '../config/colors.json';
9+
10+
if (Astro.props.target === undefined) {
11+
Astro.props.target = '_self';
12+
}
13+
14+
if (Astro.props.color === undefined) {
15+
Astro.props.color = colors.colors[Math.floor(Math.random() * colors.colors.length)];
16+
;
17+
}
1018
1119
const { href, target, color } = Astro.props;
20+
1221
---
13-
<style>
14-
a.btn {
22+
<style define:vars={{ color: color}}>
23+
a.brutal-btn {
1524
filter: drop-shadow(5px 5px 0 rgb(0 0 0 / 1));
25+
background-color: white;
1626
}
17-
a.btn:hover {
27+
a.brutal-btn:hover {
1828
filter: drop-shadow(3px 3px 0 rgb(0 0 0 / 1));
29+
background-color: var(--color);
1930
}
2031
</style>
2132

2233
<a
2334
href={href}
2435
target={target}
25-
class:list={[
26-
color
27-
? `hover:bg-${color}`
28-
: `hover:bg-${colors[Math.floor(Math.random() * colors.length)]}`,
29-
'btn bg-white sanchez inline-block py-2 px-4 border-2 border-black transition-all ease-in-out duration-150',
30-
]}
36+
class="brutal-btn sanchez inline-block py-2 px-4 border-2 border-black transition-all ease-in-out duration-150"
3137
>
32-
test
3338
<slot />
3439
</a>

0 commit comments

Comments
 (0)