@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
165 lines (164 loc) • 5.87 kB
JavaScript
import { h, Host } from "@stencil/core";
import { convertPropsToClasses } from "./modus-wc-avatar.tailwind";
import { inheritAriaAttributes } from "../utils";
/**
* A customizable avatar component used to create avatars with different images.
*/
export class ModusWcAvatar {
constructor() {
this.inheritedAttributes = {};
/** Custom CSS class to apply to the inner div. */
this.customClass = '';
/** The location of the image. */
this.imgSrc = '';
// TODO - add placeholder support (need UX logic)
/** The shape of the avatar. */
this.shape = 'circle';
/** The size of the avatar. */
this.size = 'md';
}
componentWillLoad() {
if (!this.alt || !this.el.ariaLabel) {
this.el.ariaLabel = this.el.ariaLabel || `Avatar ${this.alt || 'image'}`;
this.alt = this.alt || 'Avatar image';
}
this.inheritedAttributes = inheritAriaAttributes(this.el);
}
getClasses() {
const classList = [];
const propClasses = convertPropsToClasses({
shape: this.shape,
size: this.size,
});
// 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: '74b2dc1cfcb9d73281d7ad3fea109a113254e52a' }, h("div", Object.assign({ key: '2429d8991e4b8467e432210331481f23ce19cb9f', class: "modus-wc-avatar", tabindex: -1 }, this.inheritedAttributes), h("div", { key: 'dc7a02e2a442a1d0dd50f946be8f45657ee1f7aa', class: this.getClasses() }, h("img", { key: 'b18286cf860566cc2176af6df9f8e38ccb488d91', src: this.imgSrc, alt: this.alt })))));
}
static get is() { return "modus-wc-avatar"; }
static get originalStyleUrls() {
return {
"$": ["modus-wc-avatar.scss"]
};
}
static get styleUrls() {
return {
"$": ["modus-wc-avatar.css"]
};
}
static get properties() {
return {
"alt": {
"type": "string",
"attribute": "alt",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": true,
"optional": false,
"docs": {
"tags": [],
"text": "The image alt attribute for accessibility."
},
"getter": false,
"setter": false,
"reflect": 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 to the inner div."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"imgSrc": {
"type": "string",
"attribute": "img-src",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "The location of the image."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "''"
},
"shape": {
"type": "string",
"attribute": "shape",
"mutable": false,
"complexType": {
"original": "'circle' | 'square'",
"resolved": "\"circle\" | \"square\" | undefined",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The shape of the avatar."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'circle'"
},
"size": {
"type": "string",
"attribute": "size",
"mutable": false,
"complexType": {
"original": "DaisySize",
"resolved": "\"lg\" | \"md\" | \"sm\" | \"xs\" | undefined",
"references": {
"DaisySize": {
"location": "import",
"path": "../types",
"id": "src/components/types.ts::DaisySize"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The size of the avatar."
},
"getter": false,
"setter": false,
"reflect": false,
"defaultValue": "'md'"
}
};
}
static get elementRef() { return "el"; }
}