@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
81 lines (76 loc) • 3.79 kB
JavaScript
import { r as registerInstance, h, e as Host, g as getElement } from './index-C1-Dpkp7.js';
import { h as handleShadowDOMStyles } from './base-component-tWS3Egrk.js';
import { i as inheritAriaAttributes, a as inheritAttributes, s as sanitizeUrl } from './utils-DN2BGzSQ.js';
const convertPropsToClasses = ({ color, underline, }) => {
let classes = '';
if (color) {
classes = `${classes} modus-wc-link-color-${color}`;
}
if (underline) {
switch (underline) {
case 'hover':
classes = `${classes} modus-wc-link-hover`;
break;
case 'none':
classes = `${classes} modus-wc-no-underline`;
break;
}
}
return classes.trim();
};
const modusWcLinkCss = "modus-wc-link a.modus-wc-link.modus-wc-link-color-primary{color:var(--modus-wc-color-primary)}modus-wc-link a.modus-wc-link.modus-wc-link-color-secondary{color:var(--modus-wc-color-secondary)}modus-wc-link a.modus-wc-link.modus-wc-link-color-tertiary{color:var(--modus-wc-color-base-inverted)}modus-wc-link a.modus-wc-link.modus-wc-link-color-success{color:var(--modus-wc-color-success)}modus-wc-link a.modus-wc-link.modus-wc-link-color-info{color:var(--modus-wc-color-info)}modus-wc-link a.modus-wc-link.modus-wc-link-color-warning{color:var(--modus-wc-color-warning)}modus-wc-link a.modus-wc-link.modus-wc-link-color-danger{color:var(--modus-wc-color-error)}modus-wc-link a.modus-wc-link.modus-wc-link-color-inherit{color:inherit}";
const ModusWcLink = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.inheritedAttributes = {};
/** The color of the link. */
this.color = 'primary';
/** Custom CSS class to apply to the link element. */
this.customClass = '';
/** The underline behavior of the link. */
this.underline = 'always';
}
componentWillLoad() {
handleShadowDOMStyles(this.el);
this.inheritedAttributes = Object.assign(Object.assign({}, inheritAriaAttributes(this.el)), inheritAttributes(this.el, ['title']));
}
getClasses() {
const classList = ['modus-wc-link'];
const propClasses = convertPropsToClasses({
color: this.color,
underline: this.underline,
});
if (propClasses)
classList.push(propClasses);
if (this.customClass)
classList.push(this.customClass);
return classList.join(' ');
}
getRelAttribute() {
var _a;
const relValues = new Set(((_a = this.rel) !== null && _a !== void 0 ? _a : '')
.split(/\s+/)
.map((value) => value.trim())
.filter(Boolean));
if (this.target === '_blank') {
relValues.add('noopener');
relValues.add('noreferrer');
}
return relValues.size > 0 ? Array.from(relValues).join(' ') : undefined;
}
getHrefAttribute() {
var _a;
const trimmedHref = (_a = this.href) === null || _a === void 0 ? void 0 : _a.trim();
if (!trimmedHref || trimmedHref === 'undefined' || trimmedHref === 'null') {
return undefined;
}
return sanitizeUrl(trimmedHref);
}
render() {
const sanitizedHref = this.getHrefAttribute();
return (h(Host, { key: '22c340bcfde4e205d6ced4597e6404a2b08e8686' }, h("a", Object.assign({ key: '4925c2396ae4e7c7a86cf3b260370e5ef44aed7b', class: this.getClasses(), href: sanitizedHref, rel: this.getRelAttribute(), target: this.target }, this.inheritedAttributes), h("slot", { key: 'bbdddec44e7ab8dd94e7504739565dc6fd18a49e' }))));
}
get el() { return getElement(this); }
};
ModusWcLink.style = modusWcLinkCss;
export { ModusWcLink as modus_wc_link };