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.

43 lines
1.6 KiB

  1. // maunium-stickerpicker - A fast and simple Matrix sticker picker widget.
  2. // Copyright (C) 2020 Tulir Asokan
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. import { html } from "../lib/htm/preact.js"
  17. const Spinner = ({ size = 40, noCenter = false, noMargin = false, green = false }) => {
  18. let margin = 0
  19. if (!isNaN(+size)) {
  20. size = +size
  21. margin = noMargin ? 0 : `${Math.round(size / 6)}px`
  22. size = `${size}px`
  23. }
  24. const noInnerMargin = !noCenter || !margin
  25. const comp = html`
  26. <div style="width: ${size}; height: ${size}; margin: ${noInnerMargin ? 0 : margin} 0;"
  27. class="sk-chase ${green && "green"}">
  28. <div class="sk-chase-dot" />
  29. <div class="sk-chase-dot" />
  30. <div class="sk-chase-dot" />
  31. <div class="sk-chase-dot" />
  32. <div class="sk-chase-dot" />
  33. <div class="sk-chase-dot" />
  34. </div>
  35. `
  36. if (!noCenter) {
  37. return html`<div style="margin: ${margin} 0;" class="sk-center-wrapper">${comp}</div>`
  38. }
  39. return comp
  40. }
  41. export default Spinner