Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 5843d89

Browse files
sukimaegoist
authored andcommitted
Add support for loading spinner in alert boxes (#53)
The pattern of placing a spinner in an alert (styled info) to notify that something is loading is very common for me. I realize the material design suggests to use a progress bar but hack.css doesn't yet support an indefinite progress bar. Till then I will often use an alert box with a spinner. The former style had no display type so it defaulted to block for `<div>`s and inline for `<span>`s. The problem with a div is it means the text next to a spinner drop to another row. This caused rendering the spinner in an alert box looking off. It also forced the user to explicitly set the display to inline-block or float. For me that last think I conclude when using a CSS library like this is to manually understand floating a spinner or changing it's display type. Normally I would simply define the spinner as a `<span>` not a `<div>`. Since inline elements have no width or height it renders awful. To make things easier this adds some opinions to the display of a span or div with .loading class on it. However, to prevent changes to style when upgrading the spinner in a button defined as a div will stay float left. The example docs were updated and I moved the spinner to the right in the button example because in almost all cases where I've seen loading buttons the spinner has been on the right.
1 parent 6b7097d commit 5843d89

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/css/components.css

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,22 +342,32 @@ select.form-control {
342342
* Loading
343343
*/
344344
.loading {
345+
display: inline-block;
346+
content: '&nbsp;';
345347
height: 20px;
346348
width: 20px;
349+
margin: 0 .5rem;
347350
animation: rotate 0.6s infinite linear;
348351
border: 2px solid $pink;
349352
border-right-color: transparent;
350353
border-radius: 50%;
351354
}
352355

353356
.btn .loading {
354-
display: inline-block;
355-
float: left;
356-
margin-right: .5rem;
357+
margin-bottom: 0;
357358
width: 14px;
358359
height: 14px;
359360
}
360361

362+
/* Remains for backwards compatibility */
363+
.btn div.loading {
364+
float: left;
365+
}
366+
367+
.alert .loading {
368+
margin-bottom: -5px;
369+
}
370+
361371
@keyframes rotate {
362372
0% { transform: rotate(0deg); }
363373
100% { transform: rotate(360deg); }

src/html/components.jade

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,26 @@ p hack.css gives you a default loading element, but you can find more at <a href
311311

312312
.example
313313
button.btn.btn-info.btn-ghost
314-
.loading
315-
| Loading...
314+
| Loading&hellip;
315+
span.loading
316+
317+
.example
318+
.alert.alert-info
319+
span.loading
320+
| Loading in an alert box&hellip;
316321

317322
:marked
318323
```html
319324
<div class="loading"></div>
320325

321326
<button class="btn btn-info btn-ghost">
322-
<div class="loading"></div>
323-
Loading...
327+
Loading&hellip;
328+
<span class="loading"></span>
324329
</button>
330+
331+
<div class="alert alert-info">
332+
<span class="loading"></span>
333+
Loading in an alert box&hellip;
334+
</div>
325335
```
326336

0 commit comments

Comments
 (0)