calcite-radio-group_2.cjs.entry.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-5c65e149.js');
  9. const dom = require('./dom-9ac0341c.js');
  10. const label = require('./label-165fc611.js');
  11. const form = require('./form-11926121.js');
  12. const interactive = require('./interactive-e294111f.js');
  13. require('./guid-8b6d6cb4.js');
  14. const radioGroupCss = "@-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:-ms-flexbox;display:flex;background-color:var(--calcite-ui-foreground-1);width:-moz-fit-content;width:-webkit-fit-content;width:fit-content;outline:1px solid var(--calcite-ui-border-input);outline-offset:-1px}: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}:host([layout=vertical]){-ms-flex-direction:column;flex-direction:column;-ms-flex-align:start;align-items:flex-start;-ms-flex-item-align:start;align-self:flex-start}:host([width=full]){width:100%;min-width:-moz-fit-content;min-width:-webkit-fit-content;min-width:fit-content}:host([width=full]) ::slotted(calcite-radio-group-item){-ms-flex:1 1 auto;flex:1 1 auto}:host([width=full][layout=vertical]) ::slotted(calcite-radio-group-item){-ms-flex-pack:start;justify-content:flex-start}::slotted(calcite-radio-group-item[checked]),::slotted(calcite-radio-group-item:focus){z-index:0}::slotted(input[slot=hidden-form-input]){bottom:0 !important;left:0 !important;margin:0 !important;opacity:0 !important;outline:none !important;padding:0 !important;position:absolute !important;right:0 !important;top:0 !important;-webkit-transform:none !important;transform:none !important;-webkit-appearance:none !important;z-index:-1 !important}";
  15. const RadioGroup = class {
  16. constructor(hostRef) {
  17. index.registerInstance(this, hostRef);
  18. this.calciteRadioGroupChange = index.createEvent(this, "calciteRadioGroupChange", 7);
  19. //--------------------------------------------------------------------------
  20. //
  21. // Properties
  22. //
  23. //--------------------------------------------------------------------------
  24. /** specify the appearance style of the radio group, defaults to solid. */
  25. this.appearance = "solid";
  26. /** is the radio group disabled */
  27. this.disabled = false;
  28. /**
  29. * When true, makes the component required for form-submission.
  30. *
  31. * @internal
  32. */
  33. this.required = false;
  34. /** specify the layout of the radio group, defaults to horizontal */
  35. this.layout = "horizontal";
  36. /** The scale of the radio group */
  37. this.scale = "m";
  38. /** The value of the selectedItem */
  39. this.value = null;
  40. /** specify the width of the group, defaults to auto */
  41. this.width = "auto";
  42. //--------------------------------------------------------------------------
  43. //
  44. // Event Listeners
  45. //
  46. //--------------------------------------------------------------------------
  47. this.handleClick = (event) => {
  48. if (event.target.localName === "calcite-radio-group-item") {
  49. this.selectItem(event.target, true);
  50. }
  51. };
  52. }
  53. valueHandler(value) {
  54. const items = this.getItems();
  55. items.forEach((item) => (item.checked = item.value === value));
  56. }
  57. handleSelectedItemChange(newItem, oldItem) {
  58. this.value = newItem === null || newItem === void 0 ? void 0 : newItem.value;
  59. if (newItem === oldItem) {
  60. return;
  61. }
  62. const items = this.getItems();
  63. const match = Array.from(items)
  64. .filter((item) => item === newItem)
  65. .pop();
  66. if (match) {
  67. this.selectItem(match);
  68. }
  69. else if (items[0]) {
  70. items[0].tabIndex = 0;
  71. }
  72. }
  73. //--------------------------------------------------------------------------
  74. //
  75. // Lifecycle
  76. //
  77. //--------------------------------------------------------------------------
  78. componentWillLoad() {
  79. const items = this.getItems();
  80. const lastChecked = Array.from(items)
  81. .filter((item) => item.checked)
  82. .pop();
  83. if (lastChecked) {
  84. this.selectItem(lastChecked);
  85. }
  86. else if (items[0]) {
  87. items[0].tabIndex = 0;
  88. }
  89. }
  90. connectedCallback() {
  91. label.connectLabel(this);
  92. form.connectForm(this);
  93. }
  94. disconnectedCallback() {
  95. label.disconnectLabel(this);
  96. form.disconnectForm(this);
  97. }
  98. componentDidRender() {
  99. interactive.updateHostInteraction(this);
  100. }
  101. render() {
  102. return (index.h(index.Host, { onClick: this.handleClick, role: "radiogroup" }, index.h("slot", null), index.h(form.HiddenFormInputSlot, { component: this })));
  103. }
  104. handleSelected(event) {
  105. event.stopPropagation();
  106. event.preventDefault();
  107. this.selectItem(event.target);
  108. }
  109. handleKeyDown(event) {
  110. const keys = ["ArrowLeft", "ArrowUp", "ArrowRight", "ArrowDown", " "];
  111. const key = event.key;
  112. const { el, selectedItem } = this;
  113. if (keys.indexOf(key) === -1) {
  114. return;
  115. }
  116. let adjustedKey = key;
  117. if (dom.getElementDir(el) === "rtl") {
  118. if (key === "ArrowRight") {
  119. adjustedKey = "ArrowLeft";
  120. }
  121. if (key === "ArrowLeft") {
  122. adjustedKey = "ArrowRight";
  123. }
  124. }
  125. const items = this.getItems();
  126. let selectedIndex = -1;
  127. items.forEach((item, index) => {
  128. if (item === selectedItem) {
  129. selectedIndex = index;
  130. }
  131. });
  132. switch (adjustedKey) {
  133. case "ArrowLeft":
  134. case "ArrowUp":
  135. event.preventDefault();
  136. const previous = selectedIndex < 1 ? items.item(items.length - 1) : items.item(selectedIndex - 1);
  137. this.selectItem(previous, true);
  138. return;
  139. case "ArrowRight":
  140. case "ArrowDown":
  141. event.preventDefault();
  142. const next = selectedIndex === -1 ? items.item(1) : items.item(selectedIndex + 1) || items.item(0);
  143. this.selectItem(next, true);
  144. return;
  145. case " ":
  146. event.preventDefault();
  147. this.selectItem(event.target, true);
  148. return;
  149. default:
  150. return;
  151. }
  152. }
  153. // --------------------------------------------------------------------------
  154. //
  155. // Methods
  156. //
  157. // --------------------------------------------------------------------------
  158. /** Sets focus on the component. */
  159. async setFocus() {
  160. var _a;
  161. (_a = (this.selectedItem || this.getItems()[0])) === null || _a === void 0 ? void 0 : _a.focus();
  162. }
  163. //--------------------------------------------------------------------------
  164. //
  165. // Private Methods
  166. //
  167. //--------------------------------------------------------------------------
  168. onLabelClick() {
  169. this.setFocus();
  170. }
  171. getItems() {
  172. return this.el.querySelectorAll("calcite-radio-group-item");
  173. }
  174. selectItem(selected, emit = false) {
  175. if (selected === this.selectedItem) {
  176. return;
  177. }
  178. const items = this.getItems();
  179. let match = null;
  180. items.forEach((item) => {
  181. const matches = item.value === selected.value;
  182. if ((matches && !item.checked) || (!matches && item.checked)) {
  183. item.checked = matches;
  184. }
  185. item.tabIndex = matches ? 0 : -1;
  186. if (matches) {
  187. match = item;
  188. if (emit) {
  189. this.calciteRadioGroupChange.emit(match.value);
  190. }
  191. }
  192. });
  193. this.selectedItem = match;
  194. if (match) {
  195. match.focus();
  196. }
  197. }
  198. get el() { return index.getElement(this); }
  199. static get watchers() { return {
  200. "value": ["valueHandler"],
  201. "selectedItem": ["handleSelectedItemChange"]
  202. }; }
  203. };
  204. RadioGroup.style = radioGroupCss;
  205. const SLOTS = {
  206. input: "input"
  207. };
  208. const CSS = {
  209. radioGroupItemIcon: "radio-group-item-icon"
  210. };
  211. const radioGroupItemCss = "@-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:-ms-flexbox;display:flex;cursor:pointer;-ms-flex-item-align:stretch;align-self:stretch;font-weight:var(--calcite-font-weight-normal);-webkit-transition:background-color var(--calcite-internal-animation-timing-fast) ease-in-out, border-color var(--calcite-animation-timing) ease-in-out;transition:background-color var(--calcite-internal-animation-timing-fast) ease-in-out, border-color var(--calcite-animation-timing) ease-in-out}:host label{pointer-events:none;margin:0.125rem;-webkit-box-sizing:border-box;box-sizing:border-box;display:-ms-flexbox;display:flex;-ms-flex:1 1 0%;flex:1 1 0%;-ms-flex-align:center;align-items:center;color:var(--calcite-ui-text-3);-webkit-transition:background-color var(--calcite-internal-animation-timing-fast) ease-in-out, border-color var(--calcite-internal-animation-timing-fast) ease-in-out, color var(--calcite-internal-animation-timing-fast) ease-in-out;transition:background-color var(--calcite-internal-animation-timing-fast) ease-in-out, border-color var(--calcite-internal-animation-timing-fast) ease-in-out, color var(--calcite-internal-animation-timing-fast) ease-in-out}.label--horizontal{-ms-flex-pack:center;justify-content:center}:host{outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out}:host(:focus){outline:2px solid var(--calcite-ui-brand);outline-offset:-1px}.label--scale-s{padding-left:0.5rem;padding-right:0.5rem;font-size:var(--calcite-font-size--2);line-height:1rem;padding-top:0.125rem;padding-bottom:0.125rem}.label--scale-m{padding-left:0.75rem;padding-right:0.75rem;font-size:var(--calcite-font-size--1);line-height:1rem;padding-top:0.375rem;padding-bottom:0.375rem}.label--scale-l{padding-left:1rem;padding-right:1rem;padding-top:0.625rem;padding-bottom:0.625rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}:host(:hover) label{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1)}:host(:active) label{background-color:var(--calcite-ui-foreground-3)}:host([checked]) label{cursor:default;border-color:var(--calcite-ui-brand);background-color:var(--calcite-ui-brand);color:var(--calcite-ui-background)}:host([checked]) .label--outline{border-color:var(--calcite-ui-brand);background-color:var(--calcite-ui-foreground-1);-webkit-box-shadow:inset 0 0 0 1px var(--calcite-ui-brand);box-shadow:inset 0 0 0 1px var(--calcite-ui-brand);color:var(--calcite-ui-brand)}::slotted(input){display:none}.radio-group-item-icon{position:relative;margin:0px;display:-ms-inline-flexbox;display:inline-flex;line-height:inherit}:host([icon-position=start]) .label--scale-s .radio-group-item-icon{-webkit-margin-end:0.5rem;margin-inline-end:0.5rem}:host([icon-position=end]) .label--scale-s .radio-group-item-icon{-webkit-margin-end:unset;margin-inline-end:unset;-webkit-margin-start:0.5rem;margin-inline-start:0.5rem}:host([icon-position=start]) .label--scale-m .radio-group-item-icon{-webkit-margin-end:0.75rem;margin-inline-end:0.75rem}:host([icon-position=end]) .label--scale-m .radio-group-item-icon{-webkit-margin-end:unset;margin-inline-end:unset;-webkit-margin-start:0.75rem;margin-inline-start:0.75rem}:host([icon-position=start]) .label--scale-l .radio-group-item-icon{-webkit-margin-end:1rem;margin-inline-end:1rem}:host([icon-position=end]) .label--scale-l .radio-group-item-icon{-webkit-margin-end:unset;margin-inline-end:unset;-webkit-margin-start:1rem;margin-inline-start:1rem}";
  212. const RadioGroupItem = class {
  213. constructor(hostRef) {
  214. index.registerInstance(this, hostRef);
  215. this.calciteRadioGroupItemChange = index.createEvent(this, "calciteRadioGroupItemChange", 7);
  216. //--------------------------------------------------------------------------
  217. //
  218. // Properties
  219. //
  220. //--------------------------------------------------------------------------
  221. /** Indicates whether the control is checked. */
  222. this.checked = false;
  223. /** flip the icon in rtl */
  224. this.iconFlipRtl = false;
  225. /** optionally used with icon, select where to position the icon */
  226. this.iconPosition = "start";
  227. }
  228. handleCheckedChange() {
  229. this.calciteRadioGroupItemChange.emit();
  230. }
  231. render() {
  232. const { checked, value } = this;
  233. const scale = dom.getElementProp(this.el, "scale", "m");
  234. const appearance = dom.getElementProp(this.el, "appearance", "solid");
  235. const layout = dom.getElementProp(this.el, "layout", "horizontal");
  236. const iconEl = (index.h("calcite-icon", { class: CSS.radioGroupItemIcon, flipRtl: this.iconFlipRtl, icon: this.icon, scale: "s" }));
  237. return (index.h(index.Host, { "aria-checked": dom.toAriaBoolean(checked), role: "radio" }, index.h("label", { class: {
  238. "label--scale-s": scale === "s",
  239. "label--scale-m": scale === "m",
  240. "label--scale-l": scale === "l",
  241. "label--horizontal": layout === "horizontal",
  242. "label--outline": appearance === "outline"
  243. } }, this.icon && this.iconPosition === "start" ? iconEl : null, index.h("slot", null, value), index.h("slot", { name: SLOTS.input }), this.icon && this.iconPosition === "end" ? iconEl : null)));
  244. }
  245. get el() { return index.getElement(this); }
  246. static get watchers() { return {
  247. "checked": ["handleCheckedChange"]
  248. }; }
  249. };
  250. RadioGroupItem.style = radioGroupItemCss;
  251. exports.calcite_radio_group = RadioGroup;
  252. exports.calcite_radio_group_item = RadioGroupItem;