@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
163 lines (162 loc) • 6.8 kB
JavaScript
import { h, Host } from "@stencil/core";
import { convertPropsToClasses } from "./modus-wc-card.tailwind";
import { handleShadowDOMStyles } from "../base-component";
import { inheritAriaAttributes } from "../utils";
/**
* A customizable card component used to group and display content in a way that is easily readable.
*
* This component supports multiple `<slot>` elements including 'header' for images or custom content, 'title', 'subtitle', a default slot for main content, 'actions' for buttons or interactive elements, and 'footer'.
*/
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 the interior padding size */
this.padding = 'compact';
}
componentWillLoad() {
handleShadowDOMStyles(this.el, true);
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: '2bd530d739a71856714ed46e2772a8a85b5c7067' }, h("article", Object.assign({ key: 'e351aa543600dff1d6b167ff55d7a58423e4e077', class: this.getClasses(), tabindex: -1 }, this.inheritedAttributes), h("slot", { key: 'dae0870810ba669f93dcd51bbc6582a4526fac00', name: "header" }), h("div", { key: '6fefc0bfd64b1a5506dae7ba37784a7700960e5d', class: "modus-wc-card-body" }, h("div", { key: '29b989e5e957c9c8f12e230fd99f968d9eac58eb', class: "modus-wc-card-title" }, h("slot", { key: 'ef72977e5b29a7fee99e8fbd05b635ccba50fffe', name: "title" })), h("div", { key: '64091544637258f092240ee28b98e578c2cbd8aa', class: "modus-wc-card-subtitle" }, h("slot", { key: '335c5fadc770f622f1cedfd1af75e1ae3be1d598', name: "subtitle" })), h("slot", { key: '225b91c2035f2782b9ba65e4b49c985f962ad725' }), " ", h("div", { key: 'c154dfacdffb83c09a420d67c02ad15b4073e958', class: "modus-wc-card-actions" }, h("slot", { key: '386f07253453a5a9937597344db4d72ff2fda9b1', name: "actions" }))), h("slot", { key: '2f64d76f0909c0fd898a1359cdb3fab84dd7c208', 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": "'compact' | 'comfortable'",
"resolved": "\"comfortable\" | \"compact\" | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Determines the interior padding size"
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'compact'"
}
};
}
static get elementRef() { return "el"; }
}