calcite-tile-select_2.cjs.entry.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-a0010f96.js');
  9. const guid = require('./guid-f4f03a7a.js');
  10. const interactive = require('./interactive-32293bca.js');
  11. const CSS = {
  12. checked: "checked",
  13. description: "description",
  14. descriptionOnly: "description-only",
  15. disabled: "disabled",
  16. heading: "heading",
  17. headingOnly: "heading-only",
  18. icon: "icon",
  19. iconOnly: "icon-only",
  20. inputAlignmentEnd: "input-alignment-end",
  21. inputAlignmentStart: "input-alignment-start",
  22. inputEnabled: "input-enabled",
  23. largeVisual: "large-visual",
  24. widthAuto: "width-auto",
  25. widthFull: "width-full"
  26. };
  27. const tileSelectCss = "@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:block}:host .container{background-color:var(--calcite-ui-foreground-1);box-shadow:0 0 0 1px var(--calcite-ui-border-2);box-sizing:border-box;cursor:pointer;display:inline-block;block-size:100%;max-inline-size:300px;padding:0.75rem;position:relative;vertical-align:top;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s}:host .container.checked{z-index:1;box-shadow:0 0 0 1px var(--calcite-ui-brand)}:host .container.heading-only{align-items:center}:host .container:not(.input-enabled) ::slotted(calcite-checkbox),:host .container:not(.input-enabled) ::slotted(calcite-radio-button){position:absolute;inline-size:1px;block-size:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);white-space:nowrap;border-width:0}:host .container.focused{outline-color:transparent}:host .container.focused:not(.disabled):not(.input-enabled){outline:2px solid var(--calcite-ui-brand);outline-offset:-4px;box-shadow:0 0 0 1px var(--calcite-ui-brand), inset 0 0 0 2px var(--calcite-ui-foreground-1)}: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: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{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: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:flex;max-inline-size:none}:host .container.width-full calcite-tile{flex:1 1 auto}:host(:hover) .container:not(.input-enabled){box-shadow:0 0 0 1px var(--calcite-ui-brand)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}";
  28. const TileSelect = class {
  29. constructor(hostRef) {
  30. index.registerInstance(this, hostRef);
  31. this.calciteTileSelectChange = index.createEvent(this, "calciteTileSelectChange", 6);
  32. //--------------------------------------------------------------------------
  33. //
  34. // Properties
  35. //
  36. //--------------------------------------------------------------------------
  37. /** When `true`, the component is checked. */
  38. this.checked = false;
  39. /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
  40. this.disabled = false;
  41. /** When `true`, the component is not displayed and is not focusable or checkable. */
  42. this.hidden = false;
  43. /** When `true`, displays an interactive input based on the `type` property. */
  44. this.inputEnabled = false;
  45. /** When `inputEnabled` is `true`, specifies the placement of the interactive input on the component. */
  46. this.inputAlignment = "start";
  47. /**
  48. * The selection mode of the component.
  49. *
  50. * Use radio for single selection, and checkbox for multiple selections.
  51. */
  52. this.type = "radio";
  53. /** Specifies the width of the component. */
  54. this.width = "auto";
  55. this.guid = `calcite-tile-select-${guid.guid()}`;
  56. //--------------------------------------------------------------------------
  57. //
  58. // State
  59. //
  60. //--------------------------------------------------------------------------
  61. /** The focused state of the tile-select. */
  62. this.focused = false;
  63. }
  64. checkedChanged(newChecked) {
  65. this.input.checked = newChecked;
  66. }
  67. nameChanged(newName) {
  68. this.input.name = newName;
  69. }
  70. //--------------------------------------------------------------------------
  71. //
  72. // Public Methods
  73. //
  74. //--------------------------------------------------------------------------
  75. /** Sets focus on the component. */
  76. async setFocus() {
  77. var _a;
  78. (_a = this.input) === null || _a === void 0 ? void 0 : _a.setFocus();
  79. }
  80. //--------------------------------------------------------------------------
  81. //
  82. // Event Listeners
  83. //
  84. //--------------------------------------------------------------------------
  85. checkboxChangeHandler(event) {
  86. const checkbox = event.target;
  87. if (checkbox === this.input) {
  88. this.checked = checkbox.checked;
  89. }
  90. event.stopPropagation();
  91. this.calciteTileSelectChange.emit();
  92. }
  93. checkboxFocusBlurHandler(event) {
  94. const checkbox = event.target;
  95. if (checkbox === this.input) {
  96. this.focused = event.detail;
  97. }
  98. event.stopPropagation();
  99. }
  100. radioButtonChangeHandler(event) {
  101. const radioButton = event.target;
  102. if (radioButton === this.input) {
  103. this.checked = radioButton.checked;
  104. }
  105. event.stopPropagation();
  106. this.calciteTileSelectChange.emit();
  107. }
  108. radioButtonCheckedChangeHandler(event) {
  109. const radioButton = event.target;
  110. if (radioButton === this.input) {
  111. this.checked = radioButton.checked;
  112. }
  113. event.stopPropagation();
  114. }
  115. radioButtonFocusBlurHandler(event) {
  116. const radioButton = event.target;
  117. if (radioButton === this.input) {
  118. this.focused = radioButton.focused;
  119. }
  120. event.stopPropagation();
  121. }
  122. click(event) {
  123. const target = event.target;
  124. const targets = ["calcite-tile", "calcite-tile-select"];
  125. if (targets.includes(target.localName)) {
  126. this.input.click();
  127. }
  128. }
  129. mouseenter() {
  130. if (this.input.localName === "calcite-radio-button") {
  131. this.input.hovered = true;
  132. }
  133. if (this.input.localName === "calcite-checkbox") {
  134. this.input.hovered = true;
  135. }
  136. }
  137. mouseleave() {
  138. if (this.input.localName === "calcite-radio-button") {
  139. this.input.hovered = false;
  140. }
  141. if (this.input.localName === "calcite-checkbox") {
  142. this.input.hovered = false;
  143. }
  144. }
  145. //--------------------------------------------------------------------------
  146. //
  147. // Lifecycle
  148. //
  149. //--------------------------------------------------------------------------
  150. connectedCallback() {
  151. this.renderInput();
  152. }
  153. disconnectedCallback() {
  154. this.input.parentNode.removeChild(this.input);
  155. }
  156. componentDidRender() {
  157. interactive.updateHostInteraction(this);
  158. }
  159. // --------------------------------------------------------------------------
  160. //
  161. // Render Methods
  162. //
  163. // --------------------------------------------------------------------------
  164. renderInput() {
  165. this.input = document.createElement(this.type === "radio" ? "calcite-radio-button" : "calcite-checkbox");
  166. this.input.checked = this.checked;
  167. this.input.disabled = this.disabled;
  168. this.input.hidden = this.hidden;
  169. this.input.id = this.guid;
  170. this.input.label = this.heading || this.name || "";
  171. if (this.name) {
  172. this.input.name = this.name;
  173. }
  174. if (this.value) {
  175. this.input.value = this.value != null ? this.value.toString() : "";
  176. }
  177. this.el.insertAdjacentElement("beforeend", this.input);
  178. }
  179. render() {
  180. const { checked, description, disabled, focused, heading, icon, inputAlignment, inputEnabled, width } = this;
  181. return (index.h("div", { class: {
  182. checked,
  183. container: true,
  184. [CSS.description]: Boolean(description),
  185. [CSS.descriptionOnly]: Boolean(!heading && !icon && description),
  186. disabled,
  187. focused,
  188. [CSS.heading]: Boolean(heading),
  189. [CSS.headingOnly]: heading && !icon && !description,
  190. [CSS.icon]: Boolean(icon),
  191. [CSS.iconOnly]: !heading && icon && !description,
  192. [CSS.inputAlignmentEnd]: inputAlignment === "end",
  193. [CSS.inputAlignmentStart]: inputAlignment === "start",
  194. [CSS.inputEnabled]: inputEnabled,
  195. [CSS.largeVisual]: heading && icon && !description,
  196. [CSS.widthAuto]: width === "auto",
  197. [CSS.widthFull]: width === "full"
  198. } }, index.h("calcite-tile", { active: checked, description: description, embed: true, heading: heading, icon: icon }), index.h("slot", null)));
  199. }
  200. get el() { return index.getElement(this); }
  201. static get watchers() { return {
  202. "checked": ["checkedChanged"],
  203. "name": ["nameChanged"]
  204. }; }
  205. };
  206. TileSelect.style = tileSelectCss;
  207. const tileSelectGroupCss = "@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;flex-wrap:wrap}:host ::slotted(calcite-tile-select){margin-block-end:1px;margin-inline-end:1px}:host([layout=vertical]){flex-direction:column}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}";
  208. const TileSelectGroup = class {
  209. constructor(hostRef) {
  210. index.registerInstance(this, hostRef);
  211. //--------------------------------------------------------------------------
  212. //
  213. // Properties
  214. //
  215. //--------------------------------------------------------------------------
  216. /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
  217. this.disabled = false;
  218. /**
  219. * Defines the layout of the component.
  220. *
  221. * Use `"horizontal"` for rows, and `"vertical"` for a single column.
  222. */
  223. this.layout = "horizontal";
  224. }
  225. //--------------------------------------------------------------------------
  226. //
  227. // Lifecycle
  228. //
  229. //--------------------------------------------------------------------------
  230. componentDidRender() {
  231. interactive.updateHostInteraction(this);
  232. }
  233. render() {
  234. return index.h("slot", null);
  235. }
  236. get el() { return index.getElement(this); }
  237. };
  238. TileSelectGroup.style = tileSelectGroupCss;
  239. exports.calcite_tile_select = TileSelect;
  240. exports.calcite_tile_select_group = TileSelectGroup;