Skip to content

Commit 52a86cc

Browse files
mdoXhmikosR
authored andcommitted
Add Bootstrap's very first spinners omfg it's actually happening
1 parent f3bd860 commit 52a86cc

File tree

5 files changed

+249
-0
lines changed

5 files changed

+249
-0
lines changed

scss/_spinners.scss

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// Rotating border
3+
//
4+
5+
@keyframes spinner-border {
6+
to { transform: rotate(360deg); }
7+
}
8+
9+
.spinner-border {
10+
position: relative;
11+
display: inline-block;
12+
width: $spinner-width;
13+
height: $spinner-height;
14+
overflow: hidden;
15+
text-indent: -999em;
16+
vertical-align: text-bottom;
17+
border: $spinner-border-width solid;
18+
border-color: currentColor transparent currentColor currentColor;
19+
border-radius: 50%;
20+
animation-name: spinner-border;
21+
animation-duration: .75s;
22+
animation-timing-function: linear;
23+
animation-iteration-count: infinite;
24+
}
25+
26+
.spinner-border-sm {
27+
width: $spinner-width-sm;
28+
height: $spinner-height-sm;
29+
border-width: $spinner-border-width-sm;
30+
}
31+
32+
//
33+
// Growing circle
34+
//
35+
36+
@keyframes spinner-grow {
37+
0% {
38+
opacity: 0;
39+
transform: scale(0);
40+
}
41+
50% {
42+
opacity: 1;
43+
}
44+
100% {
45+
opacity: 0;
46+
transform: scale(1);
47+
}
48+
}
49+
50+
.spinner-grow {
51+
position: relative;
52+
display: inline-block;
53+
width: $spinner-width;
54+
height: $spinner-height;
55+
overflow: hidden;
56+
text-indent: -999em;
57+
vertical-align: text-bottom;
58+
background-color: currentColor;
59+
border-radius: 50%;
60+
animation-name: spinner-grow;
61+
animation-duration: .75s;
62+
animation-timing-function: linear;
63+
animation-iteration-count: infinite;
64+
}
65+
66+
.spinner-grow-sm {
67+
width: $spinner-width-sm;
68+
height: $spinner-height-sm;
69+
}

scss/_variables.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,17 @@ $carousel-transition-duration: .6s !default;
10241024
$carousel-transition: transform $carousel-transition-duration ease-in-out !default; // Define transform transition first if using multiple transitions (e.g., `transform 2s ease, opacity .5s ease-out`)
10251025

10261026

1027+
// Spinners
1028+
1029+
$spinner-width: 2rem !default;
1030+
$spinner-height: $spinner-width !default;
1031+
$spinner-border-width: .25em !default;
1032+
1033+
$spinner-width-sm: 1rem !default;
1034+
$spinner-height-sm: $spinner-width-sm !default;
1035+
$spinner-border-width-sm: .2em !default;
1036+
1037+
10271038
// Close
10281039

10291040
$close-font-size: $font-size-base * 1.5 !default;

scss/bootstrap.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
@import "tooltip";
3939
@import "popover";
4040
@import "carousel";
41+
@import "spinners";
4142
@import "utilities";
4243
@import "print";

site/_data/nav.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
- title: Popovers
5050
- title: Progress
5151
- title: Scrollspy
52+
- title: Spinners
5253
- title: Tooltips
5354

5455
- title: Utilities

