@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
284 lines (277 loc) • 13.4 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
'use strict';
var index = require('./index-BrhW8s5h.js');
var tslib_es6 = require('./tslib.es6-Cm0ytgPY.js');
var common = require('./common-DPb6NWR4.js');
var component$1 = require('./component-BUJSMbIY.js');
var accessAndShortKey = require('./access-and-short-key-CspEpGOV.js');
var ariaExpanded = require('./aria-expanded-CVaHNiQi.js');
var customClass = require('./custom-class-6BetCmYR.js');
var disabled = require('./disabled-GY6LfYNH.js');
var hideLabel = require('./hide-label-BnMTmbm4.js');
var icons = require('./icons-C4O3H4TU.js');
var inline = require('./inline-D-XZg3UD.js');
var label = require('./label-8vcJJEVI.js');
var tooltipAlign = require('./tooltip-align-BeYhiCq6.js');
var variantClassName = require('./variant-class-name-BCWuCRd0.js');
var variantQuote = require('./variant-quote-DpNzmCtr.js');
var component = require('./component-kXVnT0Wy.js');
var controller = require('./controller-DiB9pVnb.js');
var clsx = require('./clsx-Bm_HQUnh.js');
var elementInteraction = require('./element-interaction-CXkAVgKs.js');
var events = require('./events-Jc2wxPjR.js');
var controller$1 = require('./controller-BMDxsRHs.js');
var associated_controller = require('./associated.controller-DLy6rpeW.js');
require('./bem-registry-DevvgGUu.js');
require('./component-CuHGwo27.js');
require('./isArray-BOIOdEQh.js');
require('./align-B8NMKvjk.js');
require('./normalizers-BCLslVaT.js');
require('./_Uint8Array-BAQUGozM.js');
require('./align-floating-elements-BkrTeMF3.js');
require('./tooltip-open-tracking-Ba0udJRU.js');
require('./label-DRrPbj-j.js');
require('./base-controller-DAzsTqX9.js');
require('./element-focus-DeVevBcF.js');
require('./component-names-5KS_pYRF.js');
require('./bootstrap-ByVQ9oF5.js');
require('./i18n-CgUN6lev.js');
const validateAriaSelected = (component, value) => {
common.watchBoolean(component, '_ariaSelected', value);
};
const validateButtonCallbacks = (component, value) => {
common.watchValidator(component, `_on`, (value) => typeof value === 'object' && value !== null, new Set(['ButtonCallbacksPropType {Events.onClick, Events.onMouseDown, Events.onFocus, Events.onBlur}']), value);
};
const buttonTypePropTypeOptions = ['button', 'reset', 'submit'];
const validateButtonType = (component, value) => {
common.watchValidator(component, `_type`, (value) => typeof value === 'string' && buttonTypePropTypeOptions.includes(value), new Set([`KoliBriButtonType {${buttonTypePropTypeOptions.join(', ')}`]), value);
};
const KolButtonWc = class {
async focus() { }
async click() { }
render() {
var _a;
const hasExpertSlot = component$1.showExpertSlot(this.state._label);
const ariaDescription = (_a = this.state._ariaDescription) === null || _a === void 0 ? void 0 : _a.trim();
const badgeText = this.state._accessKey || this.state._shortKey;
const isDisabled = this.state._disabled === true;
const hideLabel = this.state._hideLabel === true;
return (index.h(index.Host, { key: '16666b7bbc5590d87a4278b11b42eed9305905d7' }, index.h("button", { key: 'cbe00d5dd3039399bca51581b4610a7628829f62', ref: this.ctaRef, accessKey: this.state._accessKey, "aria-controls": this.state._ariaControls, "aria-description": ariaDescription || undefined, "aria-expanded": common.mapBoolean2String(this.state._ariaExpanded), "aria-haspopup": this._ariaHasPopup, "aria-keyshortcuts": this.state._shortKey, "aria-label": hideLabel && typeof this.state._label === 'string' && this.state._label.length > 0 ? this.state._label : undefined, "aria-selected": common.mapStringOrBoolean2String(this.state._ariaSelected), class: clsx.clsx('kol-button', {
'kol-button--disabled': isDisabled,
[`kol-button--${this.state._variant}`]: this.state._variant !== 'custom',
'kol-button--inline': this.state._inline === true,
'kol-button--standalone': this.state._inline === false,
'kol-button--hide-label': hideLabel,
[this.state._customClass]: typeof this.state._customClass === 'string' && this.state._customClass.length > 0,
}), disabled: isDisabled, id: this.state._id, name: this.state._name, onClick: this.onClick, onMouseDown: this.onMouseDown, onFocus: this.onFocus, onBlur: this.onBlur, role: this.state._role, tabIndex: this.state._tabIndex, type: this.state._type }, index.h(component$1.SpanFC, { key: '0bcd901be3e67d7d49d3edd0e2de43a46a09eb43', class: "kol-button__text", badgeText: badgeText, icons: this.state._icons, hideLabel: hideLabel, label: hasExpertSlot ? '' : this.state._label }, index.h("slot", { key: 'c60cec4abe221171e48dcc5cd5b4be2ad32ac03a', name: "expert", slot: "expert" }))), hideLabel && typeof this.state._label === 'string' && this.state._label.length > 0 && (index.h("div", { key: 'f8c1b2830178a37482cd1ae7b25e4186954c3195', class: "kol-button__tooltip" }, index.h(component.TooltipFC, { key: '3e6110b1ddf4188efd8546cd20635c9732940a5e', badgeText: badgeText || '', label: this.state._label, id: this.tooltipCtrl.getRenderProp('id'), refFloating: this.tooltipCtrl.setTooltipElementRef })))));
}
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.ctaRef = elementInteraction.createCtaRef();
this.tooltipCtrl = new controller.TooltipController(variantQuote.BaseWebComponent.stateLess);
this.onClick = (event) => {
var _a, _b;
event.stopPropagation();
this.tooltipCtrl.hideTooltip();
if (this.state._type === 'submit') {
controller$1.propagateSubmitEventToForm({
form: this.host});
}
else if (this.state._type === 'reset') {
controller$1.propagateResetEventToForm({
form: this.host});
}
else {
this.controller.setFormAssociatedValue(this.state._value);
if (typeof ((_a = this.state._on) === null || _a === void 0 ? void 0 : _a.onClick) === 'function') {
common.setEventTarget(event, this.ctaRef.el);
(_b = this.state._on) === null || _b === void 0 ? void 0 : _b.onClick(event, this.state._value);
}
}
if (this.host) {
events.dispatchDomEvent(this.host, events.KolEvent.click, this.state._value);
}
};
this.onMouseDown = (event) => {
var _a, _b, _c;
(_c = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a._on) === null || _b === void 0 ? void 0 : _b.onMouseDown) === null || _c === void 0 ? void 0 : _c.call(_b, event);
if (this.host) {
events.dispatchDomEvent(this.host, events.KolEvent.mousedown);
}
};
this.onFocus = (event) => {
var _a, _b, _c;
(_c = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a._on) === null || _b === void 0 ? void 0 : _b.onFocus) === null || _c === void 0 ? void 0 : _c.call(_b, event);
if (this.host) {
events.dispatchDomEvent(this.host, events.KolEvent.focus);
}
};
this.onBlur = (event) => {
var _a, _b, _c;
(_c = (_b = (_a = this.state) === null || _a === void 0 ? void 0 : _a._on) === null || _b === void 0 ? void 0 : _b.onBlur) === null || _c === void 0 ? void 0 : _c.call(_b, event);
if (this.host) {
events.dispatchDomEvent(this.host, events.KolEvent.blur);
}
};
this._disabled = false;
this._hideLabel = false;
this._inline = false;
this._tooltipAlign = 'top';
this._type = 'button';
this.state = {
_icons: {},
_label: '',
_on: {},
_type: 'button',
_variant: 'normal',
};
this.controller = new associated_controller.AssociatedInputController(this, 'button', this.host);
}
validateAccessKey(value) {
accessAndShortKey.validateAccessKey(this, value);
accessAndShortKey.validateAccessAndShortKey(value, this._shortKey);
}
validateAriaControls(value) {
ariaExpanded.validateAriaControls(this, value);
}
validateAriaDescription(value) {
ariaExpanded.validateAriaDescription(this, value);
}
validateAriaExpanded(value) {
ariaExpanded.validateAriaExpanded(this, value);
}
validateAriaSelected(value) {
validateAriaSelected(this, value);
}
validateCustomClass(value) {
customClass.validateCustomClass(this, value);
}
validateDisabled(value) {
disabled.validateDisabled(this, value);
}
validateHideLabel(value) {
hideLabel.validateHideLabel(this, value);
}
validateIcons(value) {
icons.validateIcons(this, value);
}
validateId(value) {
common.watchString(this, '_id', value);
}
validateInline(value) {
inline.validateInline(this, value, {
defaultValue: false,
});
}
validateLabel(value) {
label.validateLabelWithExpertSlot(this, value, {
required: true,
});
this.tooltipCtrl.watchLabel(typeof value === 'string' ? value : undefined);
}
validateName(value) {
this.controller.validateName(value);
}
validateOn(value) {
validateButtonCallbacks(this, value);
}
validateRole(value) {
ariaExpanded.validateAlternativeButtonLinkRole(this, value);
}
validateShortKey(value) {
accessAndShortKey.validateShortKey(this, value);
accessAndShortKey.validateAccessAndShortKey(this._accessKey, value);
}
validateSyncValueBySelector(value) {
this.controller.validateSyncValueBySelector(value);
}
validateTabIndex(value) {
accessAndShortKey.validateTabIndex(this, value);
}
validateTooltipAlign(value) {
tooltipAlign.validateTooltipAlign(this, value);
this.tooltipCtrl.watchAlign(value);
}
validateType(value) {
validateButtonType(this, value);
}
validateValue(value) {
common.setState(this, '_value', value);
this.controller.setFormAssociatedValue(this.state._value);
}
validateVariant(value) {
variantClassName.validateVariantClassName(this, value);
}
componentWillLoad() {
this.validateAccessKey(this._accessKey);
this.validateAriaControls(this._ariaControls);
this.validateAriaDescription(this._ariaDescription);
this.validateAriaExpanded(this._ariaExpanded);
this.validateAriaSelected(this._ariaSelected);
this.validateCustomClass(this._customClass);
this.validateDisabled(this._disabled);
this.validateHideLabel(this._hideLabel);
this.validateIcons(this._icons);
this.validateId(this._id);
this.validateInline(this._inline);
this.validateLabel(this._label);
this.validateName(this._name);
this.validateOn(this._on);
this.validateRole(this._role);
this.validateShortKey(this._shortKey);
this.validateSyncValueBySelector(this._syncValueBySelector);
this.validateTabIndex(this._tabIndex);
this.validateTooltipAlign(this._tooltipAlign);
this.validateType(this._type);
this.validateValue(this._value);
this.validateVariant(this._variant);
accessAndShortKey.validateAccessAndShortKey(this._accessKey, this._shortKey);
this.tooltipCtrl.componentWillLoad({
label: typeof this.state._label === 'string' ? this.state._label : '',
align: this._tooltipAlign,
});
}
componentDidRender() {
if (this.ctaRef.el) {
this.tooltipCtrl.syncListeners(undefined, this.ctaRef.el, true);
}
}
disconnectedCallback() {
this.tooltipCtrl.destroy();
}
get host() { return index.getElement(this); }
static get watchers() { return {
"_accessKey": ["validateAccessKey"],
"_ariaControls": ["validateAriaControls"],
"_ariaDescription": ["validateAriaDescription"],
"_ariaExpanded": ["validateAriaExpanded"],
"_ariaSelected": ["validateAriaSelected"],
"_customClass": ["validateCustomClass"],
"_disabled": ["validateDisabled"],
"_hideLabel": ["validateHideLabel"],
"_icons": ["validateIcons"],
"_id": ["validateId"],
"_inline": ["validateInline"],
"_label": ["validateLabel"],
"_name": ["validateName"],
"_on": ["validateOn"],
"_role": ["validateRole"],
"_shortKey": ["validateShortKey"],
"_syncValueBySelector": ["validateSyncValueBySelector"],
"_tabIndex": ["validateTabIndex"],
"_tooltipAlign": ["validateTooltipAlign"],
"_type": ["validateType"],
"_value": ["validateValue"],
"_variant": ["validateVariant"]
}; }
};
tslib_es6.__decorate([
elementInteraction.directFocus('ctaRef')
], KolButtonWc.prototype, "focus", null);
tslib_es6.__decorate([
elementInteraction.directClick('ctaRef')
], KolButtonWc.prototype, "click", null);
exports.kol_button_wc = KolButtonWc;
//# sourceMappingURL=kol-button-wc.entry.cjs.js.map