UNPKG

@public-ui/components

Version:

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

4 lines 19.8 kB
/*! * KoliBri - The accessible HTML-Standard */ import{h as n,r as e,g as t}from"./index-1ed13705.js";import{c as i}from"./clsx-09a06a12.js";import{n as o}from"./dev.utils-cb61837d.js";import{i as a,w as l,t as s,l as r}from"./index-ebe5a881.js";import{I as c}from"./controller-ce246aad.js";import{c as d,a as h,g as u,F as f}from"./getRenderStates-c4b5c6cb.js";import{F as b}from"./FieldControlStateWrapper-7dba1400.js";import{_ as p}from"./tslib.es6-1173d062.js";import{K as k}from"./Icon-446dff9e.js";import{I as m}from"./Input-8502a991.js";import"./orientation-409d844a.js";import"./label-bf9966d0.js";import"./events-bad0a075.js";import"./associated.controller-92af2554.js";import"./bootstrap-93c7a706.js";import"./component-names-7924d82a.js";import"./i18n-45224cc3.js";import"./access-and-short-key-f743a5c4.js";import"./tooltip-align-465a8590.js";import"./align-d2572387.js";import"./hide-label-8b3a8709.js";import"./Alert-112aec59.js";import"./i18n-260f0fe9.js";import"./bem-e4c3a2e6.js";import"./browser-f629a56a.js";import"./Heading-733c8dda.js";import"./InternalUnderlinedBadgeText-781ef373.js";import"./isArray-7a60fa7f.js";const v=["button","default","switch"],g=(e,n)=>{a(e,"_checked",n)},y=(e,n)=>{a(e,"_indeterminate",n)},_=["left","right"],x=(e,n)=>{l(e,"_labelAlign",(e=>"string"==typeof e&&_.includes(e)),new Set([`KoliBriLabelAlign {${_.join(", ")}`]),n)};class w extends c{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){g(this.component,e),this.setFormAssociatedCheckboxValue(this.component.state._value)}validateIcons(e){l(this.component,"_icons",(e=>"object"==typeof e&&null!==e&&(s(e.checked,1)||s(e.indeterminate,1)||s(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){y(this.component,e)}validateLabelAlign(e){x(this.component,e)}validateValue(e){r(this.component,"_value",e),this.setFormAssociatedCheckboxValue(this.component.state._value)}validateVariant(e){l(this.component,"_variant",(e=>"string"==typeof e&&v.includes(e)),new Set([`String {${v.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 j=e=>{var{class:t}=e,o=p(e,["class"]);return n(k,Object.assign({class:i("kol-checkbox__icon",t)},o))},z=e=>{var{class:t}=e,o=p(e,["class"]);return n(m,Object.assign({class:i("kol-checkbox__input",t)},o,{type:"checkbox"}))},S=e=>{var t,{class:o,variant:a="default",icon:l,inputProps:s}=e,r=p(e,["class","variant","icon","inputProps"]);const c=d(null==s?void 0:s.msg,null==s?void 0:s.touched),h={[`kol-checkbox--variant-${a}`]:!0,"kol-checkbox--checked":null==s?void 0:s.checked,"kol-checkbox--indeterminate":null==s?void 0:s.indeterminate,"kol-checkbox--disabled":Boolean(null==s?void 0:s.disabled),"kol-checkbox--required":Boolean(null==s?void 0:s.required),"kol-checkbox--touched":Boolean(null==s?void 0:s.touched),[`kol-checkbox--${(null===(t=null==s?void 0:s.msg)||void 0===t?void 0:t.type)||"error"}`]:Boolean(c)};return n("label",Object.assign({class:i("kol-checkbox",h,o)},r),n(j,{label:"",icons:l}),n(z,Object.assign({},s)))};function I(e,n={}){const{ariaDescribedBy:t}=u(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=h(e._msg)),Object.assign(Object.assign({},i),n)}const A=e=>{var{state:t,inputProps:i}=e,o=p(e,["state","inputProps"]);const a=(null==t?void 0:t._variant)||"default";return n(S,Object.assign({variant:a,inputProps:I(t,i)},o))},O='/*\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 * {\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n hyphens: auto;\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 * 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 .kol-input .input {\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: 1px;\n overflow: hidden;\n position: absolute;\n white-space: nowrap;\n width: 1px;\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 font-size: rem(16);\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 .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 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 }\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 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}',B=O,V=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:i("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:i("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:i({"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 n(f,Object.assign({key:"7fb2ecb21c81667431909cd393b331609c83be4e"},this.getFormFieldProps(),{renderNoLabel:!0}),n(b,Object.assign({key:"b7211c6548c3cab0a5a7f9d71efe6c7bfd56f90b"},this.getFieldControlProps(),{renderNoHint:!0}),n(A,Object.assign({key:"9a6294d54e1ea9d51942eb13b27c1de2a036c431"},this.getInputProps()))))}constructor(n){e(this,n),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-${o()}`,_indeterminate:!1,_label:"",_value:!0,_variant:"default",_labelAlign:"right"},this.inputHasFocus=!1,this.controller=new w(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 t(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"]}}};V.style={default:B};export{V as kol_input_checkbox};