calcite-option_3.cjs.entry.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 observers = require('./observers-5706326b.js');
  10. const dom = require('./dom-2ec8c9ed.js');
  11. const label = require('./label-28060b83.js');
  12. const form = require('./form-1d831023.js');
  13. const interactive = require('./interactive-32293bca.js');
  14. require('./resources-b5a5f8a7.js');
  15. require('./guid-f4f03a7a.js');
  16. const optionCss = "@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{display:block}";
  17. const Option = class {
  18. constructor(hostRef) {
  19. index.registerInstance(this, hostRef);
  20. this.calciteInternalOptionChange = index.createEvent(this, "calciteInternalOptionChange", 6);
  21. //--------------------------------------------------------------------------
  22. //
  23. // Properties
  24. //
  25. //--------------------------------------------------------------------------
  26. /**
  27. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  28. */
  29. this.disabled = false;
  30. this.mutationObserver = observers.createObserver("mutation", () => {
  31. this.ensureTextContentDependentProps();
  32. this.calciteInternalOptionChange.emit();
  33. });
  34. }
  35. handlePropChange(_newValue, _oldValue, propName) {
  36. if (propName === "label" || propName === "value") {
  37. this.ensureTextContentDependentProps();
  38. }
  39. this.calciteInternalOptionChange.emit();
  40. }
  41. //--------------------------------------------------------------------------
  42. //
  43. // Private Methods
  44. //
  45. //--------------------------------------------------------------------------
  46. ensureTextContentDependentProps() {
  47. const { el: { textContent } } = this;
  48. if (!this.label || this.label === this.internallySetLabel) {
  49. this.label = textContent;
  50. this.internallySetLabel = textContent;
  51. }
  52. if (!this.value || this.value === this.internallySetValue) {
  53. this.value = textContent;
  54. this.internallySetValue = textContent;
  55. }
  56. }
  57. //--------------------------------------------------------------------------
  58. //
  59. // Lifecycle
  60. //
  61. //--------------------------------------------------------------------------
  62. connectedCallback() {
  63. var _a;
  64. this.ensureTextContentDependentProps();
  65. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, {
  66. attributeFilter: ["label", "value"],
  67. characterData: true,
  68. childList: true,
  69. subtree: true
  70. });
  71. }
  72. disconnectedCallback() {
  73. var _a;
  74. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  75. }
  76. //--------------------------------------------------------------------------
  77. //
  78. // Render Methods
  79. //
  80. //--------------------------------------------------------------------------
  81. render() {
  82. return index.h("slot", null, this.label);
  83. }
  84. get el() { return index.getElement(this); }
  85. static get watchers() { return {
  86. "disabled": ["handlePropChange"],
  87. "label": ["handlePropChange"],
  88. "selected": ["handlePropChange"],
  89. "value": ["handlePropChange"]
  90. }; }
  91. };
  92. Option.style = optionCss;
  93. const optionGroupCss = "@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{display:block}";
  94. const OptionGroup = class {
  95. constructor(hostRef) {
  96. index.registerInstance(this, hostRef);
  97. this.calciteInternalOptionGroupChange = index.createEvent(this, "calciteInternalOptionGroupChange", 6);
  98. //--------------------------------------------------------------------------
  99. //
  100. // Properties
  101. //
  102. //--------------------------------------------------------------------------
  103. /**
  104. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  105. */
  106. this.disabled = false;
  107. }
  108. handlePropChange() {
  109. this.calciteInternalOptionGroupChange.emit();
  110. }
  111. //--------------------------------------------------------------------------
  112. //
  113. // Render Methods
  114. //
  115. //--------------------------------------------------------------------------
  116. render() {
  117. return (index.h(index.Fragment, null, index.h("div", null, this.label), index.h("slot", null)));
  118. }
  119. static get watchers() { return {
  120. "disabled": ["handlePropChange"],
  121. "label": ["handlePropChange"]
  122. }; }
  123. };
  124. OptionGroup.style = optionGroupCss;
  125. const CSS = {
  126. icon: "icon",
  127. iconContainer: "icon-container",
  128. select: "select"
  129. };
  130. const selectCss = "@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}}:host{--calcite-icon-size:1rem;--calcite-spacing-eighth:0.125rem;--calcite-spacing-quarter:0.25rem;--calcite-spacing-half:0.5rem;--calcite-spacing-three-quarters:0.75rem;--calcite-spacing:1rem;--calcite-spacing-plus-quarter:1.25rem;--calcite-spacing-plus-half:1.5rem;--calcite-spacing-double:2rem;--calcite-menu-min-width:10rem;--calcite-header-min-height:3rem;--calcite-footer-min-height:3rem}: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{position:relative;display:flex;align-items:stretch;inline-size:var(--select-width)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host([scale=s]){block-size:1.5rem;--calcite-select-font-size:var(--calcite-font-size--2);--calcite-select-spacing-inline:0.5rem 2rem}:host([scale=s]) .icon-container{padding-inline:0.5rem}:host([scale=m]){block-size:2rem;--calcite-select-font-size:var(--calcite-font-size--1);--calcite-select-spacing-inline:0.75rem 2.5rem}:host([scale=m]) .icon-container{padding-inline:0.75rem}:host([scale=l]){block-size:44px;--calcite-select-font-size:var(--calcite-font-size-0);--calcite-select-spacing-inline:1rem 3rem}:host([scale=l]) .icon-container{padding-inline:1rem}:host([width=auto]){inline-size:auto}:host([width=half]){inline-size:50%}:host([width=full]){inline-size:100%}.select{margin:0px;box-sizing:border-box;inline-size:100%;cursor:pointer;-webkit-appearance:none;appearance:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-radius:0px;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);background-color:var(--calcite-ui-foreground-1);font-family:inherit;color:var(--calcite-ui-text-2);outline-color:transparent;font-size:var(--calcite-select-font-size);padding-inline:var(--calcite-select-spacing-inline);border-inline-end-width:0px}.select:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.select:hover{background-color:var(--calcite-ui-foreground-2)}select:disabled{border-color:var(--calcite-ui-border-input);--tw-bg-opacity:1}.icon-container{pointer-events:none;position:absolute;inset-block:0px;display:flex;align-items:center;border-width:0px;border-style:solid;border-color:var(--calcite-ui-border-input);background-color:transparent;color:var(--calcite-ui-text-2);inset-inline-end:0px;border-inline-width:0px 1px}.select:focus~.icon-container{border-color:transparent}::slotted(input[slot=hidden-form-input]){margin:0 !important;opacity:0 !important;outline:none !important;padding:0 !important;position:absolute !important;inset:0 !important;transform:none !important;-webkit-appearance:none !important;z-index:-1 !important}";
  131. function isOption(optionOrGroup) {
  132. return optionOrGroup.tagName === "CALCITE-OPTION";
  133. }
  134. function isOptionGroup(optionOrGroup) {
  135. return optionOrGroup.tagName === "CALCITE-OPTION-GROUP";
  136. }
  137. const Select = class {
  138. constructor(hostRef) {
  139. index.registerInstance(this, hostRef);
  140. this.calciteSelectChange = index.createEvent(this, "calciteSelectChange", 6);
  141. //--------------------------------------------------------------------------
  142. //
  143. // Properties
  144. //
  145. //--------------------------------------------------------------------------
  146. /**
  147. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  148. */
  149. this.disabled = false;
  150. /**
  151. * When `true`, the component must have a value in order for the form to submit.
  152. *
  153. * @internal
  154. */
  155. this.required = false;
  156. /**
  157. * Specifies the size of the component.
  158. */
  159. this.scale = "m";
  160. /** The component's `selectedOption` value. */
  161. this.value = null;
  162. /**
  163. * Specifies the width of the component.
  164. */
  165. this.width = "auto";
  166. this.componentToNativeEl = new Map();
  167. this.mutationObserver = observers.createObserver("mutation", () => this.populateInternalSelect());
  168. this.handleInternalSelectChange = () => {
  169. const selected = this.selectEl.selectedOptions[0];
  170. this.selectFromNativeOption(selected);
  171. requestAnimationFrame(() => this.emitChangeEvent());
  172. };
  173. this.populateInternalSelect = () => {
  174. const optionsAndGroups = Array.from(this.el.children).filter((child) => child.tagName === "CALCITE-OPTION" || child.tagName === "CALCITE-OPTION-GROUP");
  175. this.clearInternalSelect();
  176. optionsAndGroups.forEach((optionOrGroup) => { var _a; return (_a = this.selectEl) === null || _a === void 0 ? void 0 : _a.append(this.toNativeElement(optionOrGroup)); });
  177. };
  178. this.storeSelectRef = (node) => {
  179. this.selectEl = node;
  180. this.populateInternalSelect();
  181. const selected = this.selectEl.selectedOptions[0];
  182. this.selectFromNativeOption(selected);
  183. };
  184. this.emitChangeEvent = () => {
  185. this.calciteSelectChange.emit();
  186. };
  187. }
  188. valueHandler(value) {
  189. const items = this.el.querySelectorAll("calcite-option");
  190. items.forEach((item) => (item.selected = item.value === value));
  191. }
  192. selectedOptionHandler(selectedOption) {
  193. this.value = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value;
  194. }
  195. //--------------------------------------------------------------------------
  196. //
  197. // Lifecycle
  198. //
  199. //--------------------------------------------------------------------------
  200. connectedCallback() {
  201. var _a;
  202. const { el } = this;
  203. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(el, {
  204. subtree: true,
  205. childList: true
  206. });
  207. label.connectLabel(this);
  208. form.connectForm(this);
  209. }
  210. disconnectedCallback() {
  211. var _a;
  212. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  213. label.disconnectLabel(this);
  214. form.disconnectForm(this);
  215. }
  216. componentDidLoad() {
  217. var _a, _b;
  218. form.afterConnectDefaultValueSet(this, (_b = (_a = this.selectedOption) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "");
  219. }
  220. componentDidRender() {
  221. interactive.updateHostInteraction(this);
  222. }
  223. //--------------------------------------------------------------------------
  224. //
  225. // Public Methods
  226. //
  227. //--------------------------------------------------------------------------
  228. /** Sets focus on the component. */
  229. async setFocus() {
  230. dom.focusElement(this.selectEl);
  231. }
  232. handleOptionOrGroupChange(event) {
  233. event.stopPropagation();
  234. const optionOrGroup = event.target;
  235. const nativeEl = this.componentToNativeEl.get(optionOrGroup);
  236. if (!nativeEl) {
  237. return;
  238. }
  239. this.updateNativeElement(optionOrGroup, nativeEl);
  240. if (isOption(optionOrGroup) && optionOrGroup.selected) {
  241. this.deselectAllExcept(optionOrGroup);
  242. this.selectedOption = optionOrGroup;
  243. }
  244. }
  245. //--------------------------------------------------------------------------
  246. //
  247. // Private Methods
  248. //
  249. //--------------------------------------------------------------------------
  250. onLabelClick() {
  251. this.setFocus();
  252. }
  253. updateNativeElement(optionOrGroup, nativeOptionOrGroup) {
  254. nativeOptionOrGroup.disabled = optionOrGroup.disabled;
  255. nativeOptionOrGroup.label = optionOrGroup.label;
  256. if (isOption(optionOrGroup)) {
  257. const option = nativeOptionOrGroup;
  258. option.selected = optionOrGroup.selected;
  259. option.value = optionOrGroup.value;
  260. // need to set innerText for mobile
  261. // see https://stackoverflow.com/questions/35021620/ios-safari-not-showing-all-options-for-select-menu/41749701
  262. option.innerText = optionOrGroup.label;
  263. }
  264. }
  265. clearInternalSelect() {
  266. this.componentToNativeEl.forEach((value) => value.remove());
  267. this.componentToNativeEl.clear();
  268. }
  269. selectFromNativeOption(nativeOption) {
  270. if (!nativeOption) {
  271. return;
  272. }
  273. let futureSelected;
  274. this.componentToNativeEl.forEach((nativeOptionOrGroup, optionOrGroup) => {
  275. if (isOption(optionOrGroup) && nativeOptionOrGroup === nativeOption) {
  276. optionOrGroup.selected = true;
  277. futureSelected = optionOrGroup;
  278. this.deselectAllExcept(optionOrGroup);
  279. }
  280. });
  281. if (futureSelected) {
  282. this.selectedOption = futureSelected;
  283. }
  284. }
  285. toNativeElement(optionOrGroup) {
  286. if (isOption(optionOrGroup)) {
  287. const option = document.createElement("option");
  288. this.updateNativeElement(optionOrGroup, option);
  289. this.componentToNativeEl.set(optionOrGroup, option);
  290. return option;
  291. }
  292. if (isOptionGroup(optionOrGroup)) {
  293. const group = document.createElement("optgroup");
  294. this.updateNativeElement(optionOrGroup, group);
  295. Array.from(optionOrGroup.children).forEach((option) => {
  296. const nativeOption = this.toNativeElement(option);
  297. group.append(nativeOption);
  298. this.componentToNativeEl.set(optionOrGroup, nativeOption);
  299. });
  300. this.componentToNativeEl.set(optionOrGroup, group);
  301. return group;
  302. }
  303. throw new Error("unsupported element child provided");
  304. }
  305. deselectAllExcept(except) {
  306. this.el.querySelectorAll("calcite-option").forEach((option) => {
  307. if (option === except) {
  308. return;
  309. }
  310. option.selected = false;
  311. });
  312. }
  313. //--------------------------------------------------------------------------
  314. //
  315. // Render Methods
  316. //
  317. //--------------------------------------------------------------------------
  318. renderChevron() {
  319. return (index.h("div", { class: CSS.iconContainer }, index.h("calcite-icon", { class: CSS.icon, icon: "chevron-down", scale: "s" })));
  320. }
  321. render() {
  322. return (index.h(index.Fragment, null, index.h("select", { "aria-label": this.label, class: CSS.select, disabled: this.disabled, onChange: this.handleInternalSelectChange, ref: this.storeSelectRef }, index.h("slot", null)), this.renderChevron(), index.h(form.HiddenFormInputSlot, { component: this })));
  323. }
  324. get el() { return index.getElement(this); }
  325. static get watchers() { return {
  326. "value": ["valueHandler"],
  327. "selectedOption": ["selectedOptionHandler"]
  328. }; }
  329. };
  330. Select.style = selectCss;
  331. exports.calcite_option = Option;
  332. exports.calcite_option_group = OptionGroup;
  333. exports.calcite_select = Select;