tile.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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, Fragment, h, Prop } from "@stencil/core";
  7. import { SLOTS } from "./resources";
  8. import { getSlotted } from "../../utils/dom";
  9. import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot";
  10. import { updateHostInteraction } from "../../utils/interactive";
  11. /**
  12. * @slot content-start - A slot for adding non-actionable elements before the tile content.
  13. * @slot content-end - A slot for adding non-actionable elements after the tile content.
  14. */
  15. export class Tile {
  16. constructor() {
  17. //--------------------------------------------------------------------------
  18. //
  19. // Properties
  20. //
  21. //--------------------------------------------------------------------------
  22. /** The active state of the tile. */
  23. this.active = false;
  24. /**
  25. * When true, prevents interaction.
  26. */
  27. this.disabled = false;
  28. /** The embed mode of the tile. When true, renders without a border and padding for use by other components. */
  29. this.embed = false;
  30. /**
  31. * The focused state of the tile.
  32. * @internal
  33. */
  34. this.focused = false;
  35. /** The hidden state of the tile. */
  36. this.hidden = false;
  37. }
  38. // --------------------------------------------------------------------------
  39. //
  40. // Lifecycle
  41. //
  42. // --------------------------------------------------------------------------
  43. connectedCallback() {
  44. connectConditionalSlotComponent(this);
  45. }
  46. disconnectedCallback() {
  47. disconnectConditionalSlotComponent(this);
  48. }
  49. componentDidRender() {
  50. updateHostInteraction(this);
  51. }
  52. // --------------------------------------------------------------------------
  53. //
  54. // Render Methods
  55. //
  56. // --------------------------------------------------------------------------
  57. renderTile() {
  58. const { icon, el, heading, description } = this;
  59. const isLargeVisual = heading && icon && !description;
  60. const iconStyle = isLargeVisual
  61. ? {
  62. height: "64px",
  63. width: "64px"
  64. }
  65. : undefined;
  66. return (h("div", { class: { container: true, "large-visual": isLargeVisual } },
  67. icon && (h("div", { class: "icon" },
  68. h("calcite-icon", { icon: icon, scale: "l", style: iconStyle }))),
  69. h("div", { class: "content-container" },
  70. getSlotted(el, SLOTS.contentStart) ? (h("div", { class: "content-slot-container" },
  71. h("slot", { name: SLOTS.contentStart }))) : null,
  72. h("div", { class: "content" },
  73. heading && h("div", { class: "heading" }, heading),
  74. description && h("div", { class: "description" }, description)),
  75. getSlotted(el, SLOTS.contentEnd) ? (h("div", { class: "content-slot-container" },
  76. h("slot", { name: SLOTS.contentEnd }))) : null)));
  77. }
  78. render() {
  79. return (h(Fragment, null, this.href ? (h("calcite-link", { disabled: this.disabled, href: this.href }, this.renderTile())) : (this.renderTile())));
  80. }
  81. static get is() { return "calcite-tile"; }
  82. static get encapsulation() { return "shadow"; }
  83. static get originalStyleUrls() { return {
  84. "$": ["tile.scss"]
  85. }; }
  86. static get styleUrls() { return {
  87. "$": ["tile.css"]
  88. }; }
  89. static get properties() { return {
  90. "active": {
  91. "type": "boolean",
  92. "mutable": false,
  93. "complexType": {
  94. "original": "boolean",
  95. "resolved": "boolean",
  96. "references": {}
  97. },
  98. "required": false,
  99. "optional": false,
  100. "docs": {
  101. "tags": [],
  102. "text": "The active state of the tile."
  103. },
  104. "attribute": "active",
  105. "reflect": true,
  106. "defaultValue": "false"
  107. },
  108. "description": {
  109. "type": "string",
  110. "mutable": false,
  111. "complexType": {
  112. "original": "string",
  113. "resolved": "string",
  114. "references": {}
  115. },
  116. "required": false,
  117. "optional": true,
  118. "docs": {
  119. "tags": [],
  120. "text": "The description text that appears beneath the heading of the tile."
  121. },
  122. "attribute": "description",
  123. "reflect": true
  124. },
  125. "disabled": {
  126. "type": "boolean",
  127. "mutable": false,
  128. "complexType": {
  129. "original": "boolean",
  130. "resolved": "boolean",
  131. "references": {}
  132. },
  133. "required": false,
  134. "optional": false,
  135. "docs": {
  136. "tags": [],
  137. "text": "When true, prevents interaction."
  138. },
  139. "attribute": "disabled",
  140. "reflect": true,
  141. "defaultValue": "false"
  142. },
  143. "embed": {
  144. "type": "boolean",
  145. "mutable": false,
  146. "complexType": {
  147. "original": "boolean",
  148. "resolved": "boolean",
  149. "references": {}
  150. },
  151. "required": false,
  152. "optional": false,
  153. "docs": {
  154. "tags": [],
  155. "text": "The embed mode of the tile. When true, renders without a border and padding for use by other components."
  156. },
  157. "attribute": "embed",
  158. "reflect": true,
  159. "defaultValue": "false"
  160. },
  161. "focused": {
  162. "type": "boolean",
  163. "mutable": false,
  164. "complexType": {
  165. "original": "boolean",
  166. "resolved": "boolean",
  167. "references": {}
  168. },
  169. "required": false,
  170. "optional": false,
  171. "docs": {
  172. "tags": [{
  173. "name": "internal",
  174. "text": undefined
  175. }],
  176. "text": "The focused state of the tile."
  177. },
  178. "attribute": "focused",
  179. "reflect": true,
  180. "defaultValue": "false"
  181. },
  182. "heading": {
  183. "type": "string",
  184. "mutable": false,
  185. "complexType": {
  186. "original": "string",
  187. "resolved": "string",
  188. "references": {}
  189. },
  190. "required": false,
  191. "optional": true,
  192. "docs": {
  193. "tags": [],
  194. "text": "The heading text that appears between the icon and description of the tile."
  195. },
  196. "attribute": "heading",
  197. "reflect": true
  198. },
  199. "hidden": {
  200. "type": "boolean",
  201. "mutable": false,
  202. "complexType": {
  203. "original": "boolean",
  204. "resolved": "boolean",
  205. "references": {}
  206. },
  207. "required": false,
  208. "optional": false,
  209. "docs": {
  210. "tags": [],
  211. "text": "The hidden state of the tile."
  212. },
  213. "attribute": "hidden",
  214. "reflect": true,
  215. "defaultValue": "false"
  216. },
  217. "href": {
  218. "type": "string",
  219. "mutable": false,
  220. "complexType": {
  221. "original": "string",
  222. "resolved": "string",
  223. "references": {}
  224. },
  225. "required": false,
  226. "optional": true,
  227. "docs": {
  228. "tags": [],
  229. "text": "The (optional) url for the tile. (Only applies when embed is set to false)"
  230. },
  231. "attribute": "href",
  232. "reflect": true
  233. },
  234. "icon": {
  235. "type": "string",
  236. "mutable": false,
  237. "complexType": {
  238. "original": "string",
  239. "resolved": "string",
  240. "references": {}
  241. },
  242. "required": false,
  243. "optional": true,
  244. "docs": {
  245. "tags": [],
  246. "text": "The icon that appears at the top of the tile."
  247. },
  248. "attribute": "icon",
  249. "reflect": true
  250. }
  251. }; }
  252. static get elementRef() { return "el"; }
  253. }