calcite-tile-select_2.entry.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 { r as registerInstance, c as createEvent, h, g as getElement } from './index-1f9b54dc.js';
  7. import { g as guid } from './guid-9f15e57a.js';
  8. import { u as updateHostInteraction } from './interactive-5db230e8.js';
  9. const CSS = {
  10. checked: "checked",
  11. description: "description",
  12. descriptionOnly: "description-only",
  13. disabled: "disabled",
  14. heading: "heading",
  15. headingOnly: "heading-only",
  16. icon: "icon",
  17. iconOnly: "icon-only",
  18. inputAlignmentEnd: "input-alignment-end",
  19. inputAlignmentStart: "input-alignment-start",
  20. inputEnabled: "input-enabled",
  21. largeVisual: "large-visual",
  22. widthAuto: "width-auto",
  23. widthFull: "width-full"
  24. };
  25. 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}";
  26. const TileSelect = class {
  27. constructor(hostRef) {
  28. registerInstance(this, hostRef);
  29. this.calciteTileSelectChange = createEvent(this, "calciteTileSelectChange", 6);
  30. //--------------------------------------------------------------------------
  31. //
  32. // Properties
  33. //
  34. //--------------------------------------------------------------------------
  35. /** When `true`, the component is checked. */
  36. this.checked = false;
  37. /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
  38. this.disabled = false;
  39. /** When `true`, the component is not displayed and is not focusable or checkable. */
  40. this.hidden = false;
  41. /** When `true`, displays an interactive input based on the `type` property. */
  42. this.inputEnabled = false;
  43. /** When `inputEnabled` is `true`, specifies the placement of the interactive input on the component. */
  44. this.inputAlignment = "start";
  45. /**
  46. * The selection mode of the component.
  47. *
  48. * Use radio for single selection, and checkbox for multiple selections.
  49. */
  50. this.type = "radio";
  51. /** Specifies the width of the component. */
  52. this.width = "auto";
  53. this.guid = `calcite-tile-select-${guid()}`;
  54. //--------------------------------------------------------------------------
  55. //
  56. // State
  57. //
  58. //--------------------------------------------------------------------------
  59. /** The focused state of the tile-select. */
  60. this.focused = false;
  61. }
  62. checkedChanged(newChecked) {
  63. this.input.checked = newChecked;
  64. }
  65. nameChanged(newName) {
  66. this.input.name = newName;
  67. }
  68. //--------------------------------------------------------------------------
  69. //
  70. // Public Methods
  71. //
  72. //--------------------------------------------------------------------------
  73. /** Sets focus on the component. */
  74. async setFocus() {
  75. var _a;
  76. (_a = this.input) === null || _a === void 0 ? void 0 : _a.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 getElement(this); }
  199. static get watchers() { return {
  200. "checked": ["checkedChanged"],
  201. "name": ["nameChanged"]
  202. }; }
  203. };
  204. TileSelect.style = tileSelectCss;
  205. 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}";
  206. const TileSelectGroup = class {
  207. constructor(hostRef) {
  208. registerInstance(this, hostRef);
  209. //--------------------------------------------------------------------------
  210. //
  211. // Properties
  212. //
  213. //--------------------------------------------------------------------------
  214. /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
  215. this.disabled = false;
  216. /**
  217. * Defines the layout of the component.
  218. *
  219. * Use `"horizontal"` for rows, and `"vertical"` for a single column.
  220. */
  221. this.layout = "horizontal";
  222. }
  223. //--------------------------------------------------------------------------
  224. //
  225. // Lifecycle
  226. //
  227. //--------------------------------------------------------------------------
  228. componentDidRender() {
  229. updateHostInteraction(this);
  230. }
  231. render() {
  232. return h("slot", null);
  233. }
  234. get el() { return getElement(this); }
  235. };
  236. TileSelectGroup.style = tileSelectGroupCss;
  237. export { TileSelect as calcite_tile_select, TileSelectGroup as calcite_tile_select_group };