@randstad-uca/design-system 1.0.58 → 1.0.59
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.
|
@@ -5,6 +5,7 @@ export declare class DatePickerComponent extends BaseControl {
|
|
|
5
5
|
isRenderClearButton: boolean;
|
|
6
6
|
minDate?: string;
|
|
7
7
|
maxDate?: string;
|
|
8
|
+
eighteenOrOlder: boolean;
|
|
8
9
|
private isOpen;
|
|
9
10
|
private selectedDate;
|
|
10
11
|
private viewDate;
|
|
@@ -12,6 +13,7 @@ export declare class DatePickerComponent extends BaseControl {
|
|
|
12
13
|
private calendarWidth;
|
|
13
14
|
private inputContainer;
|
|
14
15
|
static styles: import("lit").CSSResult;
|
|
16
|
+
private setMessageErrorFormatInvalid;
|
|
15
17
|
/**
|
|
16
18
|
* Ciclo de vida: se ejecuta al conectar el componente al DOM.
|
|
17
19
|
* Inicializa el modo responsivo y listeners globales.
|
|
@@ -92,6 +94,14 @@ export declare class DatePickerComponent extends BaseControl {
|
|
|
92
94
|
* @param value La cadena de fecha pasada desde una propiedad externa.
|
|
93
95
|
*/
|
|
94
96
|
private _syncValue;
|
|
97
|
+
/**
|
|
98
|
+
* Valida una fecha basándose en las reglas del componente.
|
|
99
|
+
* Esto incluye la validación de edad y el rango de fechas.
|
|
100
|
+
|
|
101
|
+
* @param date - El objeto Date a validar.
|
|
102
|
+
* @returns `true` si la fecha es válida, `false` de lo contrario.
|
|
103
|
+
*/
|
|
104
|
+
private _validateDate;
|
|
95
105
|
/**
|
|
96
106
|
* Valida la entrada del usuario en el campo de texto.
|
|
97
107
|
|
package/dist/index.js
CHANGED
|
@@ -3300,7 +3300,7 @@ const Yt=o`@layer{:host{display:inline-flex;height:var(--md-radio-icon-size, 20p
|
|
|
3300
3300
|
<div class="calendar-container" style="width: ${this.calendarWidth}px;">
|
|
3301
3301
|
${i}
|
|
3302
3302
|
</div>
|
|
3303
|
-
`}};a([A({type:Object}),s("design:type",Object)],si.prototype,"selectedDate",void 0),a([A({type:Object}),s("design:type",Date)],si.prototype,"viewDate",void 0),a([A({type:Boolean}),s("design:type",Object)],si.prototype,"isMobile",void 0),a([A({type:Number}),s("design:type",Number)],si.prototype,"calendarWidth",void 0),a([A({type:Object}),s("design:type",Object)],si.prototype,"minDate",void 0),a([A({type:Object}),s("design:type",Object)],si.prototype,"maxDate",void 0),a([T(),s("design:type",String)],si.prototype,"currentView",void 0),si=a([d("calendar-overlay")],si);let di=class extends L{constructor(){super(...arguments),this.isRenderClearButton=!0,this.isOpen=!1,this.selectedDate=null,this.viewDate=new Date,this.isMobile=!1,this.calendarWidth=0,this.updateResponsiveModeBound=this.updateResponsiveMode.bind(this),this.handleClickOutside=t=>{t.composedPath().includes(this)||(this.isOpen=!1)}}static{this.styles=o`
|
|
3303
|
+
`}};a([A({type:Object}),s("design:type",Object)],si.prototype,"selectedDate",void 0),a([A({type:Object}),s("design:type",Date)],si.prototype,"viewDate",void 0),a([A({type:Boolean}),s("design:type",Object)],si.prototype,"isMobile",void 0),a([A({type:Number}),s("design:type",Number)],si.prototype,"calendarWidth",void 0),a([A({type:Object}),s("design:type",Object)],si.prototype,"minDate",void 0),a([A({type:Object}),s("design:type",Object)],si.prototype,"maxDate",void 0),a([T(),s("design:type",String)],si.prototype,"currentView",void 0),si=a([d("calendar-overlay")],si);let di=class extends L{constructor(){super(...arguments),this.isRenderClearButton=!0,this.eighteenOrOlder=!1,this.isOpen=!1,this.selectedDate=null,this.viewDate=new Date,this.isMobile=!1,this.calendarWidth=0,this.updateResponsiveModeBound=this.updateResponsiveMode.bind(this),this.handleClickOutside=t=>{t.composedPath().includes(this)||(this.isOpen=!1)}}static{this.styles=o`
|
|
3304
3304
|
${X}
|
|
3305
3305
|
${Q}
|
|
3306
3306
|
${K}
|
|
@@ -3401,7 +3401,7 @@ const Yt=o`@layer{:host{display:inline-flex;height:var(--md-radio-icon-size, 20p
|
|
|
3401
3401
|
.calendar-button randstad-icon {
|
|
3402
3402
|
font-size: 18px;
|
|
3403
3403
|
}
|
|
3404
|
-
`}connectedCallback(){super.connectedCallback(),this.updateResponsiveMode(),window.addEventListener("resize",this.updateResponsiveModeBound),document.addEventListener("click",this.handleClickOutside)}disconnectedCallback(){window.removeEventListener("resize",this.updateResponsiveModeBound),document.removeEventListener("click",this.handleClickOutside),super.disconnectedCallback()}firstUpdated(){this.setInitialWidth()}updated(t){t.has("value")&&this._syncValue(this.value),(t.has("isOpen")||t.has("value"))&&this.setInitialWidth(),super.updated(t)}setInitialWidth(){this.inputContainer&&(this.calendarWidth=this.inputContainer.getBoundingClientRect().width)}updateResponsiveMode(){this.isMobile=window.innerWidth<=940,this.setInitialWidth()}handleInput(t){const e=t.target;this._parseAndValidateDate(e.value,!0)}handleCalendarButtonClick(t){this.disabled||(t.stopPropagation(),this.isOpen=!this.isOpen,this.selectedDate?this.viewDate=this.selectedDate:this.viewDate=new Date,this.requestUpdate())}handleClearDate(){this.selectedDate=null,this.error=!1,this.errorMessage=null,this.closeOverlay(null)}handleDateSelect(t){const e=t.detail.date;e&&(this.selectedDate=e,this.viewDate=e,this.closeOverlay(Je(e,"dd-MM-yyyy")))}handleViewDateChange(t){this.viewDate=t.detail.date}closeOverlay(t){this.value=t,this.dispatchEvent(new CustomEvent("date-selected",{detail:{value:t}})),this.isOpen=!1}_syncValue(t){if(""===t||null===t)return void(this.error||(this.selectedDate=null,this.errorMessage=null));const e=this._parseDate(t);e&&this.
|
|
3404
|
+
`}setMessageErrorFormatInvalid(){return"formato de fecha inválido, se esperaba 'dd-MM-yyyy'"}connectedCallback(){super.connectedCallback(),this.updateResponsiveMode(),window.addEventListener("resize",this.updateResponsiveModeBound),document.addEventListener("click",this.handleClickOutside)}disconnectedCallback(){window.removeEventListener("resize",this.updateResponsiveModeBound),document.removeEventListener("click",this.handleClickOutside),super.disconnectedCallback()}firstUpdated(){this.setInitialWidth()}updated(t){t.has("value")&&this._syncValue(this.value),(t.has("isOpen")||t.has("value"))&&this.setInitialWidth(),super.updated(t)}setInitialWidth(){this.inputContainer&&(this.calendarWidth=this.inputContainer.getBoundingClientRect().width)}updateResponsiveMode(){this.isMobile=window.innerWidth<=940,this.setInitialWidth()}handleInput(t){const e=t.target;this._parseAndValidateDate(e.value,!0)}handleCalendarButtonClick(t){this.disabled||(t.stopPropagation(),this.isOpen=!this.isOpen,this.selectedDate?this.viewDate=this.selectedDate:this.viewDate=new Date,this.requestUpdate())}handleClearDate(){this.selectedDate=null,this.error=!1,this.errorMessage=null,this.closeOverlay(null)}handleDateSelect(t){const e=t.detail.date;e&&(this.selectedDate=e,this.viewDate=e,this.closeOverlay(Je(e,"dd-MM-yyyy")))}handleViewDateChange(t){this.viewDate=t.detail.date}closeOverlay(t){this.value=t,this.dispatchEvent(new CustomEvent("date-selected",{detail:{value:t}})),this.isOpen=!1}_syncValue(t){if(""===t||null===t)return void(this.error||(this.selectedDate=null,this.errorMessage=null));const e=this._parseDate(t);e&&this._validateDate(e)?(this.selectedDate=e,this.viewDate=e,this.error=!1,this.errorMessage=null,this.value=Je(e,"dd-MM-yyyy")):this.selectedDate=e}_validateDate(t){if(!t)return!1;if(this.error=!1,this.errorMessage=null,this.eighteenOrOlder){const e=function(t,e,i){return be(t,-18,i)}(new Date);if(ii(t,e))return this.error=!0,this.errorMessage="tenés que ser mayor de 18 años",!1}if(!this._isWithinBounds(t)){this.error=!0;const t=this._getValidDateRange();return this.errorMessage=`la fecha debe estar entre ${t?.minDate?Je(t.minDate,"dd-MM-yyyy"):""} y ${t?.maxDate?Je(t.maxDate,"dd-MM-yyyy"):""}.`,!1}return!0}_parseAndValidateDate(t,e){if(this.disabled)return;if(""===t||null===t)return this.selectedDate=null,this.error=!1,this.errorMessage=null,void(e&&this.closeOverlay(null));const i=this._parseDate(t);i?this._validateDate(i)?(this.selectedDate=i,this.viewDate=i,this.error=!1,this.errorMessage=null,e&&this.closeOverlay(Je(i,"dd-MM-yyyy"))):(e&&this.closeOverlay(null),console.error("La fecha es inválida.")):(this.error=!0,this.errorMessage=this.setMessageErrorFormatInvalid(),e&&this.closeOverlay(null),console.error("Formato de fecha no válido."))}_parseDate(t){const e=t.split("-").map(Number);if(3===e.length){const[i,o,r]=e;if(i&&o&&r&&o>=1&&o<=12&&r>1e3){const e=new Date(r,o-1,i,12);if(me(e)&&Je(e,"dd-MM-yyyy")===t)return e}}const i=t.split("-").map(Number);if(3===i.length){const[e,o,r]=i;if(e&&o&&r&&o>=1&&o<=12&&e>1e3){const i=new Date(e,o-1,r,12);if(me(i)&&Je(i,"yyyy-MM-dd")===t)return i}}return null}_parseDateString(t){if(!t)return null;const e=t.split("-").map(Number);if(3===e.length&&!isNaN(e[0])&&!isNaN(e[1])&&!isNaN(e[2])){return new Date(e[0],e[1]-1,e[2],12)}return null}_getValidDateRange(){const t=this._parseDateString(this.minDate),e=this._parseDateString(this.maxDate);return t||e?t&&e&&ii(t,e)?null:{minDate:t,maxDate:e}:{minDate:null,maxDate:null}}_isWithinBounds(t){const e=this._getValidDateRange();return!e||(!e.minDate||!oi(t,e.minDate))&&(!e.maxDate||!ii(t,e.maxDate))}render(){const t=n({"input-wrapper":!0,active:this.isOpen,error:this.error,disabled:this.disabled}),o=`width: ${this.width||"100%"};`,r=this._getValidDateRange();return e`
|
|
3405
3405
|
<div class="datepicker-container" style="${this.labelColor?` --label-color: ${this.labelColor}`:""} ${o}">
|
|
3406
3406
|
${this.renderLabelContainer()}
|
|
3407
3407
|
|
|
@@ -3453,7 +3453,7 @@ const Yt=o`@layer{:host{display:inline-flex;height:var(--md-radio-icon-size, 20p
|
|
|
3453
3453
|
|
|
3454
3454
|
${this.renderHelper()}
|
|
3455
3455
|
</div>
|
|
3456
|
-
`}};a([A({type:String}),s("design:type",String)],di.prototype,"width",void 0),a([A({type:Boolean}),s("design:type",Object)],di.prototype,"isRenderClearButton",void 0),a([A({type:String}),s("design:type",String)],di.prototype,"minDate",void 0),a([A({type:String}),s("design:type",String)],di.prototype,"maxDate",void 0),a([T(),s("design:type",Object)],di.prototype,"isOpen",void 0),a([T(),s("design:type",Object)],di.prototype,"selectedDate",void 0),a([T(),s("design:type",Date)],di.prototype,"viewDate",void 0),a([T(),s("design:type",Object)],di.prototype,"isMobile",void 0),a([T(),s("design:type",Number)],di.prototype,"calendarWidth",void 0),a([z(".input-container"),s("design:type",HTMLDivElement)],di.prototype,"inputContainer",void 0),di=a([d("datepicker-component")],di);const li={"application/pdf":"PDF","application/msword":"Word (.doc)","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"Word (.docx)","image/jpeg":"JPEG","image/png":"PNG","text/plain":"Texto (.txt)"};let ci=class extends L{constructor(){super(...arguments),this.files=[],this.maxFiles=1,this.acceptedFileTypes=[],this.maxFileSize=5242880,this.buttonText="Agregar archivo",this.simulatedDelay=0,this.loading=!1,this.progress=0}static{this.styles=o`
|
|
3456
|
+
`}};a([A({type:String}),s("design:type",String)],di.prototype,"width",void 0),a([A({type:Boolean}),s("design:type",Object)],di.prototype,"isRenderClearButton",void 0),a([A({type:String}),s("design:type",String)],di.prototype,"minDate",void 0),a([A({type:String}),s("design:type",String)],di.prototype,"maxDate",void 0),a([A({type:Boolean}),s("design:type",Object)],di.prototype,"eighteenOrOlder",void 0),a([T(),s("design:type",Object)],di.prototype,"isOpen",void 0),a([T(),s("design:type",Object)],di.prototype,"selectedDate",void 0),a([T(),s("design:type",Date)],di.prototype,"viewDate",void 0),a([T(),s("design:type",Object)],di.prototype,"isMobile",void 0),a([T(),s("design:type",Number)],di.prototype,"calendarWidth",void 0),a([z(".input-container"),s("design:type",HTMLDivElement)],di.prototype,"inputContainer",void 0),di=a([d("datepicker-component")],di);const li={"application/pdf":"PDF","application/msword":"Word (.doc)","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"Word (.docx)","image/jpeg":"JPEG","image/png":"PNG","text/plain":"Texto (.txt)"};let ci=class extends L{constructor(){super(...arguments),this.files=[],this.maxFiles=1,this.acceptedFileTypes=[],this.maxFileSize=5242880,this.buttonText="Agregar archivo",this.simulatedDelay=0,this.loading=!1,this.progress=0}static{this.styles=o`
|
|
3457
3457
|
${X}
|
|
3458
3458
|
${Q}
|
|
3459
3459
|
${K}
|
|
@@ -3514,7 +3514,7 @@ const Yt=o`@layer{:host{display:inline-flex;height:var(--md-radio-icon-size, 20p
|
|
|
3514
3514
|
.progress-bar {
|
|
3515
3515
|
width: 100%;
|
|
3516
3516
|
}
|
|
3517
|
-
`}updated(t){super.updated(t),this.applyWidth()}applyWidth(){this.width&&this.style.setProperty("--upload-file-width",this.width)}getReadableFileTypes(){const t=this.acceptedFileTypes.map((t=>li[t]||t));if(t.length<=1)return t.join("");const e=t.pop();return`${t.join(", ")} y ${e}`}validateFiles(t){const e=this.maxFileSize/1024/1024;for(const i of t){if(this.acceptedFileTypes.length>0&&!this.acceptedFileTypes.includes(i.type))return this.errorMessage=`
|
|
3517
|
+
`}updated(t){super.updated(t),this.applyWidth()}applyWidth(){this.width&&this.style.setProperty("--upload-file-width",this.width)}getReadableFileTypes(){const t=this.acceptedFileTypes.map((t=>li[t]||t));if(t.length<=1)return t.join("");const e=t.pop();return`${t.join(", ")} y ${e}`}validateFiles(t){const e=this.maxFileSize/1024/1024;for(const i of t){if(this.acceptedFileTypes.length>0&&!this.acceptedFileTypes.includes(i.type))return this.errorMessage=`formato de archivo no válido, se aceptan: ${this.getReadableFileTypes()}`,!1;if(i.size>this.maxFileSize)return this.errorMessage=`el archivo es demasiado grande, el máximo es de ${e}MB`,!1}return!0}async handleFiles(t){if(this.error=!1,this.errorMessage=null,!t||this.disabled||this.loading)return;const e=Number.isFinite(this.maxFiles)&&this.maxFiles>0?this.maxFiles:1,i=Array.from(t),o=e-this.files.length;if(o<=0)return this.error=!0,void(this.errorMessage=`se ha alcanzado el número máximo de archivos (${e}).`);const r=i.slice(0,o);if(!this.validateFiles(r))return void(this.error=!0);const n=this.simulatedDelay??0;if(n<=0)return this.files=[...this.files,...r],void this.dispatchEvent(new CustomEvent("files-changed",{detail:this.files}));this.loading=!0,this.progress=0,await this.updateComplete;const a=Date.now(),s=setInterval((()=>{const t=Date.now()-a,e=Math.min(Math.round(t/n*100),100);this.progress=e,this.progress>=100&&(clearInterval(s),this.files=[...this.files,...r],this.loading=!1,this.progress=0,this.dispatchEvent(new CustomEvent("files-changed",{detail:this.files})))}),10);this.fileInput&&(this.fileInput.value="")}onFileInputChange(t){const e=t.target;this.handleFiles(e.files),this.fileInput&&(this.fileInput.value="")}removeFile(t){this.files=this.files.filter(((e,i)=>i!==t)),this.dispatchEvent(new CustomEvent("files-changed",{detail:this.files})),0===this.files.length&&(this.error=!1,this.errorMessage=null)}render(){const t=this.files.length>=this.maxFiles,o=this.disabled||t;return e`
|
|
3518
3518
|
<div class="file-container" style="${this.labelColor?`--label-color: ${this.labelColor};`:""}">
|
|
3519
3519
|
${this.renderLabelContainer()}
|
|
3520
3520
|
|