@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
278 lines (270 loc) • 13.6 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import { r as registerInstance, h, H as Host, g as getElement } from './index-BQlHOxik.js';
import { _ as __decorate } from './tslib.es6-QNbPBOk5.js';
import { B as BaseWebComponent } from './variant-quote-y0Z1TRdz.js';
import { I as IconFC } from './component-DzaT2WlJ.js';
import { T as TooltipFC } from './component-Dh0cPCxF.js';
import { T as TooltipController } from './controller-Bdve6A-Q.js';
import { b as watchValidator, g as watchString, M as setEventTarget, j as devHint } from './common-Cx_AGO_M.js';
import { S as SpanFC, s as showExpertSlot } from './component-DvjvBJeK.js';
import { v as validateAccessKey, a as validateAccessAndShortKey, b as validateShortKey, c as validateTabIndex } from './access-and-short-key-D734WtlX.js';
import { v as validateAriaControls, a as validateAriaDescription, b as validateAriaExpanded, c as validateAlternativeButtonLinkRole } from './aria-expanded-hGdEA1jy.js';
import { v as validateCustomClass } from './custom-class-DlT-QmWF.js';
import { v as validateDisabled } from './disabled-gyBUQRnY.js';
import { v as validateHideLabel } from './hide-label-6Bx1MH20.js';
import { v as validateHref } from './href-Dp4go7zq.js';
import { v as validateIcons } from './icons-oAzMYWgV.js';
import { v as validateInline } from './inline-DnwpECF8.js';
import { a as validateLabelWithExpertSlot } from './label-Fyi30H9j.js';
import { v as validateTooltipAlign } from './tooltip-align-mwhvx9nK.js';
import { v as validateVariantClassName } from './variant-class-name-BCcQYpIV.js';
import { b as directFocus, e as directClick, c as createCtaRef } from './element-interaction-Bv-mPSBn.js';
import { d as dispatchDomEvent, K as KolEvent } from './events-VVvk1win.js';
import { o as onLocationChange } from './ariaCurrentService-YoLNpD5S.js';
import { t as translate } from './i18n-Br16IAnY.js';
import { c as clsx } from './clsx-COFh-Vc8.js';
import './normalizers-m3s9sgmq.js';
import './_Uint8Array-kJHDjtoP.js';
import './isArray-CcrBs4JM.js';
import './bem-registry-CWvl2xho.js';
import './align-floating-elements-D5XJiLiU.js';
import './tooltip-open-tracking-D3tCiiGP.js';
import './align-DxZmRFcp.js';
import './label-KTv-zMW0.js';
import './base-controller-CXhqh4cR.js';
import './element-focus-CRwW4N4R.js';
import './i18n-B2d_exHc.js';
const ariaCurrentValuePropTypeOptions = ['date', 'location', 'page', 'step', 'time', 'true', 'false'];
const validateAriaCurrentValue = (component, value) => {
watchValidator(component, `_ariaCurrentValue`, (value) => typeof value === 'string' && ariaCurrentValuePropTypeOptions.includes(value), new Set([`AriaCurrentValue {${ariaCurrentValuePropTypeOptions.join(', ')}`]), value, {
defaultValue: 'page',
});
};
const validateAriaOwns = (component, value) => {
watchString(component, '_ariaOwns', value, {
defaultValue: undefined,
});
};
const validateDownload = (component, value) => {
watchString(component, '_download', value);
};
const validateLinkCallbacks = (component, value) => {
if (typeof value === 'object' && typeof (value === null || value === void 0 ? void 0 : value.onClick) === 'function') {
component.state = Object.assign(Object.assign({}, component.state), { _on: value });
}
};
const validateLinkTarget = (component, value) => {
watchString(component, '_target', value);
};
const KolLinkWc = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.ctaRef = createCtaRef();
this.tooltipCtrl = new TooltipController(BaseWebComponent.stateLess);
this.translateOpenLinkInTab = translate('kol-open-link-in-tab');
this.onClick = (event) => {
var _a, _b;
this.tooltipCtrl.hideTooltip();
if (this.state._disabled === true) {
event.preventDefault();
}
else {
if (typeof ((_a = this.state._on) === null || _a === void 0 ? void 0 : _a.onClick) === 'function') {
setEventTarget(event, this.ctaRef.el);
(_b = this.state._on) === null || _b === void 0 ? void 0 : _b.onClick(event, this.state._href);
}
if (this.host) {
dispatchDomEvent(this.host, KolEvent.click, this.state._href);
}
}
};
this.getRenderValues = () => {
const isExternal = typeof this.state._target === 'string' && this.state._target !== '_self';
const tagAttrs = {
href: typeof this.state._href === 'string' && this.state._href.length > 0 ? this.state._href : 'javascript:void(0);',
target: typeof this.state._target === 'string' && this.state._target.length > 0 ? this.state._target : undefined,
rel: isExternal ? 'noopener' : undefined,
download: typeof this.state._download === 'string' ? this.state._download : undefined,
};
if (this.state._hideLabel === true && !this.state._label) {
devHint(`[KolLink] An aria-label must be set when _hide-label is set.`);
}
return { isExternal, tagAttrs };
};
this._disabled = false;
this._hideLabel = false;
this._inline = true;
this._tooltipAlign = 'right';
this.state = {
_ariaCurrentValue: 'page',
_href: '',
_icons: {},
};
}
async focus() { }
async click() { }
render() {
var _a;
const { isExternal, tagAttrs } = this.getRenderValues();
const hasExpertSlot = showExpertSlot(this.state._label);
const ariaDescription = (_a = this.state._ariaDescription) === null || _a === void 0 ? void 0 : _a.trim();
return (h(Host, { key: '4ec894cf85b4e39361eb7001a0bb073a07527416' }, h("a", Object.assign({ key: '92604427272ad2f3d676ad375e18279979fd70f3', ref: this.ctaRef }, tagAttrs, { accessKey: this.state._accessKey, "aria-current": this.state._ariaCurrent, "aria-controls": this.state._ariaControls, "aria-description": ariaDescription || undefined, "aria-disabled": this.state._disabled ? 'true' : undefined, "aria-expanded": typeof this.state._ariaExpanded === 'boolean' ? String(this.state._ariaExpanded) : undefined, "aria-owns": this.state._ariaOwns, "aria-label": this.state._hideLabel && typeof this.state._label === 'string'
? `${this.state._label}${isExternal ? ` (${this.translateOpenLinkInTab})` : ''}`
: undefined, "aria-keyshortcuts": this.state._shortKey, class: clsx('kol-link', {
'kol-link--disabled': this.state._disabled === true,
'kol-link--external-link': isExternal,
'kol-link--hide-label': this.state._hideLabel === true,
[`kol-link--${this.state._variant}`]: this.state._variant !== undefined,
'kol-link--inline': this.state._inline === true,
'kol-link--standalone': this.state._inline === false,
[this.state._customClass]: this.state._variant === 'custom' && typeof this.state._customClass === 'string' && this.state._customClass.length > 0,
}) }, this.state._on, { onClick: this.onClick, onKeyPress: this.onClick, role: this.state._role, tabIndex: this.state._disabled ? -1 : this.state._tabIndex }), h(SpanFC, { key: '35b2e3835032e2e906c0513d0cd859c0ab5b241f', class: "kol-link__text", badgeText: this.state._accessKey || this.state._shortKey, icons: this.state._icons, hideLabel: this.state._hideLabel, label: hasExpertSlot ? '' : this.state._label || this.state._href }, h("slot", { key: '499674edbdda752d1c2718ec4cea4574db4eb7ad', name: "expert", slot: "expert" })), isExternal && (h(IconFC, { key: 'edbebe0db35b755c1c2eaaa93969b25d19dc3fd6', class: "kol-link__icon", label: this.state._hideLabel ? '' : this.translateOpenLinkInTab, icons: 'kolicon-link-external', "aria-hidden": this.state._hideLabel }))), this.state._hideLabel === true && !hasExpertSlot && (h("div", { key: '881fe1237ddae06da94ea578fbe96211b0f0f2e8', class: "kol-link__tooltip" }, h(TooltipFC, { key: 'e5553e15922cc7f41999f05b5539e4f93113ac84', badgeText: this.state._accessKey || this.state._shortKey || '', label: typeof this.state._label === 'string' ? this.state._label : typeof this.state._href === 'string' ? this.state._href : '', id: this.tooltipCtrl.getRenderProp('id'), refFloating: this.tooltipCtrl.setTooltipElementRef })))));
}
validateAccessKey(value) {
validateAccessKey(this, value);
validateAccessAndShortKey(value, this._shortKey);
}
validateAriaCurrentValue(value) {
validateAriaCurrentValue(this, value);
}
validateAriaControls(value) {
validateAriaControls(this, value);
}
validateAriaDescription(value) {
validateAriaDescription(this, value);
}
validateAriaExpanded(value) {
validateAriaExpanded(this, value);
}
validateAriaOwns(value) {
validateAriaOwns(this, value);
}
validateCustomClass(value) {
validateCustomClass(this, value);
}
validateDisabled(value) {
validateDisabled(this, value);
}
validateDownload(value) {
validateDownload(this, value);
}
validateHideLabel(value) {
validateHideLabel(this, value);
}
validateHref(value) {
validateHref(this, value, {
required: true,
});
}
validateIcons(value) {
validateIcons(this, value);
}
validateInline(value) {
validateInline(this, value, {
defaultValue: true,
});
}
validateLabel(value) {
validateLabelWithExpertSlot(this, value);
this.tooltipCtrl.watchLabel(typeof value === 'string' ? value : undefined);
}
validateOn(value) {
validateLinkCallbacks(this, value);
}
validateRole(value) {
validateAlternativeButtonLinkRole(this, value);
}
validateShortKey(value) {
validateShortKey(this, value);
validateAccessAndShortKey(this._accessKey, value);
}
validateTabIndex(value) {
validateTabIndex(this, value);
}
validateTarget(value) {
validateLinkTarget(this, value);
}
validateTooltipAlign(value) {
validateTooltipAlign(this, value);
this.tooltipCtrl.watchAlign(value);
}
validateVariantClassName(value) {
validateVariantClassName(this, value);
}
componentWillLoad() {
this.validateAccessKey(this._accessKey);
this.validateAriaCurrentValue(this._ariaCurrentValue);
this.validateAriaControls(this._ariaControls);
this.validateAriaDescription(this._ariaDescription);
this.validateAriaExpanded(this._ariaExpanded);
this.validateAriaOwns(this._ariaOwns);
this.validateCustomClass(this._customClass);
this.validateDisabled(this._disabled);
this.validateDownload(this._download);
this.validateHideLabel(this._hideLabel);
this.validateHref(this._href);
this.validateIcons(this._icons);
this.validateInline(this._inline);
this.validateLabel(this._label);
this.validateOn(this._on);
this.validateRole(this._role);
this.validateShortKey(this._shortKey);
this.validateTabIndex(this._tabIndex);
this.validateTarget(this._target);
this.validateTooltipAlign(this._tooltipAlign);
this.validateVariantClassName(this._variant);
this.unsubscribeOnLocationChange = onLocationChange((location) => {
this.state._ariaCurrent = location === this.state._href ? this.state._ariaCurrentValue : undefined;
});
validateAccessAndShortKey(this._accessKey, this._shortKey);
this.tooltipCtrl.componentWillLoad({
label: typeof this.state._label === 'string' ? this.state._label : typeof this.state._href === 'string' ? this.state._href : '',
align: this._tooltipAlign,
});
}
componentDidRender() {
if (this.ctaRef.el) {
this.tooltipCtrl.syncListeners(undefined, this.ctaRef.el, true);
}
}
disconnectedCallback() {
if (this.unsubscribeOnLocationChange) {
this.unsubscribeOnLocationChange();
}
this.tooltipCtrl.destroy();
}
get host() { return getElement(this); }
static get watchers() { return {
"_accessKey": ["validateAccessKey"],
"_ariaCurrentValue": ["validateAriaCurrentValue"],
"_ariaControls": ["validateAriaControls"],
"_ariaDescription": ["validateAriaDescription"],
"_ariaExpanded": ["validateAriaExpanded"],
"_ariaOwns": ["validateAriaOwns"],
"_customClass": ["validateCustomClass"],
"_disabled": ["validateDisabled"],
"_download": ["validateDownload"],
"_hideLabel": ["validateHideLabel"],
"_href": ["validateHref"],
"_icons": ["validateIcons"],
"_inline": ["validateInline"],
"_label": ["validateLabel"],
"_on": ["validateOn"],
"_role": ["validateRole"],
"_shortKey": ["validateShortKey"],
"_tabIndex": ["validateTabIndex"],
"_target": ["validateTarget"],
"_tooltipAlign": ["validateTooltipAlign"],
"_variant": ["validateVariantClassName"]
}; }
};
__decorate([
directFocus('ctaRef')
], KolLinkWc.prototype, "focus", null);
__decorate([
directClick('ctaRef')
], KolLinkWc.prototype, "click", null);
export { KolLinkWc as kol_link_wc };
//# sourceMappingURL=kol-link-wc.entry.js.map