calcite-dropdown-group.js 5.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 { g as getElementProp } from './dom.js';
  8. const CSS = {
  9. containerSmall: "container--s",
  10. containerMedium: "container--m",
  11. containerLarge: "container--l"
  12. };
  13. const dropdownGroupCss = "@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}.container{text-align:start}.container--s{font-size:var(--calcite-font-size--2);line-height:1rem}.container--s .dropdown-title{padding:0.5rem}.container--m{font-size:var(--calcite-font-size--1);line-height:1rem}.container--m .dropdown-title{padding:0.75rem}.container--l{font-size:var(--calcite-font-size-0);line-height:1.25rem}.container--l .dropdown-title{padding:1rem}.dropdown-title{margin-block-end:-1px;display:block;cursor:default;overflow-wrap:break-word;border-width:0px;border-block-end-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);font-weight:var(--calcite-font-weight-bold);color:var(--calcite-ui-text-2)}.dropdown-separator{display:block;block-size:1px;background-color:var(--calcite-ui-border-3)}";
  14. const DropdownGroup = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  15. constructor() {
  16. super();
  17. this.__registerHost();
  18. this.__attachShadow();
  19. this.calciteInternalDropdownItemChange = createEvent(this, "calciteInternalDropdownItemChange", 6);
  20. /**
  21. specify the selection mode - multi (allow any number of (or no) active items), single (allow and require one active item),
  22. none (no active items), defaults to single
  23. */
  24. this.selectionMode = "single";
  25. }
  26. //--------------------------------------------------------------------------
  27. //
  28. // Lifecycle
  29. //
  30. //--------------------------------------------------------------------------
  31. componentWillLoad() {
  32. this.groupPosition = this.getGroupPosition();
  33. }
  34. render() {
  35. const scale = this.scale || getElementProp(this.el, "scale", "m");
  36. const groupTitle = this.groupTitle ? (h("span", { "aria-hidden": "true", class: "dropdown-title" }, this.groupTitle)) : null;
  37. const dropdownSeparator = this.groupPosition > 0 ? h("div", { class: "dropdown-separator", role: "separator" }) : null;
  38. return (h(Host, { "aria-label": this.groupTitle, role: "group" }, h("div", { class: {
  39. container: true,
  40. [CSS.containerSmall]: scale === "s",
  41. [CSS.containerMedium]: scale === "m",
  42. [CSS.containerLarge]: scale === "l"
  43. }, title: this.groupTitle }, dropdownSeparator, groupTitle, h("slot", null))));
  44. }
  45. //--------------------------------------------------------------------------
  46. //
  47. // Event Listeners
  48. //
  49. //--------------------------------------------------------------------------
  50. updateActiveItemOnChange(event) {
  51. this.requestedDropdownGroup = event.detail.requestedDropdownGroup;
  52. this.requestedDropdownItem = event.detail.requestedDropdownItem;
  53. this.calciteInternalDropdownItemChange.emit({
  54. requestedDropdownGroup: this.requestedDropdownGroup,
  55. requestedDropdownItem: this.requestedDropdownItem
  56. });
  57. }
  58. //--------------------------------------------------------------------------
  59. //
  60. // Private Methods
  61. //
  62. //--------------------------------------------------------------------------
  63. getGroupPosition() {
  64. return Array.prototype.indexOf.call(this.el.parentElement.querySelectorAll("calcite-dropdown-group"), this.el);
  65. }
  66. get el() { return this; }
  67. static get style() { return dropdownGroupCss; }
  68. }, [1, "calcite-dropdown-group", {
  69. "groupTitle": [513, "group-title"],
  70. "selectionMode": [513, "selection-mode"],
  71. "scale": [513]
  72. }, [[0, "calciteInternalDropdownItemSelect", "updateActiveItemOnChange"]]]);
  73. function defineCustomElement$1() {
  74. if (typeof customElements === "undefined") {
  75. return;
  76. }
  77. const components = ["calcite-dropdown-group"];
  78. components.forEach(tagName => { switch (tagName) {
  79. case "calcite-dropdown-group":
  80. if (!customElements.get(tagName)) {
  81. customElements.define(tagName, DropdownGroup);
  82. }
  83. break;
  84. } });
  85. }
  86. defineCustomElement$1();
  87. const CalciteDropdownGroup = DropdownGroup;
  88. const defineCustomElement = defineCustomElement$1;
  89. export { CalciteDropdownGroup, defineCustomElement };