dropdown-group.js 5.4 KB

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