fab.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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, Method, Prop, h } from "@stencil/core";
  7. import { CSS, ICONS } from "./resources";
  8. import { focusElement } from "../../utils/dom";
  9. import { updateHostInteraction } from "../../utils/interactive";
  10. export class Fab {
  11. constructor() {
  12. // --------------------------------------------------------------------------
  13. //
  14. // Properties
  15. //
  16. // --------------------------------------------------------------------------
  17. /**
  18. * Used to set the button's appearance. Default is outline.
  19. */
  20. this.appearance = "outline";
  21. /**
  22. * Used to set the button's color. Default is light.
  23. */
  24. this.color = "neutral";
  25. /**
  26. * When true, disabled prevents interaction. This state shows items with lower opacity/grayed.
  27. */
  28. this.disabled = false;
  29. /**
  30. * The name of the icon to display. The value of this property must match the icon name from https://esri.github.io/calcite-ui-icons/.
  31. * @default "plus"
  32. */
  33. this.icon = ICONS.plus;
  34. /**
  35. * When true, content is waiting to be loaded. This state shows a busy indicator.
  36. */
  37. this.loading = false;
  38. /**
  39. * Specifies the size of the fab.
  40. */
  41. this.scale = "m";
  42. /**
  43. * Indicates whether the text is displayed.
  44. */
  45. this.textEnabled = false;
  46. }
  47. //--------------------------------------------------------------------------
  48. //
  49. // Lifecycle
  50. //
  51. //--------------------------------------------------------------------------
  52. componentDidRender() {
  53. updateHostInteraction(this);
  54. }
  55. // --------------------------------------------------------------------------
  56. //
  57. // Methods
  58. //
  59. // --------------------------------------------------------------------------
  60. /** Sets focus on the component. */
  61. async setFocus() {
  62. focusElement(this.buttonEl);
  63. }
  64. // --------------------------------------------------------------------------
  65. //
  66. // Render Methods
  67. //
  68. // --------------------------------------------------------------------------
  69. render() {
  70. const { appearance, color, disabled, loading, scale, textEnabled, icon, label, text } = this;
  71. const title = !textEnabled ? label || text || null : null;
  72. return (h("calcite-button", { appearance: appearance === "solid" ? "solid" : "outline", class: CSS.button, color: color, disabled: disabled, iconStart: icon, label: label, loading: loading, ref: (buttonEl) => {
  73. this.buttonEl = buttonEl;
  74. }, round: true, scale: scale, title: title, type: "button", width: "auto" }, this.textEnabled ? this.text : null));
  75. }
  76. static get is() { return "calcite-fab"; }
  77. static get encapsulation() { return "shadow"; }
  78. static get originalStyleUrls() { return {
  79. "$": ["fab.scss"]
  80. }; }
  81. static get styleUrls() { return {
  82. "$": ["fab.css"]
  83. }; }
  84. static get properties() { return {
  85. "appearance": {
  86. "type": "string",
  87. "mutable": false,
  88. "complexType": {
  89. "original": "Extract<\"solid\" | \"outline\", Appearance>",
  90. "resolved": "\"outline\" | \"solid\"",
  91. "references": {
  92. "Extract": {
  93. "location": "global"
  94. },
  95. "Appearance": {
  96. "location": "import",
  97. "path": "../interfaces"
  98. }
  99. }
  100. },
  101. "required": false,
  102. "optional": false,
  103. "docs": {
  104. "tags": [],
  105. "text": "Used to set the button's appearance. Default is outline."
  106. },
  107. "attribute": "appearance",
  108. "reflect": true,
  109. "defaultValue": "\"outline\""
  110. },
  111. "color": {
  112. "type": "string",
  113. "mutable": false,
  114. "complexType": {
  115. "original": "ButtonColor",
  116. "resolved": "\"blue\" | \"inverse\" | \"neutral\" | \"red\"",
  117. "references": {
  118. "ButtonColor": {
  119. "location": "import",
  120. "path": "../button/interfaces"
  121. }
  122. }
  123. },
  124. "required": false,
  125. "optional": false,
  126. "docs": {
  127. "tags": [],
  128. "text": "Used to set the button's color. Default is light."
  129. },
  130. "attribute": "color",
  131. "reflect": true,
  132. "defaultValue": "\"neutral\""
  133. },
  134. "disabled": {
  135. "type": "boolean",
  136. "mutable": false,
  137. "complexType": {
  138. "original": "boolean",
  139. "resolved": "boolean",
  140. "references": {}
  141. },
  142. "required": false,
  143. "optional": false,
  144. "docs": {
  145. "tags": [],
  146. "text": "When true, disabled prevents interaction. This state shows items with lower opacity/grayed."
  147. },
  148. "attribute": "disabled",
  149. "reflect": true,
  150. "defaultValue": "false"
  151. },
  152. "icon": {
  153. "type": "string",
  154. "mutable": false,
  155. "complexType": {
  156. "original": "string",
  157. "resolved": "string",
  158. "references": {}
  159. },
  160. "required": false,
  161. "optional": true,
  162. "docs": {
  163. "tags": [{
  164. "name": "default",
  165. "text": "\"plus\""
  166. }],
  167. "text": "The name of the icon to display. The value of this property must match the icon name from https://esri.github.io/calcite-ui-icons/."
  168. },
  169. "attribute": "icon",
  170. "reflect": false,
  171. "defaultValue": "ICONS.plus"
  172. },
  173. "label": {
  174. "type": "string",
  175. "mutable": false,
  176. "complexType": {
  177. "original": "string",
  178. "resolved": "string",
  179. "references": {}
  180. },
  181. "required": false,
  182. "optional": true,
  183. "docs": {
  184. "tags": [],
  185. "text": "Label of the FAB, exposed on hover when textEnabled is false. If no label is provided, the label inherits what's provided for the `text` prop."
  186. },
  187. "attribute": "label",
  188. "reflect": false
  189. },
  190. "loading": {
  191. "type": "boolean",
  192. "mutable": false,
  193. "complexType": {
  194. "original": "boolean",
  195. "resolved": "boolean",
  196. "references": {}
  197. },
  198. "required": false,
  199. "optional": false,
  200. "docs": {
  201. "tags": [],
  202. "text": "When true, content is waiting to be loaded. This state shows a busy indicator."
  203. },
  204. "attribute": "loading",
  205. "reflect": true,
  206. "defaultValue": "false"
  207. },
  208. "scale": {
  209. "type": "string",
  210. "mutable": false,
  211. "complexType": {
  212. "original": "Scale",
  213. "resolved": "\"l\" | \"m\" | \"s\"",
  214. "references": {
  215. "Scale": {
  216. "location": "import",
  217. "path": "../interfaces"
  218. }
  219. }
  220. },
  221. "required": false,
  222. "optional": false,
  223. "docs": {
  224. "tags": [],
  225. "text": "Specifies the size of the fab."
  226. },
  227. "attribute": "scale",
  228. "reflect": true,
  229. "defaultValue": "\"m\""
  230. },
  231. "text": {
  232. "type": "string",
  233. "mutable": false,
  234. "complexType": {
  235. "original": "string",
  236. "resolved": "string",
  237. "references": {}
  238. },
  239. "required": false,
  240. "optional": true,
  241. "docs": {
  242. "tags": [],
  243. "text": "Text that accompanies the FAB icon."
  244. },
  245. "attribute": "text",
  246. "reflect": false
  247. },
  248. "textEnabled": {
  249. "type": "boolean",
  250. "mutable": false,
  251. "complexType": {
  252. "original": "boolean",
  253. "resolved": "boolean",
  254. "references": {}
  255. },
  256. "required": false,
  257. "optional": false,
  258. "docs": {
  259. "tags": [],
  260. "text": "Indicates whether the text is displayed."
  261. },
  262. "attribute": "text-enabled",
  263. "reflect": true,
  264. "defaultValue": "false"
  265. }
  266. }; }
  267. static get methods() { return {
  268. "setFocus": {
  269. "complexType": {
  270. "signature": "() => Promise<void>",
  271. "parameters": [],
  272. "references": {
  273. "Promise": {
  274. "location": "global"
  275. }
  276. },
  277. "return": "Promise<void>"
  278. },
  279. "docs": {
  280. "text": "Sets focus on the component.",
  281. "tags": []
  282. }
  283. }
  284. }; }
  285. static get elementRef() { return "el"; }
  286. }