split-button.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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, Prop, Watch } from "@stencil/core";
  7. import { CSS } from "./resources";
  8. import { updateHostInteraction } from "../../utils/interactive";
  9. /**
  10. * @slot - A slot for adding `calcite-dropdown` content.
  11. */
  12. export class SplitButton {
  13. constructor() {
  14. /** specify the appearance style of the button, defaults to solid. */
  15. this.appearance = "solid";
  16. /** specify the color of the control, defaults to blue */
  17. this.color = "blue";
  18. /** is the control disabled */
  19. this.disabled = false;
  20. /**
  21. * Is the dropdown currently active or not
  22. * @internal
  23. */
  24. this.active = false;
  25. /** specify the icon used for the dropdown menu, defaults to chevron */
  26. this.dropdownIconType = "chevron";
  27. /** optionally add a calcite-loader component to the control,
  28. disabling interaction. with the primary button */
  29. this.loading = false;
  30. /** Describes the type of positioning to use for the dropdown. If your element is in a fixed container, use the 'fixed' value. */
  31. this.overlayPositioning = "absolute";
  32. /** specify the scale of the control, defaults to m */
  33. this.scale = "m";
  34. /** specify the width of the button, defaults to auto */
  35. this.width = "auto";
  36. this.calciteSplitButtonPrimaryClickHandler = (e) => this.calciteSplitButtonPrimaryClick.emit(e);
  37. this.calciteSplitButtonSecondaryClickHandler = (e) => this.calciteSplitButtonSecondaryClick.emit(e);
  38. }
  39. handleDisabledChange(value) {
  40. if (!value) {
  41. this.active = false;
  42. }
  43. }
  44. activeHandler() {
  45. if (this.disabled) {
  46. this.active = false;
  47. }
  48. }
  49. //--------------------------------------------------------------------------
  50. //
  51. // Lifecycle
  52. //
  53. //--------------------------------------------------------------------------
  54. componentDidRender() {
  55. updateHostInteraction(this);
  56. }
  57. render() {
  58. const widthClasses = {
  59. [CSS.container]: true,
  60. [CSS.widthAuto]: this.width === "auto",
  61. [CSS.widthHalf]: this.width === "half",
  62. [CSS.widthFull]: this.width === "full"
  63. };
  64. const buttonWidth = this.width === "auto" ? "auto" : "full";
  65. return (h("div", { class: widthClasses },
  66. h("calcite-button", { appearance: this.appearance, color: this.color, disabled: this.disabled, "icon-end": this.primaryIconEnd ? this.primaryIconEnd : null, "icon-start": this.primaryIconStart ? this.primaryIconStart : null, iconFlipRtl: this.primaryIconFlipRtl ? this.primaryIconFlipRtl : null, label: this.primaryLabel, loading: this.loading, onClick: this.calciteSplitButtonPrimaryClickHandler, scale: this.scale, splitChild: "primary", type: "button", width: buttonWidth }, this.primaryText),
  67. h("div", { class: CSS.dividerContainer },
  68. h("div", { class: CSS.divider })),
  69. h("calcite-dropdown", { active: this.active, disabled: this.disabled, onClick: this.calciteSplitButtonSecondaryClickHandler, overlayPositioning: this.overlayPositioning, placement: "bottom-trailing", scale: this.scale, width: this.scale },
  70. h("calcite-button", { appearance: this.appearance, color: this.color, disabled: this.disabled, "icon-start": this.dropdownIcon, label: this.dropdownLabel, scale: this.scale, slot: "dropdown-trigger", splitChild: "secondary", type: "button" }),
  71. h("slot", null))));
  72. }
  73. get dropdownIcon() {
  74. return this.dropdownIconType === "chevron"
  75. ? "chevronDown"
  76. : this.dropdownIconType === "caret"
  77. ? "caretDown"
  78. : this.dropdownIconType === "ellipsis"
  79. ? "ellipsis"
  80. : "handle-vertical";
  81. }
  82. static get is() { return "calcite-split-button"; }
  83. static get encapsulation() { return "shadow"; }
  84. static get originalStyleUrls() { return {
  85. "$": ["split-button.scss"]
  86. }; }
  87. static get styleUrls() { return {
  88. "$": ["split-button.css"]
  89. }; }
  90. static get properties() { return {
  91. "appearance": {
  92. "type": "string",
  93. "mutable": false,
  94. "complexType": {
  95. "original": "ButtonAppearance",
  96. "resolved": "\"clear\" | \"outline\" | \"solid\" | \"transparent\"",
  97. "references": {
  98. "ButtonAppearance": {
  99. "location": "import",
  100. "path": "../button/interfaces"
  101. }
  102. }
  103. },
  104. "required": false,
  105. "optional": false,
  106. "docs": {
  107. "tags": [],
  108. "text": "specify the appearance style of the button, defaults to solid."
  109. },
  110. "attribute": "appearance",
  111. "reflect": true,
  112. "defaultValue": "\"solid\""
  113. },
  114. "color": {
  115. "type": "string",
  116. "mutable": false,
  117. "complexType": {
  118. "original": "ButtonColor",
  119. "resolved": "\"blue\" | \"inverse\" | \"neutral\" | \"red\"",
  120. "references": {
  121. "ButtonColor": {
  122. "location": "import",
  123. "path": "../button/interfaces"
  124. }
  125. }
  126. },
  127. "required": false,
  128. "optional": false,
  129. "docs": {
  130. "tags": [],
  131. "text": "specify the color of the control, defaults to blue"
  132. },
  133. "attribute": "color",
  134. "reflect": true,
  135. "defaultValue": "\"blue\""
  136. },
  137. "disabled": {
  138. "type": "boolean",
  139. "mutable": false,
  140. "complexType": {
  141. "original": "boolean",
  142. "resolved": "boolean",
  143. "references": {}
  144. },
  145. "required": false,
  146. "optional": false,
  147. "docs": {
  148. "tags": [],
  149. "text": "is the control disabled"
  150. },
  151. "attribute": "disabled",
  152. "reflect": true,
  153. "defaultValue": "false"
  154. },
  155. "active": {
  156. "type": "boolean",
  157. "mutable": true,
  158. "complexType": {
  159. "original": "boolean",
  160. "resolved": "boolean",
  161. "references": {}
  162. },
  163. "required": false,
  164. "optional": false,
  165. "docs": {
  166. "tags": [{
  167. "name": "internal",
  168. "text": undefined
  169. }],
  170. "text": "Is the dropdown currently active or not"
  171. },
  172. "attribute": "active",
  173. "reflect": true,
  174. "defaultValue": "false"
  175. },
  176. "dropdownIconType": {
  177. "type": "string",
  178. "mutable": false,
  179. "complexType": {
  180. "original": "DropdownIconType",
  181. "resolved": "\"caret\" | \"chevron\" | \"ellipsis\" | \"overflow\"",
  182. "references": {
  183. "DropdownIconType": {
  184. "location": "import",
  185. "path": "../button/interfaces"
  186. }
  187. }
  188. },
  189. "required": false,
  190. "optional": false,
  191. "docs": {
  192. "tags": [],
  193. "text": "specify the icon used for the dropdown menu, defaults to chevron"
  194. },
  195. "attribute": "dropdown-icon-type",
  196. "reflect": true,
  197. "defaultValue": "\"chevron\""
  198. },
  199. "dropdownLabel": {
  200. "type": "string",
  201. "mutable": false,
  202. "complexType": {
  203. "original": "string",
  204. "resolved": "string",
  205. "references": {}
  206. },
  207. "required": false,
  208. "optional": true,
  209. "docs": {
  210. "tags": [],
  211. "text": "aria label for overflow button"
  212. },
  213. "attribute": "dropdown-label",
  214. "reflect": true
  215. },
  216. "loading": {
  217. "type": "boolean",
  218. "mutable": false,
  219. "complexType": {
  220. "original": "boolean",
  221. "resolved": "boolean",
  222. "references": {}
  223. },
  224. "required": false,
  225. "optional": false,
  226. "docs": {
  227. "tags": [],
  228. "text": "optionally add a calcite-loader component to the control,\ndisabling interaction. with the primary button"
  229. },
  230. "attribute": "loading",
  231. "reflect": true,
  232. "defaultValue": "false"
  233. },
  234. "overlayPositioning": {
  235. "type": "string",
  236. "mutable": false,
  237. "complexType": {
  238. "original": "OverlayPositioning",
  239. "resolved": "\"absolute\" | \"fixed\"",
  240. "references": {
  241. "OverlayPositioning": {
  242. "location": "import",
  243. "path": "../../utils/popper"
  244. }
  245. }
  246. },
  247. "required": false,
  248. "optional": false,
  249. "docs": {
  250. "tags": [],
  251. "text": "Describes the type of positioning to use for the dropdown. If your element is in a fixed container, use the 'fixed' value."
  252. },
  253. "attribute": "overlay-positioning",
  254. "reflect": false,
  255. "defaultValue": "\"absolute\""
  256. },
  257. "primaryIconEnd": {
  258. "type": "string",
  259. "mutable": false,
  260. "complexType": {
  261. "original": "string",
  262. "resolved": "string",
  263. "references": {}
  264. },
  265. "required": false,
  266. "optional": true,
  267. "docs": {
  268. "tags": [],
  269. "text": "optionally pass an icon to display at the end of the primary button - accepts Calcite UI icon names"
  270. },
  271. "attribute": "primary-icon-end",
  272. "reflect": true
  273. },
  274. "primaryIconFlipRtl": {
  275. "type": "string",
  276. "mutable": false,
  277. "complexType": {
  278. "original": "FlipContext",
  279. "resolved": "\"both\" | \"end\" | \"start\"",
  280. "references": {
  281. "FlipContext": {
  282. "location": "import",
  283. "path": "../interfaces"
  284. }
  285. }
  286. },
  287. "required": false,
  288. "optional": true,
  289. "docs": {
  290. "tags": [],
  291. "text": "flip the primary icon(s) in rtl"
  292. },
  293. "attribute": "primary-icon-flip-rtl",
  294. "reflect": true
  295. },
  296. "primaryIconStart": {
  297. "type": "string",
  298. "mutable": false,
  299. "complexType": {
  300. "original": "string",
  301. "resolved": "string",
  302. "references": {}
  303. },
  304. "required": false,
  305. "optional": true,
  306. "docs": {
  307. "tags": [],
  308. "text": "optionally pass an icon to display at the start of the primary button - accepts Calcite UI icon names"
  309. },
  310. "attribute": "primary-icon-start",
  311. "reflect": true
  312. },
  313. "primaryLabel": {
  314. "type": "string",
  315. "mutable": false,
  316. "complexType": {
  317. "original": "string",
  318. "resolved": "string",
  319. "references": {}
  320. },
  321. "required": false,
  322. "optional": true,
  323. "docs": {
  324. "tags": [],
  325. "text": "optionally pass an aria-label for the primary button"
  326. },
  327. "attribute": "primary-label",
  328. "reflect": true
  329. },
  330. "primaryText": {
  331. "type": "string",
  332. "mutable": false,
  333. "complexType": {
  334. "original": "string",
  335. "resolved": "string",
  336. "references": {}
  337. },
  338. "required": false,
  339. "optional": false,
  340. "docs": {
  341. "tags": [],
  342. "text": "text for primary action button"
  343. },
  344. "attribute": "primary-text",
  345. "reflect": true
  346. },
  347. "scale": {
  348. "type": "string",
  349. "mutable": false,
  350. "complexType": {
  351. "original": "Scale",
  352. "resolved": "\"l\" | \"m\" | \"s\"",
  353. "references": {
  354. "Scale": {
  355. "location": "import",
  356. "path": "../interfaces"
  357. }
  358. }
  359. },
  360. "required": false,
  361. "optional": false,
  362. "docs": {
  363. "tags": [],
  364. "text": "specify the scale of the control, defaults to m"
  365. },
  366. "attribute": "scale",
  367. "reflect": true,
  368. "defaultValue": "\"m\""
  369. },
  370. "width": {
  371. "type": "string",
  372. "mutable": false,
  373. "complexType": {
  374. "original": "Width",
  375. "resolved": "\"auto\" | \"full\" | \"half\"",
  376. "references": {
  377. "Width": {
  378. "location": "import",
  379. "path": "../interfaces"
  380. }
  381. }
  382. },
  383. "required": false,
  384. "optional": false,
  385. "docs": {
  386. "tags": [],
  387. "text": "specify the width of the button, defaults to auto"
  388. },
  389. "attribute": "width",
  390. "reflect": true,
  391. "defaultValue": "\"auto\""
  392. }
  393. }; }
  394. static get events() { return [{
  395. "method": "calciteSplitButtonPrimaryClick",
  396. "name": "calciteSplitButtonPrimaryClick",
  397. "bubbles": true,
  398. "cancelable": true,
  399. "composed": true,
  400. "docs": {
  401. "tags": [],
  402. "text": "fired when the primary button is clicked"
  403. },
  404. "complexType": {
  405. "original": "any",
  406. "resolved": "any",
  407. "references": {}
  408. }
  409. }, {
  410. "method": "calciteSplitButtonSecondaryClick",
  411. "name": "calciteSplitButtonSecondaryClick",
  412. "bubbles": true,
  413. "cancelable": true,
  414. "composed": true,
  415. "docs": {
  416. "tags": [],
  417. "text": "fired when the secondary button is clicked"
  418. },
  419. "complexType": {
  420. "original": "any",
  421. "resolved": "any",
  422. "references": {}
  423. }
  424. }]; }
  425. static get elementRef() { return "el"; }
  426. static get watchers() { return [{
  427. "propName": "disabled",
  428. "methodName": "handleDisabledChange"
  429. }, {
  430. "propName": "active",
  431. "methodName": "activeHandler"
  432. }]; }
  433. }