calcite-radio-button-group.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client/index.js';
  7. import { c as createObserver } from './observers.js';
  8. const radioButtonGroupCss = "@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:flex;max-inline-size:100vw}:host([layout=horizontal]){flex-direction:row;flex-wrap:wrap}:host([layout=horizontal][scale=s]){gap:1rem}:host([layout=horizontal][scale=m]){gap:1.25rem}:host([layout=horizontal][scale=l]){gap:1.5rem}:host([layout=vertical]){flex-direction:column}";
  9. const RadioButtonGroup = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  10. constructor() {
  11. super();
  12. this.__registerHost();
  13. this.__attachShadow();
  14. this.calciteRadioButtonGroupChange = createEvent(this, "calciteRadioButtonGroupChange", 6);
  15. //--------------------------------------------------------------------------
  16. //
  17. // Properties
  18. //
  19. //--------------------------------------------------------------------------
  20. /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
  21. this.disabled = false;
  22. /** When `true`, the component is not displayed and its `calcite-radio-button`s are not focusable or checkable. */
  23. this.hidden = false;
  24. /** Defines the layout of the component. */
  25. this.layout = "horizontal";
  26. /** When `true`, the component must have a value in order for the form to submit. */
  27. this.required = false;
  28. /** Specifies the size of the component. */
  29. this.scale = "m";
  30. // --------------------------------------------------------------------------
  31. //
  32. // Private Properties
  33. //
  34. // --------------------------------------------------------------------------
  35. this.mutationObserver = createObserver("mutation", () => this.passPropsToRadioButtons());
  36. //--------------------------------------------------------------------------
  37. //
  38. // Private Methods
  39. //
  40. //--------------------------------------------------------------------------
  41. this.passPropsToRadioButtons = () => {
  42. const radioButtons = this.el.querySelectorAll("calcite-radio-button");
  43. if (radioButtons.length > 0) {
  44. radioButtons.forEach((radioButton) => {
  45. radioButton.disabled = this.disabled || radioButton.disabled;
  46. radioButton.hidden = this.hidden;
  47. radioButton.name = this.name;
  48. radioButton.required = this.required;
  49. radioButton.scale = this.scale;
  50. });
  51. }
  52. };
  53. }
  54. onDisabledChange() {
  55. this.passPropsToRadioButtons();
  56. }
  57. onHiddenChange() {
  58. this.passPropsToRadioButtons();
  59. }
  60. onLayoutChange() {
  61. this.passPropsToRadioButtons();
  62. }
  63. onScaleChange() {
  64. this.passPropsToRadioButtons();
  65. }
  66. //--------------------------------------------------------------------------
  67. //
  68. // Lifecycle
  69. //
  70. //--------------------------------------------------------------------------
  71. connectedCallback() {
  72. var _a;
  73. this.passPropsToRadioButtons();
  74. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
  75. }
  76. disconnectedCallback() {
  77. var _a;
  78. (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  79. }
  80. //--------------------------------------------------------------------------
  81. //
  82. // Event Listeners
  83. //
  84. //--------------------------------------------------------------------------
  85. radioButtonChangeHandler(event) {
  86. this.calciteRadioButtonGroupChange.emit(event.target.value);
  87. }
  88. // --------------------------------------------------------------------------
  89. //
  90. // Render Methods
  91. //
  92. // --------------------------------------------------------------------------
  93. render() {
  94. return (h(Host, { role: "radiogroup" }, h("slot", null)));
  95. }
  96. get el() { return this; }
  97. static get watchers() { return {
  98. "disabled": ["onDisabledChange"],
  99. "hidden": ["onHiddenChange"],
  100. "layout": ["onLayoutChange"],
  101. "scale": ["onScaleChange"]
  102. }; }
  103. static get style() { return radioButtonGroupCss; }
  104. }, [1, "calcite-radio-button-group", {
  105. "disabled": [516],
  106. "hidden": [516],
  107. "layout": [513],
  108. "name": [513],
  109. "required": [516],
  110. "scale": [513]
  111. }, [[0, "calciteRadioButtonChange", "radioButtonChangeHandler"]]]);
  112. function defineCustomElement$1() {
  113. if (typeof customElements === "undefined") {
  114. return;
  115. }
  116. const components = ["calcite-radio-button-group"];
  117. components.forEach(tagName => { switch (tagName) {
  118. case "calcite-radio-button-group":
  119. if (!customElements.get(tagName)) {
  120. customElements.define(tagName, RadioButtonGroup);
  121. }
  122. break;
  123. } });
  124. }
  125. defineCustomElement$1();
  126. const CalciteRadioButtonGroup = RadioButtonGroup;
  127. const defineCustomElement = defineCustomElement$1;
  128. export { CalciteRadioButtonGroup, defineCustomElement };