@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
186 lines (180 loc) • 18.1 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { a as __rest } from './tslib.es6.js';
import { c as KolLinkWcTag, b as KolButtonWcTag } from './component-names.js';
import './common.js';
import { N as emptyStringByArrayHandler, o as objectObjectHandler, p as parseJson, s as setState } from './prop.validators.js';
import { v as validateLabel } from './label.js';
import { K as KeyboardKey } from './keyboard.js';
import { v as validateOrientation } from './orientation.js';
import { d as delegateFocus, b as setFocus, a as delegateClick, s as setClick } from './element-focus.js';
const validateToolbarItems = (component, value) => {
emptyStringByArrayHandler(value, () => {
objectObjectHandler(value, () => {
if (typeof value === 'undefined') {
value = [];
}
try {
value = parseJson(value);
}
catch (_a) {
}
if (Array.isArray(value) && value.every((items) => typeof items === 'object' && items !== null)) {
setState(component, '_items', value);
}
});
});
};
const defaultStyleCss = "@charset \"UTF-8\";\n/* forward the rem function */\n/*\n* This file defines the layer order for all CSS layers used in KoliBri.\n* The order is important as it determines the cascade priority.\n*\n* Layer order (lowest to highest priority):\n* 1. kol-a11y - Accessibility defaults and requirements\n* 2. kol-global - Global component styles and resets\n* 3. kol-component - Component-specific styles\n* 4. kol-theme-global - Theme-specific global styles\n* 5. kol-theme-component - Theme-specific component styles\n*/\n@layer kol-a11y, kol-global, kol-component, kol-theme-global, kol-theme-component;\n/*\n * This file contains all rules for accessibility.\n */\n@layer kol-a11y {\n :host {\n /*\n * Minimum size of interactive elements.\n */\n --a11y-min-size: calc(44 * 1rem / var(--kolibri-root-font-size, 16));\n /*\n * No element should be used without verifying the contrast ratio of its background and font colors.\n * By initially setting the background color to white and the font color to black,\n * the contrast ratio is ensured and explicit adjustment is forced.\n */\n color: black;\n background-color: white;\n /*\n * Verdana is an accessible font that can be used without requiring additional loading time.\n */\n font-family: Verdana;\n /*\n * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\n /*\n * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n /*\n * Text should be aligned left by default to provide a predictable starting point.\n */\n text-align: left;\n }\n * {\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n hyphens: auto;\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n word-break: break-word;\n }\n /*\n * All interactive elements should have a minimum size of to-rem(44).\n */\n /* input:not([type='checkbox'], [type='radio'], [type='range']), */\n /* option, */\n /* select, */\n /* textarea, */\n button,\n .kol-input .input {\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n }\n /*\n * Some interactive elements should not inherit the font-family and font-size.\n */\n a,\n button,\n h1,\n h2,\n h3,\n h4,\n h5,\n h6,\n input,\n option,\n select,\n textarea {\n /*\n * All elements should inherit the text color from his parent element.\n */\n color: inherit;\n /*\n * All elements should inherit the font family from his parent element.\n */\n font-family: inherit;\n /*\n * All elements should inherit the font size from his parent element.\n */\n font-size: inherit;\n /*\n * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\n /*\n * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n }\n /**\n * Sometimes we need the semantic element for accessibility reasons,\n * but we don't want to show it.\n *\n * - https://www.a11yproject.com/posts/how-to-hide-content/\n */\n .visually-hidden {\n position: fixed;\n top: 0;\n left: 0;\n width: 1px;\n height: 1px;\n overflow: hidden;\n white-space: nowrap;\n clip-path: inset(50%);\n }\n}\n@layer kol-global {\n /*\n * Dieses CSS stellt sicher, dass der Standard-Style\n * von A und Button resettet werden.\n */\n :is(a, button) {\n background-color: transparent;\n width: 100%;\n margin: 0;\n padding: 0;\n border: none;\n /* 100% needed for custom width from outside */\n }\n /*\n * Ensure elements with hidden attribute to be actually not visible\n * @see https://meowni.ca/hidden.is.a.lie.html\n */\n [hidden] {\n display: none !important;\n }\n .badge-text-hint {\n color: black;\n background-color: white;\n }\n}\n@layer kol-global {\n :host {\n /*\n * The max-width is needed to prevent the table from overflowing the\n * parent node, if the table is wider than the parent node.\n */\n max-width: 100%;\n font-size: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n }\n * {\n /*\n * We prefer to box-sizing: border-box for all elements.\n */\n box-sizing: border-box;\n }\n .kol-span {\n /* KolSpan is a layout component with icons in all directions and a label text in the middle. */\n display: flex;\n flex-flow: column;\n align-items: center;\n justify-content: center;\n /* The sub span in KolSpan is the horizontal span with icon left and right and the label text in the middle. */\n }\n .kol-span__container {\n display: flex;\n align-items: center;\n }\n a,\n button {\n cursor: pointer;\n }\n .kol-span .kol-span__label--hide-label .kol-span__label {\n display: none;\n }\n /* Reset browser agent style. */\n button:disabled {\n color: unset;\n }\n .disabled label,\n .disabled:focus-within label,\n [aria-disabled=true],\n [aria-disabled=true]:focus,\n [disabled],\n [disabled]:focus {\n outline: none;\n cursor: not-allowed;\n }\n [aria-disabled=true]:focus .kol-span,\n [disabled]:focus .kol-span {\n outline: none !important;\n }\n .hastooltip {\n z-index: 900 !important;\n }\n}\n@font-face {\n font-family: \"kolicons\";\n src: url(\"kolicons.eot?t=1780571516250\"); /* IE9*/\n src: url(\"kolicons.eot?t=1780571516250#iefix\") format(\"embedded-opentype\"), url(\"kolicons.woff2?t=1780571516250\") format(\"woff2\"), url(\"kolicons.woff?t=1780571516250\") format(\"woff\"), url(\"kolicons.ttf?t=1780571516250\") format(\"truetype\"), url(\"kolicons.svg?t=1780571516250#kolicons\") format(\"svg\"); /* iOS 4.1- */\n}\n@layer kol-component {\n [class^=kolicon-], [class*=\" kolicon-\"] {\n font-family: \"kolicons\";\n font-style: normal;\n font-weight: 400;\n line-height: 1em;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n }\n .kolicon-alert-error::before {\n content: \"\\ea01\";\n }\n .kolicon-alert-info::before {\n content: \"\\ea02\";\n }\n .kolicon-alert-success::before {\n content: \"\\ea03\";\n }\n .kolicon-alert-warning::before {\n content: \"\\ea04\";\n }\n .kolicon-check::before {\n content: \"\\ea05\";\n }\n .kolicon-chevron-double-left::before {\n content: \"\\ea06\";\n }\n .kolicon-chevron-double-right::before {\n content: \"\\ea07\";\n }\n .kolicon-chevron-down::before {\n content: \"\\ea08\";\n }\n .kolicon-chevron-left::before {\n content: \"\\ea09\";\n }\n .kolicon-chevron-right::before {\n content: \"\\ea0a\";\n }\n .kolicon-chevron-up::before {\n content: \"\\ea0b\";\n }\n .kolicon-cogwheel::before {\n content: \"\\ea0c\";\n }\n .kolicon-cross::before {\n content: \"\\ea0d\";\n }\n .kolicon-eye-closed::before {\n content: \"\\ea0e\";\n }\n .kolicon-eye::before {\n content: \"\\ea0f\";\n }\n .kolicon-house::before {\n content: \"\\ea10\";\n }\n .kolicon-kolibri::before {\n content: \"\\ea11\";\n }\n .kolicon-link-external::before {\n content: \"\\ea12\";\n }\n .kolicon-link::before {\n content: \"\\ea13\";\n }\n .kolicon-minus::before {\n content: \"\\ea14\";\n }\n .kolicon-plus::before {\n content: \"\\ea15\";\n }\n .kolicon-settings::before {\n content: \"\\ea16\";\n }\n .kolicon-sort-asc::before {\n content: \"\\ea17\";\n }\n .kolicon-sort-desc::before {\n content: \"\\ea18\";\n }\n .kolicon-sort-neutral::before {\n content: \"\\ea19\";\n }\n .kolicon-up::before {\n content: \"\\ea1a\";\n }\n .kolicon-version::before {\n content: \"\\ea1b\";\n }\n}\n@layer kol-component {\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-tooltip {\n display: contents;\n }\n .kol-tooltip__floating {\n opacity: 0;\n display: none;\n position: fixed;\n /* Avoid layout interference - see https://floating-ui.com/docs/computePosition */\n top: 0;\n left: 0;\n /* Can be used to specify the tooltip-width from the outside. Unset by default. */\n width: var(--kol-tooltip-width, max-content);\n min-width: calc(8 * 1rem / var(--kolibri-root-font-size, 16));\n max-width: 90vw;\n max-height: 90vh;\n animation-direction: normal;\n /* Can be used to specify the animation duration from the outside. 250ms by default. */\n animation-duration: var(--kolibri-tooltip-animation-duration, 250ms);\n animation-fill-mode: forwards;\n animation-iteration-count: 1;\n animation-timing-function: ease-in;\n }\n .kol-tooltip__floating.hide {\n animation-name: hideTooltip;\n }\n .kol-tooltip__floating.show {\n animation-name: showTooltip;\n }\n .kol-tooltip__arrow {\n transform: rotate(45deg);\n color: black;\n background-color: white;\n position: absolute;\n z-index: 999;\n width: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n height: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n }\n .kol-tooltip__content {\n color: black;\n background-color: white;\n position: relative;\n z-index: 1000;\n }\n @keyframes hideTooltip {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n display: none;\n }\n }\n @keyframes showTooltip {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n}\n@layer kol-component {\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n :host {\n display: inline-block;\n }\n .kol-link {\n display: flex;\n min-height: var(--a11y-min-size);\n font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n text-decoration-line: none;\n }\n .kol-link::before {\n /* Render zero-width character as first element to set the baseline correctly. */\n content: \"\";\n }\n .kol-link__text {\n flex: 1 0 100%;\n }\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n :host {\n display: inline-block;\n }\n .kol-button {\n display: flex;\n min-height: var(--a11y-min-size);\n font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n text-decoration-line: none;\n }\n .kol-button::before {\n /* Render zero-width character as first element to set the baseline correctly. */\n content: \"\";\n }\n .kol-button__text {\n flex: 1 0 100%;\n }\n .kol-toolbar {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n }\n .kol-toolbar--orientation-vertical {\n flex-direction: column;\n align-items: stretch;\n }\n .kol-toolbar--orientation-vertical .kol-span {\n align-items: flex-start;\n }\n .kol-toolbar:focus-within {\n outline: 1px solid;\n outline-offset: 2px;\n }\n}";
const KolToolbar$1 = proxyCustomElement(class KolToolbar extends HTMLElement {
constructor(registerHost) {
super();
if (registerHost !== false) {
this.__registerHost();
}
this.__attachShadow();
this.state = {
_label: '',
_items: [],
};
this.currentIndex = 0;
this.indexToElement = new Map();
this.renderItem = (raw, index) => {
const element = this.normalizeItem(raw);
const tabIndex = index === this.currentIndex && !(element === null || element === void 0 ? void 0 : element._disabled) ? 0 : -1;
const props = {
key: index,
class: 'button normal kol-toolbar__item',
_tabIndex: tabIndex,
_variant: 'normal',
};
const catchRef = (el) => {
if (el)
this.indexToElement.set(index, el);
};
return element.type === 'link' ? (h(KolLinkWcTag, Object.assign({}, props, element, { ref: catchRef }))) : (h(KolButtonWcTag, Object.assign({}, props, element, { ref: catchRef })));
};
}
async focus() {
const firstEnabledItem = this.indexToElement.get(this.currentIndex);
if (firstEnabledItem) {
return delegateFocus(this.host, () => setFocus(firstEnabledItem));
}
}
async click() {
const currentItem = this.indexToElement.get(this.currentIndex);
if (currentItem) {
return delegateClick(this.host, async () => setClick(currentItem));
}
}
normalizeItem(item) {
const { _icons, _disabled } = item, rest = __rest(item, ["_icons", "_disabled"]);
return Object.assign(Object.assign({}, rest), { _icons, _disabled });
}
render() {
return (h("div", { key: '275f13ac813c33395731de5b9073f1a3ab573734', class: `kol-toolbar kol-toolbar--orientation-${this.state._orientation}`, role: "toolbar", "aria-label": this.state._label }, this.state._items.map(this.renderItem)));
}
validateLabel(value) {
validateLabel(this, value);
}
validateItems(value) {
validateToolbarItems(this, value);
this.indexToElement.clear();
this.setFirstEnabledItemIndex();
}
validateOrientation(value) {
validateOrientation(this, value);
}
getCurrentToolbarItem(index) {
return typeof index === 'number' ? this.indexToElement.get(index) : undefined;
}
setFirstEnabledItemIndex() {
var _a;
this.currentIndex = (_a = this.state._items) === null || _a === void 0 ? void 0 : _a.findIndex((item) => !item._disabled);
}
handleKeyDown(event) {
var _a, _b, _c, _d;
const pressedKey = event.code;
const isArrowKey = [KeyboardKey.ArrowUp, KeyboardKey.ArrowDown, KeyboardKey.ArrowRight, KeyboardKey.ArrowLeft].includes(pressedKey);
if (!isArrowKey)
return;
event.preventDefault();
const lastItemIndex = ((_b = (_a = this._items) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) - 1;
if (lastItemIndex < 0)
return;
const currentIndex = this.currentIndex;
let nextIndex = currentIndex;
switch (pressedKey) {
case KeyboardKey.ArrowUp:
case KeyboardKey.ArrowLeft:
nextIndex = currentIndex > 0 ? currentIndex - 1 : lastItemIndex;
break;
case KeyboardKey.ArrowDown:
case KeyboardKey.ArrowRight:
nextIndex = currentIndex < lastItemIndex ? currentIndex + 1 : 0;
break;
}
if (currentIndex === nextIndex) {
return;
}
if ((_d = (_c = this.state._items) === null || _c === void 0 ? void 0 : _c[nextIndex]) === null || _d === void 0 ? void 0 : _d._disabled) {
return;
}
this.currentIndex = nextIndex;
const item = this.getCurrentToolbarItem(nextIndex);
if (this.host) {
void (item === null || item === void 0 ? void 0 : item.focus());
}
}
handleFocusout(event) {
if (event.target === this.host)
this.setFirstEnabledItemIndex();
}
componentWillLoad() {
this.validateLabel(this._label);
this.validateItems(this._items);
this.validateOrientation(this._orientation);
this.setFirstEnabledItemIndex();
}
get host() { return this; }
static get watchers() { return {
"_label": ["validateLabel"],
"_items": ["validateItems"],
"_orientation": ["validateOrientation"]
}; }
static get style() { return {
default: defaultStyleCss
}; }
}, [289, "kol-toolbar", {
"_label": [1],
"_items": [16],
"_orientation": [1],
"state": [32],
"currentIndex": [32],
"focus": [64],
"click": [64]
}, [[0, "keydown", "handleKeyDown"], [2, "focusout", "handleFocusout"]], {
"_label": ["validateLabel"],
"_items": ["validateItems"],
"_orientation": ["validateOrientation"]
}]);
function defineCustomElement$1() {
if (typeof customElements === "undefined") {
return;
}
const components = ["kol-toolbar"];
components.forEach(tagName => { switch (tagName) {
case "kol-toolbar":
if (!customElements.get(tagName)) {
customElements.define(tagName, KolToolbar$1);
}
break;
} });
}
const KolToolbar = KolToolbar$1;
const defineCustomElement = defineCustomElement$1;
export { KolToolbar, defineCustomElement };
//# sourceMappingURL=kol-toolbar.js.map
//# sourceMappingURL=kol-toolbar.js.map