UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

4 lines 21.3 kB
/*! * KoliBri - The accessible HTML-Standard */ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const index$1=require("./index-03ef29aa.js"),clsx=require("./clsx-dd4d6dd1.js"),dev_utils=require("./dev.utils-f6da9b54.js"),index=require("./index-8b802221.js"),controller=require("./controller-3eecbf98.js"),getRenderStates=require("./getRenderStates-8e102335.js"),FieldControlStateWrapper=require("./FieldControlStateWrapper-b83a1e2e.js"),tslib_es6=require("./tslib.es6-5e301284.js"),Icon=require("./Icon-9e0021e7.js"),Input=require("./Input-c953eb09.js");require("./label-21c38949.js"),require("./events-40771c95.js"),require("./associated.controller-949dd4e2.js"),require("./bootstrap-7c830737.js"),require("./component-names-82c4d68d.js"),require("./i18n-8c288a27.js"),require("./access-and-short-key-2167fc7c.js"),require("./tooltip-align-4446177f.js"),require("./align-4abb9b20.js"),require("./hide-label-5889f019.js"),require("./Alert-22c49278.js"),require("./i18n-b9d16ebc.js"),require("./bem-85316256.js"),require("./browser-4433089a.js"),require("./Heading-b8bbd132.js"),require("./InternalUnderlinedBadgeText-6c8700f2.js"),require("./isArray-e114fe6e.js");const inputCheckboxVariantOptions=["button","default","switch"],validateChecked=(e,n)=>{index.watchBoolean(e,"_checked",n)},validateIndeterminate=(e,n)=>{index.watchBoolean(e,"_indeterminate",n)},labelAlignPropTypeOptions=["left","right"],validateLabelAlign=(e,n)=>{index.watchValidator(e,"_labelAlign",(e=>"string"==typeof e&&labelAlignPropTypeOptions.includes(e)),new Set([`KoliBriLabelAlign {${labelAlignPropTypeOptions.join(", ")}`]),n)};class InputCheckboxController extends controller.InputCheckboxRadioController{constructor(e,n,t){super(e,n,t),this.setFormAssociatedCheckboxValue=e=>{this.component._checked?this.setFormAssociatedValue(e):this.setFormAssociatedValue(null)},this.component=e}validateChecked(e){validateChecked(this.component,e),this.setFormAssociatedCheckboxValue(this.component.state._value)}validateIcons(e){index.watchValidator(this.component,"_icons",(e=>"object"==typeof e&&null!==e&&(index.isString(e.checked,1)||index.isString(e.indeterminate,1)||index.isString(e.unchecked,1))),new Set(["InputCheckboxIcons"]),e,{hooks:{beforePatch:(e,n,t)=>{n.set("_icons",Object.assign(Object.assign({},t.state._icons),e))}}})}validateIndeterminate(e){validateIndeterminate(this.component,e)}validateLabelAlign(e){validateLabelAlign(this.component,e)}validateValue(e){index.setState(this.component,"_value",e),this.setFormAssociatedCheckboxValue(this.component.state._value)}validateVariant(e){index.watchValidator(this.component,"_variant",(e=>"string"==typeof e&&inputCheckboxVariantOptions.includes(e)),new Set([`String {${inputCheckboxVariantOptions.join(", ")}`]),e)}componentWillLoad(){super.componentWillLoad(),this.validateChecked(this.component._checked),this.validateIcons(this.component._icons),this.validateIndeterminate(this.component._indeterminate),this.validateValue(this.component._value),this.validateVariant(this.component._variant),this.validateLabelAlign(this.component._labelAlign)}}const IconWrapperFc=e=>{var{class:n}=e,t=tslib_es6.__rest(e,["class"]);return index$1.h(Icon.KolIconFc,Object.assign({class:clsx.clsx("kol-checkbox__icon",n)},t))},InputWrapperFc=e=>{var{class:n}=e,t=tslib_es6.__rest(e,["class"]);return index$1.h(Input.InputFc,Object.assign({class:clsx.clsx("kol-checkbox__input",n)},t,{type:"checkbox"}))},CheckboxFc=e=>{var n,{class:t,variant:i="default",icon:o,inputProps:a}=e,l=tslib_es6.__rest(e,["class","variant","icon","inputProps"]);const r=getRenderStates.checkHasMsg(null==a?void 0:a.msg,null==a?void 0:a.touched),s={[`kol-checkbox--variant-${i}`]:!0,"kol-checkbox--checked":null==a?void 0:a.checked,"kol-checkbox--indeterminate":null==a?void 0:a.indeterminate,"kol-checkbox--disabled":Boolean(null==a?void 0:a.disabled),"kol-checkbox--required":Boolean(null==a?void 0:a.required),"kol-checkbox--touched":Boolean(null==a?void 0:a.touched),[`kol-checkbox--${(null===(n=null==a?void 0:a.msg)||void 0===n?void 0:n.type)||"error"}`]:Boolean(r)};return index$1.h("label",Object.assign({class:clsx.clsx("kol-checkbox",s,t)},l),index$1.h(IconWrapperFc,{label:"",icons:o}),index$1.h(InputWrapperFc,Object.assign({},a)))};function getCheckboxProps(e,n={}){const{ariaDescribedBy:t}=getRenderStates.getRenderStates(e),i={id:e._id,hideLabel:e._hideLabel,label:e._label,value:e._value,accessKey:e._accessKey,disabled:e._disabled,name:e._name,ariaDescribedBy:t};return"_required"in e&&(i.required=e._required),"_checked"in e&&(i.checked=e._checked),"_indeterminate"in e&&(i.indeterminate=e._indeterminate),"_touched"in e&&(i.touched=e._touched),"_msg"in e&&(i.msg=getRenderStates.convertMsgToInternMsg(e._msg)),Object.assign(Object.assign({},i),n)}const CheckboxStateWrapper=e=>{var{state:n,inputProps:t}=e,i=tslib_es6.__rest(e,["state","inputProps"]);const o=(null==n?void 0:n._variant)||"default";return index$1.h(CheckboxFc,Object.assign({variant:o,inputProps:getCheckboxProps(n,t)},i))},defaultStyleCss='/*\n * This file contains all rules for accessibility.\n */\n@layer kol-global {\n :host {\n /*\n * Minimum size of interactive elements.\n */\n --a11y-min-size: calc(44rem / var(--kolibri-root-font-size, 16));\n /*\n * No element should be used without a background and font color whose contrast ratio has\n * not been checked. By initially setting the background color to white and the font color\n * to black, the contrast ratio is ensured and explicit adjustment is forced.\n */\n background-color: white;\n color: black;\n /*\n * Verdana is an accessible font that can be used without requiring additional loading time.\n */\n font-family: Verdana;\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 * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\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 * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n }\n /*\n * All interactive elements should have a minimum size of rem(44).\n */\n /* input:not([type=\'checkbox\'], [type=\'radio\'], [type=\'range\']), */\n /* option, */\n /* select, */\n /* textarea, */\n [role=button],\n button:not([role=link]) {\n min-height: var(--a11y-min-size);\n min-width: 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 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}\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 clip: rect(0 0 0 0);\n clip-path: inset(50%);\n height: calc(1rem / var(--kolibri-root-font-size, 16));\n overflow: hidden;\n position: absolute;\n white-space: nowrap;\n width: calc(1rem / var(--kolibri-root-font-size, 16));\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 border: none;\n margin: 0;\n padding: 0;\n width: 100%;\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 background-color: lightgray;\n color: black;\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 }\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: grid;\n place-items: 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 place-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 cursor: not-allowed;\n opacity: 0.5;\n outline: none;\n }\n [aria-disabled=true]:focus .kol-span,\n [disabled]:focus .kol-span {\n outline: none !important;\n }\n}\n@layer kol-component {\n :host {\n display: block;\n }\n}\n@layer kol-component {\n :host {\n font-size: calc(16rem / var(--kolibri-root-font-size, 16));\n }\n .kol-tooltip {\n display: contents;\n }\n .kol-tooltip__floating {\n animation-duration: 0.25s;\n animation-iteration-count: 1;\n animation-name: fadeInOpacity;\n animation-timing-function: ease-in;\n box-sizing: border-box;\n display: none;\n position: fixed;\n visibility: hidden;\n /* Avoid layout interference - see https://floating-ui.com/docs/computePosition */\n top: 0;\n left: 0;\n max-width: 90vw;\n max-height: 90vh;\n /* Can be used to specify the tooltip-width from the outside. Unset by default. */\n width: var(--kol-tooltip-width);\n }\n .kol-tooltip__arrow {\n background-color: #fff;\n color: #000;\n height: calc(10rem / var(--kolibri-root-font-size, 16));\n position: absolute;\n transform: rotate(45deg);\n width: calc(10rem / var(--kolibri-root-font-size, 16));\n z-index: 999;\n }\n .kol-tooltip__content {\n background-color: #fff;\n color: #000;\n position: relative;\n z-index: 1000;\n }\n @keyframes fadeInOpacity {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n}\n@layer kol-component {\n .kol-form-field {\n display: grid;\n font-size: calc(16rem / var(--kolibri-root-font-size, 16));\n }\n .kol-form-field:not(.kol-form-field--disabled) .kol-form-field__label {\n cursor: pointer;\n }\n .kol-form-field--disabled .kol-form-field__label {\n opacity: 0.5;\n }\n .kol-form-field--required .kol-form-field__label-text::after {\n content: "*";\n }\n .kol-form-field--disabled .kol-form-field__hint {\n opacity: 0.5;\n }\n .kol-form-field--required .kol-form-field__tooltip .span-label::after {\n content: "*";\n }\n}\n@layer kol-component {\n .kol-field-control {\n min-height: var(--a11y-min-size);\n display: grid;\n grid-template-columns: auto 1fr;\n grid-template-areas: "input label";\n grid-template-rows: auto;\n align-items: center;\n justify-content: left;\n }\n .kol-field-control:has(.kol-field-control__hint) {\n grid-template-columns: auto 1fr;\n grid-template-areas: "input label" "hint hint";\n grid-template-rows: auto auto;\n }\n .kol-field-control--label-align-left:not(.kol-field-control--hide-label) {\n grid-template-columns: 1fr auto;\n grid-template-areas: "label input";\n grid-template-rows: auto;\n }\n .kol-field-control--label-align-left:not(.kol-field-control--hide-label):has(.kol-field-control__hint) {\n grid-template-columns: 1fr auto;\n grid-template-areas: "label input" "hint hint";\n grid-template-rows: auto auto;\n }\n .kol-field-control__input {\n grid-area: input;\n display: flex;\n min-height: var(--a11y-min-size);\n align-items: center;\n }\n .kol-field-control__label {\n align-items: center;\n cursor: pointer;\n display: flex;\n flex-grow: 1;\n grid-area: label;\n min-height: var(--a11y-min-size);\n }\n .kol-field-control__label--visually-hidden {\n height: 0;\n margin: 0;\n padding: 0;\n visibility: hidden;\n }\n .kol-field-control__label-text::after {\n content: "";\n }\n .kol-field-control__tooltip .span-label::after {\n content: "";\n }\n .kol-field-control__hint {\n grid-area: hint;\n }\n .kol-field-control--disabled .kol-field-control__label {\n cursor: not-allowed;\n opacity: 0.5;\n }\n .kol-field-control--required .kol-field-control__label-text::after {\n content: "*";\n }\n .kol-field-control--required .kol-field-control__tooltip .span-label::after {\n content: "*";\n }\n}\n@layer kol-component {\n .kol-form-field {\n display: grid;\n }\n .kol-checkbox {\n align-items: center;\n cursor: pointer;\n display: flex;\n position: relative;\n }\n .kol-checkbox--disabled {\n cursor: not-allowed;\n }\n .kol-checkbox .kol-input {\n appearance: none;\n background-color: #fff;\n border-style: solid;\n border-width: 2px;\n cursor: inherit;\n font-size: calc(16rem / var(--kolibri-root-font-size, 16));\n margin: 0;\n transition: 0.5s;\n }\n .kol-checkbox .kol-input:before {\n content: "";\n }\n /**\n * Variant: Checkbox\n */\n .kol-checkbox--variant-default {\n height: var(--a11y-min-size);\n justify-content: center;\n position: relative;\n width: var(--a11y-min-size);\n }\n .kol-checkbox--variant-default .kol-icon {\n display: flex;\n inset: auto;\n position: absolute;\n z-index: 1;\n pointer-events: none;\n }\n .kol-checkbox--variant-default .kol-icon::part(icon) {\n display: none;\n }\n .kol-checkbox--variant-default .kol-input {\n width: calc(22rem / var(--kolibri-root-font-size, 16));\n height: calc(22rem / var(--kolibri-root-font-size, 16));\n }\n .kol-checkbox--variant-default.kol-checkbox--checked .kol-icon::part(icon), .kol-checkbox--variant-default.kol-checkbox--indeterminate .kol-icon::part(icon) {\n display: block;\n }\n /**\n * Variant: Switch\n */\n .kol-checkbox--variant-switch {\n position: relative;\n }\n .kol-checkbox--variant-switch .kol-input {\n display: inline-block;\n height: 1.7em;\n min-width: 3.2em;\n position: relative;\n width: 3.2em;\n }\n .kol-checkbox--variant-switch .kol-input::before {\n background-color: #000;\n height: 1.2em;\n left: calc(0.25em - (2rem / var(--kolibri-root-font-size, 16)));\n top: calc(0.25em - (2rem / var(--kolibri-root-font-size, 16)));\n position: absolute;\n transition: 0.5s;\n width: 1.2em;\n }\n .kol-checkbox--variant-switch .kol-input:checked::before {\n transform: translateX(1.5em);\n }\n .kol-checkbox--variant-switch .kol-input:indeterminate::before {\n transform: translateX(0.75em);\n }\n .kol-checkbox--variant-switch .kol-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 1.2em;\n height: 1.2em;\n position: absolute;\n z-index: 1;\n top: 50%;\n left: calc(4rem / var(--kolibri-root-font-size, 16));\n transform: translate(0, -50%);\n transition: 0.5s;\n color: #000;\n }\n .kol-checkbox--variant-switch.kol-checkbox--checked .kol-icon {\n transform: translate(1.5em, -50%);\n }\n .kol-checkbox--variant-switch.kol-checkbox--indeterminate .kol-icon {\n transform: translate(0.75em, -50%);\n }\n /**\n * Variant: Button\n */\n .kol-checkbox--variant-button {\n width: var(--a11y-min-size);\n }\n .kol-checkbox--variant-button .kol-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n width: var(--a11y-min-size);\n height: var(--a11y-min-size);\n }\n}',KolInputCheckboxDefaultStyle0=defaultStyleCss,KolInputCheckbox=class{getModelValue(){return this._checked?this.state._value:null}async getValue(){return this.getModelValue()}async kolFocus(){var e;null===(e=this.inputRef)||void 0===e||e.focus()}getFormFieldProps(){return{state:this.state,class:clsx.clsx("kol-input-checkbox",{"kol-input-checkbox--checked":this.state._checked,"kol-input-checkbox--indeterminate":this.state._indeterminate,[`kol-input-checkbox--variant-${this.state._variant||"default"}`]:!0,[`kol-input-checkbox--label-align-${this.state._labelAlign||"right"}`]:!0}),tooltipAlign:this._tooltipAlign,"data-role":"button"===this.state._variant?"button":void 0,alert:this.showAsAlert(),renderNoTooltip:!0}}getFieldControlProps(){return{class:clsx.clsx("kol-input-checkbox__field-control",{"kol-input-checkbox__field-control--checked":this.state._checked,"kol-input-checkbox__field-control--indeterminate":this.state._indeterminate,[`kol-input-checkbox__field-control--variant-${this.state._variant||"default"}`]:!0}),state:this.state}}getInputProps(){return{state:this.state,icon:this.getIcon(),inputProps:Object.assign(Object.assign({class:clsx.clsx({"visually-hidden":"button"===this.state._variant}),ref:this.catchRef},this.controller.onFacade),{onInput:this.onInput,onChange:this.onChange,onFocus:e=>{this.controller.onFacade.onFocus(e),this.inputHasFocus=!0},onBlur:e=>{this.controller.onFacade.onBlur(e),this.inputHasFocus=!1},onClick:void 0})}}getIcon(){return this.state._indeterminate?this.state._icons.indeterminate:this.state._checked?this.state._icons.checked:this.state._icons.unchecked}render(){return index$1.h(getRenderStates.FormFieldStateWrapper,Object.assign({key:"7fb2ecb21c81667431909cd393b331609c83be4e"},this.getFormFieldProps(),{renderNoLabel:!0}),index$1.h(FieldControlStateWrapper.FieldControlStateWrapper,Object.assign({key:"b7211c6548c3cab0a5a7f9d71efe6c7bfd56f90b"},this.getFieldControlProps(),{renderNoHint:!0}),index$1.h(CheckboxStateWrapper,Object.assign({key:"9a6294d54e1ea9d51942eb13b27c1de2a036c431"},this.getInputProps()))))}constructor(e){index$1.registerInstance(this,e),this.catchRef=e=>{this.inputRef=e},this.onInput=e=>{this._checked=!this._checked,this._indeterminate=!1;const n=this.getModelValue();this.controller.onFacade.onInput(e,!1,n),this.controller.setFormAssociatedCheckboxValue(n)},this.onChange=e=>{this.controller.onFacade.onChange(e,this.getModelValue())},this._accessKey=void 0,this._checked=!1,this._hideMsg=!1,this._disabled=!1,this._hideLabel=!1,this._hint="",this._icons=void 0,this._id=void 0,this._indeterminate=void 0,this._label=void 0,this._labelAlign="right",this._msg=void 0,this._name=void 0,this._on=void 0,this._required=!1,this._shortKey=void 0,this._syncValueBySelector=void 0,this._tooltipAlign="top",this._touched=!1,this._value=!0,this._variant="default",this.state={_checked:!1,_hideMsg:!1,_icons:{checked:"codicon codicon-check",indeterminate:"codicon codicon-remove",unchecked:"codicon codicon-close"},_id:`id-${dev_utils.nonce()}`,_indeterminate:!1,_label:"",_value:!0,_variant:"default",_labelAlign:"right"},this.inputHasFocus=!1,this.controller=new InputCheckboxController(this,"checkbox",this.host)}showAsAlert(){return Boolean(this.state._touched)&&!this.inputHasFocus}validateAccessKey(e){this.controller.validateAccessKey(e)}validateChecked(e){this.controller.validateChecked(e)}validateDisabled(e){this.controller.validateDisabled(e)}validateHideMsg(e){this.controller.validateHideMsg(e)}validateHideLabel(e){this.controller.validateHideLabel(e)}validateHint(e){this.controller.validateHint(e)}validateIcons(e){this.controller.validateIcons(e)}validateId(e){this.controller.validateId(e)}validateIndeterminate(e){this.controller.validateIndeterminate(e)}validateLabel(e){this.controller.validateLabel(e)}validateLabelAlign(e){this.controller.validateLabelAlign(e)}validateMsg(e){this.controller.validateMsg(e)}validateName(e){this.controller.validateName(e)}validateOn(e){this.controller.validateOn(e)}validateRequired(e){this.controller.validateRequired(e)}validateShortKey(e){this.controller.validateShortKey(e)}validateSyncValueBySelector(e){this.controller.validateSyncValueBySelector(e)}validateTouched(e){this.controller.validateTouched(e)}validateValue(e){this.controller.validateValue(e)}validateVariant(e){this.controller.validateVariant(e)}componentWillLoad(){this._touched=!0===this._touched,this.controller.componentWillLoad()}static get delegatesFocus(){return!0}get host(){return index$1.getElement(this)}static get watchers(){return{_accessKey:["validateAccessKey"],_checked:["validateChecked"],_disabled:["validateDisabled"],_hideMsg:["validateHideMsg"],_hideLabel:["validateHideLabel"],_hint:["validateHint"],_icons:["validateIcons"],_id:["validateId"],_indeterminate:["validateIndeterminate"],_label:["validateLabel"],_labelAlign:["validateLabelAlign"],_msg:["validateMsg"],_name:["validateName"],_on:["validateOn"],_required:["validateRequired"],_shortKey:["validateShortKey"],_syncValueBySelector:["validateSyncValueBySelector"],_touched:["validateTouched"],_value:["validateValue"],_variant:["validateVariant"]}}};KolInputCheckbox.style={default:KolInputCheckboxDefaultStyle0},exports.kol_input_checkbox=KolInputCheckbox;