@trimble-oss/moduswebcomponents
Version:
Modus Web Components is a modern, accessible UI library built with Stencil JS that provides reusable web components following Trimble's Modus design system. This updated version focuses on improved flexibility, enhanced theming options, comprehensive cust
159 lines (158 loc) • 6.5 kB
JavaScript
import { h, Host } from "@stencil/core";
import { convertPropsToClasses } from "./modus-wc-card.tailwind";
import { inheritAriaAttributes } from "../utils";
/**
* A customizable card component used to group and display content in a way that is easily readable
*/
export class ModusWcCard {
constructor() {
this.inheritedAttributes = {};
/** Makes any \<figure> in the 'header' slot cover the background */
this.backgroundFigure = false;
/** Adds a hard border to the card */
this.bordered = false;
/** Custom CSS class to apply */
this.customClass = '';
/** Determines how the card is laid out */
this.layout = 'vertical';
/** Determines if the interior padding is compact or not */
this.padding = 'normal';
}
componentWillLoad() {
this.inheritedAttributes = inheritAriaAttributes(this.el);
}
getClasses() {
const classList = ['modus-wc-card modus-wc-rounded-card'];
const propClasses = convertPropsToClasses({
bordered: this.bordered,
fullImage: this.backgroundFigure,
layout: this.layout,
padding: this.padding,
});
// The order CSS classes are added matters to CSS specificity
if (propClasses)
classList.push(propClasses);
if (this.customClass)
classList.push(this.customClass);
return classList.join(' ');
}
render() {
return (h(Host, { key: 'ca2b66643d841254021b36a02cc009e0287547f9' }, h("article", Object.assign({ key: 'e5cfc8a5cc1d81f0f2924a596c88bb72186b66ad', class: this.getClasses(), tabindex: -1 }, this.inheritedAttributes), h("slot", { key: 'bb24bca92c338faa1d7768d11707f88620f8e9dd', name: "header" }), h("div", { key: '153d844a35591665a67b31e0f9938aa87b855fd0', class: "modus-wc-card-body" }, h("div", { key: '1a32e26e9b06c67ccf2fc067455365d3a8a59f4c', class: "modus-wc-card-title" }, h("slot", { key: 'df11f9713f650008850fe4af85f22b5d0f2da14e', name: "title" })), h("div", { key: 'e9d8c639387b70fab75e482e7a84e8e3078141b9', class: "modus-wc-card-subtitle" }, h("slot", { key: '56bb3d18aad738ed11249c7c3a12fd6aeedee389', name: "subtitle" })), h("slot", { key: '5a0a22778a3c36f4d28eb4d560e35e937e39377e' }), " ", h("div", { key: '671978aedd0cee74ed04c726e2ca4d71b77ea837', class: "modus-wc-card-actions" }, h("slot", { key: '6792bcebe07fbe000521b70ec3dd731976f4c99c', name: "actions" }))), h("slot", { key: 'cfb58923ff84b64540ed6d02e21855844d0fb42e', name: "footer" }))));
}
static get is() { return "modus-wc-card"; }
static get originalStyleUrls() {
return {
"$": ["modus-wc-card.scss"]
};
}
static get styleUrls() {
return {
"$": ["modus-wc-card.css"]
};
}
static get properties() {
return {
"backgroundFigure": {
"type": "boolean",
"attribute": "background-figure",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Makes any \\<figure> in the 'header' slot cover the background"
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "false"
},
"bordered": {
"type": "boolean",
"attribute": "bordered",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Adds a hard border to the card"
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "false"
},
"customClass": {
"type": "string",
"attribute": "custom-class",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Custom CSS class to apply"
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"layout": {
"type": "string",
"attribute": "layout",
"mutable": false,
"complexType": {
"original": "'vertical' | 'horizontal'",
"resolved": "\"horizontal\" | \"vertical\" | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Determines how the card is laid out"
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'vertical'"
},
"padding": {
"type": "string",
"attribute": "padding",
"mutable": false,
"complexType": {
"original": "'normal' | 'compact'",
"resolved": "\"compact\" | \"normal\" | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Determines if the interior padding is compact or not"
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'normal'"
}
};
}
static get elementRef() { return "el"; }
}