|
| 1 | +--- |
| 2 | +layout: docs |
| 3 | +title: Spinner |
| 4 | +description: Indicate the loading state of a component or page with BootCell spinners, built entirely with HTML, CSS, and no JavaScript. |
| 5 | +group: Components |
| 6 | +--- |
| 7 | + |
| 8 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 9 | +import { Button } from 'boot-cell/source/Form/Button'; |
| 10 | + |
| 11 | +import { Example } from '../../../source/component/Example'; |
| 12 | + |
| 13 | +## About |
| 14 | + |
| 15 | +BootCell “spinners” can be used to show the loading state in your projects. |
| 16 | +They’re built only with HTML and CSS, meaning you don’t need any JavaScript to create them. |
| 17 | +You will, however, need some custom JavaScript to toggle their visibility. |
| 18 | +Their appearance, alignment, and sizing can be easily customized with our amazing utility classes. |
| 19 | + |
| 20 | +## Border spinner |
| 21 | + |
| 22 | +Use the border spinners for a lightweight loading indicator. |
| 23 | + |
| 24 | +<Example> |
| 25 | + <Spinner /> |
| 26 | +</Example> |
| 27 | + |
| 28 | +```TSX |
| 29 | +import { render, createCell } from 'web-cell'; |
| 30 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 31 | + |
| 32 | +render(<Spinner />); |
| 33 | +``` |
| 34 | + |
| 35 | +### Colors |
| 36 | + |
| 37 | +The border spinner uses `currentColor` for its `border-color`, |
| 38 | +meaning you can customize the color with [text color utilities][1]. |
| 39 | +You can use any of our text color utilities on the standard spinner. |
| 40 | + |
| 41 | +<Example> |
| 42 | + <Spinner color="primary" /> |
| 43 | + <Spinner color="secondary" /> |
| 44 | + <Spinner color="success" /> |
| 45 | + <Spinner color="danger" /> |
| 46 | + <Spinner color="warning" /> |
| 47 | + <Spinner color="info" /> |
| 48 | + <Spinner color="light" /> |
| 49 | + <Spinner color="dark" /> |
| 50 | +</Example> |
| 51 | + |
| 52 | +```TSX |
| 53 | +import { render, createCell, Fragment } from 'web-cell'; |
| 54 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 55 | + |
| 56 | +render( |
| 57 | + <Fragment> |
| 58 | + <Spinner color="primary" /> |
| 59 | + <Spinner color="secondary" /> |
| 60 | + <Spinner color="success" /> |
| 61 | + <Spinner color="danger" /> |
| 62 | + <Spinner color="warning" /> |
| 63 | + <Spinner color="info" /> |
| 64 | + <Spinner color="light" /> |
| 65 | + <Spinner color="dark" /> |
| 66 | + </Fragment> |
| 67 | +); |
| 68 | +``` |
| 69 | + |
| 70 | +> **Why not use `border-color` utilities?** Each border spinner specifies a `transparent` border for at least one side, |
| 71 | +> so `.border-{color}` utilities would override that. |
| 72 | +
|
| 73 | +## Growing spinner |
| 74 | + |
| 75 | +If you don’t fancy a border spinner, switch to the grow spinner. |
| 76 | +While it doesn’t technically spin, it does repeatedly grow! |
| 77 | + |
| 78 | +<Example> |
| 79 | + <Spinner type="grow" /> |
| 80 | +</Example> |
| 81 | + |
| 82 | +```TSX |
| 83 | +import { render, createCell } from 'web-cell'; |
| 84 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 85 | + |
| 86 | +render(<Spinner type="grow" />); |
| 87 | +``` |
| 88 | + |
| 89 | +Once again, this spinner is built with `currentColor`, so you can easily change its appearance with [text color utilities][1]. |
| 90 | +Here it is in blue, along with the supported variants. |
| 91 | + |
| 92 | +<Example> |
| 93 | + <Spinner type="grow" color="primary" /> |
| 94 | + <Spinner type="grow" color="secondary" /> |
| 95 | + <Spinner type="grow" color="success" /> |
| 96 | + <Spinner type="grow" color="danger" /> |
| 97 | + <Spinner type="grow" color="warning" /> |
| 98 | + <Spinner type="grow" color="info" /> |
| 99 | + <Spinner type="grow" color="light" /> |
| 100 | + <Spinner type="grow" color="dark" /> |
| 101 | +</Example> |
| 102 | + |
| 103 | +```TSX |
| 104 | +import { render, createCell, Fragment } from 'web-cell'; |
| 105 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 106 | + |
| 107 | +render( |
| 108 | + <Fragment> |
| 109 | + <Spinner type="grow" color="primary" /> |
| 110 | + <Spinner type="grow" color="secondary" /> |
| 111 | + <Spinner type="grow" color="success" /> |
| 112 | + <Spinner type="grow" color="danger" /> |
| 113 | + <Spinner type="grow" color="warning" /> |
| 114 | + <Spinner type="grow" color="info" /> |
| 115 | + <Spinner type="grow" color="light" /> |
| 116 | + <Spinner type="grow" color="dark" /> |
| 117 | + </Fragment> |
| 118 | +); |
| 119 | +``` |
| 120 | + |
| 121 | +## Alignment |
| 122 | + |
| 123 | +Spinners in BootCell are built with `rem`s, `currentColor`, and `display: inline-flex`. |
| 124 | +This means they can easily be resized, recolored, and quickly aligned. |
| 125 | + |
| 126 | +### Margin |
| 127 | + |
| 128 | +Use [margin utilities][2] like `.m-5` for easy spacing. |
| 129 | + |
| 130 | +<Example> |
| 131 | + <Spinner className="m-5" /> |
| 132 | +</Example> |
| 133 | + |
| 134 | +```TSX |
| 135 | +import { render, createCell } from 'web-cell'; |
| 136 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 137 | + |
| 138 | +render(<Spinner className="m-5" />); |
| 139 | +``` |
| 140 | + |
| 141 | +### Placement |
| 142 | + |
| 143 | +Use [flexbox utilities][3], [float utilities][4], or [text alignment][5] utilities to place spinners exactly |
| 144 | +where you need them in any situation. |
| 145 | + |
| 146 | +#### Flex |
| 147 | + |
| 148 | +<Example> |
| 149 | + <div className="d-flex justify-content-center"> |
| 150 | + <Spinner /> |
| 151 | + </div> |
| 152 | +</Example> |
| 153 | + |
| 154 | +```TSX |
| 155 | +import { render, createCell } from 'web-cell'; |
| 156 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 157 | + |
| 158 | +render( |
| 159 | + <div className="d-flex justify-content-center"> |
| 160 | + <Spinner /> |
| 161 | + </div> |
| 162 | +); |
| 163 | +``` |
| 164 | + |
| 165 | +<Example> |
| 166 | + <div className="d-flex align-items-center"> |
| 167 | + <strong>Loading...</strong> |
| 168 | + <Spinner className="ml-auto" aria-hidden="true" /> |
| 169 | + </div> |
| 170 | +</Example> |
| 171 | + |
| 172 | +```TSX |
| 173 | +import { render, createCell } from 'web-cell'; |
| 174 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 175 | + |
| 176 | +render( |
| 177 | + <div className="d-flex align-items-center"> |
| 178 | + <strong>Loading...</strong> |
| 179 | + <Spinner className="ml-auto" aria-hidden="true" /> |
| 180 | + </div> |
| 181 | +); |
| 182 | +``` |
| 183 | + |
| 184 | +#### Floats |
| 185 | + |
| 186 | +<Example> |
| 187 | + <div className="clearfix"> |
| 188 | + <Spinner className="float-right" /> |
| 189 | + </div> |
| 190 | +</Example> |
| 191 | + |
| 192 | +```TSX |
| 193 | +import { render, createCell } from 'web-cell'; |
| 194 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 195 | + |
| 196 | +render( |
| 197 | + <div className="clearfix"> |
| 198 | + <Spinner className="float-right" /> |
| 199 | + </div> |
| 200 | +); |
| 201 | +``` |
| 202 | + |
| 203 | +#### Text align |
| 204 | + |
| 205 | +<Example> |
| 206 | + <div className="text-center"> |
| 207 | + <Spinner /> |
| 208 | + </div> |
| 209 | +</Example> |
| 210 | + |
| 211 | +```TSX |
| 212 | +import { render, createCell } from 'web-cell'; |
| 213 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 214 | + |
| 215 | +render( |
| 216 | + <div className="text-center"> |
| 217 | + <Spinner /> |
| 218 | + </div> |
| 219 | +); |
| 220 | +``` |
| 221 | + |
| 222 | +## Size |
| 223 | + |
| 224 | +Add `small` property to make a smaller spinner that can quickly be used within other components. |
| 225 | + |
| 226 | +<Example> |
| 227 | + <Spinner small /> |
| 228 | + <Spinner type="grow" small /> |
| 229 | +</Example> |
| 230 | + |
| 231 | +```TSX |
| 232 | +import { render, createCell, Fragment } from 'web-cell'; |
| 233 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 234 | + |
| 235 | +render( |
| 236 | + <Fragment> |
| 237 | + <Spinner small /> |
| 238 | + <Spinner type="grow" small /> |
| 239 | + </Fragment> |
| 240 | +); |
| 241 | +``` |
| 242 | + |
| 243 | +Or, use custom CSS or inline styles to change the dimensions as needed. |
| 244 | + |
| 245 | +<Example> |
| 246 | + <Spinner style={{ width: '3rem', height: '3rem' }} /> |
| 247 | + <Spinner type="grow" style={{ width: '3rem', height: '3rem' }} /> |
| 248 | +</Example> |
| 249 | + |
| 250 | +```TSX |
| 251 | +import { render, createCell, Fragment } from 'web-cell'; |
| 252 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 253 | + |
| 254 | +render( |
| 255 | + <Fragment> |
| 256 | + <Spinner style={{ width: '3rem', height: '3rem' }} /> |
| 257 | + <Spinner type="grow" style={{ width: '3rem', height: '3rem' }} /> |
| 258 | + </Fragment> |
| 259 | +); |
| 260 | +``` |
| 261 | + |
| 262 | +## Buttons |
| 263 | + |
| 264 | +Use spinners within buttons to indicate an action is currently processing or taking place. |
| 265 | +You may also swap the text out of the spinner element and utilize button text as needed. |
| 266 | + |
| 267 | +<Example> |
| 268 | + <Button disabled> |
| 269 | + <Spinner small aria-hidden="true" /> |
| 270 | + <span className="sr-only">Loading...</span> |
| 271 | + </Button> |
| 272 | + <Button disabled> |
| 273 | + <Spinner small aria-hidden="true" /> |
| 274 | + Loading... |
| 275 | + </Button> |
| 276 | +</Example> |
| 277 | + |
| 278 | +```TSX |
| 279 | +import { render, createCell, Fragment } from 'web-cell'; |
| 280 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 281 | +import { Button } from 'boot-cell/source/Form/Button'; |
| 282 | + |
| 283 | +render( |
| 284 | + <Fragment> |
| 285 | + <Button disabled> |
| 286 | + <Spinner small aria-hidden="true" /> |
| 287 | + <span className="sr-only">Loading...</span> |
| 288 | + </Button> |
| 289 | + <Button disabled> |
| 290 | + <Spinner small aria-hidden="true" /> |
| 291 | + Loading... |
| 292 | + </Button> |
| 293 | + </Fragment> |
| 294 | +); |
| 295 | +``` |
| 296 | + |
| 297 | +<Example> |
| 298 | + <Button disabled> |
| 299 | + <Spinner type="grow" small aria-hidden="true" /> |
| 300 | + <span className="sr-only">Loading...</span> |
| 301 | + </Button> |
| 302 | + <Button disabled> |
| 303 | + <Spinner type="grow" small aria-hidden="true" /> |
| 304 | + Loading... |
| 305 | + </Button> |
| 306 | +</Example> |
| 307 | + |
| 308 | +```TSX |
| 309 | +import { render, createCell, Fragment } from 'web-cell'; |
| 310 | +import { Spinner } from 'boot-cell/source/Prompt/Spinner'; |
| 311 | +import { Button } from 'boot-cell/source/Form/Button'; |
| 312 | + |
| 313 | +render( |
| 314 | + <Fragment> |
| 315 | + <Button disabled> |
| 316 | + <Spinner type="grow" small aria-hidden="true" /> |
| 317 | + <span className="sr-only">Loading...</span> |
| 318 | + </Button> |
| 319 | + <Button disabled> |
| 320 | + <Spinner type="grow" small aria-hidden="true" /> |
| 321 | + Loading... |
| 322 | + </Button> |
| 323 | + </Fragment> |
| 324 | +); |
| 325 | +``` |
| 326 | + |
| 327 | +[1]: https://getbootstrap.com/docs/4.4/utilities/colors/ |
| 328 | +[2]: https://getbootstrap.com/docs/4.4/utilities/spacing/ |
| 329 | +[3]: https://getbootstrap.com/docs/4.4/utilities/flex/ |
| 330 | +[4]: https://getbootstrap.com/docs/4.4/utilities/float/ |
| 331 | +[5]: https://getbootstrap.com/docs/4.4/content/typography/ |
0 commit comments