calcite-card.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
  7. import { t as toAriaBoolean, b as getSlotted } from './dom.js';
  8. import { c as connectConditionalSlotComponent, d as disconnectConditionalSlotComponent } from './conditionalSlot.js';
  9. import { d as defineCustomElement$4 } from './checkbox.js';
  10. import { d as defineCustomElement$3 } from './label2.js';
  11. import { d as defineCustomElement$2 } from './loader.js';
  12. const CSS = {
  13. container: "container",
  14. header: "header",
  15. footer: "footer",
  16. title: "title",
  17. subtitle: "subtitle",
  18. thumbnailWrapper: "thumbnail-wrapper",
  19. checkboxWrapper: "checkbox-wrapper"
  20. };
  21. const SLOTS = {
  22. thumbnail: "thumbnail",
  23. title: "title",
  24. subtitle: "subtitle",
  25. footerLeading: "footer-leading",
  26. footerTrailing: "footer-trailing"
  27. };
  28. const TEXT = {
  29. select: "Select",
  30. deselect: "Deselect",
  31. loading: "Loading"
  32. };
  33. const cardCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:block;max-width:100%}:host .calcite-card-container{position:relative;display:-ms-flexbox;display:flex;height:100%;-ms-flex-direction:column;flex-direction:column;-ms-flex-pack:justify;justify-content:space-between;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-2);background-color:var(--calcite-ui-foreground-1);color:var(--calcite-ui-text-3);--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);border-radius:var(--calcite-border-radius-base)}:host .calcite-card-container:hover{--tw-shadow:0 4px 16px 0 rgba(0, 0, 0, 0.08), 0 2px 8px 0 rgba(0, 0, 0, 0.04);--tw-shadow-colored:0 4px 16px 0 var(--tw-shadow-color), 0 2px 8px 0 var(--tw-shadow-color);-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);z-index:1}:host .calcite-card-container:active{--tw-shadow:0 1px 6px -1px rgba(0, 0, 0, 0.16), 0 1px 2px -1px rgba(0, 0, 0, 0.08);--tw-shadow-colored:0 1px 6px -1px var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);-webkit-transition-duration:75ms;transition-duration:75ms;z-index:1}.container{display:-ms-flexbox;display:flex;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-direction:column;flex-direction:column}:host([loading]) .calcite-card-container *:not(calcite-loader):not(.calcite-card-loader-container){pointer-events:none;opacity:0}:host([loading]) .calcite-card-loader-container{position:absolute;top:0px;right:0px;bottom:0px;left:0px;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center}.header,.footer{display:-ms-flexbox;display:flex;padding-left:0.75rem;padding-right:0.75rem;padding-top:0.75rem;padding-bottom:0.25rem}.header{-ms-flex-direction:column;flex-direction:column}.footer{margin-top:auto;-ms-flex-direction:row;flex-direction:row;-ms-flex-line-pack:justify;align-content:space-between;-ms-flex-pack:justify;justify-content:space-between;padding-left:0.75rem;padding-right:0.75rem;padding-top:0.25rem;padding-bottom:0.75rem}.card-content{padding:0.75rem;font-size:var(--calcite-font-size--2);line-height:1.375;color:var(--calcite-ui-text-3)}:host([selectable]) .calcite-card-container:active{--tw-shadow:0 1px 6px -1px rgba(0, 0, 0, 0.16), 0 1px 2px -1px rgba(0, 0, 0, 0.08);--tw-shadow-colored:0 1px 6px -1px var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host([selected]) .calcite-card-container{border-color:var(--calcite-ui-brand)}slot[name=title]::slotted(*),*::slotted([slot=title]){margin:0px;font-size:var(--calcite-font-size--1);line-height:1.375;font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-1)}slot[name=subtitle]::slotted(*),*::slotted([slot=subtitle]){margin:0px;margin-top:0.5rem;font-size:var(--calcite-font-size--2);line-height:1.375;font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-2)}slot[name=thumbnail]::slotted(img),img::slotted([slot=thumbnail]){min-width:100%;max-width:100%}slot[name=footer-leading]::slotted(*),*::slotted([slot=footer-leading]){-ms-flex-item-align:center;align-self:center;font-size:var(--calcite-font-size--2);line-height:1.375;-webkit-margin-end:auto;margin-inline-end:auto}slot[name=footer-trailing]::slotted(*),*::slotted([slot=footer-trailing]){-ms-flex-item-align:center;align-self:center;font-size:var(--calcite-font-size--2);line-height:1.375}.thumbnail-wrapper{font-size:var(--calcite-font-size-0);line-height:1.375}.checkbox-wrapper{position:absolute;margin:0px;padding:0px;top:0.5rem;inset-inline-end:0.5rem}";
  34. const Card = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  35. constructor() {
  36. super();
  37. this.__registerHost();
  38. this.__attachShadow();
  39. this.calciteCardSelect = createEvent(this, "calciteCardSelect", 7);
  40. //--------------------------------------------------------------------------
  41. //
  42. // Public Properties
  43. //
  44. //--------------------------------------------------------------------------
  45. /** When true, the cards content is waiting to be loaded. This state shows a busy indicator.*/
  46. this.loading = false;
  47. /** Indicates whether the card is selected. */
  48. this.selected = false;
  49. /** Indicates whether the card is selectable. */
  50. this.selectable = false;
  51. /** string to override English loading text
  52. * @default "Loading"
  53. */
  54. this.intlLoading = TEXT.loading;
  55. /** string to override English select text for checkbox when selectable is true
  56. * @default "Select"
  57. */
  58. this.intlSelect = TEXT.select;
  59. /** string to override English deselect text for checkbox when selectable is true
  60. * @default "Deselect"
  61. */
  62. this.intlDeselect = TEXT.deselect;
  63. //--------------------------------------------------------------------------
  64. //
  65. // Private State/Props
  66. //
  67. //--------------------------------------------------------------------------
  68. //--------------------------------------------------------------------------
  69. //
  70. // Private Methods
  71. //
  72. //--------------------------------------------------------------------------
  73. this.cardSelectClick = () => {
  74. this.selectCard();
  75. };
  76. this.cardSelectKeyDown = (e) => {
  77. switch (e.key) {
  78. case " ":
  79. case "Enter":
  80. this.selectCard();
  81. e.preventDefault();
  82. break;
  83. }
  84. };
  85. }
  86. // --------------------------------------------------------------------------
  87. //
  88. // Lifecycle
  89. //
  90. // --------------------------------------------------------------------------
  91. connectedCallback() {
  92. connectConditionalSlotComponent(this);
  93. }
  94. disonnectedCallback() {
  95. disconnectConditionalSlotComponent(this);
  96. }
  97. render() {
  98. return (h("div", { class: "calcite-card-container" }, this.loading ? (h("div", { class: "calcite-card-loader-container" }, h("calcite-loader", { active: true, label: this.intlLoading }))) : null, h("section", { "aria-busy": toAriaBoolean(this.loading), class: { [CSS.container]: true } }, this.selectable ? this.renderCheckbox() : null, this.renderThumbnail(), this.renderHeader(), h("div", { class: "card-content" }, h("slot", null)), this.renderFooter())));
  99. }
  100. selectCard() {
  101. this.selected = !this.selected;
  102. this.calciteCardSelect.emit();
  103. }
  104. renderThumbnail() {
  105. return getSlotted(this.el, SLOTS.thumbnail) ? (h("div", { class: CSS.thumbnailWrapper, key: "thumbnail-wrapper" }, h("slot", { name: SLOTS.thumbnail }))) : null;
  106. }
  107. renderCheckbox() {
  108. const checkboxLabel = this.selected ? this.intlDeselect : this.intlSelect;
  109. return (h("calcite-label", { class: CSS.checkboxWrapper, onClick: this.cardSelectClick, onKeyDown: this.cardSelectKeyDown }, h("calcite-checkbox", { checked: this.selected, label: checkboxLabel })));
  110. }
  111. renderHeader() {
  112. const { el } = this;
  113. const title = getSlotted(el, SLOTS.title);
  114. const subtitle = getSlotted(el, SLOTS.subtitle);
  115. const hasHeader = title || subtitle;
  116. return hasHeader ? (h("header", { class: CSS.header }, h("slot", { name: SLOTS.title }), h("slot", { name: SLOTS.subtitle }))) : null;
  117. }
  118. renderFooter() {
  119. const { el } = this;
  120. const leadingFooter = getSlotted(el, SLOTS.footerLeading);
  121. const trailingFooter = getSlotted(el, SLOTS.footerTrailing);
  122. const hasFooter = leadingFooter || trailingFooter;
  123. return hasFooter ? (h("footer", { class: CSS.footer }, h("slot", { name: SLOTS.footerLeading }), h("slot", { name: SLOTS.footerTrailing }))) : null;
  124. }
  125. get el() { return this; }
  126. static get style() { return cardCss; }
  127. }, [1, "calcite-card", {
  128. "loading": [516],
  129. "selected": [1540],
  130. "selectable": [516],
  131. "intlLoading": [1, "intl-loading"],
  132. "intlSelect": [1, "intl-select"],
  133. "intlDeselect": [1, "intl-deselect"]
  134. }]);
  135. function defineCustomElement$1() {
  136. if (typeof customElements === "undefined") {
  137. return;
  138. }
  139. const components = ["calcite-card", "calcite-checkbox", "calcite-label", "calcite-loader"];
  140. components.forEach(tagName => { switch (tagName) {
  141. case "calcite-card":
  142. if (!customElements.get(tagName)) {
  143. customElements.define(tagName, Card);
  144. }
  145. break;
  146. case "calcite-checkbox":
  147. if (!customElements.get(tagName)) {
  148. defineCustomElement$4();
  149. }
  150. break;
  151. case "calcite-label":
  152. if (!customElements.get(tagName)) {
  153. defineCustomElement$3();
  154. }
  155. break;
  156. case "calcite-loader":
  157. if (!customElements.get(tagName)) {
  158. defineCustomElement$2();
  159. }
  160. break;
  161. } });
  162. }
  163. defineCustomElement$1();
  164. const CalciteCard = Card;
  165. const defineCustomElement = defineCustomElement$1;
  166. export { CalciteCard, defineCustomElement };