@kelvininc/ui-components
Version:
Kelvin UI Components
1 lines • 5.93 kB
JavaScript
import{r as t,c as s,h as i,H as e}from"./p-WTwLUJcM.js";import{f as a,i as o,d as r,c as n,j as h}from"./p-COrzvkrr.js";import{H as d,b as c,u as l,n as p,t as f}from"./p-BS8xGxWJ.js";import{C as u,D as m,a as b}from"./p-jTjLvKa0.js";import{c as v,D as k,b as j,a as y,d as D,h as g}from"./p-C_KkAiiZ.js";import{i as x}from"./p-GpUjqmUL.js";import{i as C}from"./p-DjSNdVAB.js";import{i as w}from"./p-C9bG1i86.js";import{m as S}from"./p-DlXzUI51.js";import"./p-B85MJLTf.js";import"./p-CJTtq_QG.js";import"./p-B4OowdnI.js";import"./p-DumtFo-s.js";import"./p-Dkd2PDJ-.js";import"./p-BL_6ssnk.js";import"./p-CK4jS9_E.js";const _=(t,s)=>{if(x(t))return!1;if(s===a.Single){const[s]=t;return w(s)}const[i,e]=t;return w(i)&&w(e)},B=class{constructor(i){t(this,i),this.selectedDatesChange=s(this,"selectedDatesChange",7),this.cancelClicked=s(this,"cancelClicked",7),this.dropdownStateChange=s(this,"dropdownStateChange",7),this.inputConfig={},this.dropdownPositionOptions=k,this.selectedDates=[],this.timezones=c(l()),this.disabledDates=[],this.mode=a.Single,this.tooltipPosition=r.BottomStart,this.headerTitle="",this.disabled=!1,this.dropdownOpen=!1,this.calendarInitialDate=this.initialDate,this.selectedDateState=[],this.getSelectedTimezone=()=>{if(!x(this.timezone))return this.timezone;const t=p();return{name:t,offset:f(t)}},this.handleAbsoluteDatesChange=({detail:t})=>{const s=t.range,{name:i}=this.getSelectedTimezone();this.selectedDateState=((t,s,i)=>{if(0===(null==t?void 0:t.length))return[];if(this.mode===a.Single){const[s]=t;return[v(s,i,u)]}const[e,o]=t;return[v(e,i,u),x(o)?void 0:v(o,i,u)]})(s,0,i)},this.getAbsoluteRange=()=>{const{name:t}=this.getSelectedTimezone();return((t,s,i)=>{if(x(t))return[];if(s===a.Single){const[s]=t;return[d(s).tz(i).format(u)]}const[e,o]=t;return[d(e).tz(i).format(u),C(o)?void 0:d(o).tz(i).format(u)]})(this.selectedDateState,this.mode,t)},this.getCalendarLimitDatesFormatted=t=>{if(!w(t))return;const s=this.getSelectedTimezone();return d(t).tz(s.name).format(m)},this.onDropdownChange=({detail:t})=>{this.dropdownOpen=t,this.dropdownStateChange.emit(t)},this.getTextFieldTooltip=()=>{var t;if((null===(t=this.selectedDates)||void 0===t?void 0:t.length)>0)return j(this.selectedDates,this.getSelectedTimezone(),this.timezones)},this.getDropdownInputValue=()=>y(this.selectedDates,this.getSelectedTimezone().name),this.getInputConfig=()=>{const t=this.getDropdownInputValue();return S({},D,this.inputConfig,{value:t,tooltipConfig:{text:this.getTextFieldTooltip(),position:this.tooltipPosition}})},this.onClickApply=()=>{this.selectedDatesChange.emit(this.selectedDateState),this.dropdownStateChange.emit(!1),this.dropdownOpen=!1},this.onClickCancel=t=>{this.undoLastChanges(),this.cancelClicked.emit(t),this.dropdownOpen=!1},this.undoLastChanges=()=>{this.selectedDateState=x(this.selectedDates)?[]:this.selectedDates}}componentWillLoad(){var t,s;(null===(t=this.selectedDates)||void 0===t?void 0:t.length)>0&&0===(null===(s=this.selectedDateState)||void 0===s?void 0:s.length)&&(this.selectedDateState=this.selectedDates,this.handleSelecteDatesChange(this.selectedDates))}handleSelecteDatesChange(t){if(this.selectedDateState=t,x(this.initialDate)&&(null==t?void 0:t.length)>0){const[s]=t;this.calendarInitialDate=d(s).format(b)}}render(){const t=this.dropdownPositionOptions,s=this.getInputConfig(),r=((t,s,i)=>{if(!_(t,s))return;if(s===a.Single){const[s]=t;return i.minDate&&d(s).isBefore(i.minDate)?o.StartDateBeforeMinimumDate:i.maxDate&&d(s).isAfter(i.maxDate)?o.EndDateAfterMaximumDate:void 0}const[e,r]=t;return d(r).isAfter(e)?i.minDate&&d(e).isBefore(i.minDate)?o.StartDateBeforeMinimumDate:i.maxDate&&d(r).isAfter(i.maxDate)?o.EndDateAfterMaximumDate:void 0:o.EndDateBeforeStartDate})(this.selectedDateState,this.mode,{minDate:this.calendarInputMinDate,maxDate:this.calendarInputMaxDate}),c=_(this.selectedDateState,this.mode),l=g(this.selectedDateState,this.selectedDates),p=!c||void 0!==r||!l;return i(e,{key:"e8a6c8392f1fd83a285f5464f325d285666566e1"},i("kv-dropdown",{key:"f8184559f8ea3e54c3e68a62b75cc674524e96c9",isOpen:this.dropdownOpen,onOpenStateChange:this.onDropdownChange,inputConfig:s,options:t,disabled:this.disabled},i("div",{key:"7f9a37b66cdde9c499787fc92e81bba976b1e229",class:"absolute-time-content"},i("kv-absolute-time-picker",{key:"5f0321217c06709ba47cc1269be3fd0fd73c70f7",mode:this.mode,headerTitle:this.headerTitle,selectedDates:this.getAbsoluteRange(),disabledDates:this.disabledDates,initialDate:this.calendarInitialDate,onSelectedDatesChange:this.handleAbsoluteDatesChange,calendarInputMinDate:this.getCalendarLimitDatesFormatted(this.calendarInputMinDate),calendarInputMaxDate:this.getCalendarLimitDatesFormatted(this.calendarInputMaxDate),error:r}),i("div",{key:"4665e0872f9b6cbd9067f3b45c2253ce10ecc710",class:"footer"},i("div",{key:"46779a15bdf99ae88ce29a99ad6d45c417342bb5",class:"actions"},i("kv-action-button-text",{key:"53601132a95621dd5b1deb6f0998aa724dc01621",type:h.Tertiary,size:n.Small,text:"Cancel",onClickButton:this.onClickCancel}),i("kv-action-button-text",{key:"36dbacf08df298b9d522ad9d62cb63a4825e1da1",type:h.Primary,size:n.Small,text:"Apply",disabled:p,onClickButton:this.onClickApply}))))))}static get watchers(){return{selectedDates:["handleSelecteDatesChange"]}}};B.style='@property --rotation{syntax:"<angle>";initial-value:0deg;inherits:false}@keyframes rotate-border{to{--rotation:360deg}}kv-dropdown-base:not(.hydrated)>[slot=list]{display:none}:host{display:block}.absolute-time-content{background-color:var(--background-container-elevated-slider);border:1px solid var(--slider-border-color-default);border-radius:var(--radius-md);width:max-content}.absolute-time-content .footer{display:flex;justify-content:flex-end;padding:var(--spacing-2xl);border-top:1px solid var(--slider-border-color-default)}.absolute-time-content .footer .actions{display:flex;gap:var(--spacing-md)}';export{B as kv_absolute_time_picker_dropdown}