fab.js 8.2 KB

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