UNPKG

@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

83 lines (77 loc) 3.75 kB
'use strict'; var index = require('./index-CtEGR9Z7.js'); var baseComponent = require('./base-component-Dx-Crsr_.js'); var utils = require('./utils-B2oo-h7a.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) { index.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() { baseComponent.handleShadowDOMStyles(this.el); this.inheritedAttributes = Object.assign(Object.assign({}, utils.inheritAriaAttributes(this.el)), utils.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 utils.sanitizeUrl(trimmedHref); } render() { const sanitizedHref = this.getHrefAttribute(); return (index.h(index.Host, { key: '22c340bcfde4e205d6ced4597e6404a2b08e8686' }, index.h("a", Object.assign({ key: '4925c2396ae4e7c7a86cf3b260370e5ef44aed7b', class: this.getClasses(), href: sanitizedHref, rel: this.getRelAttribute(), target: this.target }, this.inheritedAttributes), index.h("slot", { key: 'bbdddec44e7ab8dd94e7504739565dc6fd18a49e' })))); } get el() { return index.getElement(this); } }; ModusWcLink.style = modusWcLinkCss; exports.modus_wc_link = ModusWcLink;