tile.js 7.7 KB

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