Skip to content

Commit b51d9c0

Browse files
authored
Merge pull request #34 from devmount:enhancements/buttons
Button enhancements
2 parents 1fc52f6 + 5476f04 commit b51d9c0

File tree

4 files changed

+93
-7
lines changed

4 files changed

+93
-7
lines changed

docs/_includes/default.njk

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@
4242
</a>
4343
<div>
4444
<div class="text-xl font-semibold">Sloth.css</div>
45-
<div class="text-sm text-muted font-sans flex gap-2">v{{ meta.version }}</div>
45+
<code class="text-muted">v{{ meta.version }}</code>
4646
</div>
4747
</div>
4848
<div class="actions">
49-
<a href="{{ repoUrl }}" target="_blank" class="button hollow neutral sm">GitHub</a>
50-
<a href="{{ donationUrl }}" target="_blank" class="button hollow sm">Support</a>
49+
<a href="{{ repoUrl }}" target="_blank" class="button hollow neutral sm">
50+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5" /></svg>
51+
GitHub
52+
</a>
53+
<a href="{{ donationUrl }}" target="_blank" class="button hollow sm">
54+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M19.5 12.572l-7.5 7.428l-7.5 -7.428a5 5 0 1 1 7.5 -6.566a5 5 0 1 1 7.5 6.572" /></svg>
55+
Support
56+
</a>
5157
</div>
5258
</header>
5359

docs/assets/styles/docs.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ body {
5353
display: flex;
5454
align-items: center;
5555
gap: 1rem;
56+
code {
57+
font-size: .625rem;
58+
}
5659
}
5760
.actions {
5861
display: flex;
59-
gap: .5rem;
62+
align-items: center;
63+
gap: .75rem;
6064
}
6165
}
6266

docs/pages/components/button.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ description: Button component of Sloth.css.
55

66
## Button
77

8-
Buttons indicate actions the user can trigger on click. Buttons already have a base styling via the drop-in core of Sloth.css. However, this CSS component extends those by several color variations and button groups.
8+
Buttons indicate actions the user can trigger on click. Buttons already have a base styling via the drop-in core of Sloth.css. However, this CSS component extends those by several variations, sizes, groups and more.
99

10-
### Color variants
10+
### Button variants
1111

1212
The default button without any class is already utilizing accent coloring. In addition, you can use `neutral`, `success` and `alert` classes for the corresponding colors.
1313

@@ -41,6 +41,22 @@ Using the `disabled` attribute deactivates buttons. If you're using `onclick` ev
4141
<button class="alert" disabled>Delete account</button>
4242
```
4343

44+
### Button sizes
45+
46+
Use the `sm` or `lg` classes to reduce or increase the font size and padding of a button. Note that the actual width and height are still depending on the buttons content (content won't overflow the button but stretch it).
47+
48+
<div class="demo flex flex-wrap items-center gap-4">
49+
<button class="sm">Click me!</button>
50+
<button>No me!</button>
51+
<button class="lg">NO ME!</button>
52+
</div>
53+
54+
```html
55+
<button class="sm">Click me!</button>
56+
<button>No me!</button>
57+
<button class="lg">NO ME!</button>
58+
```
59+
4460
### Secondary button
4561

4662
For less important buttons with outline and transparent backgrounds, the `hollow` class can be used. It can be combined with all other button related classes.
@@ -121,6 +137,40 @@ Use the `ghost` class to keep button sizing without background color or border.
121137
<a class="ghost button" href="#">GitHub</a>
122138
```
123139

140+
### Icon button
141+
142+
Sloth.css doesn't ship any icons, since there are lots of icon libraries out there. However SVG icons are directly supported using the `icon` class. Buttons are set to _inline-flex_ per default, so multiple elements inside buttons are nicely aligned next to each other.
143+
144+
The beautiful <a href="https://tabler.io/icons" target="_blank">Tabler Icons</a> work well with Sloth.css for example. You can also create icon buttons without any text. You might want to use the `rounded-full` utility for those.
145+
146+
<div class="demo flex flex-wrap gap-4">
147+
<button>
148+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M19.875 6.27a2.225 2.225 0 0 1 1.125 1.948v7.284c0 .809 -.443 1.555 -1.158 1.948l-6.75 4.27a2.269 2.269 0 0 1 -2.184 0l-6.75 -4.27a2.225 2.225 0 0 1 -1.158 -1.948v-7.285c0 -.809 .443 -1.554 1.158 -1.947l6.75 -3.98a2.33 2.33 0 0 1 2.25 0l6.75 3.98h-.033z" /><path d="M12 12m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0" /></svg>
149+
Settings
150+
</button>
151+
<button class="hollow alert">
152+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M19.5 12.572l-7.5 7.428l-7.5 -7.428a5 5 0 1 1 7.5 -6.566a5 5 0 1 1 7.5 6.572" /></svg>
153+
Donations
154+
</button>
155+
<button class="hollow neutral rounded-full">
156+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="icon"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" /><path d="M21 21l-6 -6" /></svg>
157+
</button>
158+
</div>
159+
160+
```html
161+
<button>
162+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="icon">...</svg>
163+
Settings
164+
</button>
165+
<button class="hollow alert">
166+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="icon">...</svg>
167+
Donations
168+
</button>
169+
<button class="hollow neutral rounded-full">
170+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="icon">...</svg>
171+
</button>
172+
```
173+
124174
### Busy button
125175

126176
Use the `busy` class to replace the text of a button with a <a href="/components/loader">loader</a> while keeping the button size. Works with secondary buttons, link buttons and pill buttons. Busy buttons are disabled.

src/components/_button.css

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ a.button {
1010
box-shadow: black var(--shadow-float);
1111
box-sizing: border-box;
1212
color: white;
13-
display: inline-block;
13+
display: inline-flex;
14+
align-items: center;
15+
gap: .5rem;
1416
font-family: inherit;
1517
font-size: .875rem;
1618
padding: .75rem 1rem;
@@ -23,6 +25,17 @@ a.button {
2325
user-select: none;
2426
white-space: nowrap;
2527

28+
&.sm {
29+
gap: .25rem;
30+
font-size: .75rem;
31+
padding: .25rem .5rem;
32+
}
33+
&.lg {
34+
gap: .75rem;
35+
font-size: 1rem;
36+
padding: 1rem 1.25rem;
37+
}
38+
2639
&.neutral {
2740
background-color: var(--color-neutral);
2841
}
@@ -162,6 +175,19 @@ a.button {
162175
cursor: not-allowed;
163176
opacity: .5;
164177
}
178+
179+
& > .icon {
180+
width: 1.5em;
181+
height: 1.5em;
182+
fill: none;
183+
stroke: currentColor;
184+
stroke-width: 1.5;
185+
stroke-linecap: round;
186+
stroke-linejoin: round;
187+
}
188+
&.rounded-full:has(.icon:only-child) {
189+
padding: .75rem;
190+
}
165191
}
166192

167193
.button-group {

0 commit comments

Comments
 (0)