Source: element/IconElement.js

  1. import {
  2. LitElement, svg, css, nothing,
  3. } from 'lit';
  4. import icons from 'bootstrap-icons/bootstrap-icons.svg';
  5. /**
  6. * @class IconElement
  7. *
  8. * This class provides an icon element
  9. *
  10. * @example
  11. * <js-icon size="large">1-circle</js-icon>
  12. */
  13. export class IconElement extends LitElement {
  14. static get localName() {
  15. return 'js-icon';
  16. }
  17. constructor() {
  18. super();
  19. this.size = 'default';
  20. }
  21. static get properties() {
  22. return {
  23. size: { type: String, reflect: true },
  24. };
  25. }
  26. static get styles() {
  27. return css`
  28. :host {
  29. display: inline-block;
  30. vertical-align: middle;
  31. }
  32. .size-small {
  33. width: var(--icon-size-small);
  34. height: var(--icon-size-small);
  35. }
  36. .size-medium, .size-default {
  37. width: var(--icon-size-medium);
  38. height: var(--icon-size-medium);
  39. }
  40. .size-large {
  41. width: var(--icon-size-large);
  42. height: var(--icon-size-large);
  43. }
  44. .size-xlarge {
  45. width: var(--icon-size-xlarge);
  46. height: var(--icon-size-xlarge);
  47. }
  48. svg {
  49. width: 100%;
  50. height: 100%;
  51. fill: currentColor;
  52. }
  53. `;
  54. }
  55. get classes() {
  56. const classes = [];
  57. classes.push(`size-${this.size}`);
  58. return classes;
  59. }
  60. get name() {
  61. return this.textContent.trim() || 'bootstrap-reboot';
  62. }
  63. render() {
  64. return svg`<div class=${this.classes.join(' ') || nothing}><svg class=${this.classes.join(' ') || nothing}><use href="${icons}#${this.name}"/></svg></div>`;
  65. }
  66. }