dropdown-group.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 { Component, Element, Event, h, Host, Listen, Prop } from "@stencil/core";
  7. import { getElementProp } from "../../utils/dom";
  8. import { CSS } from "./resources";
  9. /**
  10. * @slot - A slot for adding `calcite-dropdown-item`s.
  11. */
  12. export class DropdownGroup {
  13. constructor() {
  14. /** specify the selection mode - multi (allow any number of (or no) active items), single (allow and require one active item),
  15. none (no active items), defaults to single */
  16. this.selectionMode = "single";
  17. }
  18. //--------------------------------------------------------------------------
  19. //
  20. // Lifecycle
  21. //
  22. //--------------------------------------------------------------------------
  23. componentWillLoad() {
  24. this.groupPosition = this.getGroupPosition();
  25. }
  26. render() {
  27. const scale = this.scale || getElementProp(this.el, "scale", "m");
  28. const groupTitle = this.groupTitle ? (h("span", { "aria-hidden": "true", class: "dropdown-title" }, this.groupTitle)) : null;
  29. const dropdownSeparator = this.groupPosition > 0 ? h("div", { class: "dropdown-separator", role: "separator" }) : null;
  30. return (h(Host, { role: "menu" },
  31. h("div", { class: {
  32. container: true,
  33. [CSS.containerSmall]: scale === "s",
  34. [CSS.containerMedium]: scale === "m",
  35. [CSS.containerLarge]: scale === "l"
  36. }, title: this.groupTitle },
  37. dropdownSeparator,
  38. groupTitle,
  39. h("slot", null))));
  40. }
  41. //--------------------------------------------------------------------------
  42. //
  43. // Event Listeners
  44. //
  45. //--------------------------------------------------------------------------
  46. updateActiveItemOnChange(event) {
  47. this.requestedDropdownGroup = event.detail.requestedDropdownGroup;
  48. this.requestedDropdownItem = event.detail.requestedDropdownItem;
  49. this.calciteDropdownItemChange.emit({
  50. requestedDropdownGroup: this.requestedDropdownGroup,
  51. requestedDropdownItem: this.requestedDropdownItem
  52. });
  53. }
  54. //--------------------------------------------------------------------------
  55. //
  56. // Private Methods
  57. //
  58. //--------------------------------------------------------------------------
  59. getGroupPosition() {
  60. return Array.prototype.indexOf.call(this.el.parentElement.querySelectorAll("calcite-dropdown-group"), this.el);
  61. }
  62. static get is() { return "calcite-dropdown-group"; }
  63. static get encapsulation() { return "shadow"; }
  64. static get originalStyleUrls() { return {
  65. "$": ["dropdown-group.scss"]
  66. }; }
  67. static get styleUrls() { return {
  68. "$": ["dropdown-group.css"]
  69. }; }
  70. static get properties() { return {
  71. "groupTitle": {
  72. "type": "string",
  73. "mutable": false,
  74. "complexType": {
  75. "original": "string",
  76. "resolved": "string",
  77. "references": {}
  78. },
  79. "required": false,
  80. "optional": true,
  81. "docs": {
  82. "tags": [],
  83. "text": "optionally set a group title for display"
  84. },
  85. "attribute": "group-title",
  86. "reflect": true
  87. },
  88. "selectionMode": {
  89. "type": "string",
  90. "mutable": false,
  91. "complexType": {
  92. "original": "SelectionMode",
  93. "resolved": "\"multi\" | \"none\" | \"single\"",
  94. "references": {
  95. "SelectionMode": {
  96. "location": "import",
  97. "path": "./interfaces"
  98. }
  99. }
  100. },
  101. "required": false,
  102. "optional": false,
  103. "docs": {
  104. "tags": [],
  105. "text": "specify the selection mode - multi (allow any number of (or no) active items), single (allow and require one active item),\nnone (no active items), defaults to single"
  106. },
  107. "attribute": "selection-mode",
  108. "reflect": true,
  109. "defaultValue": "\"single\""
  110. },
  111. "scale": {
  112. "type": "string",
  113. "mutable": false,
  114. "complexType": {
  115. "original": "Scale",
  116. "resolved": "\"l\" | \"m\" | \"s\"",
  117. "references": {
  118. "Scale": {
  119. "location": "import",
  120. "path": "../interfaces"
  121. }
  122. }
  123. },
  124. "required": false,
  125. "optional": false,
  126. "docs": {
  127. "tags": [],
  128. "text": "Specifies the size of the action."
  129. },
  130. "attribute": "scale",
  131. "reflect": true
  132. }
  133. }; }
  134. static get events() { return [{
  135. "method": "calciteDropdownItemChange",
  136. "name": "calciteDropdownItemChange",
  137. "bubbles": true,
  138. "cancelable": true,
  139. "composed": true,
  140. "docs": {
  141. "tags": [{
  142. "name": "internal",
  143. "text": undefined
  144. }],
  145. "text": ""
  146. },
  147. "complexType": {
  148. "original": "any",
  149. "resolved": "any",
  150. "references": {}
  151. }
  152. }]; }
  153. static get elementRef() { return "el"; }
  154. static get listeners() { return [{
  155. "name": "calciteDropdownItemSelect",
  156. "method": "updateActiveItemOnChange",
  157. "target": undefined,
  158. "capture": false,
  159. "passive": false
  160. }]; }
  161. }