calcite-fab.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client/index.js';
  7. import { f as focusElement } from './dom.js';
  8. import { u as updateHostInteraction } from './interactive.js';
  9. import { d as defineCustomElement$4 } from './button.js';
  10. import { d as defineCustomElement$3 } from './icon.js';
  11. import { d as defineCustomElement$2 } from './loader.js';
  12. const CSS = {
  13. button: "button"
  14. };
  15. const ICONS = {
  16. plus: "plus"
  17. };
  18. const fabCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{display:flex;background-color:transparent}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}calcite-button{--tw-shadow:0 6px 20px -4px rgba(0, 0, 0, 0.1), 0 4px 12px -2px rgba(0, 0, 0, 0.08);--tw-shadow-colored:0 6px 20px -4px var(--tw-shadow-color), 0 4px 12px -2px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}calcite-button:hover{--tw-shadow:0 12px 32px -2px rgba(0, 0, 0, 0.1), 0 4px 20px 0 rgba(0, 0, 0, 0.08);--tw-shadow-colored:0 12px 32px -2px var(--tw-shadow-color), 0 4px 20px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}calcite-button:active{--tw-shadow:0 2px 12px -4px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.16);--tw-shadow-colored:0 2px 12px -4px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}";
  19. const Fab = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  20. constructor() {
  21. super();
  22. this.__registerHost();
  23. this.__attachShadow();
  24. // --------------------------------------------------------------------------
  25. //
  26. // Properties
  27. //
  28. // --------------------------------------------------------------------------
  29. /**
  30. * Used to set the button's appearance. Default is outline.
  31. */
  32. this.appearance = "outline";
  33. /**
  34. * Used to set the button's color. Default is light.
  35. */
  36. this.color = "neutral";
  37. /**
  38. * When true, disabled prevents interaction. This state shows items with lower opacity/grayed.
  39. */
  40. this.disabled = false;
  41. /**
  42. * Specifies an icon to display.
  43. *
  44. * @default "plus"
  45. */
  46. this.icon = ICONS.plus;
  47. /**
  48. * When true, content is waiting to be loaded. This state shows a busy indicator.
  49. */
  50. this.loading = false;
  51. /**
  52. * Specifies the size of the fab.
  53. */
  54. this.scale = "m";
  55. /**
  56. * Indicates whether the text is displayed.
  57. */
  58. this.textEnabled = false;
  59. }
  60. //--------------------------------------------------------------------------
  61. //
  62. // Lifecycle
  63. //
  64. //--------------------------------------------------------------------------
  65. componentDidRender() {
  66. updateHostInteraction(this);
  67. }
  68. // --------------------------------------------------------------------------
  69. //
  70. // Methods
  71. //
  72. // --------------------------------------------------------------------------
  73. /** Sets focus on the component. */
  74. async setFocus() {
  75. focusElement(this.buttonEl);
  76. }
  77. // --------------------------------------------------------------------------
  78. //
  79. // Render Methods
  80. //
  81. // --------------------------------------------------------------------------
  82. render() {
  83. const { appearance, color, disabled, loading, scale, textEnabled, icon, label, text } = this;
  84. const title = !textEnabled ? label || text || null : null;
  85. return (h("calcite-button", { appearance: appearance === "solid" ? "solid" : "outline", class: CSS.button, color: color, disabled: disabled, iconStart: icon, label: label, loading: loading, ref: (buttonEl) => {
  86. this.buttonEl = buttonEl;
  87. }, round: true, scale: scale, title: title, type: "button", width: "auto" }, this.textEnabled ? this.text : null));
  88. }
  89. get el() { return this; }
  90. static get style() { return fabCss; }
  91. }, [1, "calcite-fab", {
  92. "appearance": [513],
  93. "color": [513],
  94. "disabled": [516],
  95. "icon": [513],
  96. "label": [1],
  97. "loading": [516],
  98. "scale": [513],
  99. "text": [1],
  100. "textEnabled": [516, "text-enabled"],
  101. "setFocus": [64]
  102. }]);
  103. function defineCustomElement$1() {
  104. if (typeof customElements === "undefined") {
  105. return;
  106. }
  107. const components = ["calcite-fab", "calcite-button", "calcite-icon", "calcite-loader"];
  108. components.forEach(tagName => { switch (tagName) {
  109. case "calcite-fab":
  110. if (!customElements.get(tagName)) {
  111. customElements.define(tagName, Fab);
  112. }
  113. break;
  114. case "calcite-button":
  115. if (!customElements.get(tagName)) {
  116. defineCustomElement$4();
  117. }
  118. break;
  119. case "calcite-icon":
  120. if (!customElements.get(tagName)) {
  121. defineCustomElement$3();
  122. }
  123. break;
  124. case "calcite-loader":
  125. if (!customElements.get(tagName)) {
  126. defineCustomElement$2();
  127. }
  128. break;
  129. } });
  130. }
  131. defineCustomElement$1();
  132. const CalciteFab = Fab;
  133. const defineCustomElement = defineCustomElement$1;
  134. export { CalciteFab, defineCustomElement };