UNPKG

@public-ui/components

Version:

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

4 lines 10.7 kB
/*! * KoliBri - The accessible HTML-Standard */ import{r as e,h as n,H as t}from"./index-f0de5c73.js";import{v as i}from"./label-e8ec0e3a.js";import{k as r,i as a,w as s}from"./prop.validators-64749272.js";import"./index-da3e0c00.js";import"./dev.utils-fab45cbc.js";var o;!function(e){e.bar="bar",e.cycle="cycle"}(o||(o={}));const l="/*\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 .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: 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%; /* 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}\n@layer kol-global {\n :host {\n font-size: calc(16rem / var(--kolibri-root-font-size, 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 /* KolSpan is a layout component with icons in all directions and a label text in the middle. */\n .kol-span-wc {\n display: grid;\n place-items: center;\n }\n /* The sub span in KolSpan is the horizontal span with icon left and right and the label text in the middle. */\n .kol-span-wc > span {\n display: flex;\n place-items: center;\n }\n a,\n button {\n cursor: pointer;\n }\n /* This is the text label. */\n .hide-label > .kol-span-wc > span > span {\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-wc,\n [disabled]:focus .kol-span-wc {\n outline: none !important;\n }\n}\n@layer kol-component {\n progress {\n display: block;\n height: 0;\n overflow: hidden;\n width: 0;\n }\n .bar {\n display: grid;\n grid-template-columns: 1fr auto;\n grid-template-areas: \"LABEL LABEL LABEL\" \"BAR VALUE UNIT\";\n align-items: center;\n column-gap: 0.05rem;\n }\n .bar .label {\n grid-column-end: 2;\n grid-area: LABEL;\n }\n .bar svg {\n grid-area: BAR;\n }\n .bar .value {\n grid-area: VALUE;\n text-align: right;\n }\n .bar .unit {\n grid-area: UNIT;\n }\n .bar .border {\n fill: transparent;\n stroke: black;\n }\n .bar .background {\n fill: lightgray;\n stroke: white;\n }\n .bar .progress {\n fill: #0075ff;\n stroke: transparent;\n transition: 250ms ease-in-out 50ms;\n }\n .cycle {\n display: grid;\n grid-template-columns: auto;\n grid-template-areas: \"ALL\";\n justify-items: center;\n align-content: center;\n }\n .cycle > * {\n grid-area: ALL;\n }\n .cycle .text {\n text-align: center;\n display: flex;\n justify-content: center;\n flex-direction: column;\n font-size: x-small;\n }\n .cycle .text * {\n background-color: white;\n }\n .cycle .background {\n fill: transparent;\n stroke: lightgray;\n }\n .cycle .border {\n fill: transparent;\n stroke: black;\n }\n .cycle .whitespace {\n fill: transparent;\n stroke: white;\n }\n .cycle .progress {\n fill: transparent;\n stroke: #0075ff;\n transform-origin: 50% 50%;\n transform: rotate(-90deg);\n transition: 250ms ease-in-out 50ms;\n }\n /* https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion */\n @media (prefers-reduced-motion) {\n .progress {\n transition-duration: 0s;\n transition-delay: 0s;\n }\n }\n}",c=l,d=Object.keys(o),h=({state:e})=>n("svg",{width:"100",viewBox:"0 0 120 120",xmlns:"http://www.w3.org/2000/svg"},n("circle",{class:"background",cx:"60",cy:"60",r:"54.5",fill:"currentColor",stroke:"currentColor","stroke-width":"8"}),n("circle",{class:"whitespace",cx:"60",cy:"60",r:"59",fill:"currentColor",stroke:"currentColor","stroke-width":"3"}),n("circle",{class:"border",cx:"60",cy:"60",r:"59",fill:"currentColor",stroke:"currentColor","stroke-width":"1"}),n("circle",{class:"whitespace",cx:"60",cy:"60",r:"51",fill:"currentColor",stroke:"currentColor","stroke-width":"1"}),n("circle",{class:"border",cx:"60",cy:"60",r:"50",fill:"currentColor",stroke:"currentColor","stroke-width":"1"}),n("circle",{class:"progress",fill:"currentColor",stroke:"currentColor","stroke-linecap":"round","stroke-dasharray":`${Math.round(e._value/e._max*342)}px 342px`,"stroke-width":"6",cx:"60",cy:"60",r:"54.5"})),b=({state:e})=>{const t=e._value/e._max*100;return n("svg",{xmlns:"http://www.w3.org/2000/svg",width:"100%",height:"12",overflow:"visible"},n("rect",{class:"background",x:"1",y:"1",height:"11",rx:"5",fill:"currentColor",stroke:"currentColor","stroke-width":"3",style:{width:"100%"}}),n("rect",{class:"border",x:"1",y:"1",height:"11",rx:"5",fill:"currentColor",stroke:"currentColor","stroke-width":"1",style:{width:"100%"}}),n("rect",{class:"progress",x:"3",y:"3",height:"7",rx:"3.5",fill:"currentColor",stroke:"currentColor","stroke-width":"3",style:{width:`calc(${t}% - 4px)`}}))},u=e=>{switch(e._variant){case"cycle":return n(h,{state:e});case"bar":return n(b,{state:e});default:throw new Error(`Progress variant ${e._variant} not implemented.`)}},f=class{constructor(t){e(this,t),this._label=void 0,this._max=void 0,this._unit="%",this._value=void 0,this._variant=void 0,this.state={_max:100,_unit:"%",_value:0,_variant:"bar",_liveValue:0}}render(){const e="%"===this.state._unit,a=e?`${Math.round(this.state._liveValue/this.state._max*100)}%`:this.state._liveValue,i=e?Math.round(this.state._value/this.state._max*100):this.state._value;return n(t,{key:"c7038d1d330d5c4bdf6960549ae7c6d952553e51",class:"kol-progress"},n("div",{key:"15be68272d0e03b68443739aab91ae6daeb465d8","aria-hidden":"true",class:{cycle:"cycle"===this.state._variant,bar:"bar"===this.state._variant}},"bar"===this.state._variant&&this.state._label&&n("div",{key:"05c419229cff39beefc7005694cdc1d748234b46",class:"label"},this.state._label),u(this.state),"cycle"==this.state._variant&&n("div",{key:"0188b544292da04562cee304698a59dd12e1346f",class:"text"},this.state._label&&n("div",{key:"f6628e38358433f61545f766d6bb538201e78d2f",class:"label"},this.state._label),n("div",{key:"7f01889c9b5ca9235857dd9b5012a21459754e4b",class:"value"},`${i} ${this.state._unit}`)),"bar"==this.state._variant&&n("div",{key:"8de6b13e3e4cf31e84617175a20cf4eca343852c",class:"value",style:{width:`${`${(e?100:this.state._max)+1}`.length}ch`}},i),"bar"==this.state._variant&&n("div",{key:"cce7b2b6db10b7c488806775bbe033ca10b488dd",class:"unit"},this.state._unit)),n("progress",{key:"9db3ba73f90ad8eb16ce35b7fc76b15f8b255c95","aria-busy":this.state._value<this.state._max?"true":"false",max:this.state._max,value:this.state._value}),n("span",{key:"a349064adebe8f230c4c288ab72eb4a4a7eb8865","aria-live":"polite","aria-relevant":"removals text",class:"visually-hidden"},e?`${a} %`:`${a} von ${this.state._max} ${this.state._unit}`))}validateLabel(e){i(this,e)}validateMax(e){"number"!=typeof e&&(e=100),r(this,"_max",e,{required:!0})}validateUnit(e){a(this,"_unit",e)}validateValue(e){"number"!=typeof e&&(e=0),r(this,"_value",e,{required:!0})}validateVariant(e){s(this,"_variant",(e=>"string"==typeof e&&d.includes(e)),new Set(d),e)}componentWillLoad(){this.validateLabel(this._label),this.validateMax(this._max),this.validateUnit(this._unit),this.validateValue(this._value),this.validateVariant(this._variant),this.interval=setInterval((()=>{this.state._liveValue!==this.state._value&&(this.state=Object.assign(Object.assign({},this.state),{_liveValue:this.state._value}))}),5e3)}disconnectedCallback(){clearInterval(this.interval)}static get watchers(){return{_label:["validateLabel"],_max:["validateMax"],_unit:["validateUnit"],_value:["validateValue"],_variant:["validateVariant"]}}};f.style={default:c};export{f as kol_progress};