calcite-dropdown-group.js 6.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
  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 = "@-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:block}.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-bottom:-1px;display:block;cursor:default;overflow-wrap:break-word;border-width:0px;border-bottom-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;height: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.calciteDropdownItemChange = createEvent(this, "calciteDropdownItemChange", 7);
  20. /** specify the selection mode - multi (allow any number of (or no) active items), single (allow and require one active item),
  21. none (no active items), defaults to single */
  22. this.selectionMode = "single";
  23. }
  24. //--------------------------------------------------------------------------
  25. //
  26. // Lifecycle
  27. //
  28. //--------------------------------------------------------------------------
  29. componentWillLoad() {
  30. this.groupPosition = this.getGroupPosition();
  31. }
  32. render() {
  33. const scale = this.scale || getElementProp(this.el, "scale", "m");
  34. const groupTitle = this.groupTitle ? (h("span", { "aria-hidden": "true", class: "dropdown-title" }, this.groupTitle)) : null;
  35. const dropdownSeparator = this.groupPosition > 0 ? h("div", { class: "dropdown-separator", role: "separator" }) : null;
  36. return (h(Host, { role: "menu" }, h("div", { class: {
  37. container: true,
  38. [CSS.containerSmall]: scale === "s",
  39. [CSS.containerMedium]: scale === "m",
  40. [CSS.containerLarge]: scale === "l"
  41. }, title: this.groupTitle }, dropdownSeparator, groupTitle, h("slot", null))));
  42. }
  43. //--------------------------------------------------------------------------
  44. //
  45. // Event Listeners
  46. //
  47. //--------------------------------------------------------------------------
  48. updateActiveItemOnChange(event) {
  49. this.requestedDropdownGroup = event.detail.requestedDropdownGroup;
  50. this.requestedDropdownItem = event.detail.requestedDropdownItem;
  51. this.calciteDropdownItemChange.emit({
  52. requestedDropdownGroup: this.requestedDropdownGroup,
  53. requestedDropdownItem: this.requestedDropdownItem
  54. });
  55. }
  56. //--------------------------------------------------------------------------
  57. //
  58. // Private Methods
  59. //
  60. //--------------------------------------------------------------------------
  61. getGroupPosition() {
  62. return Array.prototype.indexOf.call(this.el.parentElement.querySelectorAll("calcite-dropdown-group"), this.el);
  63. }
  64. get el() { return this; }
  65. static get style() { return dropdownGroupCss; }
  66. }, [1, "calcite-dropdown-group", {
  67. "groupTitle": [513, "group-title"],
  68. "selectionMode": [513, "selection-mode"],
  69. "scale": [513]
  70. }, [[0, "calciteDropdownItemSelect", "updateActiveItemOnChange"]]]);
  71. function defineCustomElement$1() {
  72. if (typeof customElements === "undefined") {
  73. return;
  74. }
  75. const components = ["calcite-dropdown-group"];
  76. components.forEach(tagName => { switch (tagName) {
  77. case "calcite-dropdown-group":
  78. if (!customElements.get(tagName)) {
  79. customElements.define(tagName, DropdownGroup);
  80. }
  81. break;
  82. } });
  83. }
  84. defineCustomElement$1();
  85. const CalciteDropdownGroup = DropdownGroup;
  86. const defineCustomElement = defineCustomElement$1;
  87. export { CalciteDropdownGroup, defineCustomElement };