You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.1 KiB

  1. // Copyright (c) 2020 Tulir Asokan
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. import { html } from "https://unpkg.com/htm/preact/index.mjs?module"
  7. export const Spinner = ({ size = 40, noCenter = false, noMargin = false, green = false }) => {
  8. let margin = 0
  9. if (!isNaN(+size)) {
  10. size = +size
  11. margin = noMargin ? 0 : `${Math.round(size / 6)}px`
  12. size = `${size}px`
  13. }
  14. const noInnerMargin = !noCenter || !margin
  15. const comp = html`
  16. <div style="width: ${size}; height: ${size}; margin: ${noInnerMargin ? 0 : margin} 0;"
  17. class="sk-chase ${green && "green"}">
  18. <div class="sk-chase-dot" />
  19. <div class="sk-chase-dot" />
  20. <div class="sk-chase-dot" />
  21. <div class="sk-chase-dot" />
  22. <div class="sk-chase-dot" />
  23. <div class="sk-chase-dot" />
  24. </div>
  25. `
  26. if (!noCenter) {
  27. return html`<div style="margin: ${margin} 0;" class="sk-center-wrapper">${comp}</div>`
  28. }
  29. return comp
  30. }