@randstad-uca/design-system 1.0.128 → 1.0.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Navbar.d.ts +35 -1
- package/dist/components/Navbar.js +1 -1
- package/dist/components/Select.d.ts +30 -0
- package/dist/components/Select.js +2 -2
- package/dist/helpers/overlayEvents.d.ts +14 -0
- package/dist/helpers/overlayEvents.js +1 -0
- package/dist/package.json +1 -1
- package/dist/randstad-design-system.css +1 -1
- package/dist/stories/Navbar.stories.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LitElement, TemplateResult } from 'lit';
|
|
1
|
+
import { LitElement, TemplateResult, PropertyValues } from 'lit';
|
|
2
2
|
import './Icon';
|
|
3
3
|
export interface NavItem {
|
|
4
4
|
readonly icon: string;
|
|
@@ -12,11 +12,45 @@ export declare class RandstadNavbar extends LitElement {
|
|
|
12
12
|
hidden: boolean;
|
|
13
13
|
desktop: boolean;
|
|
14
14
|
selectedIndex: number;
|
|
15
|
+
hideOnInputFocus: boolean;
|
|
15
16
|
private _rafId;
|
|
17
|
+
private _hiddenByScroll;
|
|
18
|
+
private _hiddenByFocus;
|
|
19
|
+
/** Overlays mobile abiertos (p. ej. el desplegable de filterable-select). */
|
|
20
|
+
private _openOverlays;
|
|
21
|
+
private _focusListenersAttached;
|
|
16
22
|
constructor();
|
|
23
|
+
private syncHidden;
|
|
24
|
+
/**
|
|
25
|
+
* Con `hideOnInputFocus` activo, mientras un componente tenga abierto su overlay
|
|
26
|
+
* mobile la navbar se oculta sin depender del foco de su input interno.
|
|
27
|
+
* Los overlays se registran siempre, para que activar la propiedad con uno ya
|
|
28
|
+
* abierto lo refleje de inmediato.
|
|
29
|
+
*/
|
|
30
|
+
private handleMobileOverlay;
|
|
17
31
|
private handleScroll;
|
|
18
32
|
private handleScrollThrottled;
|
|
33
|
+
/** Devuelve el elemento con foco atravesando shadow roots. */
|
|
34
|
+
private static getDeepActiveElement;
|
|
35
|
+
private static isTouchDevice;
|
|
36
|
+
private static opensVirtualKeyboard;
|
|
37
|
+
private updateFocusState;
|
|
38
|
+
/**
|
|
39
|
+
* `focusin`/`focusout` burbujean y son `composed`, por lo que se reciben en `document`
|
|
40
|
+
* aunque el input esté dentro del shadow DOM de un componente de la librería.
|
|
41
|
+
* `composedPath()[0]` devuelve el input real (no el host re-targeteado).
|
|
42
|
+
*/
|
|
43
|
+
private handleFocusIn;
|
|
44
|
+
/**
|
|
45
|
+
* Al perder el foco se libera el flag. Si el foco pasa a otro input, el `focusin`
|
|
46
|
+
* siguiente se dispara en la misma tarea y vuelve a activarlo antes de que Lit
|
|
47
|
+
* renderice, por lo que no hay parpadeo.
|
|
48
|
+
*/
|
|
49
|
+
private handleFocusOut;
|
|
50
|
+
private attachFocusListeners;
|
|
51
|
+
private detachFocusListeners;
|
|
19
52
|
connectedCallback(): void;
|
|
53
|
+
protected updated(changed: PropertyValues<this>): void;
|
|
20
54
|
disconnectedCallback(): void;
|
|
21
55
|
private handleItemClick;
|
|
22
56
|
private handleCenterClick;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorateMetadata.js";import t from"../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorate.js";import"./Icon.js";import{LitElement as
|
|
1
|
+
import e from"../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorateMetadata.js";import t from"../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorate.js";import"./Icon.js";import{MOBILE_OVERLAY_EVENT as n}from"../helpers/overlayEvents.js";import{LitElement as r,css as i,html as a,nothing as o}from"lit";import{customElement as s,property as c}from"lit/decorators.js";import{classMap as l}from"lit/directives/class-map.js";var u;const d=/* @__PURE__ */ new Set([`button`,`checkbox`,`color`,`file`,`hidden`,`image`,`radio`,`range`,`reset`,`submit`]);let f=class extends r{static{u=this}constructor(){super(),this.centerIcon=`search`,this.centerLabel=``,this.hidden=!1,this.desktop=!1,this.selectedIndex=-1,this.hideOnInputFocus=!1,this._rafId=null,this._hiddenByScroll=!1,this._hiddenByFocus=!1,this._openOverlays=/* @__PURE__ */ new Set,this._focusListenersAttached=!1,this.handleMobileOverlay=e=>{let{open:t,source:n}=e.detail;t?this._openOverlays.add(n):this._openOverlays.delete(n),this.syncHidden()},this.handleScroll=()=>{let e=window.innerHeight+window.scrollY,t=document.documentElement.scrollHeight;this._hiddenByScroll=e>=t-50,this.syncHidden()},this.handleScrollThrottled=()=>{this._rafId??=requestAnimationFrame(()=>{this._rafId=null,this.handleScroll()})},this.handleFocusIn=e=>{this.updateFocusState(e.composedPath()[0])},this.handleFocusOut=()=>{this._hiddenByFocus=!1,this.syncHidden()},this.items=[{icon:`home`,label:`Home`},{icon:`postulation`,label:`Applications`},{icon:`user`,label:`Users`},{icon:`settings`,label:`Settings`}]}syncHidden(){let e=this.hideOnInputFocus&&this._openOverlays.size>0;this.hidden=this._hiddenByScroll||this._hiddenByFocus||e}static getDeepActiveElement(){let e=document.activeElement;for(;e?.shadowRoot?.activeElement;)e=e.shadowRoot.activeElement;return e}static isTouchDevice(){return typeof window.matchMedia!=`function`||window.matchMedia(`(hover: none) and (pointer: coarse)`).matches}static opensVirtualKeyboard(e){return!(e instanceof HTMLElement)||e.getAttribute(`inputmode`)===`none`?!1:e instanceof HTMLInputElement?!e.disabled&&!e.readOnly&&!d.has(e.type):e instanceof HTMLTextAreaElement?!e.disabled&&!e.readOnly:e.isContentEditable}updateFocusState(e){this._hiddenByFocus=this.hideOnInputFocus&&u.isTouchDevice()&&u.opensVirtualKeyboard(e),this.syncHidden()}attachFocusListeners(){this._focusListenersAttached||(document.addEventListener(`focusin`,this.handleFocusIn),document.addEventListener(`focusout`,this.handleFocusOut),this._focusListenersAttached=!0,this.updateFocusState(u.getDeepActiveElement()))}detachFocusListeners(){this._focusListenersAttached&&(document.removeEventListener(`focusin`,this.handleFocusIn),document.removeEventListener(`focusout`,this.handleFocusOut),this._focusListenersAttached=!1,this._hiddenByFocus=!1,this.syncHidden())}connectedCallback(){super.connectedCallback(),window.addEventListener(`scroll`,this.handleScrollThrottled,{passive:!0}),window.addEventListener(n,this.handleMobileOverlay),this.handleScroll(),this.hideOnInputFocus&&this.attachFocusListeners()}updated(e){super.updated(e),e.has(`hideOnInputFocus`)&&this.isConnected&&(this.hideOnInputFocus?this.attachFocusListeners():this.detachFocusListeners())}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener(`scroll`,this.handleScrollThrottled),window.removeEventListener(n,this.handleMobileOverlay),this._openOverlays.clear(),this.detachFocusListeners(),this._rafId!=null&&(cancelAnimationFrame(this._rafId),this._rafId=null),this.ownerDocument.querySelector(`randstad-snackbar`)?.classList.remove(`navbar-visible`)}handleItemClick(e,t){this.selectedIndex=e,this.dispatchEvent(new CustomEvent(`nav-item-click`,{detail:{index:e,item:t},bubbles:!0,composed:!0}))}handleCenterClick(){this.dispatchEvent(new CustomEvent(`center-click`,{bubbles:!0,composed:!0}))}static{this.styles=i`:host{display:none;position:fixed;bottom:0;left:0;right:0;z-index:998;font-family:'Graphik',sans-serif;transition:transform 0.3s ease,opacity 0.3s ease}:host([hidden]){transform:translateY(100%);opacity:0}@media (max-width:940px){:host{display:block}}@media (prefers-reduced-motion:reduce){:host{transition:none}}@media (min-width:941px){:host([desktop]){display:block}}.navbar{display:flex;align-items:center;justify-content:center;height:71px;background:var(--white,#ffffff);border-radius:16px 16px 0 0;box-shadow:0px -1px 16px 1px rgba(15,25,65,0.15),0px -1px 16px 0px rgba(15,25,65,0.3);padding:0 16px}.side-item{display:flex;flex-direction:column;align-items:center;justify-content:center;min-width:34px;height:51px;text-decoration:none;cursor:pointer;gap:8px;flex:1}.side-item .item-icon{width:24px;height:24px;display:flex;align-items:center;justify-content:center}.side-item .item-icon randstad-icon{--icon-color:var(--secondary-color-80,#404767)}.side-item.active .item-icon randstad-icon{--icon-color:var(--primary-color,#2175d9)}.side-item .item-label{font-family:'Graphik',sans-serif;font-weight:400;font-size:10px;line-height:12px;letter-spacing:0%;color:var(--secondary-color-80,#404767);text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}.side-item.active .item-label{color:var(--primary-color,#2175d9)}.center-button{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;cursor:pointer;background:none;border:none;padding:0;margin:0 12px;flex-shrink:0}.center-circle{width:60px;height:60px;border-radius:100px;background:var(--primary-color,#2175d9);border:4px solid rgba(211,227,247,1);display:flex;align-items:center;justify-content:center;transform:translateY(-12px)}.center-circle randstad-icon{--icon-color:var(--white,#ffffff)}.center-label{font-family:'Graphik',sans-serif;font-weight:400;font-size:10px;line-height:12px;letter-spacing:0%;color:var(--secondary-color,#0f1941);text-align:center}@media (max-width:940px){.center-button{margin:0}.side-item{min-width:unset}}`}render(){let e=this.items.slice(0,2),t=this.items.slice(2,4),n=(e,t)=>{let n=t===this.selectedIndex,r=l({"side-item":!0,active:n});return a`<a class=${r} href=${e.href||`#`} @click=${n=>{e.href||n.preventDefault(),this.handleItemClick(t,e)}} aria-label=${e.label} aria-current=${n?`page`:o} ><span class="item-icon"><randstad-icon name=${e.icon} size="24" aria-hidden="true"></randstad-icon></span><span class="item-label">${e.label}</span></a>`};return a`<nav class="navbar" role="navigation" aria-label="Navegación principal">${e.map((e,t)=>n(e,t))}<button class="center-button" @click=${this.handleCenterClick} aria-label="Abrir menú"><span class="center-circle"><randstad-icon name=${this.centerIcon} size="28" aria-hidden="true"></randstad-icon></span>${this.centerLabel?a`<span class="center-label">${this.centerLabel}</span>`:o}</button>${t.map((e,t)=>n(e,t+2))}</nav>`}};t([c({type:Array}),e(`design:type`,Array)],f.prototype,`items`,void 0),t([c({type:String}),e(`design:type`,Object)],f.prototype,`centerIcon`,void 0),t([c({type:String}),e(`design:type`,Object)],f.prototype,`centerLabel`,void 0),t([c({type:Boolean,reflect:!0}),e(`design:type`,Object)],f.prototype,`hidden`,void 0),t([c({type:Boolean,reflect:!0}),e(`design:type`,Object)],f.prototype,`desktop`,void 0),t([c({type:Number}),e(`design:type`,Object)],f.prototype,`selectedIndex`,void 0),t([c({type:Boolean,attribute:`hide-on-input-focus`}),e(`design:type`,Object)],f.prototype,`hideOnInputFocus`,void 0),f=u=t([s(`randstad-navbar`),e(`design:paramtypes`,[])],f);export{f as RandstadNavbar};
|
|
@@ -31,6 +31,11 @@ export declare class FilterableSelect extends BaseControl {
|
|
|
31
31
|
private _isCleared;
|
|
32
32
|
private static _scrollLockCount;
|
|
33
33
|
private static _scrollLockStylesheet;
|
|
34
|
+
private static _savedScrollY;
|
|
35
|
+
private static _savedBodyStyle;
|
|
36
|
+
/** Contenedores padre scrolleables (p. ej. .modal-body de custom-modal) con su estado previo. */
|
|
37
|
+
private _preparedAncestors;
|
|
38
|
+
private _lockedAncestors;
|
|
34
39
|
filteredOptions: SelectOption[];
|
|
35
40
|
filterValue: string;
|
|
36
41
|
isOpen: boolean;
|
|
@@ -55,6 +60,31 @@ export declare class FilterableSelect extends BaseControl {
|
|
|
55
60
|
*/
|
|
56
61
|
private static _ensureScrollLockStyles;
|
|
57
62
|
private toggleDynamicScrollLock;
|
|
63
|
+
/**
|
|
64
|
+
* Fija el body con position: fixed (único patrón confiable en iOS Safari para que
|
|
65
|
+
* el teclado no desplace el documento). Guarda el scroll para restaurarlo al cerrar.
|
|
66
|
+
*/
|
|
67
|
+
private _lockBodyScroll;
|
|
68
|
+
private _unlockBodyScroll;
|
|
69
|
+
/**
|
|
70
|
+
* Devuelve los contenedores padre scrolleables del componente atravesando slots y
|
|
71
|
+
* shadow roots (p. ej. el .modal-body interno de <custom-modal>). Excluye html/body.
|
|
72
|
+
*/
|
|
73
|
+
private _getScrollableAncestors;
|
|
74
|
+
/**
|
|
75
|
+
* Se ejecuta en fase de captura (pointerdown / Enter / Space) ANTES de que iOS mueva
|
|
76
|
+
* el foco y scrollee el contenedor padre: guarda su scrollTop y overflowY previos.
|
|
77
|
+
*/
|
|
78
|
+
private _prepareAncestors;
|
|
79
|
+
/** Al abrirse el overlay mobile: fuerza el scrollTop guardado y bloquea el overflow. */
|
|
80
|
+
private _lockAncestors;
|
|
81
|
+
private _unlockAncestors;
|
|
82
|
+
/**
|
|
83
|
+
* Bloquea touchmove en el backdrop (iOS): solo deja pasar el gesto si cae dentro de
|
|
84
|
+
* .options-list y la lista tiene scroll real. composedPath() atraviesa el Shadow DOM.
|
|
85
|
+
* Se registra con passive: false para poder llamar a preventDefault().
|
|
86
|
+
*/
|
|
87
|
+
private _overlayTouchMoveListener;
|
|
58
88
|
private getOptionLabel;
|
|
59
89
|
/**
|
|
60
90
|
* Normaliza un texto eliminando acentos y convertiendo a minúsculas.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import e from"../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorateMetadata.js";import t from"../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorate.js";import"./Icon.js";import{BaseControl as n}from"../helpers/BaseControl.js";import{bodyL as r}from"../styles/fontStyles.js";import{tooltipStyles as i}from"../styles/tooltip.js";import{mixStyles as a}from"../styles/mix.js";import{errorStyles as o}from"../styles/error.js";import{scrollbarStyles as s}from"../styles/scrollbar.js";import{css as
|
|
1
|
+
import e from"../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorateMetadata.js";import t from"../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorate.js";import"./Icon.js";import{BaseControl as n}from"../helpers/BaseControl.js";import{bodyL as r}from"../styles/fontStyles.js";import{tooltipStyles as i}from"../styles/tooltip.js";import{mixStyles as a}from"../styles/mix.js";import{errorStyles as o}from"../styles/error.js";import{scrollbarStyles as s}from"../styles/scrollbar.js";import{dispatchMobileOverlay as c}from"../helpers/overlayEvents.js";import{css as l,html as u,nothing as d}from"lit";import{customElement as f,property as p,query as m,state as h}from"lit/decorators.js";var g;const _=/[\p{Extended_Pictographic}\u{FE0F}\u{1F3FB}-\u{1F3FF}\u{1F9B0}-\u{1F9B3}\u{200D}]/gu;let v=class extends n{static{g=this}constructor(...e){super(...e),this.value=``,this.defaultValue=``,this.options=[],this.textLabelFilterNotResult=``,this.textLabelMobileSearch=``,this.isRenderClearButton=!1,this.sortable=!0,this.minSearch=3,this.textLabelLoading=`Cargando...`,this.debounceMs=300,this.isMobile=!1,this.highlightedIndex=-1,this._isCleared=!1,this._preparedAncestors=[],this._lockedAncestors=[],this.filteredOptions=[],this.filterValue=``,this.isOpen=!1,this.mobileFilterValue=``,this.showNoResults=!1,this._isLoading=!1,this.lastElement=!1,this._prevIsMobile=!1,this._lastFetchTerm=null,this._fetchedOptions=[],this.debounceTimeout=null,this._abortController=null,this._boundHandleClickOutside=this.handleClickOutside.bind(this),this._prepareAncestors=e=>{!this.isMobile||this.isOpen||this.disabled||e instanceof KeyboardEvent&&e.key!==`Enter`&&e.key!==` `||(this._preparedAncestors=this._getScrollableAncestors().map(e=>({el:e,scrollTop:e.scrollTop,overflowY:e.style.overflowY})))},this._overlayTouchMoveListener={handleEvent:e=>{let t=e.composedPath().find(e=>e instanceof HTMLElement&&e.classList.contains(`options-list`));t&&t.scrollHeight>t.clientHeight||e.cancelable&&e.preventDefault()},passive:!1},this.getOptionLabel=e=>typeof e==`string`?e:e.label,this.handleGlobalOverlayOpen=e=>{e.detail!==this&&this.isOpen&&(this.isOpen=!1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0})))},this.updateResponsiveModeBound=this.updateResponsiveMode.bind(this),this._firstCharRegex=null}get _effectiveFilterable(){let e=this.getAttribute(`filterable`);return e===null?this.filterable===void 0?this.options.length>5:this.filterable:e!==`false`}static{this._scrollLockCount=0}static{this._scrollLockStylesheet=null}static{this._savedScrollY=0}static{this._savedBodyStyle=null}static{this.styles=[s,l`${a}${o}${i}:host([error]) .input-container:not(.open) .input-wrapper:hover{box-shadow:0px 0px 0px 4px #E00F0F1A !important}:host([error]) .input-container.open:not(.mobile) .input-wrapper{border-bottom-left-radius:0;border-bottom-right-radius:0;border:1px solid var(--ui-negative,red) !important;border-bottom:1px solid transparent !important}:host([error]) .input-container:not(.mobile) .options-list{border:1px solid var(--ui-negative,red) !important;border-top:none !important;border-radius:0 0 4px 4px}.input-wrapper.disabled .filter-input,.input-wrapper.disabled .filter-fake{background-color:var(--secondary-color-10);color:#9FA3B3;cursor:default}.input-wrapper.disabled .icon-button,.input-wrapper.disabled .icon-button randstad-icon,.input-wrapper.disabled .icon-button .close-icon{color:#9FA3B3;cursor:default;--icon-color:var(--secondary-color-40,#9FA3B3) !important}.input-wrapper.disabled .icon-selected svg{fill:#9FA3B3}.input-wrapper .icon-button .close-icon{color:var(--primary-color)}.select-container{display:flex;flex-direction:column;gap:8px;width:100%}.input-container.focused:not(.open):not(.mobile) .input-wrapper{border:1px solid var(--primary-color);border-radius:4px;box-shadow:none;z-index:11}.input-container.focused:not(.open):not(.mobile) .input-wrapper:hover{box-shadow:none}:host(:not([error])) .input-container.open:not(.mobile){border-radius:4px;border-bottom-left-radius:0;border-bottom-right-radius:0}:host(:not([error])) .input-container.open:not(.mobile) .input-wrapper{border:1px solid var(--primary-color);border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-left-radius:0;border-bottom-right-radius:0;border-bottom:1px solid transparent;box-shadow:none;z-index:11}:host(:not([error])) .input-wrapper:hover{box-shadow:0px 0px 0px 4px #0F19411A}:host .input-container.open:not(.mobile)::after{content:'';position:absolute;top:calc(100% - 1px);left:20px;right:20px;height:1px;background-color:var(--gray-20);z-index:10}.input-wrapper{border:1px solid var(--secondary-color-10);border-radius:4px;overflow:hidden;display:flex;align-items:center;width:100%;transition:box-shadow 0.2s ease-in-out;background-color:white}.mobile-modal .filter-input{border-bottom:1px solid var(--gray-20)}.filter-input{${r};padding:16px;padding-right:40px;border:none;outline:none;width:100%;box-sizing:border-box;background:white;cursor:pointer;color:var(--secondary-color);flex-grow:1}.filter-input,.filter-fake,.input-wrapper,.mobile-modal{-webkit-tap-highlight-color:transparent !important;caret-color:var(--primary-color) !important}.filter-input::placeholder{${r};color:var(--filter-text-color,var(--secondary-color-40))}.filter-input:-webkit-autofill,.filter-input:-webkit-autofill:hover,.filter-input:-webkit-autofill:focus,.filter-input:-webkit-autofill:active{-webkit-box-shadow:0 0 0px 1000px #ffffff inset;-webkit-text-fill-color:var(--secondary-color);transition:background-color 5000s ease-in-out 0s}.icon-button{position:absolute;right:10px;top:50%;transform:translateY(-50%);background:transparent;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;width:40px;height:40px;border-radius:50%;transition:background-color 0.2s ease;padding:0}.input-wrapper:not(.disabled) .icon-button:hover{background-color:var(--primary-color-10)}randstad-icon{width:24px;height:24px;color:var(--primary-color)}.options-list{width:100%;position:absolute;top:99%;left:0;right:0;max-height:200px;overflow-y:auto;border:1px solid var(--primary-color);border-top:none;border-radius:0 0 4px 4px;background:white;list-style:none;margin:0;padding:0;z-index:10}.options-list li{${r};padding:8px 16px 8px 16px;color:var(--secondary-color-80);display:flex;align-items:center}.options-list li:not(.state-item){cursor:pointer}.options-list li.highlighted{background-color:var(--primary-color-10)}.options-list li:not(.state-item):hover,.options-list li.highlighted:not(.state-item):hover{background-color:#D3E3F7}.mobile-modal{position:fixed;top:20dvh;width:100%;bottom:0;background-color:white;z-index:1000;border-radius:12px 12px 0 0;box-shadow:0 -4px 10px rgba(0,0,0,0.15);display:flex;flex-direction:column;padding:0px;animation:slideUp 0.5s ease-out;min-height:80dvh;overflow-y:hidden}.mobile-modal .options-list{position:static;max-height:none;border:none;box-shadow:none;flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch}.mobile-modal .modal-input-container{position:relative;flex-shrink:0}.mobile-modal .modal-input-container input::placeholder{${r}color:rgba(159,163,179,1)}.mobile-modal .modal-close-button{position:absolute;top:50%;right:12px;transform:translateY(-50%);background:transparent;border:none;cursor:pointer;padding:4px;display:flex;align-items:center;justify-content:center}.mobile-modal .no-results-icon{position:absolute;top:50%;right:48px;transform:translateY(-50%);display:flex;align-items:center;justify-content:center;padding:4px}.mobile-modal .modal-close-button randstad-icon,.mobile-modal randstad-icon.no-results-icon{width:24px;height:24px}.mobile-modal .modal-close-button randstad-icon{color:var(--primary-color)}.mobile-modal randstad-icon.no-results-icon{color:var(--ui-negative)}.no-results-icon{position:absolute;right:44px;display:flex;align-items:center;justify-content:center;padding:4px;color:var(--ui-negative)}.mobile-backdrop{position:fixed;inset:0;background-color:rgba(0,0,0,0.4);z-index:999;display:flex;align-items:flex-end}.filter-fake{${r};padding:15px;padding-right:40px;width:100%;background:white;box-sizing:border-box;cursor:pointer;color:var(--filter-text-color,var(--secondary-color-80));white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:flex;align-items:center}.filter-fake span{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.filter-fake span.placeholder{color:var(--filter-text-color,var(--secondary-color-40))}@keyframes slideUp{from{transform:translateY(100%)}to{transform:translateY(0)}}.icon-selected{width:24px;height:auto;margin-left:4px;padding-right:12px;border-right:1px solid var(--secondary-color-20);display:flex;align-items:center;justify-content:center;flex-shrink:0}@media (min-width:941px){.icon-selected{margin-left:16px;padding-right:18px}}.icon-selected svg,.icon-list svg{display:block;width:100%;height:auto}.icon-list{width:24px;height:auto;margin-right:8px;flex-shrink:0}.options-list li.state-item{${r}cursor:default !important;background-color:white !important;pointer-events:none;color:rgba(64,71,103,1);border-bottom:none !important}@media (max-width:940px){.icon-button:hover{background-color:transparent}}`]}static _ensureScrollLockStyles(){if(!g._scrollLockStylesheet){g._scrollLockStylesheet=new CSSStyleSheet,g._scrollLockStylesheet.replaceSync(`
|
|
2
2
|
.scroll-locked { overflow: hidden !important; }
|
|
3
|
-
`);try{document.adoptedStyleSheets=[...document.adoptedStyleSheets,h._scrollLockStylesheet]}catch{let e=document.createElement(`style`);e.textContent=`.scroll-locked { overflow: hidden !important; }`,document.head.appendChild(e)}}}toggleDynamicScrollLock(e){let t=document.documentElement;if(e){if(h._ensureScrollLockStyles(),h._scrollLockCount++,h._scrollLockCount===1&&(t.classList.add(`scroll-locked`),t.scrollHeight>t.clientHeight)){let e=window.innerWidth-t.clientWidth;t.style.paddingRight=`${e}px`}}else h._scrollLockCount=Math.max(0,h._scrollLockCount-1),h._scrollLockCount===0&&(t.classList.remove(`scroll-locked`),t.style.paddingRight=``)}normalizeText(e){return e?e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``):``}sortOptions(e,t,n){let r=e=>typeof e==`string`?e:typeof e.value==`string`?e.value:``,i=this.getOptionLabel(e),a=this.getOptionLabel(t),o=this.normalizeText(i),s=this.normalizeText(a);if(n&&n.length>0){let e=this.normalizeText(n),t=o.startsWith(e),r=s.startsWith(e);if(t&&!r)return-1;if(!t&&r)return 1}let c=r(e),l=r(t);if(c===`+54`)return-1;if(l===`+54`)return 1;if(c===`+54`&&l===`+54`)return 0;let u=i.match(/^\d+(\.\d+)?/),d=a.match(/^\d+(\.\d+)?/),f=u?Number(u[0]):NaN,p=d?Number(d[0]):NaN;return!isNaN(f)&&!isNaN(p)?f-p:i.localeCompare(a,`es`,{usage:`sort`,sensitivity:`accent`})}_computeFilteredOptions(e){if(!this._effectiveFilterable||!e||e.length===0){let e=this.sortable?[...this.options].sort((e,t)=>this.sortOptions(e,t,void 0)):[...this.options];return this.highlightedIndex=-1,this.showNoResults=!1,e}let t=this.normalizeText(e),n=this.options.filter(e=>{let n=this.getOptionLabel(e);return this.normalizeText(n).includes(t)});return this.sortable&&(n=n.sort((t,n)=>this.sortOptions(t,n,e))),this.highlightedIndex=n.length>0?0:-1,this.showNoResults=n.length===0,n}handleOptionHover(e){this.highlightedIndex!==e&&(this.highlightedIndex=e)}update(e){if(!this.fetcher){if((e.has(`defaultValue`)||e.has(`options`)||e.has(`value`)&&this.value)&&!this._isCleared){let e=this.value||this.defaultValue,t=this.options.find(t=>typeof t==`string`?t===e:t.value===e);t?(this.filterValue=typeof t==`string`?t:t.label,this.value=typeof t==`string`?t:t.value):((!this.isOpen&&!this.filterValue||!this.isOpen&&this.value===``)&&(this.filterValue=``),this.value=``)}this._isCleared&&this.value===``&&(this._isCleared=!1)}super.update(e)}willUpdate(e){if(e.has(`keydownRegex`)){if(this.keydownRegex){let e=this.keydownRegex.match(/\[\^?[^\]]+\]/g)?.[0]??`[${this.keydownRegex}]`;this._firstCharRegex=new RegExp(e)}else this._firstCharRegex=null}this.fetcher||(e.has(`filterValue`)||e.has(`options`))&&(this.filteredOptions=this._computeFilteredOptions(this.filterValue))}updated(e){super.updated(e),e.has(`isOpen`)&&this.isMobile&&this.toggleDynamicScrollLock(this.isOpen),this._prevIsMobile&&!this.isMobile&&this.toggleDynamicScrollLock(!1),this._prevIsMobile=this.isMobile;let t=e.get(`isOpen`)===!1;this.isMobile&&this.isOpen&&e.has(`isOpen`)&&t&&this.updateComplete.then(()=>{let e=this.mobileInputRef;e&&window.setTimeout(()=>{e.focus(),e.setSelectionRange(e.value.length,e.value.length)},0)})}connectedCallback(){super.connectedCallback(),this.updateResponsiveMode(),window.addEventListener(`resize`,this.updateResponsiveModeBound),document.addEventListener(`click`,this._boundHandleClickOutside),window.addEventListener(`overlay-opened`,this.handleGlobalOverlayOpen)}disconnectedCallback(){window.removeEventListener(`resize`,this.updateResponsiveModeBound),document.removeEventListener(`click`,this._boundHandleClickOutside),window.removeEventListener(`overlay-opened`,this.handleGlobalOverlayOpen),this.debounceTimeout&&=(clearTimeout(this.debounceTimeout),null),this._abortController&&=(this._abortController.abort(),null),this.isMobile&&this.isOpen&&this.toggleDynamicScrollLock(!1),super.disconnectedCallback()}notifyOverlayOpened(){window.dispatchEvent(new CustomEvent(`overlay-opened`,{detail:this}))}updateResponsiveMode(){this.isMobile=window.innerWidth<=940}handleInputClick(e){this.disabled||(!this.fetcher||this.isMobile)&&(this.isOpen||(this.notifyOverlayOpened(),this.fetcher&&this.isMobile?(this.filteredOptions=[],this.showNoResults=!1,this._isLoading=!1,this.value&&this.filterValue?(this.mobileFilterValue=this.filterValue,this.mobileFilterValue.length>=this.minSearch&&this._fetchAsyncResults(this.mobileFilterValue)):this.mobileFilterValue=``):(this.filteredOptions=this._computeFilteredOptions(``),this.showNoResults=!1),this.isMobile&&!this.fetcher&&(this.mobileFilterValue=``)),this.isOpen=!this.isOpen,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:this.isOpen},bubbles:!0,composed:!0})),this.requestUpdate())}handleInput(e){if(!this._effectiveFilterable)return;this._isCleared=!1;let t=e.target,n=this._sanitizeInputValue(t.value,t);this.filterValue=n,this.fetcher?(n.length>=this.minSearch?(this.isOpen=!0,this.notifyOverlayOpened(),this._fetchAsyncResults(n)):(this.isOpen=!1,this.filteredOptions=[],this._isLoading=!1,this.showNoResults=!1,this._lastFetchTerm=null,this._fetchedOptions=[],this.debounceTimeout&&=(clearTimeout(this.debounceTimeout),null),this._abortController&&=(this._abortController.abort(),null)),this.requestUpdate()):(this.notifyOverlayOpened(),this.isOpen=!0,n===``&&(this._emitEmptySelection(),this.filteredOptions=this._computeFilteredOptions(``),this.showNoResults=!1),this.debounceTimeout&&clearTimeout(this.debounceTimeout),this.debounceTimeout=window.setTimeout(()=>{this.filterValue.length>2&&this.dispatchEvent(new CustomEvent(`filter-location`,{detail:{value:this.filterValue},bubbles:!0,composed:!0}))},300),this.requestUpdate())}handleMobileInput(e){this._isCleared=!1;let t=e.target,n=this._sanitizeInputValue(t.value,t);this.mobileFilterValue=n,this.fetcher?(n.length>=this.minSearch?this._fetchAsyncResults(n):(this.filteredOptions=[],this._isLoading=!1,this.showNoResults=!1,this._lastFetchTerm=null,this._fetchedOptions=[],this.debounceTimeout&&=(clearTimeout(this.debounceTimeout),null),this._abortController&&=(this._abortController.abort(),null)),this.requestUpdate()):(n===``?(this._emitEmptySelection(),this.filteredOptions=this._computeFilteredOptions(``),this.showNoResults=!1):this.filteredOptions=this._computeFilteredOptions(n),this.requestUpdate(),this.debounceTimeout&&clearTimeout(this.debounceTimeout),this.debounceTimeout=window.setTimeout(()=>{n.length>2?this.dispatchEvent(new CustomEvent(`filter-location`,{detail:{value:n},bubbles:!0,composed:!0})):n.length===0&&(this.filteredOptions=this._computeFilteredOptions(``))},300))}handleSelect(e){this._isCleared=!1,this.highlightedIndex=-1;let t=typeof e==`string`?e:e.value;this.dispatchEvent(new CustomEvent(`option-selected`,{detail:{value:t},bubbles:!0,composed:!0})),this.filterValue=typeof e==`string`?e:e.label,this.value=t,this.isOpen=!1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0})),this.mobileFilterValue=this.filterValue,this.fetcher||(this.filteredOptions=this._computeFilteredOptions(``)),this.showNoResults=!1,this._lastFetchTerm=null,this._fetchedOptions=[],this.requestUpdate()}handleIconClick(){if(this.disabled)return;this.highlightedIndex=-1;let e=this.isRenderClearButton,t=typeof this.value==`string`&&this.value!==``,n=typeof this.value==`object`&&this.value!==null&&Object.keys(this.value).length>0;if(e&&(t||n))this._emitEmptySelection(),this.filterValue=``,this.filteredOptions=this._computeFilteredOptions(``),this._lastFetchTerm=null,this._fetchedOptions=[],this.isOpen=!1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0}));else{let e=!this.isOpen;if(e&&this.fetcher&&this.filterValue&&this.filterValue.length>=this.minSearch)this.notifyOverlayOpened(),this.isOpen=!0,this.mobileFilterValue=``,this.showNoResults=!1,this._fetchAsyncResults(this.filterValue);else if(e&&this.fetcher&&this.filterValue&&this.filterValue.length<this.minSearch)return;else this.notifyOverlayOpened(),this.isOpen=!this.isOpen,this.isOpen?(this.mobileFilterValue=``,this.showNoResults=!1,this.filteredOptions=this._computeFilteredOptions(``)):(this.mobileFilterValue=``,this.filteredOptions=this._computeFilteredOptions(``));this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:this.isOpen},bubbles:!0,composed:!0})),this.isOpen&&!this.isMobile&&this.updateComplete.then(()=>{this._desktopInput?.focus()})}this.requestUpdate()}handleClickOutside(e){let t=e.target;t instanceof Node&&(!this.contains(t)&&this.isOpen&&(this.isOpen=!1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0})),this.requestUpdate()),this.isMobile&&!this.contains(t)&&(this.mobileFilterValue=``,this.filteredOptions=this._computeFilteredOptions(``)))}preventInvalidStart(e){let t=e.target;return t&&t.tagName===`INPUT`&&t.selectionStart===0&&e.key.length===1&&!(this.keydownRegex?this._firstCharRegex?.test(e.key)??!0:/[a-zA-ZáéíóúÁÉÍÓÚñÑüÜ0-9]/.test(e.key))?(e.preventDefault(),!0):!1}onlyRegex(e){if(!this.keydownRegex)return e;let t=this.keydownRegex.match(/\[\^?[^\]]+\]/g);t||=[`[${this.keydownRegex}]`];let n=``,r=t.length>=2,i=new RegExp(t[0]),a=r?new RegExp(t[1]):i,o=e.split(``);for(let e=0;e<o.length;e++){let t=o[e];e===0?i.test(t)&&(n+=t):a.test(t)&&(n+=t)}return n.trimStart()}handlePaste(e){let t=e.target;if(t&&t.tagName===`INPUT`&&t.selectionStart===0){let n=t.selectionStart,r=t.selectionEnd;if(n===null||r===null)return;e.preventDefault();let i=e.clipboardData?.getData(`text`)||``,a=this._sanitize(i,!0);a&&(t.setRangeText(a,n,r,`end`),t.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})))}}handleKeyDown(e){if(this.preventInvalidStart(e))return;let{key:t}=e,n=this._desktopInput;if(t===`Backspace`&&this._effectiveFilterable){let e=n?.value||``,t=n&&n.selectionStart!==n.selectionEnd,r=e.length===1&&!t,i=e.length===0;this.fetcher?(i?0:e.length-(t?n.selectionEnd-n.selectionStart:1))<this.minSearch&&(this.isOpen=!1,this.filteredOptions=[],this._isLoading=!1,this.showNoResults=!1,this._lastFetchTerm=null,this._fetchedOptions=[],this.debounceTimeout&&=(clearTimeout(this.debounceTimeout),null),this._abortController&&=(this._abortController.abort(),null),this.requestUpdate()):(r||i)&&(this._emitEmptySelection(),this.filterValue=``,this.filteredOptions=this._computeFilteredOptions(``),this.isOpen=!0,this.requestUpdate())}let r=this.filteredOptions.filter(e=>!(typeof e==`object`&&e.disabled));if(!this.isOpen&&(t===`Enter`||t===` `)){e.preventDefault(),this.notifyOverlayOpened(),this.isOpen=!0;let t=this.filteredOptions.findIndex(e=>!(typeof e==`object`&&e.disabled));this.highlightedIndex=t===-1?-1:t,this.requestUpdate()}else{if(this.isOpen){if(t===`ArrowDown`){e.preventDefault();let t=this.highlightedIndex+1;for(;t<this.filteredOptions.length;){let e=this.filteredOptions[t];if(!(typeof e==`object`&&e.disabled)){this.highlightedIndex=t;break}t++}if(t>=this.filteredOptions.length){if(r.length>0){let e=r[r.length-1];this.highlightedIndex=this.filteredOptions.indexOf(e)}else this.highlightedIndex=-1}this.requestUpdate(),this.updateComplete.then(()=>this.scrollHighlightedIntoView())}else if(t===`ArrowUp`){e.preventDefault();let t=this.highlightedIndex-1;for(;t>=0;){let e=this.filteredOptions[t];if(!(typeof e==`object`&&e.disabled)){this.highlightedIndex=t;break}t--}t<0&&(this.highlightedIndex=-1),this.requestUpdate(),this.updateComplete.then(()=>this.scrollHighlightedIntoView())}else if(t===`Enter`||!this._effectiveFilterable&&t===` `){this.highlightedIndex>=0&&e.preventDefault();let t=this.filteredOptions[this.highlightedIndex];if(this.highlightedIndex>=0&&t&&!(typeof t==`object`&&t.disabled)){this.handleSelect(t),this._desktopInput?this._desktopInput.focus():this._desktopFake?.focus(),this.highlightedIndex=-1;return}}else t===`Escape`?(e.preventDefault(),this.isOpen=!1,this.highlightedIndex=-1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0})),this._desktopInput?this._desktopInput.focus():this._desktopFake?.focus()):t===`Tab`?(this.isOpen=!1,this.highlightedIndex=-1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0})),this.requestUpdate()):!this.isMobile&&this._effectiveFilterable&&t.length===1&&(this.highlightedIndex=-1);if((t===`ArrowLeft`||t===`ArrowRight`)&&this._effectiveFilterable)return}if(t===`ArrowRight`){let t=!n||n.selectionStart===n.value.length;(!this._effectiveFilterable||t)&&(e.preventDefault(),this._iconButton?.focus())}}}handleButtonKeyDown(e){let{key:t}=e,n=this._desktopInput,r=this._desktopFake,i=n||r;t===`ArrowLeft`?(e.preventDefault(),i?.focus(),i instanceof HTMLInputElement&&(i.selectionStart=i.selectionEnd=i.value.length)):t===`Enter`||t===` `?(e.preventDefault(),this._effectiveFilterable&&this.filterValue?(this.handleIconClick(),i?.focus()):(this.isOpen=!this.isOpen,this.isOpen&&(this.highlightedIndex=-1,i?.focus())),this.requestUpdate()):t===`Tab`&&this.isOpen&&(this.isOpen=!1,this.highlightedIndex=-1,this.requestUpdate())}handleBlur(){window.setTimeout(()=>{this.validateAndCleanOnBlur(),this.requestUpdate()},200)}scrollHighlightedIntoView(){if(this.isMobile||this.highlightedIndex<0)return;let e=this._optionsList;if(!e)return;let t=e.querySelector(`li.highlighted`);t&&t.scrollIntoView({block:`nearest`})}_emitEmptySelection(){this.value=``,this._isCleared=!0,this.dispatchEvent(new CustomEvent(`option-selected`,{detail:{value:``},bubbles:!0,composed:!0}))}_fetchAsyncResults(e){if(this._lastFetchTerm!==null&&this._fetchedOptions.length>0&&this.normalizeText(e).startsWith(this.normalizeText(this._lastFetchTerm))){let t=this.normalizeText(e);this.filteredOptions=this._fetchedOptions.filter(e=>{let n=this.getOptionLabel(e);return this.normalizeText(n).includes(t)}),this.showNoResults=this.filteredOptions.length===0,this.highlightedIndex=this.filteredOptions.length>0?0:-1,this._isLoading=!1,this.requestUpdate();return}this._abortController&&this._abortController.abort(),this.debounceTimeout&&clearTimeout(this.debounceTimeout),this._isLoading=!0,this.showNoResults=!1,this.filteredOptions=[],this.requestUpdate();let t=()=>{this._abortController=new AbortController,this.fetcher(e,{signal:this._abortController.signal}).then(t=>{this._abortController?.signal.aborted||(this._fetchedOptions=t,this._lastFetchTerm=e,this.filteredOptions=t,this.showNoResults=t.length===0,this.highlightedIndex=t.length>0?0:-1,this._isLoading=!1,this.requestUpdate())}).catch(()=>{this._abortController?.signal.aborted||(this.filteredOptions=[],this.showNoResults=!0,this._isLoading=!1,this.requestUpdate())})};this.debounceMs>0?this.debounceTimeout=window.setTimeout(t,this.debounceMs):t()}_sanitize(e,t){let n=e.replace(g,``);if(this.maxLength&&(n=n.slice(0,this.maxLength)),n.startsWith(` `)&&(n=n.trimStart()),this.keydownRegex&&(n=this.onlyRegex(n)),t&&n.length>0){let e=n[0];(this.keydownRegex?this._firstCharRegex?.test(e)??!0:/[a-zA-ZáéíóúÁÉÍÓÚñÑüÜ0-9]/.test(e))||(n=this.keydownRegex&&this._firstCharRegex?n.replace(RegExp(`^[^${this._firstCharRegex.source.replace(/^\[/,``).replace(/\]$/,``)}]+`),``):n.replace(/^[^a-zA-ZáéíóúÁÉÍÓÚñÑüÜ0-9]+/,``))}return n}_sanitizeInputValue(e,t){let n=t.selectionStart||0,r=e.slice(0,n).replace(g,``).length,i=this._sanitize(e,!1);return t.value=i,t.setSelectionRange(r,r),i}renderOptionIcon(e){if(!e||typeof e!=`string`)return u;let t=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,``).replace(/\bon\w+\s*=/gi,``).replace(/javascript:/gi,``);return l`<span class="icon-list" .innerHTML="${t}"></span>`}_renderOptionItem(e,t){let n=typeof e==`string`?e:e.label,r=typeof e==`object`&&e.disabled,i=typeof e==`object`?e.icon:void 0;return l`<li id="option-${t}" class="${r?`disabled`:``} ${t===this.highlightedIndex?`highlighted`:``}" role="option" aria-selected="${t===this.highlightedIndex}" @click="${()=>{r||this.handleSelect(e)}}" @mouseenter="${()=>this.handleOptionHover(t)}" >${this.renderOptionIcon(i)} ${n}</li>`}validateAndCleanOnBlur(){if(!this._effectiveFilterable)return;let e=this.normalizeText((this.filterValue||``).trim());if(!e){this.value!==``&&this._emitEmptySelection(),this.filterValue=``,this.filteredOptions=this._computeFilteredOptions(``),this.showNoResults=!1;return}let t=(this.fetcher?this.filteredOptions:this.options).find(t=>{let n=typeof t==`string`?t:t.label;return this.normalizeText(String(n))===e});if(!t)this._emitEmptySelection(),this.filterValue=``,this.filteredOptions=this._computeFilteredOptions(``),this.showNoResults=!1;else{let e=typeof t==`string`?t:t.value,n=typeof t==`string`?t:t.label;this.value!==e&&(this.value=e,this.dispatchEvent(new CustomEvent(`option-selected`,{detail:{value:e},bubbles:!0,composed:!0}))),this.filterValue=n,this.showNoResults=!1}}render(){let e=this.isMobile,t=l`<randstad-icon name="${this.isOpen&&this.filteredOptions.length>0?`arrow_up`:`arrow_down`}" size="24px" .color=${`var( --primary-color )`} ></randstad-icon>`,n=this.isRenderClearButton===!0,r=this.isOpen&&(this.filteredOptions.length>0||this.filterValue.length>0),i=!this.textLabelFilterNotResult||typeof this.textLabelFilterNotResult!=`string`,a=!this.textLabelMobileSearch||typeof this.textLabelMobileSearch!=`string`,o=!this.placeholder||typeof this.placeholder!=`string`,s=i?`No se encontraron resultados`:this.textLabelFilterNotResult,c=a?`buscá una opción`:this.textLabelMobileSearch,d=o?`seleccioná una opción`:this.placeholder;return l`<div class="select-container" style="${this.labelColor?` --label-color: ${this.labelColor};`:``}">${this.renderLabelContainer()}<div class="list-container"><div class="input-container ${this.isOpen?`focused`:``} ${r?`open`:``} ${e?`mobile`:``}"><div class="input-wrapper ${this.disabled?`disabled`:``}">${e?l`<div class="filter-fake" @click="${this.handleInputClick}" @keydown="${this.handleKeyDown}" @blur="${this.handleBlur}" tabindex="0" role="combobox" autocomplete="new-password" aria-expanded="${this.isOpen}" aria-controls="options-list" aria-haspopup="listbox" aria-activedescendant="${this.isOpen&&this.highlightedIndex!==-1?`option-${this.highlightedIndex}`:u}" ><span class="${this.filterValue?``:`placeholder`}">${this.filterValue||d}</span></div>`:l`<input class="filter-input" .value="${this.filterValue||``}" @click="${this.handleInputClick}" @keydown="${this.handleKeyDown}" @input=${this.handleInput} @paste="${this.handlePaste}" @blur="${this.handleBlur}" placeholder="${this.filterValue?``:d}" ?disabled="${this.disabled}" ?readonly="${!this._effectiveFilterable}" maxlength="${this.maxLength??``}" tabindex="0" role="combobox" inputmode="search" autocomplete="new-password" aria-expanded="${this.isOpen}" aria-controls="options-list" aria-haspopup="listbox" aria-busy="${this._isLoading}" aria-activedescendant="${this.isOpen&&this.highlightedIndex!==-1?`option-${this.highlightedIndex}`:u}" />`} ${!e&&this.showNoResults?l`<randstad-icon name="warning" size="24px" class="no-results-icon"></randstad-icon>`:u} ${!this.fetcher||this.filteredOptions.length>0||this._isLoading?l`<button class="icon-button" @click="${this.handleIconClick}" @keydown="${this.handleButtonKeyDown}" ?disabled="${this.disabled}" tabindex="0" aria-label="${this.value&&this.value!==``?`Clear selection`:`Toggle options`}" >${n&&this.value&&this.value!==``?l`<randstad-icon name="close" size="24px"></randstad-icon>`:t}</button>`:u} ${!e&&this.isOpen?l` ${this._isLoading?l`<ul id="options-list" class="options-list" role="listbox" aria-live="polite"><li class="state-item" role="status">${this.textLabelLoading}</li></ul>`:this.filteredOptions.length>0?l`<ul id="options-list" class="options-list" role="listbox" aria-live="polite">${this.filteredOptions.map((e,t)=>this._renderOptionItem(e,t))}</ul>`:this.showNoResults?l`<ul id="options-list" class="options-list" role="listbox" aria-live="polite"><li class="state-item">${s}</li></ul>`:u} `:u}</div></div>${this.renderError()}</div>${this.renderHelper()} ${e&&this.isOpen?l`<div class="mobile-backdrop" @click="${()=>{this.isOpen=!1}}"><div class="mobile-modal" @click="${e=>e.stopPropagation()}"><div class="modal-input-container">${this._effectiveFilterable?l`<input class="filter-input" .value="${this.mobileFilterValue||``}" @input=${e=>this.handleMobileInput(e)} @keydown="${this.preventInvalidStart}" @paste="${this.handlePaste}" placeholder="${c}" inputmode="search" maxlength="${this.maxLength??``}" role="combobox" aria-expanded="${this.isOpen}" aria-controls="mobile-options-list" aria-haspopup="listbox" />${!this._isLoading&&this.showNoResults?l`<randstad-icon name="warning" size="24px" class="no-results-icon"></randstad-icon>`:u} `:u}<button class="modal-close-button" @click="${()=>{this.isOpen=!1,this.mobileFilterValue=``,this.filteredOptions=this._computeFilteredOptions(``),this._lastFetchTerm=null,this._fetchedOptions=[],this.debounceTimeout&&=(clearTimeout(this.debounceTimeout),null),this._abortController&&=(this._abortController.abort(),null),this._isLoading=!1}}"><randstad-icon name="close" size="24px"></randstad-icon></button></div>${this._isLoading?l`<ul id="mobile-options-list" class="options-list" role="listbox" aria-live="polite"><li class="state-item" role="status">${this.textLabelLoading}</li></ul>`:this.filteredOptions.length>0?l`<ul id="mobile-options-list" class="options-list" role="listbox" aria-live="polite">${this.filteredOptions.map((e,t)=>this._renderOptionItem(e,t))}</ul>`:this.showNoResults?l`<ul id="mobile-options-list" class="options-list" role="listbox" aria-live="polite"><li class="state-item mobile-item">${s}</li></ul>`:u}</div></div>`:u} `}};t([f({type:Object}),e(`design:type`,Object)],_.prototype,`value`,void 0),t([f({type:String,attribute:`default-value`}),e(`design:type`,Object)],_.prototype,`defaultValue`,void 0),t([f({type:Array}),e(`design:type`,Array)],_.prototype,`options`,void 0),t([f({type:Boolean}),e(`design:type`,Object)],_.prototype,`filterable`,void 0),t([f({type:Number}),e(`design:type`,Number)],_.prototype,`maxLength`,void 0),t([f({type:String}),e(`design:type`,String)],_.prototype,`keydownRegex`,void 0),t([f({type:String}),e(`design:type`,String)],_.prototype,`textLabelFilterNotResult`,void 0),t([f({type:String}),e(`design:type`,String)],_.prototype,`textLabelMobileSearch`,void 0),t([f({type:Boolean}),e(`design:type`,Object)],_.prototype,`isRenderClearButton`,void 0),t([f({type:Boolean}),e(`design:type`,Object)],_.prototype,`sortable`,void 0),t([f({type:Function}),e(`design:type`,Object)],_.prototype,`fetcher`,void 0),t([f({type:Number}),e(`design:type`,Number)],_.prototype,`minSearch`,void 0),t([f({type:String}),e(`design:type`,String)],_.prototype,`textLabelLoading`,void 0),t([f({type:Number,attribute:`debounce-ms`}),e(`design:type`,Number)],_.prototype,`debounceMs`,void 0),t([m(),e(`design:type`,Boolean)],_.prototype,`isMobile`,void 0),t([m(),e(`design:type`,Object)],_.prototype,`highlightedIndex`,void 0),t([m(),e(`design:type`,Boolean)],_.prototype,`_isCleared`,void 0),t([m(),e(`design:type`,Array)],_.prototype,`filteredOptions`,void 0),t([m(),e(`design:type`,Object)],_.prototype,`filterValue`,void 0),t([m(),e(`design:type`,Object)],_.prototype,`isOpen`,void 0),t([m(),e(`design:type`,Object)],_.prototype,`mobileFilterValue`,void 0),t([m(),e(`design:type`,Boolean)],_.prototype,`showNoResults`,void 0),t([m(),e(`design:type`,Boolean)],_.prototype,`_isLoading`,void 0),t([f({type:Boolean,attribute:`last-element`}),e(`design:type`,Object)],_.prototype,`lastElement`,void 0),t([p(`.mobile-modal .filter-input`),e(`design:type`,typeof HTMLInputElement>`u`?Object:HTMLInputElement)],_.prototype,`mobileInputRef`,void 0),t([p(`.filter-input`),e(`design:type`,typeof HTMLInputElement>`u`?Object:HTMLInputElement)],_.prototype,`_desktopInput`,void 0),t([p(`.filter-fake`),e(`design:type`,typeof HTMLElement>`u`?Object:HTMLElement)],_.prototype,`_desktopFake`,void 0),t([p(`.icon-button`),e(`design:type`,typeof HTMLButtonElement>`u`?Object:HTMLButtonElement)],_.prototype,`_iconButton`,void 0),t([p(`.options-list`),e(`design:type`,typeof HTMLUListElement>`u`?Object:HTMLUListElement)],_.prototype,`_optionsList`,void 0),_=h=t([d(`filterable-select`)],_);export{_ as FilterableSelect};
|
|
3
|
+
`);try{document.adoptedStyleSheets=[...document.adoptedStyleSheets,g._scrollLockStylesheet]}catch{let e=document.createElement(`style`);e.textContent=`.scroll-locked { overflow: hidden !important; }`,document.head.appendChild(e)}}}toggleDynamicScrollLock(e){let t=document.documentElement;if(e){if(g._ensureScrollLockStyles(),g._scrollLockCount++,g._scrollLockCount===1){let e=t.scrollHeight>t.clientHeight?window.innerWidth-t.clientWidth:0;t.classList.add(`scroll-locked`),e>0&&(t.style.paddingRight=`${e}px`),this._lockBodyScroll()}this._lockAncestors()}else{this._unlockAncestors();let e=g._scrollLockCount>0;g._scrollLockCount=Math.max(0,g._scrollLockCount-1),e&&g._scrollLockCount===0&&(t.classList.remove(`scroll-locked`),t.style.paddingRight=``,this._unlockBodyScroll())}c(this,e)}_lockBodyScroll(){let e=document.body;g._savedScrollY=window.scrollY||document.documentElement.scrollTop||0,g._savedBodyStyle=e.getAttribute(`style`),e.style.position=`fixed`,e.style.top=`-${g._savedScrollY}px`,e.style.left=`0`,e.style.width=`100%`,e.style.overflow=`hidden`}_unlockBodyScroll(){let e=document.body,t=document.documentElement,n=g._savedBodyStyle;n===null?e.removeAttribute(`style`):e.setAttribute(`style`,n),g._savedBodyStyle=null;let r=t.style.scrollBehavior;t.style.scrollBehavior=`auto`,window.scrollTo(0,g._savedScrollY),t.style.scrollBehavior=r}_getScrollableAncestors(){let e=[],t=e=>{if(e.assignedSlot)return e.assignedSlot;if(e.parentElement)return e.parentElement;let t=e.getRootNode();return t instanceof ShadowRoot?t.host:null},n=t(this);for(;n&&n!==document.body&&n!==document.documentElement;){if(n instanceof HTMLElement){let{overflowY:t}=getComputedStyle(n);/(auto|scroll|overlay)/.test(t)&&n.scrollHeight>n.clientHeight&&e.push(n)}n=t(n)}return e}_lockAncestors(){if(this._lockedAncestors.length>0)return;let e=this._preparedAncestors.length>0?this._preparedAncestors:this._getScrollableAncestors().map(e=>({el:e,scrollTop:e.scrollTop,overflowY:e.style.overflowY}));this._preparedAncestors=[];for(let{el:t,scrollTop:n}of e)t.scrollTop=n,t.style.overflowY=`hidden`;this._lockedAncestors=e}_unlockAncestors(){for(let{el:e,scrollTop:t,overflowY:n}of this._lockedAncestors)e.style.overflowY=n,e.scrollTop=t;this._lockedAncestors=[]}normalizeText(e){return e?e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``):``}sortOptions(e,t,n){let r=e=>typeof e==`string`?e:typeof e.value==`string`?e.value:``,i=this.getOptionLabel(e),a=this.getOptionLabel(t),o=this.normalizeText(i),s=this.normalizeText(a);if(n&&n.length>0){let e=this.normalizeText(n),t=o.startsWith(e),r=s.startsWith(e);if(t&&!r)return-1;if(!t&&r)return 1}let c=r(e),l=r(t);if(c===`+54`)return-1;if(l===`+54`)return 1;if(c===`+54`&&l===`+54`)return 0;let u=i.match(/^\d+(\.\d+)?/),d=a.match(/^\d+(\.\d+)?/),f=u?Number(u[0]):NaN,p=d?Number(d[0]):NaN;return!isNaN(f)&&!isNaN(p)?f-p:i.localeCompare(a,`es`,{usage:`sort`,sensitivity:`accent`})}_computeFilteredOptions(e){if(!this._effectiveFilterable||!e||e.length===0){let e=this.sortable?[...this.options].sort((e,t)=>this.sortOptions(e,t,void 0)):[...this.options];return this.highlightedIndex=-1,this.showNoResults=!1,e}let t=this.normalizeText(e),n=this.options.filter(e=>{let n=this.getOptionLabel(e);return this.normalizeText(n).includes(t)});return this.sortable&&(n=n.sort((t,n)=>this.sortOptions(t,n,e))),this.highlightedIndex=n.length>0?0:-1,this.showNoResults=n.length===0,n}handleOptionHover(e){this.highlightedIndex!==e&&(this.highlightedIndex=e)}update(e){if(!this.fetcher){if((e.has(`defaultValue`)||e.has(`options`)||e.has(`value`)&&this.value)&&!this._isCleared){let e=this.value||this.defaultValue,t=this.options.find(t=>typeof t==`string`?t===e:t.value===e);t?(this.filterValue=typeof t==`string`?t:t.label,this.value=typeof t==`string`?t:t.value):((!this.isOpen&&!this.filterValue||!this.isOpen&&this.value===``)&&(this.filterValue=``),this.value=``)}this._isCleared&&this.value===``&&(this._isCleared=!1)}super.update(e)}willUpdate(e){if(e.has(`keydownRegex`)){if(this.keydownRegex){let e=this.keydownRegex.match(/\[\^?[^\]]+\]/g)?.[0]??`[${this.keydownRegex}]`;this._firstCharRegex=new RegExp(e)}else this._firstCharRegex=null}this.fetcher||(e.has(`filterValue`)||e.has(`options`))&&(this.filteredOptions=this._computeFilteredOptions(this.filterValue))}updated(e){super.updated(e),e.has(`isOpen`)&&this.isMobile&&this.toggleDynamicScrollLock(this.isOpen),this._prevIsMobile&&!this.isMobile&&this.toggleDynamicScrollLock(!1),this._prevIsMobile=this.isMobile;let t=e.get(`isOpen`)===!1;this.isMobile&&this.isOpen&&e.has(`isOpen`)&&t&&this.updateComplete.then(()=>{let e=this.mobileInputRef;e&&window.setTimeout(()=>{e.focus(),e.setSelectionRange(e.value.length,e.value.length)},0)})}connectedCallback(){super.connectedCallback(),this.updateResponsiveMode(),window.addEventListener(`resize`,this.updateResponsiveModeBound),document.addEventListener(`click`,this._boundHandleClickOutside),window.addEventListener(`overlay-opened`,this.handleGlobalOverlayOpen),this.addEventListener(`pointerdown`,this._prepareAncestors,!0),this.addEventListener(`keydown`,this._prepareAncestors,!0)}disconnectedCallback(){this.removeEventListener(`pointerdown`,this._prepareAncestors,!0),this.removeEventListener(`keydown`,this._prepareAncestors,!0),window.removeEventListener(`resize`,this.updateResponsiveModeBound),document.removeEventListener(`click`,this._boundHandleClickOutside),window.removeEventListener(`overlay-opened`,this.handleGlobalOverlayOpen),this.debounceTimeout&&=(clearTimeout(this.debounceTimeout),null),this._abortController&&=(this._abortController.abort(),null),this.isMobile&&this.isOpen&&this.toggleDynamicScrollLock(!1),super.disconnectedCallback()}notifyOverlayOpened(){window.dispatchEvent(new CustomEvent(`overlay-opened`,{detail:this}))}updateResponsiveMode(){this.isMobile=window.innerWidth<=940}handleInputClick(e){this.disabled||(!this.fetcher||this.isMobile)&&(this.isOpen||(this.notifyOverlayOpened(),this.fetcher&&this.isMobile?(this.filteredOptions=[],this.showNoResults=!1,this._isLoading=!1,this.value&&this.filterValue?(this.mobileFilterValue=this.filterValue,this.mobileFilterValue.length>=this.minSearch&&this._fetchAsyncResults(this.mobileFilterValue)):this.mobileFilterValue=``):(this.filteredOptions=this._computeFilteredOptions(``),this.showNoResults=!1),this.isMobile&&!this.fetcher&&(this.mobileFilterValue=``)),this.isOpen=!this.isOpen,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:this.isOpen},bubbles:!0,composed:!0})),this.requestUpdate())}handleInput(e){if(!this._effectiveFilterable)return;this._isCleared=!1;let t=e.target,n=this._sanitizeInputValue(t.value,t);this.filterValue=n,this.fetcher?(n.length>=this.minSearch?(this.isOpen=!0,this.notifyOverlayOpened(),this._fetchAsyncResults(n)):(this.isOpen=!1,this.filteredOptions=[],this._isLoading=!1,this.showNoResults=!1,this._lastFetchTerm=null,this._fetchedOptions=[],this.debounceTimeout&&=(clearTimeout(this.debounceTimeout),null),this._abortController&&=(this._abortController.abort(),null)),this.requestUpdate()):(this.notifyOverlayOpened(),this.isOpen=!0,n===``&&(this._emitEmptySelection(),this.filteredOptions=this._computeFilteredOptions(``),this.showNoResults=!1),this.debounceTimeout&&clearTimeout(this.debounceTimeout),this.debounceTimeout=window.setTimeout(()=>{this.filterValue.length>2&&this.dispatchEvent(new CustomEvent(`filter-location`,{detail:{value:this.filterValue},bubbles:!0,composed:!0}))},300),this.requestUpdate())}handleMobileInput(e){this._isCleared=!1;let t=e.target,n=this._sanitizeInputValue(t.value,t);this.mobileFilterValue=n,this.fetcher?(n.length>=this.minSearch?this._fetchAsyncResults(n):(this.filteredOptions=[],this._isLoading=!1,this.showNoResults=!1,this._lastFetchTerm=null,this._fetchedOptions=[],this.debounceTimeout&&=(clearTimeout(this.debounceTimeout),null),this._abortController&&=(this._abortController.abort(),null)),this.requestUpdate()):(n===``?(this._emitEmptySelection(),this.filteredOptions=this._computeFilteredOptions(``),this.showNoResults=!1):this.filteredOptions=this._computeFilteredOptions(n),this.requestUpdate(),this.debounceTimeout&&clearTimeout(this.debounceTimeout),this.debounceTimeout=window.setTimeout(()=>{n.length>2?this.dispatchEvent(new CustomEvent(`filter-location`,{detail:{value:n},bubbles:!0,composed:!0})):n.length===0&&(this.filteredOptions=this._computeFilteredOptions(``))},300))}handleSelect(e){this._isCleared=!1,this.highlightedIndex=-1;let t=typeof e==`string`?e:e.value;this.dispatchEvent(new CustomEvent(`option-selected`,{detail:{value:t},bubbles:!0,composed:!0})),this.filterValue=typeof e==`string`?e:e.label,this.value=t,this.isOpen=!1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0})),this.mobileFilterValue=this.filterValue,this.fetcher||(this.filteredOptions=this._computeFilteredOptions(``)),this.showNoResults=!1,this._lastFetchTerm=null,this._fetchedOptions=[],this.requestUpdate()}handleIconClick(){if(this.disabled)return;this.highlightedIndex=-1;let e=this.isRenderClearButton,t=typeof this.value==`string`&&this.value!==``,n=typeof this.value==`object`&&this.value!==null&&Object.keys(this.value).length>0;if(e&&(t||n))this._emitEmptySelection(),this.filterValue=``,this.filteredOptions=this._computeFilteredOptions(``),this._lastFetchTerm=null,this._fetchedOptions=[],this.isOpen=!1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0}));else{let e=!this.isOpen;if(e&&this.fetcher&&this.filterValue&&this.filterValue.length>=this.minSearch)this.notifyOverlayOpened(),this.isOpen=!0,this.mobileFilterValue=``,this.showNoResults=!1,this._fetchAsyncResults(this.filterValue);else if(e&&this.fetcher&&this.filterValue&&this.filterValue.length<this.minSearch)return;else this.notifyOverlayOpened(),this.isOpen=!this.isOpen,this.isOpen?(this.mobileFilterValue=``,this.showNoResults=!1,this.filteredOptions=this._computeFilteredOptions(``)):(this.mobileFilterValue=``,this.filteredOptions=this._computeFilteredOptions(``));this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:this.isOpen},bubbles:!0,composed:!0})),this.isOpen&&!this.isMobile&&this.updateComplete.then(()=>{this._desktopInput?.focus()})}this.requestUpdate()}handleClickOutside(e){let t=e.target;t instanceof Node&&(!this.contains(t)&&this.isOpen&&(this.isOpen=!1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0})),this.requestUpdate()),this.isMobile&&!this.contains(t)&&(this.mobileFilterValue=``,this.filteredOptions=this._computeFilteredOptions(``)))}preventInvalidStart(e){let t=e.target;return t&&t.tagName===`INPUT`&&t.selectionStart===0&&e.key.length===1&&!(this.keydownRegex?this._firstCharRegex?.test(e.key)??!0:/[a-zA-ZáéíóúÁÉÍÓÚñÑüÜ0-9]/.test(e.key))?(e.preventDefault(),!0):!1}onlyRegex(e){if(!this.keydownRegex)return e;let t=this.keydownRegex.match(/\[\^?[^\]]+\]/g);t||=[`[${this.keydownRegex}]`];let n=``,r=t.length>=2,i=new RegExp(t[0]),a=r?new RegExp(t[1]):i,o=e.split(``);for(let e=0;e<o.length;e++){let t=o[e];e===0?i.test(t)&&(n+=t):a.test(t)&&(n+=t)}return n.trimStart()}handlePaste(e){let t=e.target;if(t&&t.tagName===`INPUT`&&t.selectionStart===0){let n=t.selectionStart,r=t.selectionEnd;if(n===null||r===null)return;e.preventDefault();let i=e.clipboardData?.getData(`text`)||``,a=this._sanitize(i,!0);a&&(t.setRangeText(a,n,r,`end`),t.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})))}}handleKeyDown(e){if(this.preventInvalidStart(e))return;let{key:t}=e,n=this._desktopInput;if(t===`Backspace`&&this._effectiveFilterable){let e=n?.value||``,t=n&&n.selectionStart!==n.selectionEnd,r=e.length===1&&!t,i=e.length===0;this.fetcher?(i?0:e.length-(t?n.selectionEnd-n.selectionStart:1))<this.minSearch&&(this.isOpen=!1,this.filteredOptions=[],this._isLoading=!1,this.showNoResults=!1,this._lastFetchTerm=null,this._fetchedOptions=[],this.debounceTimeout&&=(clearTimeout(this.debounceTimeout),null),this._abortController&&=(this._abortController.abort(),null),this.requestUpdate()):(r||i)&&(this._emitEmptySelection(),this.filterValue=``,this.filteredOptions=this._computeFilteredOptions(``),this.isOpen=!0,this.requestUpdate())}let r=this.filteredOptions.filter(e=>!(typeof e==`object`&&e.disabled));if(!this.isOpen&&(t===`Enter`||t===` `)){e.preventDefault(),this.notifyOverlayOpened(),this.isOpen=!0;let t=this.filteredOptions.findIndex(e=>!(typeof e==`object`&&e.disabled));this.highlightedIndex=t===-1?-1:t,this.requestUpdate()}else{if(this.isOpen){if(t===`ArrowDown`){e.preventDefault();let t=this.highlightedIndex+1;for(;t<this.filteredOptions.length;){let e=this.filteredOptions[t];if(!(typeof e==`object`&&e.disabled)){this.highlightedIndex=t;break}t++}if(t>=this.filteredOptions.length){if(r.length>0){let e=r[r.length-1];this.highlightedIndex=this.filteredOptions.indexOf(e)}else this.highlightedIndex=-1}this.requestUpdate(),this.updateComplete.then(()=>this.scrollHighlightedIntoView())}else if(t===`ArrowUp`){e.preventDefault();let t=this.highlightedIndex-1;for(;t>=0;){let e=this.filteredOptions[t];if(!(typeof e==`object`&&e.disabled)){this.highlightedIndex=t;break}t--}t<0&&(this.highlightedIndex=-1),this.requestUpdate(),this.updateComplete.then(()=>this.scrollHighlightedIntoView())}else if(t===`Enter`||!this._effectiveFilterable&&t===` `){this.highlightedIndex>=0&&e.preventDefault();let t=this.filteredOptions[this.highlightedIndex];if(this.highlightedIndex>=0&&t&&!(typeof t==`object`&&t.disabled)){this.handleSelect(t),this._desktopInput?this._desktopInput.focus():this._desktopFake?.focus(),this.highlightedIndex=-1;return}}else t===`Escape`?(e.preventDefault(),this.isOpen=!1,this.highlightedIndex=-1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0})),this._desktopInput?this._desktopInput.focus():this._desktopFake?.focus()):t===`Tab`?(this.isOpen=!1,this.highlightedIndex=-1,this.lastElement&&!this.isMobile&&this.dispatchEvent(new CustomEvent(`dropdown-toggle`,{detail:{open:!1},bubbles:!0,composed:!0})),this.requestUpdate()):!this.isMobile&&this._effectiveFilterable&&t.length===1&&(this.highlightedIndex=-1);if((t===`ArrowLeft`||t===`ArrowRight`)&&this._effectiveFilterable)return}if(t===`ArrowRight`){let t=!n||n.selectionStart===n.value.length;(!this._effectiveFilterable||t)&&(e.preventDefault(),this._iconButton?.focus())}}}handleButtonKeyDown(e){let{key:t}=e,n=this._desktopInput,r=this._desktopFake,i=n||r;t===`ArrowLeft`?(e.preventDefault(),i?.focus(),i instanceof HTMLInputElement&&(i.selectionStart=i.selectionEnd=i.value.length)):t===`Enter`||t===` `?(e.preventDefault(),this._effectiveFilterable&&this.filterValue?(this.handleIconClick(),i?.focus()):(this.isOpen=!this.isOpen,this.isOpen&&(this.highlightedIndex=-1,i?.focus())),this.requestUpdate()):t===`Tab`&&this.isOpen&&(this.isOpen=!1,this.highlightedIndex=-1,this.requestUpdate())}handleBlur(){window.setTimeout(()=>{this.validateAndCleanOnBlur(),this.requestUpdate()},200)}scrollHighlightedIntoView(){if(this.isMobile||this.highlightedIndex<0)return;let e=this._optionsList;if(!e)return;let t=e.querySelector(`li.highlighted`);t&&t.scrollIntoView({block:`nearest`})}_emitEmptySelection(){this.value=``,this._isCleared=!0,this.dispatchEvent(new CustomEvent(`option-selected`,{detail:{value:``},bubbles:!0,composed:!0}))}_fetchAsyncResults(e){if(this._lastFetchTerm!==null&&this._fetchedOptions.length>0&&this.normalizeText(e).startsWith(this.normalizeText(this._lastFetchTerm))){let t=this.normalizeText(e);this.filteredOptions=this._fetchedOptions.filter(e=>{let n=this.getOptionLabel(e);return this.normalizeText(n).includes(t)}),this.showNoResults=this.filteredOptions.length===0,this.highlightedIndex=this.filteredOptions.length>0?0:-1,this._isLoading=!1,this.requestUpdate();return}this._abortController&&this._abortController.abort(),this.debounceTimeout&&clearTimeout(this.debounceTimeout),this._isLoading=!0,this.showNoResults=!1,this.filteredOptions=[],this.requestUpdate();let t=()=>{this._abortController=new AbortController,this.fetcher(e,{signal:this._abortController.signal}).then(t=>{this._abortController?.signal.aborted||(this._fetchedOptions=t,this._lastFetchTerm=e,this.filteredOptions=t,this.showNoResults=t.length===0,this.highlightedIndex=t.length>0?0:-1,this._isLoading=!1,this.requestUpdate())}).catch(()=>{this._abortController?.signal.aborted||(this.filteredOptions=[],this.showNoResults=!0,this._isLoading=!1,this.requestUpdate())})};this.debounceMs>0?this.debounceTimeout=window.setTimeout(t,this.debounceMs):t()}_sanitize(e,t){let n=e.replace(_,``);if(this.maxLength&&(n=n.slice(0,this.maxLength)),n.startsWith(` `)&&(n=n.trimStart()),this.keydownRegex&&(n=this.onlyRegex(n)),t&&n.length>0){let e=n[0];(this.keydownRegex?this._firstCharRegex?.test(e)??!0:/[a-zA-ZáéíóúÁÉÍÓÚñÑüÜ0-9]/.test(e))||(n=this.keydownRegex&&this._firstCharRegex?n.replace(RegExp(`^[^${this._firstCharRegex.source.replace(/^\[/,``).replace(/\]$/,``)}]+`),``):n.replace(/^[^a-zA-ZáéíóúÁÉÍÓÚñÑüÜ0-9]+/,``))}return n}_sanitizeInputValue(e,t){let n=t.selectionStart||0,r=e.slice(0,n).replace(_,``).length,i=this._sanitize(e,!1);return t.value=i,t.setSelectionRange(r,r),i}renderOptionIcon(e){if(!e||typeof e!=`string`)return d;let t=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,``).replace(/\bon\w+\s*=/gi,``).replace(/javascript:/gi,``);return u`<span class="icon-list" .innerHTML="${t}"></span>`}_renderOptionItem(e,t){let n=typeof e==`string`?e:e.label,r=typeof e==`object`&&e.disabled,i=typeof e==`object`?e.icon:void 0;return u`<li id="option-${t}" class="${r?`disabled`:``} ${t===this.highlightedIndex?`highlighted`:``}" role="option" aria-selected="${t===this.highlightedIndex}" @click="${()=>{r||this.handleSelect(e)}}" @mouseenter="${()=>this.handleOptionHover(t)}" >${this.renderOptionIcon(i)} ${n}</li>`}validateAndCleanOnBlur(){if(!this._effectiveFilterable)return;let e=this.normalizeText((this.filterValue||``).trim());if(!e){this.value!==``&&this._emitEmptySelection(),this.filterValue=``,this.filteredOptions=this._computeFilteredOptions(``),this.showNoResults=!1;return}let t=(this.fetcher?this.filteredOptions:this.options).find(t=>{let n=typeof t==`string`?t:t.label;return this.normalizeText(String(n))===e});if(!t)this._emitEmptySelection(),this.filterValue=``,this.filteredOptions=this._computeFilteredOptions(``),this.showNoResults=!1;else{let e=typeof t==`string`?t:t.value,n=typeof t==`string`?t:t.label;this.value!==e&&(this.value=e,this.dispatchEvent(new CustomEvent(`option-selected`,{detail:{value:e},bubbles:!0,composed:!0}))),this.filterValue=n,this.showNoResults=!1}}render(){let e=this.isMobile,t=u`<randstad-icon name="${this.isOpen&&this.filteredOptions.length>0?`arrow_up`:`arrow_down`}" size="24px" .color=${`var( --primary-color )`} ></randstad-icon>`,n=this.isRenderClearButton===!0,r=this.isOpen&&(this.filteredOptions.length>0||this.filterValue.length>0),i=!this.textLabelFilterNotResult||typeof this.textLabelFilterNotResult!=`string`,a=!this.textLabelMobileSearch||typeof this.textLabelMobileSearch!=`string`,o=!this.placeholder||typeof this.placeholder!=`string`,s=i?`No se encontraron resultados`:this.textLabelFilterNotResult,c=a?`buscá una opción`:this.textLabelMobileSearch,l=o?`seleccioná una opción`:this.placeholder;return u`<div class="select-container" style="${this.labelColor?` --label-color: ${this.labelColor};`:``}">${this.renderLabelContainer()}<div class="list-container"><div class="input-container ${this.isOpen?`focused`:``} ${r?`open`:``} ${e?`mobile`:``}"><div class="input-wrapper ${this.disabled?`disabled`:``}">${e?u`<div class="filter-fake" @click="${this.handleInputClick}" @keydown="${this.handleKeyDown}" @blur="${this.handleBlur}" tabindex="0" role="combobox" autocomplete="new-password" aria-expanded="${this.isOpen}" aria-controls="options-list" aria-haspopup="listbox" aria-activedescendant="${this.isOpen&&this.highlightedIndex!==-1?`option-${this.highlightedIndex}`:d}" ><span class="${this.filterValue?``:`placeholder`}">${this.filterValue||l}</span></div>`:u`<input class="filter-input" .value="${this.filterValue||``}" @click="${this.handleInputClick}" @keydown="${this.handleKeyDown}" @input=${this.handleInput} @paste="${this.handlePaste}" @blur="${this.handleBlur}" placeholder="${this.filterValue?``:l}" ?disabled="${this.disabled}" ?readonly="${!this._effectiveFilterable}" maxlength="${this.maxLength??``}" tabindex="0" role="combobox" inputmode="search" autocomplete="new-password" aria-expanded="${this.isOpen}" aria-controls="options-list" aria-haspopup="listbox" aria-busy="${this._isLoading}" aria-activedescendant="${this.isOpen&&this.highlightedIndex!==-1?`option-${this.highlightedIndex}`:d}" />`} ${!e&&this.showNoResults?u`<randstad-icon name="warning" size="24px" class="no-results-icon"></randstad-icon>`:d} ${!this.fetcher||this.filteredOptions.length>0||this._isLoading?u`<button class="icon-button" @click="${this.handleIconClick}" @keydown="${this.handleButtonKeyDown}" ?disabled="${this.disabled}" tabindex="0" aria-label="${this.value&&this.value!==``?`Clear selection`:`Toggle options`}" >${n&&this.value&&this.value!==``?u`<randstad-icon name="close" size="24px"></randstad-icon>`:t}</button>`:d} ${!e&&this.isOpen?u` ${this._isLoading?u`<ul id="options-list" class="options-list" role="listbox" aria-live="polite"><li class="state-item" role="status">${this.textLabelLoading}</li></ul>`:this.filteredOptions.length>0?u`<ul id="options-list" class="options-list" role="listbox" aria-live="polite">${this.filteredOptions.map((e,t)=>this._renderOptionItem(e,t))}</ul>`:this.showNoResults?u`<ul id="options-list" class="options-list" role="listbox" aria-live="polite"><li class="state-item">${s}</li></ul>`:d} `:d}</div></div>${this.renderError()}</div>${this.renderHelper()} ${e&&this.isOpen?u`<div class="mobile-backdrop" @click="${()=>{this.isOpen=!1}}" @touchmove=${this._overlayTouchMoveListener} ><div class="mobile-modal" @click="${e=>e.stopPropagation()}"><div class="modal-input-container">${this._effectiveFilterable?u`<input class="filter-input" .value="${this.mobileFilterValue||``}" @input=${e=>this.handleMobileInput(e)} @keydown="${this.preventInvalidStart}" @paste="${this.handlePaste}" placeholder="${c}" inputmode="search" maxlength="${this.maxLength??``}" role="combobox" aria-expanded="${this.isOpen}" aria-controls="mobile-options-list" aria-haspopup="listbox" />${!this._isLoading&&this.showNoResults?u`<randstad-icon name="warning" size="24px" class="no-results-icon"></randstad-icon>`:d} `:d}<button class="modal-close-button" @click="${()=>{this.isOpen=!1,this.mobileFilterValue=``,this.filteredOptions=this._computeFilteredOptions(``),this._lastFetchTerm=null,this._fetchedOptions=[],this.debounceTimeout&&=(clearTimeout(this.debounceTimeout),null),this._abortController&&=(this._abortController.abort(),null),this._isLoading=!1}}"><randstad-icon name="close" size="24px"></randstad-icon></button></div>${this._isLoading?u`<ul id="mobile-options-list" class="options-list" role="listbox" aria-live="polite"><li class="state-item" role="status">${this.textLabelLoading}</li></ul>`:this.filteredOptions.length>0?u`<ul id="mobile-options-list" class="options-list" role="listbox" aria-live="polite">${this.filteredOptions.map((e,t)=>this._renderOptionItem(e,t))}</ul>`:this.showNoResults?u`<ul id="mobile-options-list" class="options-list" role="listbox" aria-live="polite"><li class="state-item mobile-item">${s}</li></ul>`:d}</div></div>`:d} `}};t([p({type:Object}),e(`design:type`,Object)],v.prototype,`value`,void 0),t([p({type:String,attribute:`default-value`}),e(`design:type`,Object)],v.prototype,`defaultValue`,void 0),t([p({type:Array}),e(`design:type`,Array)],v.prototype,`options`,void 0),t([p({type:Boolean}),e(`design:type`,Object)],v.prototype,`filterable`,void 0),t([p({type:Number}),e(`design:type`,Number)],v.prototype,`maxLength`,void 0),t([p({type:String}),e(`design:type`,String)],v.prototype,`keydownRegex`,void 0),t([p({type:String}),e(`design:type`,String)],v.prototype,`textLabelFilterNotResult`,void 0),t([p({type:String}),e(`design:type`,String)],v.prototype,`textLabelMobileSearch`,void 0),t([p({type:Boolean}),e(`design:type`,Object)],v.prototype,`isRenderClearButton`,void 0),t([p({type:Boolean}),e(`design:type`,Object)],v.prototype,`sortable`,void 0),t([p({type:Function}),e(`design:type`,Object)],v.prototype,`fetcher`,void 0),t([p({type:Number}),e(`design:type`,Number)],v.prototype,`minSearch`,void 0),t([p({type:String}),e(`design:type`,String)],v.prototype,`textLabelLoading`,void 0),t([p({type:Number,attribute:`debounce-ms`}),e(`design:type`,Number)],v.prototype,`debounceMs`,void 0),t([h(),e(`design:type`,Boolean)],v.prototype,`isMobile`,void 0),t([h(),e(`design:type`,Object)],v.prototype,`highlightedIndex`,void 0),t([h(),e(`design:type`,Boolean)],v.prototype,`_isCleared`,void 0),t([h(),e(`design:type`,Array)],v.prototype,`filteredOptions`,void 0),t([h(),e(`design:type`,Object)],v.prototype,`filterValue`,void 0),t([h(),e(`design:type`,Object)],v.prototype,`isOpen`,void 0),t([h(),e(`design:type`,Object)],v.prototype,`mobileFilterValue`,void 0),t([h(),e(`design:type`,Boolean)],v.prototype,`showNoResults`,void 0),t([h(),e(`design:type`,Boolean)],v.prototype,`_isLoading`,void 0),t([p({type:Boolean,attribute:`last-element`}),e(`design:type`,Object)],v.prototype,`lastElement`,void 0),t([m(`.mobile-modal .filter-input`),e(`design:type`,typeof HTMLInputElement>`u`?Object:HTMLInputElement)],v.prototype,`mobileInputRef`,void 0),t([m(`.filter-input`),e(`design:type`,typeof HTMLInputElement>`u`?Object:HTMLInputElement)],v.prototype,`_desktopInput`,void 0),t([m(`.filter-fake`),e(`design:type`,typeof HTMLElement>`u`?Object:HTMLElement)],v.prototype,`_desktopFake`,void 0),t([m(`.icon-button`),e(`design:type`,typeof HTMLButtonElement>`u`?Object:HTMLButtonElement)],v.prototype,`_iconButton`,void 0),t([m(`.options-list`),e(`design:type`,typeof HTMLUListElement>`u`?Object:HTMLUListElement)],v.prototype,`_optionsList`,void 0),v=g=t([f(`filterable-select`)],v);export{v as FilterableSelect};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evento global (en `window`) que emiten los componentes que abren un overlay
|
|
3
|
+
* a pantalla completa en mobile (por ejemplo, el desplegable de `filterable-select`).
|
|
4
|
+
* Otros componentes, como `randstad-navbar`, lo escuchan para ocultarse mientras
|
|
5
|
+
* el overlay esté abierto.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MOBILE_OVERLAY_EVENT = "randstad-mobile-overlay";
|
|
8
|
+
export interface MobileOverlayEventDetail {
|
|
9
|
+
/** `true` al abrirse el overlay, `false` al cerrarse. */
|
|
10
|
+
readonly open: boolean;
|
|
11
|
+
/** Componente que abrió o cerró el overlay. */
|
|
12
|
+
readonly source: EventTarget;
|
|
13
|
+
}
|
|
14
|
+
export declare function dispatchMobileOverlay(source: EventTarget, open: boolean): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=`randstad-mobile-overlay`;function t(t,n){window.dispatchEvent(new CustomEvent(e,{detail:{open:n,source:t}}))}export{e as MOBILE_OVERLAY_EVENT,t as dispatchMobileOverlay};
|
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
:root{--primary-color:#2175d9;--primary-color-80:#4e90e1;--primary-color-60:#7aace8;--primary-color-40:#a6c8f0;--primary-color-20:#d3e3f7;--primary-color-10:#2175d91a;--primary-color-5:#2175d90d;--secondary-color:#0f1941;--secondary-color-80:#404767;--secondary-color-60:#6f758d;--secondary-color-40:#9fa3b3;--secondary-color-20:#cfd1d9;--secondary-color-10:#e7e8ec;--brand-randstad-blue:#2175d9;--randstad-blue-10:#e8f1fb;--randstad-blue-40:#a6c8f0;--brand-dark-blue:#0f1941;--brand-light-blue:#00d7ff;--brand-off-white:#f7f5f0;--ui-negative:#e00f0f;--ui-negative-5:#fdf3f3;--ui-negative-pink-shadow:#e00f0f1a;--ui-positive:#257156;--ui-positve-5:#f4f8f6;--ui-warning:#e9a204;--ui-warning-10:#fcf5e5;--ui-informative:#4e90e1;--ui-informative-10:#e8f1fb;--tertiary-shade:#dedcd8;--tertiary-tint:#f9f7f3;--gray-20:#d7d7d7;--gray-10:#f7f7f7;--white:#fff;--primary-button-hover:#175197;--primary-button-active:#124077;--primary-button-focus:#2175d9;--danger-button:#e00f0f;--danger-button-hover:#c90d0d;--danger-button-active:#b30c0c;--danger-button-focus:#e00f0f;--form-hover-shadow:#d1d3db;--randstad-dark-blue-40:#262626;--primary-light-blue:#00d7ff;--primary-light-blue-20:#00d7ff33}
|
|
1
|
+
:root{--primary-color:#2175d9;--primary-color-80:#4e90e1;--primary-color-60:#7aace8;--primary-color-40:#a6c8f0;--primary-color-20:#d3e3f7;--primary-color-10:#2175d91a;--primary-color-5:#2175d90d;--secondary-color:#0f1941;--secondary-color-80:#404767;--secondary-color-60:#6f758d;--secondary-color-40:#9fa3b3;--secondary-color-20:#cfd1d9;--secondary-color-10:#e7e8ec;--brand-randstad-blue:#2175d9;--randstad-blue-10:#e8f1fb;--randstad-blue-40:#a6c8f0;--brand-dark-blue:#0f1941;--brand-light-blue:#00d7ff;--brand-off-white:#f7f5f0;--ui-negative:#e00f0f;--ui-negative-5:#fdf3f3;--ui-negative-pink-shadow:#e00f0f1a;--ui-positive:#257156;--ui-positve-5:#f4f8f6;--ui-warning:#e9a204;--ui-warning-10:#fcf5e5;--ui-informative:#4e90e1;--ui-informative-10:#e8f1fb;--tertiary-shade:#dedcd8;--tertiary-tint:#f9f7f3;--gray-20:#d7d7d7;--gray-10:#f7f7f7;--white:#fff;--primary-button-hover:#175197;--primary-button-active:#124077;--primary-button-focus:#2175d9;--danger-button:#e00f0f;--danger-button-hover:#c90d0d;--danger-button-active:#b30c0c;--danger-button-focus:#e00f0f;--form-hover-shadow:#d1d3db;--randstad-dark-blue-40:#262626;--primary-light-blue:#00d7ff;--primary-light-blue-20:#00d7ff33}.button{align-items:center;border:none;border-radius:4px;cursor:pointer;display:flex;font-family:Graphik,sans-serif;font-weight:400;gap:4px;justify-content:center;padding:16px;transition:background-color .2s,color .2s,box-shadow .2s}.button-lg{font-size:18px;line-height:30px;min-width:48px}.button-md{font-size:14px;line-height:25px}.button-sm{height:62px;padding:0;width:62px}.button-primary{background-color:var(--primary-color);color:var(--white)}.button-danger{background-color:var(--danger-button,#e00f0f);color:var(--white)}.button-danger.hover{background-color:var(--danger-button-hover,#c90d0d)}.button-danger.active{background-color:var(--danger-button-active,#b30c0c)}.button-danger.focus{background-color:var(--danger-button-focus,#e00f0f)}.button-danger.disabled{background-color:#cfd1d9;color:var(--secondary-color-60)}.button-icon-img{height:24px;-o-object-fit:contain;object-fit:contain;width:24px}.button.button-danger randstad-icon{color:var(--white)}.button-primary.hover{background-color:var(--primary-button-hover)}.button-primary.active{background-color:var(--primary-button-active)}.button-primary.focus-visible{background-color:var(--primary-button-focus)}.button-primary.disabled{background-color:var(--secondary-color-20);color:var(--secondary-color-60)}.button-secondary{background:none;border:1px solid var(--primary-color);color:var(--primary-color)}.button-secondary.hover{border:1px solid var(#175197);color:var(#175197)}.button-secondary.active{border:1px solid var(--secondary-color-80);color:var(--secondary-color-80)}.button-secondary.focus-visible{border:1px solid var(--primary-color);color:var(--primary-color)}.button-secondary.disabled{border:1px solid var(--secondary-color-60);color:var(--secondary-color-60)}.button-tertiary{background:none;border:none;color:var(--primary-color)}.button-tertiary.hover{background:#2175d90d}.button-tertiary.active{background-color:#2175d91a}.button-tertiary.focus-visible{border:1px solid var(--primary-color)}.button-tertiary.disabled{color:#6f758d}.button-icon-left>.icon,.button-icon-right>.icon{display:inline-block;height:1rem;width:1rem}.button-icon-left>.icon{margin-right:.5rem}.button-icon-right>.icon{margin-left:.5rem}.button-round{align-items:center;background-color:var(--white);border:none;border-radius:50%;box-shadow:0 2px 5px rgba(0,0,0,.2);cursor:pointer;display:flex;height:48px;justify-content:center;padding:0;width:48px}.button-round img.button-icon{height:24px;-o-object-fit:contain;object-fit:contain;width:24px}.button randstad-icon,.button.button-primary randstad-icon{color:var(--white)}.button.button-secondary randstad-icon,.button.button-tertiary randstad-icon{color:var(--primary-color)}.loader{align-items:center;display:flex;gap:6px;justify-content:center}.dot{animation:growAndFade 1.2s ease-in-out infinite;border-radius:50%;display:inline-block;height:10px;width:10px}.dot:first-child{animation-delay:0s}.dot:nth-child(2){animation-delay:.2s}.dot:nth-child(3){animation-delay:.4s}@keyframes growAndFade{0%{opacity:.3;transform:scale(.9)}50%{opacity:1;transform:scale(1.4)}to{opacity:.3;transform:scale(.9)}}.button-primary.loader .dot,.button-secondary.loader .dot{background-color:var(--white)}.button-secondary.loader{background-color:var(--primary-color);border:none;color:var(--white)}@font-face{font-family:Graphik;font-style:normal;font-weight:400;src:url(/src/assets/font/Graphik-Regular.woff2) format("woff2"),url(/src/assets/font/Graphik-Regular.woff) format("woff"),url(/src/assets/font/Graphik-Regular.eot) format("embedded-opentype")}
|
|
@@ -2,6 +2,8 @@ import type { Meta, StoryObj } from '@storybook/web-components';
|
|
|
2
2
|
import type { NavItem } from '../components/Navbar';
|
|
3
3
|
import '../components/Navbar';
|
|
4
4
|
import '../components/Icon';
|
|
5
|
+
import '../components/Form';
|
|
6
|
+
import '../components/Select';
|
|
5
7
|
interface NavbarArgs {
|
|
6
8
|
items: NavItem[];
|
|
7
9
|
centerIcon: string;
|
|
@@ -9,6 +11,7 @@ interface NavbarArgs {
|
|
|
9
11
|
hidden: boolean;
|
|
10
12
|
desktop: boolean;
|
|
11
13
|
selectedIndex: number;
|
|
14
|
+
hideOnInputFocus?: boolean;
|
|
12
15
|
}
|
|
13
16
|
declare const meta: Meta<NavbarArgs>;
|
|
14
17
|
export default meta;
|
|
@@ -19,3 +22,4 @@ export declare const SelectedItem: Story;
|
|
|
19
22
|
export declare const WithCenterLabel: Story;
|
|
20
23
|
export declare const CustomItems: Story;
|
|
21
24
|
export declare const Hidden: Story;
|
|
25
|
+
export declare const HideOnKeyboard: Story;
|