calcite-tile-select.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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.82
  5. */
  6. import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
  7. import { g as guid } from './guid.js';
  8. import { u as updateHostInteraction } from './interactive.js';
  9. import { d as defineCustomElement$4 } from './icon.js';
  10. import { d as defineCustomElement$3 } from './link.js';
  11. import { d as defineCustomElement$2 } from './tile.js';
  12. const CSS = {
  13. checked: "checked",
  14. description: "description",
  15. descriptionOnly: "description-only",
  16. disabled: "disabled",
  17. heading: "heading",
  18. headingOnly: "heading-only",
  19. icon: "icon",
  20. iconOnly: "icon-only",
  21. inputAlignmentEnd: "input-alignment-end",
  22. inputAlignmentStart: "input-alignment-start",
  23. inputEnabled: "input-enabled",
  24. largeVisual: "large-visual",
  25. widthAuto: "width-auto",
  26. widthFull: "width-full"
  27. };
  28. const tileSelectCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 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;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:block}:host .container{background-color:var(--calcite-ui-foreground-1);-webkit-box-shadow:0 0 0 1px var(--calcite-ui-border-2);box-shadow:0 0 0 1px var(--calcite-ui-border-2);-webkit-box-sizing:border-box;box-sizing:border-box;cursor:pointer;display:inline-block;height:100%;max-width:300px;padding:0.75rem;position:relative;-webkit-transition:var(--calcite-animation-timing);transition:var(--calcite-animation-timing);vertical-align:top;z-index:10}:host .container.checked{z-index:30;-webkit-box-shadow:0 0 0 1px var(--calcite-ui-brand);box-shadow:0 0 0 1px var(--calcite-ui-brand)}:host .container.heading-only{-ms-flex-align:center;align-items:center}:host .container:not(.input-enabled) ::slotted(calcite-checkbox),:host .container:not(.input-enabled) ::slotted(calcite-radio-button){position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);white-space:nowrap;border-width:0}:host .container.focused:not(.disabled){z-index:30}:host .container.focused:not(.disabled):not(.input-enabled){-webkit-box-shadow:0 0 0 1px var(--calcite-ui-brand), inset 0 0 0 2px var(--calcite-ui-foreground-1), inset 0 0 0 5px var(--calcite-ui-brand);box-shadow:0 0 0 1px var(--calcite-ui-brand), inset 0 0 0 2px var(--calcite-ui-foreground-1), inset 0 0 0 5px var(--calcite-ui-brand)}:host .container.input-enabled.input-alignment-start.width-auto.heading-only,:host .container.input-enabled.input-alignment-start.width-auto.icon-only,:host .container.input-enabled.input-alignment-start.width-auto.description-only,:host .container.input-enabled.input-alignment-start.width-auto.heading.description,:host .container.input-enabled.input-alignment-start.width-auto.icon.description,:host .container.input-enabled.input-alignment-start.width-auto.heading.icon.description{display:inline-grid;grid-template-columns:-webkit-max-content 1fr;grid-template-columns:max-content 1fr}:host .container.input-enabled.input-alignment-start.heading-only,:host .container.input-enabled.input-alignment-start.icon-only,:host .container.input-enabled.input-alignment-start.description-only,:host .container.input-enabled.input-alignment-start.heading.description,:host .container.input-enabled.input-alignment-start.icon.description,:host .container.input-enabled.input-alignment-start.heading.icon.description{gap:0.75rem}:host .container.input-enabled.input-alignment-start calcite-tile{-ms-flex-order:1;order:1}:host .container.input-enabled.input-alignment-start.large-visual ::slotted(calcite-checkbox),:host .container.input-enabled.input-alignment-start.large-visual ::slotted(calcite-radio-button){position:absolute;inset-block-start:0.75rem;inset-inline-start:0.75rem}:host .container.input-enabled.input-alignment-end.width-auto.heading-only,:host .container.input-enabled.input-alignment-end.width-auto.icon-only{display:inline-grid;grid-gap:0.75rem;grid-template-columns:-webkit-max-content 1fr;grid-template-columns:max-content 1fr}:host .container.input-enabled.input-alignment-end.heading-only,:host .container.input-enabled.input-alignment-end.icon-only{gap:0.75rem}:host .container.input-enabled.input-alignment-end.description-only ::slotted(calcite-checkbox),:host .container.input-enabled.input-alignment-end.description-only ::slotted(calcite-radio-button),:host .container.input-enabled.input-alignment-end.heading.description ::slotted(calcite-checkbox),:host .container.input-enabled.input-alignment-end.heading.description ::slotted(calcite-radio-button),:host .container.input-enabled.input-alignment-end.icon.description ::slotted(calcite-checkbox),:host .container.input-enabled.input-alignment-end.icon.description ::slotted(calcite-radio-button),:host .container.input-enabled.input-alignment-end.heading.icon.description ::slotted(calcite-checkbox),:host .container.input-enabled.input-alignment-end.heading.icon.description ::slotted(calcite-radio-button){position:absolute;inset-block-start:0.75rem;inset-inline-end:0.75rem}:host .container.input-enabled.input-alignment-end.large-visual ::slotted(calcite-checkbox),:host .container.input-enabled.input-alignment-end.large-visual ::slotted(calcite-radio-button){position:absolute;inset-block-start:0.75rem;inset-inline-end:0.75rem}:host .container.width-full{display:-ms-flexbox;display:flex;max-width:none}:host .container.width-full calcite-tile{-ms-flex:1 1 auto;flex:1 1 auto}:host(:hover) .container{z-index:20}:host(:hover) .container:not(.input-enabled){-webkit-box-shadow:0 0 0 1px var(--calcite-ui-brand);box-shadow:0 0 0 1px var(--calcite-ui-brand)}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}";
  29. const TileSelect = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  30. constructor() {
  31. super();
  32. this.__registerHost();
  33. this.__attachShadow();
  34. this.calciteTileSelectChange = createEvent(this, "calciteTileSelectChange", 7);
  35. //--------------------------------------------------------------------------
  36. //
  37. // Properties
  38. //
  39. //--------------------------------------------------------------------------
  40. /** The checked state of the tile select. */
  41. this.checked = false;
  42. /** The disabled state of the tile select. */
  43. this.disabled = false;
  44. /** The hidden state of the tile select. */
  45. this.hidden = false;
  46. /** Display an interactive radio or checkbox. */
  47. this.inputEnabled = false;
  48. /** The side of the tile that the radio or checkbox appears on when inputEnabled is true. */
  49. this.inputAlignment = "start";
  50. /** The selection mode of the tile select: radio (single) or checkbox (multiple). */
  51. this.type = "radio";
  52. /** specify the width of the tile, defaults to auto */
  53. this.width = "auto";
  54. this.guid = `calcite-tile-select-${guid()}`;
  55. //--------------------------------------------------------------------------
  56. //
  57. // State
  58. //
  59. //--------------------------------------------------------------------------
  60. /** The focused state of the tile-select. */
  61. this.focused = false;
  62. }
  63. checkedChanged(newChecked) {
  64. this.input.checked = newChecked;
  65. }
  66. nameChanged(newName) {
  67. this.input.name = newName;
  68. }
  69. //--------------------------------------------------------------------------
  70. //
  71. // Public Methods
  72. //
  73. //--------------------------------------------------------------------------
  74. /** Sets focus on the component. */
  75. async setFocus() {
  76. this.input.setFocus();
  77. }
  78. //--------------------------------------------------------------------------
  79. //
  80. // Event Listeners
  81. //
  82. //--------------------------------------------------------------------------
  83. checkboxChangeHandler(event) {
  84. const checkbox = event.target;
  85. if (checkbox === this.input) {
  86. this.checked = checkbox.checked;
  87. }
  88. event.stopPropagation();
  89. this.calciteTileSelectChange.emit();
  90. }
  91. checkboxFocusBlurHandler(event) {
  92. const checkbox = event.target;
  93. if (checkbox === this.input) {
  94. this.focused = event.detail;
  95. }
  96. event.stopPropagation();
  97. }
  98. radioButtonChangeHandler(event) {
  99. const radioButton = event.target;
  100. if (radioButton === this.input) {
  101. this.checked = radioButton.checked;
  102. }
  103. event.stopPropagation();
  104. this.calciteTileSelectChange.emit();
  105. }
  106. radioButtonCheckedChangeHandler(event) {
  107. const radioButton = event.target;
  108. if (radioButton === this.input) {
  109. this.checked = radioButton.checked;
  110. }
  111. event.stopPropagation();
  112. }
  113. radioButtonFocusBlurHandler(event) {
  114. const radioButton = event.target;
  115. if (radioButton === this.input) {
  116. this.focused = radioButton.focused;
  117. }
  118. event.stopPropagation();
  119. }
  120. click(event) {
  121. const target = event.target;
  122. const targets = ["calcite-tile", "calcite-tile-select"];
  123. if (targets.includes(target.localName)) {
  124. this.input.click();
  125. }
  126. }
  127. mouseenter() {
  128. if (this.input.localName === "calcite-radio-button") {
  129. this.input.hovered = true;
  130. }
  131. if (this.input.localName === "calcite-checkbox") {
  132. this.input.hovered = true;
  133. }
  134. }
  135. mouseleave() {
  136. if (this.input.localName === "calcite-radio-button") {
  137. this.input.hovered = false;
  138. }
  139. if (this.input.localName === "calcite-checkbox") {
  140. this.input.hovered = false;
  141. }
  142. }
  143. //--------------------------------------------------------------------------
  144. //
  145. // Lifecycle
  146. //
  147. //--------------------------------------------------------------------------
  148. connectedCallback() {
  149. this.renderInput();
  150. }
  151. disconnectedCallback() {
  152. this.input.parentNode.removeChild(this.input);
  153. }
  154. componentDidRender() {
  155. updateHostInteraction(this);
  156. }
  157. // --------------------------------------------------------------------------
  158. //
  159. // Render Methods
  160. //
  161. // --------------------------------------------------------------------------
  162. renderInput() {
  163. this.input = document.createElement(this.type === "radio" ? "calcite-radio-button" : "calcite-checkbox");
  164. this.input.checked = this.checked;
  165. this.input.disabled = this.disabled;
  166. this.input.hidden = this.hidden;
  167. this.input.id = this.guid;
  168. this.input.label = this.heading || this.name || "";
  169. if (this.name) {
  170. this.input.name = this.name;
  171. }
  172. if (this.value) {
  173. this.input.value = this.value != null ? this.value.toString() : "";
  174. }
  175. this.el.insertAdjacentElement("beforeend", this.input);
  176. }
  177. render() {
  178. const { checked, description, disabled, focused, heading, icon, inputAlignment, inputEnabled, width } = this;
  179. return (h("div", { class: {
  180. checked,
  181. container: true,
  182. [CSS.description]: Boolean(description),
  183. [CSS.descriptionOnly]: Boolean(!heading && !icon && description),
  184. disabled,
  185. focused,
  186. [CSS.heading]: Boolean(heading),
  187. [CSS.headingOnly]: heading && !icon && !description,
  188. [CSS.icon]: Boolean(icon),
  189. [CSS.iconOnly]: !heading && icon && !description,
  190. [CSS.inputAlignmentEnd]: inputAlignment === "end",
  191. [CSS.inputAlignmentStart]: inputAlignment === "start",
  192. [CSS.inputEnabled]: inputEnabled,
  193. [CSS.largeVisual]: heading && icon && !description,
  194. [CSS.widthAuto]: width === "auto",
  195. [CSS.widthFull]: width === "full"
  196. } }, h("calcite-tile", { active: checked, description: description, embed: true, heading: heading, icon: icon }), h("slot", null)));
  197. }
  198. get el() { return this; }
  199. static get watchers() { return {
  200. "checked": ["checkedChanged"],
  201. "name": ["nameChanged"]
  202. }; }
  203. static get style() { return tileSelectCss; }
  204. }, [1, "calcite-tile-select", {
  205. "checked": [1540],
  206. "description": [513],
  207. "disabled": [516],
  208. "heading": [513],
  209. "hidden": [516],
  210. "icon": [513],
  211. "name": [520],
  212. "inputEnabled": [516, "input-enabled"],
  213. "inputAlignment": [513, "input-alignment"],
  214. "type": [513],
  215. "value": [8],
  216. "width": [513],
  217. "focused": [32],
  218. "setFocus": [64]
  219. }, [[0, "calciteCheckboxChange", "checkboxChangeHandler"], [0, "calciteInternalCheckboxFocus", "checkboxFocusBlurHandler"], [0, "calciteInternalCheckboxBlur", "checkboxFocusBlurHandler"], [0, "calciteRadioButtonChange", "radioButtonChangeHandler"], [0, "calciteInternalRadioButtonCheckedChange", "radioButtonCheckedChangeHandler"], [0, "calciteInternalRadioButtonFocus", "radioButtonFocusBlurHandler"], [0, "calciteInternalRadioButtonBlur", "radioButtonFocusBlurHandler"], [0, "click", "click"], [1, "mouseenter", "mouseenter"], [1, "mouseleave", "mouseleave"]]]);
  220. function defineCustomElement$1() {
  221. if (typeof customElements === "undefined") {
  222. return;
  223. }
  224. const components = ["calcite-tile-select", "calcite-icon", "calcite-link", "calcite-tile"];
  225. components.forEach(tagName => { switch (tagName) {
  226. case "calcite-tile-select":
  227. if (!customElements.get(tagName)) {
  228. customElements.define(tagName, TileSelect);
  229. }
  230. break;
  231. case "calcite-icon":
  232. if (!customElements.get(tagName)) {
  233. defineCustomElement$4();
  234. }
  235. break;
  236. case "calcite-link":
  237. if (!customElements.get(tagName)) {
  238. defineCustomElement$3();
  239. }
  240. break;
  241. case "calcite-tile":
  242. if (!customElements.get(tagName)) {
  243. defineCustomElement$2();
  244. }
  245. break;
  246. } });
  247. }
  248. defineCustomElement$1();
  249. const CalciteTileSelect = TileSelect;
  250. const defineCustomElement = defineCustomElement$1;
  251. export { CalciteTileSelect, defineCustomElement };