site/docs/4.1/components/spinners.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
layout: docs
3+
title: Spinners
4+
description: Indicate the loading state of a component or page with Bootstrap spinners, built entirely with HTML, CSS, and no JavaScript.
5+
group: components
6+
toc: true
7+
---
8+
9+
## About
10+
11+
Bootstrap "spinners" can be used to show the loading state in your projects. They're built only with HTML and CSS, meaning you don't need any JavaScript to create them. You will, however, need some custom JavaScript to toggle their visibility. Their appearance, alignment, and sizing can be easily customized with our amazing utility classes.
12+
13+
For accessibility purposes, each loader here includes `role="status"` and `Loading...` text within. We account for this in our CSS, using a text hiding technique to prevent it from rendering on screen.
14+
15+
## Border spinner
16+
17+
Use the border spinners for a lightweight loading indicator.
18+
19+
{% capture example %}
20+
<div class="spinner-border" role="status">Loading...</div>
21+
{% endcapture %}
22+
{% include example.html content=example %}
23+
24+
### Colors
25+
26+
The border spinner uses `currentColor` for its `border-color`, meaning you can customize the color with [text color utilities][color]. Here's the regular border spinner in blue.
27+
28+
<div class="bd-example">
29+
<div class="spinner-border text-primary" role="status">Loading...</div>
30+
</div>
31+
32+
Use any of our text color utilities on the standard spinner.
33+
34+
{% highlight html %}
35+
{% for color in site.data.theme-colors %}
36+
<div class="spinner-border text-{{ color.name }}" role="status">Loading...</div>{% endfor %}
37+
{% endhighlight %}
38+
39+
{% capture callout %}
40+
**Why not use `border-color` utilities?** Each border spinner specifies a `transparent` border for at least one side, so `.border-{color}` utilities would override that.
41+
{% endcapture %}
42+
{% include callout.html content=callout type="info" %}
43+
44+
## Growing spinner
45+
46+
If you don't fancy a border spinner, switch to the grow spinner. While it doesn't technically spin, it does repeatedly grow!
47+
48+
{% capture example %}
49+
<div class="spinner-grow" role="status">Loading...</div>
50+
{% endcapture %}
51+
{% include example.html content=example %}
52+
53+
Once again, this spinner is built with `currentColor`, so you can easily change its appearance with [text color utilities][color]. Here it is in blue, along with the supported variants.
54+
55+
<div class="bd-example">
56+
<div class="spinner-grow text-primary" role="status">Loading...</div>
57+
</div>
58+
59+
{% highlight html %}
60+
{% for color in site.data.theme-colors %}
61+
<div class="spinner-grow text-{{ color.name }}" role="status">Loading...</div>{% endfor %}
62+
{% endhighlight %}
63+
64+
## Alignment
65+
66+
Spinners in Bootstrap are built with `rem`s, `currentColor`, and `display: inline-flex`. This means they can easily be resized, recolored, and quickly aligned.
67+
68+
### Margin
69+
70+
Use [margin utilities][margin] like `.m-5` for easy spacing.
71+
72+
{% capture example %}
73+
<div class="spinner-border m-5" role="status">Loading...</div>
74+
{% endcapture %}
75+
{% include example.html content=example %}
76+
77+
### Placement
78+
79+
Use [flexbox utilities][flex], [float utilities][float], or [text alignment][text] utilities to place spinners exactly where you need them in any situation.
80+
81+
#### Flex
82+
83+
{% capture example %}
84+
<div class="d-flex justify-content-center">
85+
<div class="spinner-border" role="status">Loading...</div>
86+
</div>
87+
{% endcapture %}
88+
{% include example.html content=example %}
89+
90+
{% capture example %}
91+
<div class="d-flex align-items-center">
92+
<strong>Loading...</strong>
93+
<div class="spinner-border ml-auto" role="status"></div>
94+
</div>
95+
{% endcapture %}
96+
{% include example.html content=example %}
97+
98+
#### Floats
99+
100+
{% capture example %}
101+
<div class="clearfix">
102+
<div class="spinner-border float-right" role="status">Loading...</div>
103+
</div>
104+
{% endcapture %}
105+
{% include example.html content=example %}
106+
107+
#### Text align
108+
109+
{% capture example %}
110+
<div class="text-center">
111+
<div class="spinner-border" role="status">Loading...</div>
112+
</div>
113+
{% endcapture %}
114+
{% include example.html content=example %}
115+
116+
## Size
117+
118+
Add `.spinner-border-sm` and `.spinner-grow-sm` to make a smaller spinner that can quickly be used within other components.
119+
120+
{% capture example %}
121+
<div class="spinner-border spinner-border-sm" role="status">Loading...</div>
122+
<div class="spinner-grow spinner-grow-sm" role="status">Loading...</div>
123+
{% endcapture %}
124+
{% include example.html content=example %}
125+
126+
Or, use custom CSS or inline styles to change the dimensions as needed.
127+
128+
{% capture example %}
129+
<div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">Loading...</div>
130+
<div class="spinner-grow" style="width: 3rem; height: 3rem;" role="status">Loading...</div>
131+
{% endcapture %}
132+
{% include example.html content=example %}
133+
134+
## Buttons
135+
136+
Use spinners within buttons to indicate an action is currently processing or taking place. You may also swap the text out of the spinner element and utilize button text as needed.
137+
138+
{% capture example %}
139+
<button class="btn btn-primary" type="button" disabled>
140+
<span class="spinner-border spinner-border-sm" role="status">Loading...</span>
141+
</button>
142+
<button class="btn btn-primary" type="button" disabled>
143+
<span class="spinner-border spinner-border-sm" role="status"></span>
144+
Loading...
145+
</button>
146+
{% endcapture %}
147+
{% include example.html content=example %}
148+
149+
{% capture example %}
150+
<button class="btn btn-primary" type="button" disabled>
151+
<span class="spinner-grow spinner-grow-sm" role="status">Loading...</span>
152+
</button>
153+
<button class="btn btn-primary" type="button" disabled>
154+
<span class="spinner-grow spinner-grow-sm" role="status"></span>
155+
Loading...
156+
</button>
157+
{% endcapture %}
158+
{% include example.html content=example %}
159+
160+
161+
[color]: {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/colors/
162+
[display]: {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/display/
163+
[flex]: {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/flex/
164+
[float]: {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/float/
165+
[margin]: {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/spacing/
166+
[sizing]: {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/sizing/
167+
[text]: {{ site.baseurl }}/docs/{{ site.docs_version }}/content/typography/

0 commit comments

Comments
 (0)