@entur/datepicker
Advanced tools
Comparing version 9.3.3 to 9.3.4
@@ -72,7 +72,7 @@ 'use strict'; | ||
if (offset) { | ||
return new date.ZonedDateTime(date$1.getFullYear(), date$1.getMonth() + 1, date$1.getDate(), timeZone, offset, date$1.getHours(), date$1.getMinutes(), date$1.getSeconds()); | ||
return new date.ZonedDateTime(date$1.getFullYear(), date$1.getMonth() + 1, date$1.getDate(), timeZone, offset, date$1.getHours(), date$1.getMinutes(), date$1.getSeconds(), date$1.getMilliseconds()); | ||
} | ||
return date.parseAbsolute(date$1.toISOString(), timeZone); | ||
} | ||
return new date.CalendarDateTime(date$1.getFullYear(), date$1.getMonth() + 1, date$1.getDate(), date$1.getHours(), date$1.getMinutes(), date$1.getSeconds()); | ||
return new date.CalendarDateTime(date$1.getFullYear(), date$1.getMonth() + 1, date$1.getDate(), date$1.getHours(), date$1.getMinutes(), date$1.getSeconds(), date$1.getMilliseconds()); | ||
}; | ||
@@ -108,3 +108,3 @@ /** | ||
if (date$1 === null) return null; | ||
if (noDateOnlyTime) return new date.Time(date$1.getHours(), date$1.getMinutes(), date$1.getSeconds(), 0); | ||
if (noDateOnlyTime) return new date.Time(date$1.getHours(), date$1.getMinutes(), date$1.getSeconds(), date$1.getMilliseconds()); | ||
return nativeDateToDateTime(date$1, timeZone, offset); | ||
@@ -126,2 +126,3 @@ } | ||
date$1.setSeconds(value.second); | ||
date$1.setMilliseconds(value.millisecond); | ||
return date$1; | ||
@@ -136,3 +137,3 @@ } | ||
if (timeZoneForCalendarDateTime) return value.toDate(timeZoneForCalendarDateTime); | ||
return new Date(value.year, value.month - 1, value.day, value.hour, value.minute, value.second); | ||
return value.toDate(date.getLocalTimeZone()); | ||
} | ||
@@ -539,2 +540,4 @@ // type is ZonedDateTime | ||
var handleOnChange = function handleOnChange(value) { | ||
// console.log(value && value.compare(parseDate('1000-01-01')) < 0); | ||
// if (value && value.compare(parseDate('1000-01-01')) < 0) return; | ||
if (forcedReturnType !== undefined) { | ||
@@ -541,0 +544,0 @@ return onChange(convertValueToType({ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@entur/utils"),a=require("react"),t=require("@react-stately/datepicker"),n=require("@react-aria/datepicker"),r=require("@react-aria/i18n"),l=require("classnames"),i=require("@entur/form"),o=require("@internationalized/date"),s=require("@react-aria/calendar"),d=require("@react-stately/calendar"),c=require("@entur/icons"),u=require("@react-aria/button"),m=require("@entur/button"),p=require("@entur/a11y"),f=require("@floating-ui/react-dom"),b=require("react-focus-lock"),v=require("@entur/tokens"),g=require("@entur/modal");function k(){return k=Object.assign?Object.assign.bind():function(e){for(var a=1;a<arguments.length;a++){var t=arguments[a];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},k.apply(this,arguments)}function D(e,a){if(null==e)return{};var t,n,r={},l=Object.keys(e);for(n=0;n<l.length;n++)a.indexOf(t=l[n])>=0||(r[t]=e[t]);return r}var h=["segment","state"],y=function(e){var t=e.segment,r=e.state,i=D(e,h),o=a.useRef(null),s=n.useDateSegment(t,r,o).segmentProps;return a.createElement("div",k({},s,{ref:o,className:l("eds-date-and-time-field__segment",{"eds-date-and-time-field__segment--placeholder":t.isPlaceholder,"eds-date-and-time-field__segment--dot-separator":"."===t.text}),tabIndex:r.isDisabled?-1:s.tabIndex},i),t.text)},C=function(e,a,t){return a?t?new o.ZonedDateTime(e.getFullYear(),e.getMonth()+1,e.getDate(),a,t,e.getHours(),e.getMinutes(),e.getSeconds()):o.parseAbsolute(e.toISOString(),a):new o.CalendarDateTime(e.getFullYear(),e.getMonth()+1,e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds())},w=function(e){if(void 0===e&&(e="gregory"),"gregory"===e)return new o.GregorianCalendar;throw new Error("Unsupported calendar "+e)},_=function(e,a,t){return"no-no"!==a.toLowerCase()?t["aria-label"]:e},T=function(e){return o.toCalendarDateTime(e.add({days:1})).add({milliseconds:-1})},E=function(e){var a=e.value,t=e.timezone,n=void 0===t?"Europe/Oslo":t;if(null===a)return null;switch(e.type){case"CalendarDate":return"day"in a?o.toCalendarDate(a):o.today(n);case"CalendarDateTime":return"day"in a?o.toCalendarDateTime(a):o.toCalendarDateTime(o.today(n),a);case"ZonedDateTime":return o.toZoned("day"in a?a:o.toCalendarDateTime(o.today(n),a),n);case"Time":return"hour"in a?"day"in a?o.toTime(a):a:o.toTime(o.now(n));default:return a}},N=function(e,a){return(e%a+a)%a},I=function(e,a){if(e.current){var t=e.current.querySelectorAll(".eds-date-and-time-field__segment"),n=t[0],r=t[t.length-1];switch(a){case"first":return n.focus();case"last":return r.focus()}}};function F(e){if(null===e)return-1;var a=E({value:e,type:"CalendarDate"}),t=o.startOfWeek(a,"no-NO").add({days:3}),n=o.startOfYear(t);return Math.ceil((t.compare(n)+1)/7)}var S,L=["selectedDate","onChange","label","locale","showTimeZone","showTime","granularity","disabled","isDisabled","variant","feedback","validationVariant","validationFeedback","labelTooltip","minDate","maxDate","style","className","labelProps","append"],x=a.forwardRef((function(o,s){var d=o.selectedDate,c=o.onChange,u=o.label,m=o.locale,p=o.showTimeZone,f=o.showTime,b=o.granularity,v=void 0===b?"day":b,g=o.disabled,h=o.isDisabled,C=o.variant,_=o.feedback,E=o.validationVariant,N=void 0===E?"error":E,I=o.validationFeedback,F=void 0===I?"Ugyldig dato":I,S=o.labelTooltip,x=o.minDate,P=o.maxDate,R=o.style,O=o.className,A=o.labelProps,V=o.append,M=D(o,L),Z=r.useLocale(),q=t.useDateFieldState(k({},M,{locale:null!=m?m:Z.locale,createCalendar:w,value:d,onChange:c,hideTimeZone:!p,granularity:f?"minute":v,minValue:x,maxValue:"hour"in(null!=P?P:{})?P:void 0!==P?T(P):void 0,isDisabled:h||g,shouldForceLeadingZeros:!0})),B=a.useRef(null),W=n.useDateField(k({},M,{label:u}),q,B),H=W.labelProps,z=W.fieldProps,j=e.useRandomId("datefield");return a.createElement(e.ConditionalWrapper,{condition:void 0!==m,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:m},e)}},a.createElement(i.BaseFormControl,k({style:R,className:l("eds-datefield",O),labelId:j,ref:e.mergeRefs(B,s),disabled:h||g,disableLabelAnimation:!0,label:u,labelTooltip:S,labelProps:null!=A?A:H},z,{variant:null!=C?C:"invalid"===q.validationState?N:void 0,feedback:null!=_?_:"invalid"===q.validationState?F:void 0,append:V,ariaAlertOnFeedback:!0}),q.segments.map((function(e,t){return a.createElement(y,{segment:e,state:q,key:t})}))))})),P=["children","className","style"],R=function(e){var t=e.children,n=e.className,r=e.style,l=D(e,P),i=a.useRef(null),o=u.useButton(l,i);return a.createElement(m.IconButton,k({},o.buttonProps,{ref:i,className:n,style:r}),t)},O=["state","date","onSelectedCellClick","weekNumberString","classNameForDate","ariaLabelForDate"],A=function(e){var t,n,r,i,d=e.state,c=e.date,u=e.onSelectedCellClick,m=void 0===u?function(){}:u,p=e.weekNumberString,f=e.classNameForDate,b=e.ariaLabelForDate,v=D(e,O),g=a.useRef(null),h=s.useCalendarCell({date:c},d,g),y=h.cellProps,C=h.buttonProps,w=h.isSelected,_=h.isOutsideVisibleRange,T=h.isDisabled,E=h.isUnavailable,N=h.formattedDate,I=""+C["aria-label"]+p+" "+(null!=(t=null==b?void 0:b(c))?t:"");return a.createElement("td",k({},y,{className:"eds-datepicker__calendar__grid__cell__td"}),a.createElement("div",k({},C,{"aria-label":I,"aria-hidden":_,ref:g,hidden:_,className:l("eds-datepicker__calendar__grid__cell",(i={},i[null!=(n=null==f?void 0:f(c))?n:""]=!_,i["eds-datepicker__calendar__grid__cell--selected"]=w,i["eds-datepicker__calendar__grid__cell--disabled"]=T||E,i["eds-datepicker__calendar__grid__cell--outside-month"]=_,i["eds-datepicker__calendar__grid__cell--today"]=o.isEqualDay(c,o.now(null!=(r=d.timeZone)?r:o.getLocalTimeZone())),i))},v,{onClick:function(e){C.onClick&&C.onClick(e),w&&m()},onKeyDown:function(e){C.onKeyDown&&C.onKeyDown(e),"Enter"!==e.key&&" "!==e.key||w&&m()}}),N))},V=["state","navigationDescription","onSelectedCellClick","showWeekNumbers","weekNumberHeader","classNameForDate","ariaLabelForDate"],M=function(t){var n=t.state,l=t.navigationDescription,i=t.onSelectedCellClick,d=void 0===i?function(){}:i,c=t.showWeekNumbers,u=t.weekNumberHeader,m=t.classNameForDate,f=t.ariaLabelForDate,b=D(t,V),v=e.useRandomId("eds-calendar"),g=r.useLocale().locale,h=s.useCalendarGrid(b,n),y=h.gridProps,C=h.headerProps,w=h.weekDays,_=o.getWeeksInMonth(n.visibleRange.start,g),T=Array.from(Array(_).keys());return a.createElement(a.Fragment,null,a.createElement("table",k({},y,{cellSpacing:"0",className:"eds-datepicker__calendar__grid"}),a.createElement("thead",k({},C),a.createElement("tr",null,c&&a.createElement("th",{className:"eds-datepicker__calendar__grid__weeknumber-header"},u),function(){if(g.toLowerCase().includes("no"))return["ma","ti","on","to","fr","lø","sø"];if(g.toLowerCase().includes("en")){if("M"===w[0])return["Mo","Tu","We","Th","Fr","Sa","Su"];if("S"===w[0])return["Su","Mo","Tu","We","Th","Fr","Sa"]}return w.map((function(e){return e.toLowerCase()}))}().map((function(e,t){return a.createElement("th",{key:t},e)})))),a.createElement("tbody",null,T.map((function(e){var t=F(n.getDatesInWeek(e)[0]);return a.createElement("tr",{key:e},c&&a.createElement("th",{"aria-hidden":!0,className:"eds-datepicker__calendar__grid__weeknumber"},t),n.getDatesInWeek(e).map((function(e,r){return e?a.createElement(A,{key:r,state:n,date:e,"aria-describedby":v+"description",weekNumberString:c?", "+u+" "+t+",":"",onSelectedCellClick:d,classNameForDate:m,ariaLabelForDate:f}):a.createElement("td",{key:r})})))})))),a.createElement(p.VisuallyHidden,{id:v+"description"},l||(g.toLowerCase().includes("en")?"Use the arrow keys to navigate between dates":"Bruk piltastene til å navigere mellom datoer")))},Z=["locale"],q=["selectedDate","onChange","minDate","maxDate","showWeekNumbers","weekNumberHeader","style","className","navigationDescription","onSelectedCellClick","classNameForDate","ariaLabelForDate","calendarRef"],B=function(e){var t=e.locale,n=D(e,Z),l=r.useLocale();return a.createElement(r.I18nProvider,{locale:null!=t?t:l.locale},a.createElement(W,k({},n)))},W=function(e){var t=e.selectedDate,n=e.onChange,i=e.minDate,o=e.maxDate,u=e.showWeekNumbers,m=void 0!==u&&u,p=e.weekNumberHeader,f=void 0===p?"uke":p,b=e.style,v=e.className,g=e.navigationDescription,h=e.onSelectedCellClick,y=void 0===h?function(){}:h,C=e.classNameForDate,T=e.ariaLabelForDate,E=e.calendarRef,N=D(e,q),I=r.useLocale().locale,F=k({},N,{value:t,onChange:n,locale:I,createCalendar:w,minValue:i,maxValue:o}),S=d.useCalendarState(F),L=s.useCalendar(F,S),x=L.prevButtonProps,P=L.nextButtonProps,O=L.title;return a.createElement("div",k({},L.calendarProps,{ref:E,className:l("eds-datepicker__calendar",v),style:b}),a.createElement("div",{className:"eds-datepicker__calendar__header"},a.createElement(R,k({},x,{"aria-label":_("Forrige måned",I,x)}),a.createElement(c.LeftArrowIcon,{size:20})),a.createElement("h2",null,O),a.createElement(R,k({},P,{"aria-label":_("Neste måned",I,P)}),a.createElement(c.RightArrowIcon,{size:20}))),a.createElement(M,{state:S,navigationDescription:g,onSelectedCellClick:y,classNameForDate:C,ariaLabelForDate:T,showWeekNumbers:m,weekNumberHeader:f}))},H=["selectedDate","onChange","locale","disabled","showTime","showTimeZone","classNameForDate","className","style","variant","feedback","validationVariant","validationFeedback","showWeekNumbers","weekNumberHeader","disableModal","labelTooltip","navigationDescription","minDate","maxDate","modalTreshold","forcedReturnType","ariaLabelForDate"],z=["className","style","label","onChange","feedback","variant","disableLabelAnimation","prepend"],j=["onChange","variant","value"],U=a.forwardRef((function(t,n){var r=t.className,l=t.style,o=t.label,s=t.onChange,d=t.feedback,u=t.variant,m=t.disableLabelAnimation,p=t.prepend,f=void 0===p?a.createElement(c.DateIcon,{inline:!0}):p,b=D(t,z),v=e.useRandomId("eds-nativetimepicker");return a.createElement(i.BaseFormControl,{style:l,className:r,prepend:f,label:o,feedback:d,variant:u,labelId:v,disableLabelAnimation:m,isFilled:!0},a.createElement(K,k({onChange:s,"aria-labelledby":v,ref:n,variant:u},b)))})),K=a.forwardRef((function(t,n){var r=t.onChange,l=t.variant,o=t.value,s=D(t,j),d=i.useVariant(),c=l||d,u=i.useInputGroupContext(),m=u.isFilled,p=u.setFilled;return e.useOnMount((function(){p&&!m&&p(!0)})),a.useEffect((function(){o?p&&!m&&p(!0):p&&m&&p(!1)}),[o,p,m]),a.createElement("input",k({ref:n,"aria-invalid":"error"===c,type:"date",className:"eds-form-control eds-native-date-picker",onChange:function(e){i.isFilled(e.target)?p&&!m&&p(!0):p&&m&&p(!1),r&&r(e)},value:o},s))})),G=["direction","onClick","disabled","aria-label"],Y=function(e){var t=e.direction,n=e.onClick,r=e.disabled,i=e["aria-label"],o=D(e,G);return a.createElement(m.IconButton,k({className:l("eds-timepicker__arrowbutton","eds-timepicker__arrowbutton--"+t,{"eds-timepicker__arrowbutton--disabled":r}),type:"button",tabIndex:-1,onClick:n,"aria-label":i,disabled:r},o),a.createElement("left"===t?c.LeftArrowIcon:c.RightArrowIcon,null))},$=["selectedTime","onChange","disabled","className","style","label","labelTooltip","feedback","granularity","variant","locale","showTimeZone","showSeconds","minuteIncrementForArrowButtons","leftArrowButtonAriaLabel","rightArrowButtonAriaLabel","inputRef","forcedReturnType","forcedTimeZone"],J=["className","style","onChange","label","feedback","variant","prepend"],Q=["onChange","value"],X=a.forwardRef((function(t,n){var r=t.className,o=t.style,s=t.onChange,d=t.label,c=t.feedback,u=t.variant,m=t.prepend,p=D(t,J),f=e.useRandomId("eds-native-timepicker");return a.createElement(i.BaseFormControl,{style:o,className:l(r,"eds-native-timepicker"),prepend:m,label:d,feedback:c,variant:u,labelId:f,disableLabelAnimation:!0},a.createElement(ee,k({onChange:s,"aria-labelledby":f,ref:n},p)))})),ee=a.forwardRef((function(t,n){var r=t.onChange,l=t.value,o=D(t,Q),s=i.useVariant(),d=o.variant||s,c=i.useInputGroupContext(),u=c.isFilled,m=c.setFilled;return e.useOnMount((function(){m&&!u&&m(!0)})),a.useEffect((function(){l?m&&!u&&m(!0):m&&u&&m(!1)}),[l,m,u]),a.createElement("input",k({ref:n,"aria-invalid":"error"===d,type:"time",className:"eds-form-control",onChange:function(e){i.isFilled(e.target)?m&&!u&&m(!0):m&&u&&m(!1),r&&r(e)},value:l},o))})),ae=["append","className","disabled","feedback","showClockIcon","inputRef","label","labelTooltip","onChange","padding","prepend","readOnly","selectedTime","showSeconds","style","variant"],te=["onBlur","onClick","onDragStart","onFocus","onKeyDown","onKeyUp","onMouseDown","onPointerDown","onPointerUp"];!function(e){e[e.RESET_TIME=0]="RESET_TIME",e[e.INVALID=1]="INVALID"}(S||(S={})),e.warnAboutMissingStyles("datepicker","form","icons"),Object.defineProperty(exports,"CalendarDate",{enumerable:!0,get:function(){return o.CalendarDate}}),Object.defineProperty(exports,"CalendarDateTime",{enumerable:!0,get:function(){return o.CalendarDateTime}}),Object.defineProperty(exports,"Time",{enumerable:!0,get:function(){return o.Time}}),Object.defineProperty(exports,"ZonedDateTime",{enumerable:!0,get:function(){return o.ZonedDateTime}}),exports.Calendar=B,exports.DateField=x,exports.DatePicker=function(i){var o=i.selectedDate,s=i.onChange,d=i.locale,u=i.disabled,m=i.showTime,p=i.showTimeZone,h=void 0!==p&&p,y=i.classNameForDate,C=i.className,w=i.variant,_=i.feedback,N=i.validationVariant,I=i.validationFeedback,F=i.showWeekNumbers,S=i.weekNumberHeader,L=i.disableModal,P=void 0!==L&&L,O=i.labelTooltip,A=i.navigationDescription,V=i.minDate,M=i.maxDate,Z=i.modalTreshold,q=void 0===Z?1e3:Z,W=i.forcedReturnType,z=i.ariaLabelForDate,j=D(i,H),U=q,K=a.useRef(null),G=a.useRef(null),Y=a.useRef(null),$=e.useWindowDimensions().width,J=function(e){if(void 0!==W)return s(E({value:e,type:W,timezone:null!==e&&"timezone"in e?e.timezone:void 0}));s(e)},Q=t.useDatePickerState(k({},j,{minValue:V,maxValue:"hour"in(null!=M?M:{})?M:void 0!==M?T(M):void 0,value:o,onChange:J,granularity:m?"minute":j.granularity,isDisabled:u})),X=n.useDatePicker(k({},j),Q,K),ee=X.groupProps,ae=X.labelProps,te=X.fieldProps,ne=X.buttonProps,re=X.dialogProps,le=X.calendarProps,ie=f.useFloating({whileElementsMounted:f.autoUpdate,placement:"bottom-start",middleware:[f.offset(v.space.extraSmall),f.flip(),f.shift({padding:v.space.extraSmall})]}),oe=ie.x,se=ie.y,de=ie.reference,ce=ie.floating,ue=ie.strategy;e.useOnClickOutside([G],(function(){Q.setOpen(!1)})),e.useOnEscape(G,(function(){Q.setOpen(!1)}));var me=k({},re,le,{disabled:u,navigationDescription:A,onSelectedCellClick:function(){return Q.setOpen(!1)},selectedDate:o,onChange:J,minDate:V,maxDate:M,calendarRef:G,classNameForDate:y,ariaLabelForDate:z,showWeekNumbers:F,weekNumberHeader:S}),pe=void 0!==$&&$<=U&&!P,fe=a.createElement("div",{style:{position:ue,top:null!=se?se:0,left:null!=oe?oe:0,zIndex:v.zIndexes.popover},ref:function(e){ce(e)}},a.createElement(b,{disabled:!Q.isOpen||pe,returnFocus:!0},Q.isOpen&&a.createElement(B,k({},me)))),be=a.createElement(g.Modal,{size:"small",title:"",open:Q.isOpen,onDismiss:function(){return Q.setOpen(!1)},className:"eds-datepicker__calendar-modal"},a.createElement(B,k({},me)));return a.createElement(e.ConditionalWrapper,{condition:void 0!==d,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:d},e)}},a.createElement("div",{className:l("eds-datepicker",C)},a.createElement("div",k({},ee,{ref:function(e){K.current=e,de(e)},id:void 0,className:"eds-datepicker__datefield__wrapper"}),a.createElement(x,k({},te,{selectedDate:o,onChange:J,label:j.label,labelProps:ae,disabled:u,minDate:V,maxDate:M,showTime:m,showTimeZone:h,ref:Y,variant:w,feedback:_,validationVariant:N,validationFeedback:I,labelTooltip:O,className:l("eds-datepicker__datefield",{"eds-datepicker__datefield--disabled":u})})),!u&&a.createElement(R,k({},ne,{onPress:function(){return Q.setOpen(!Q.isOpen)},className:"eds-datepicker__open-calendar-button"}),a.createElement(c.CalendarIcon,null)),pe?be:fe)))},exports.NativeDatePicker=U,exports.NativeTimePicker=X,exports.SimpleTimePicker=function(s){var d=s.append,u=s.disabled,m=s.feedback,p=s.showClockIcon,f=void 0===p?"right":p,b=s.inputRef,v=s.label,g=s.labelTooltip,h=s.onChange,y=s.padding,C=void 0===y?"default":y,w=s.prepend,_=s.readOnly,T=s.selectedTime,E=s.showSeconds,N=s.style,I=s.variant,F=D(s,ae),L=a.useState(""),x=L[0],P=L[1],R=a.useRef(null),O=a.useState(null),A=O[0],V=O[1],M=r.useLocale().locale,Z=t.useTimeFieldState(k({onChange:h,label:v,locale:M,value:T,hideTimeZone:!0,isDisabled:u,isReadOnly:_},F)),q=n.useTimeField(k({},F,{label:v}),Z,R),B=q.labelProps,W=q.fieldProps;a.useEffect((function(){H(),null!==T&&V(T)}),[null==T?void 0:T.toString()]);var H=function(){var e=z(T);P(e);var a=document.activeElement===(null==R?void 0:R.current);""!==e||a||j()},z=function(e){if(null===e)return"";var a="day"in e?o.toTime(e):e;return E?a.toString().slice(0,8):a.toString().slice(0,5)},j=function(){P(E?"–– : –– : ––":"–– : ––")},U=function(){var e=K();if(e===S.INVALID)return H();(null==e?void 0:e.toString())!==(null==T?void 0:T.toString())&&(null==h||h(e))},K=function(){var e=G(x),a=Y(e);return a===S.INVALID?S.INVALID:a===S.RESET_TIME?null:$(a)},G=function(e){if(0===e.length)return S.RESET_TIME;if(e.length<3||e.length>8)return S.INVALID;var a=(e.match(new RegExp(":","g"))||[]).length,t=e.length;if(2===a&&t>=7)return e.padStart(8,"0");if(1===a)return e.padStart(5,"0");if(t>6)return S.INVALID;var n,r=t%2==0,l=e.slice(0,r?2:1),i=r?e.slice(2,4):e.slice(1,3),o=""===(n=r?e.slice(4,6):e.slice(3,5))?"00":n;return l.padStart(2,"0")+":"+i+(E?":"+o:"")},Y=function(e){if(e===S.INVALID)return S.INVALID;if(e===S.RESET_TIME)return S.RESET_TIME;var a=/^\d+$/,t=e.slice(0,2),n=e.slice(3,5),r=e.slice(6,8);if(t.match(a)&&n.match(a)&&(""===r||r.match(a)))try{return o.parseTime(e)}catch(e){return S.INVALID}return S.INVALID},$=function(e){return(null!=A?A:new o.Time).set({hour:e.hour,minute:e.minute,second:e.second})},J=D(W,te);return a.createElement(r.I18nProvider,{locale:M},a.createElement(i.TextField,k({append:d||(!0===f||"right"===f?a.createElement(c.ClockIcon,{onClick:function(){var e;return null==R||null==(e=R.current)?void 0:e.focus()}}):void 0),className:l("eds-simple-timepicker",{"eds-simple-timepicker--padding-large":"large"===C,"eds-simple-timepicker--show-seconds":E,"eds-simple-timepicker--hide-clock":!f}),disabled:u,disableLabelAnimation:!0,feedback:m,label:v,labelProps:B,labelTooltip:g,onBlur:function(){U(),null===T&&j()},onChange:function(e){return P(e.target.value)},onFocus:function(){null===T&&P("")},onKeyDown:function(e){"Enter"===e.key&&U()},placeholder:E?"–– : –– : ––":"–– : ––",prepend:w||("left"===f?a.createElement(c.ClockIcon,{onClick:function(){var e;return null==R||null==(e=R.current)?void 0:e.focus()}}):void 0),readOnly:_,ref:e.mergeRefs(R,b),style:N,value:x,variant:I},J)))},exports.TimePicker=function(s){var d=s.selectedTime,c=s.onChange,u=s.disabled,m=s.className,f=s.style,b=s.label,v=s.labelTooltip,g=s.feedback,h=s.granularity,C=s.variant,w=s.locale,_=s.showTimeZone,T=s.showSeconds,F=void 0!==T&&T,S=s.minuteIncrementForArrowButtons,L=void 0===S?30:S,x=s.leftArrowButtonAriaLabel,P=void 0===x?"Trekk fra "+L+" minutter":x,R=s.rightArrowButtonAriaLabel,O=void 0===R?"Legg til "+L+" minutter":R,A=s.inputRef,V=s.forcedReturnType,M=s.forcedTimeZone,Z=D(s,$),q=r.useLocale().locale;w&&(q=w);var B=e.useRandomId("eds-timepicker"),W=null!=M?M:null!==d&&"timezone"in d?d.timezone:"Europe/Oslo",H=function(e){if(void 0!==V)return c(E({value:e,type:V,timezone:W}));c(e)},z=t.useTimeFieldState(k({onChange:H,label:b,locale:q,value:d,granularity:(null!=h?h:F)?"second":"minute",hideTimeZone:!_,isDisabled:u,shouldForceLeadingZeros:!0},Z)),j=a.useRef(null),U=n.useTimeField(k({},Z,{label:b}),z,j),K=U.labelProps,G=U.fieldProps,J=e.useRandomId("timepicker"),Q=function(e){if(null===d)return H(E({value:o.now(W),type:null!=V?V:"ZonedDateTime"}));switch(e){case"add":return H(d.add({minutes:L-N(d.minute,L)}));case"subtract":return H(d.subtract({minutes:N(d.minute-1,L)+1}))}};return a.createElement(r.I18nProvider,{locale:q},a.createElement("div",{className:l(m,"eds-timepicker__wrapper")},a.createElement(i.BaseFormControl,k({style:f,className:l("eds-timepicker",{"eds-timepicker--disabled":u}),labelId:J,label:b,labelProps:k({},K,{"aria-describedby":B+"description"}),ref:e.mergeRefs(j,A),disabled:u,disableLabelAnimation:!0,labelTooltip:v},G,{variant:C,feedback:g,ariaAlertOnFeedback:!0,"aria-describedby":B+"description",prepend:a.createElement(Y,{direction:"left",disabled:u,"aria-label":P,onClick:function(){return Q("subtract")},onFocus:function(){return I(j,"first")}}),append:a.createElement(Y,{direction:"right",disabled:u,"aria-label":O,onClick:function(){return Q("add")},onFocus:function(){return I(j,"last")}})}),z.segments.map((function(e,t){return a.createElement(y,{segment:e,state:z,key:t,"aria-describedby":B+"description"})}))),a.createElement(p.VisuallyHidden,{id:B+"description"},null!==d?"valgt tid: "+d.hour.toString().padStart(2,"0")+":"+d.minute.toString().padStart(2,"0")+(F?":"+d.second.toString().padStart(2,"0"):""):"")))},exports.ariaLabelIfNorwegian=_,exports.convertValueToType=E,exports.createCalendar=w,exports.focusSegment=I,exports.getWeekNumberForDate=F,exports.lastMillisecondOfDay=T,exports.modulo=N,exports.nativeDateToDateValue=function(e,a,t,n){return void 0===a&&(a=!1),null===e?null:a?new o.CalendarDate(e.getFullYear(),e.getMonth()+1,e.getDate()):C(e,t,n)},exports.nativeDateToTimeValue=function(e,a,t,n){return void 0===a&&(a=!1),null===e?null:a?new o.Time(e.getHours(),e.getMinutes(),e.getSeconds(),0):C(e,t,n)},exports.timeOrDateValueToNativeDate=function(e,a){if(null===e)return null;if(!("day"in e)){var t=new Date;return t.setHours(e.hour),t.setMinutes(e.minute),t.setSeconds(e.second),t}return"hour"in e?"timeZone"in e?e.toDate():a?e.toDate(a):new Date(e.year,e.month-1,e.day,e.hour,e.minute,e.second):e.toDate(null!=a?a:o.getLocalTimeZone())}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@entur/utils"),a=require("react"),t=require("@react-stately/datepicker"),n=require("@react-aria/datepicker"),r=require("@react-aria/i18n"),l=require("classnames"),i=require("@entur/form"),o=require("@internationalized/date"),s=require("@react-aria/calendar"),d=require("@react-stately/calendar"),c=require("@entur/icons"),u=require("@react-aria/button"),m=require("@entur/button"),p=require("@entur/a11y"),f=require("@floating-ui/react-dom"),b=require("react-focus-lock"),v=require("@entur/tokens"),g=require("@entur/modal");function k(){return k=Object.assign?Object.assign.bind():function(e){for(var a=1;a<arguments.length;a++){var t=arguments[a];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},k.apply(this,arguments)}function D(e,a){if(null==e)return{};var t,n,r={},l=Object.keys(e);for(n=0;n<l.length;n++)a.indexOf(t=l[n])>=0||(r[t]=e[t]);return r}var h=["segment","state"],y=function(e){var t=e.segment,r=e.state,i=D(e,h),o=a.useRef(null),s=n.useDateSegment(t,r,o).segmentProps;return a.createElement("div",k({},s,{ref:o,className:l("eds-date-and-time-field__segment",{"eds-date-and-time-field__segment--placeholder":t.isPlaceholder,"eds-date-and-time-field__segment--dot-separator":"."===t.text}),tabIndex:r.isDisabled?-1:s.tabIndex},i),t.text)},C=function(e,a,t){return a?t?new o.ZonedDateTime(e.getFullYear(),e.getMonth()+1,e.getDate(),a,t,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()):o.parseAbsolute(e.toISOString(),a):new o.CalendarDateTime(e.getFullYear(),e.getMonth()+1,e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())},w=function(e){if(void 0===e&&(e="gregory"),"gregory"===e)return new o.GregorianCalendar;throw new Error("Unsupported calendar "+e)},_=function(e,a,t){return"no-no"!==a.toLowerCase()?t["aria-label"]:e},T=function(e){return o.toCalendarDateTime(e.add({days:1})).add({milliseconds:-1})},E=function(e){var a=e.value,t=e.timezone,n=void 0===t?"Europe/Oslo":t;if(null===a)return null;switch(e.type){case"CalendarDate":return"day"in a?o.toCalendarDate(a):o.today(n);case"CalendarDateTime":return"day"in a?o.toCalendarDateTime(a):o.toCalendarDateTime(o.today(n),a);case"ZonedDateTime":return o.toZoned("day"in a?a:o.toCalendarDateTime(o.today(n),a),n);case"Time":return"hour"in a?"day"in a?o.toTime(a):a:o.toTime(o.now(n));default:return a}},N=function(e,a){return(e%a+a)%a},I=function(e,a){if(e.current){var t=e.current.querySelectorAll(".eds-date-and-time-field__segment"),n=t[0],r=t[t.length-1];switch(a){case"first":return n.focus();case"last":return r.focus()}}};function F(e){if(null===e)return-1;var a=E({value:e,type:"CalendarDate"}),t=o.startOfWeek(a,"no-NO").add({days:3}),n=o.startOfYear(t);return Math.ceil((t.compare(n)+1)/7)}var S,L=["selectedDate","onChange","label","locale","showTimeZone","showTime","granularity","disabled","isDisabled","variant","feedback","validationVariant","validationFeedback","labelTooltip","minDate","maxDate","style","className","labelProps","append"],x=a.forwardRef((function(o,s){var d=o.selectedDate,c=o.onChange,u=o.label,m=o.locale,p=o.showTimeZone,f=o.showTime,b=o.granularity,v=void 0===b?"day":b,g=o.disabled,h=o.isDisabled,C=o.variant,_=o.feedback,E=o.validationVariant,N=void 0===E?"error":E,I=o.validationFeedback,F=void 0===I?"Ugyldig dato":I,S=o.labelTooltip,x=o.minDate,P=o.maxDate,R=o.style,O=o.className,A=o.labelProps,M=o.append,V=D(o,L),Z=r.useLocale(),q=t.useDateFieldState(k({},V,{locale:null!=m?m:Z.locale,createCalendar:w,value:d,onChange:c,hideTimeZone:!p,granularity:f?"minute":v,minValue:x,maxValue:"hour"in(null!=P?P:{})?P:void 0!==P?T(P):void 0,isDisabled:h||g,shouldForceLeadingZeros:!0})),B=a.useRef(null),W=n.useDateField(k({},V,{label:u}),q,B),H=W.labelProps,z=W.fieldProps,j=e.useRandomId("datefield");return a.createElement(e.ConditionalWrapper,{condition:void 0!==m,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:m},e)}},a.createElement(i.BaseFormControl,k({style:R,className:l("eds-datefield",O),labelId:j,ref:e.mergeRefs(B,s),disabled:h||g,disableLabelAnimation:!0,label:u,labelTooltip:S,labelProps:null!=A?A:H},z,{variant:null!=C?C:"invalid"===q.validationState?N:void 0,feedback:null!=_?_:"invalid"===q.validationState?F:void 0,append:M,ariaAlertOnFeedback:!0}),q.segments.map((function(e,t){return a.createElement(y,{segment:e,state:q,key:t})}))))})),P=["children","className","style"],R=function(e){var t=e.children,n=e.className,r=e.style,l=D(e,P),i=a.useRef(null),o=u.useButton(l,i);return a.createElement(m.IconButton,k({},o.buttonProps,{ref:i,className:n,style:r}),t)},O=["state","date","onSelectedCellClick","weekNumberString","classNameForDate","ariaLabelForDate"],A=function(e){var t,n,r,i,d=e.state,c=e.date,u=e.onSelectedCellClick,m=void 0===u?function(){}:u,p=e.weekNumberString,f=e.classNameForDate,b=e.ariaLabelForDate,v=D(e,O),g=a.useRef(null),h=s.useCalendarCell({date:c},d,g),y=h.cellProps,C=h.buttonProps,w=h.isSelected,_=h.isOutsideVisibleRange,T=h.isDisabled,E=h.isUnavailable,N=h.formattedDate,I=""+C["aria-label"]+p+" "+(null!=(t=null==b?void 0:b(c))?t:"");return a.createElement("td",k({},y,{className:"eds-datepicker__calendar__grid__cell__td"}),a.createElement("div",k({},C,{"aria-label":I,"aria-hidden":_,ref:g,hidden:_,className:l("eds-datepicker__calendar__grid__cell",(i={},i[null!=(n=null==f?void 0:f(c))?n:""]=!_,i["eds-datepicker__calendar__grid__cell--selected"]=w,i["eds-datepicker__calendar__grid__cell--disabled"]=T||E,i["eds-datepicker__calendar__grid__cell--outside-month"]=_,i["eds-datepicker__calendar__grid__cell--today"]=o.isEqualDay(c,o.now(null!=(r=d.timeZone)?r:o.getLocalTimeZone())),i))},v,{onClick:function(e){C.onClick&&C.onClick(e),w&&m()},onKeyDown:function(e){C.onKeyDown&&C.onKeyDown(e),"Enter"!==e.key&&" "!==e.key||w&&m()}}),N))},M=["state","navigationDescription","onSelectedCellClick","showWeekNumbers","weekNumberHeader","classNameForDate","ariaLabelForDate"],V=function(t){var n=t.state,l=t.navigationDescription,i=t.onSelectedCellClick,d=void 0===i?function(){}:i,c=t.showWeekNumbers,u=t.weekNumberHeader,m=t.classNameForDate,f=t.ariaLabelForDate,b=D(t,M),v=e.useRandomId("eds-calendar"),g=r.useLocale().locale,h=s.useCalendarGrid(b,n),y=h.gridProps,C=h.headerProps,w=h.weekDays,_=o.getWeeksInMonth(n.visibleRange.start,g),T=Array.from(Array(_).keys());return a.createElement(a.Fragment,null,a.createElement("table",k({},y,{cellSpacing:"0",className:"eds-datepicker__calendar__grid"}),a.createElement("thead",k({},C),a.createElement("tr",null,c&&a.createElement("th",{className:"eds-datepicker__calendar__grid__weeknumber-header"},u),function(){if(g.toLowerCase().includes("no"))return["ma","ti","on","to","fr","lø","sø"];if(g.toLowerCase().includes("en")){if("M"===w[0])return["Mo","Tu","We","Th","Fr","Sa","Su"];if("S"===w[0])return["Su","Mo","Tu","We","Th","Fr","Sa"]}return w.map((function(e){return e.toLowerCase()}))}().map((function(e,t){return a.createElement("th",{key:t},e)})))),a.createElement("tbody",null,T.map((function(e){var t=F(n.getDatesInWeek(e)[0]);return a.createElement("tr",{key:e},c&&a.createElement("th",{"aria-hidden":!0,className:"eds-datepicker__calendar__grid__weeknumber"},t),n.getDatesInWeek(e).map((function(e,r){return e?a.createElement(A,{key:r,state:n,date:e,"aria-describedby":v+"description",weekNumberString:c?", "+u+" "+t+",":"",onSelectedCellClick:d,classNameForDate:m,ariaLabelForDate:f}):a.createElement("td",{key:r})})))})))),a.createElement(p.VisuallyHidden,{id:v+"description"},l||(g.toLowerCase().includes("en")?"Use the arrow keys to navigate between dates":"Bruk piltastene til å navigere mellom datoer")))},Z=["locale"],q=["selectedDate","onChange","minDate","maxDate","showWeekNumbers","weekNumberHeader","style","className","navigationDescription","onSelectedCellClick","classNameForDate","ariaLabelForDate","calendarRef"],B=function(e){var t=e.locale,n=D(e,Z),l=r.useLocale();return a.createElement(r.I18nProvider,{locale:null!=t?t:l.locale},a.createElement(W,k({},n)))},W=function(e){var t=e.selectedDate,n=e.onChange,i=e.minDate,o=e.maxDate,u=e.showWeekNumbers,m=void 0!==u&&u,p=e.weekNumberHeader,f=void 0===p?"uke":p,b=e.style,v=e.className,g=e.navigationDescription,h=e.onSelectedCellClick,y=void 0===h?function(){}:h,C=e.classNameForDate,T=e.ariaLabelForDate,E=e.calendarRef,N=D(e,q),I=r.useLocale().locale,F=k({},N,{value:t,onChange:n,locale:I,createCalendar:w,minValue:i,maxValue:o}),S=d.useCalendarState(F),L=s.useCalendar(F,S),x=L.prevButtonProps,P=L.nextButtonProps,O=L.title;return a.createElement("div",k({},L.calendarProps,{ref:E,className:l("eds-datepicker__calendar",v),style:b}),a.createElement("div",{className:"eds-datepicker__calendar__header"},a.createElement(R,k({},x,{"aria-label":_("Forrige måned",I,x)}),a.createElement(c.LeftArrowIcon,{size:20})),a.createElement("h2",null,O),a.createElement(R,k({},P,{"aria-label":_("Neste måned",I,P)}),a.createElement(c.RightArrowIcon,{size:20}))),a.createElement(V,{state:S,navigationDescription:g,onSelectedCellClick:y,classNameForDate:C,ariaLabelForDate:T,showWeekNumbers:m,weekNumberHeader:f}))},H=["selectedDate","onChange","locale","disabled","showTime","showTimeZone","classNameForDate","className","style","variant","feedback","validationVariant","validationFeedback","showWeekNumbers","weekNumberHeader","disableModal","labelTooltip","navigationDescription","minDate","maxDate","modalTreshold","forcedReturnType","ariaLabelForDate"],z=["className","style","label","onChange","feedback","variant","disableLabelAnimation","prepend"],j=["onChange","variant","value"],U=a.forwardRef((function(t,n){var r=t.className,l=t.style,o=t.label,s=t.onChange,d=t.feedback,u=t.variant,m=t.disableLabelAnimation,p=t.prepend,f=void 0===p?a.createElement(c.DateIcon,{inline:!0}):p,b=D(t,z),v=e.useRandomId("eds-nativetimepicker");return a.createElement(i.BaseFormControl,{style:l,className:r,prepend:f,label:o,feedback:d,variant:u,labelId:v,disableLabelAnimation:m,isFilled:!0},a.createElement(K,k({onChange:s,"aria-labelledby":v,ref:n,variant:u},b)))})),K=a.forwardRef((function(t,n){var r=t.onChange,l=t.variant,o=t.value,s=D(t,j),d=i.useVariant(),c=l||d,u=i.useInputGroupContext(),m=u.isFilled,p=u.setFilled;return e.useOnMount((function(){p&&!m&&p(!0)})),a.useEffect((function(){o?p&&!m&&p(!0):p&&m&&p(!1)}),[o,p,m]),a.createElement("input",k({ref:n,"aria-invalid":"error"===c,type:"date",className:"eds-form-control eds-native-date-picker",onChange:function(e){i.isFilled(e.target)?p&&!m&&p(!0):p&&m&&p(!1),r&&r(e)},value:o},s))})),G=["direction","onClick","disabled","aria-label"],Y=function(e){var t=e.direction,n=e.onClick,r=e.disabled,i=e["aria-label"],o=D(e,G);return a.createElement(m.IconButton,k({className:l("eds-timepicker__arrowbutton","eds-timepicker__arrowbutton--"+t,{"eds-timepicker__arrowbutton--disabled":r}),type:"button",tabIndex:-1,onClick:n,"aria-label":i,disabled:r},o),a.createElement("left"===t?c.LeftArrowIcon:c.RightArrowIcon,null))},$=["selectedTime","onChange","disabled","className","style","label","labelTooltip","feedback","granularity","variant","locale","showTimeZone","showSeconds","minuteIncrementForArrowButtons","leftArrowButtonAriaLabel","rightArrowButtonAriaLabel","inputRef","forcedReturnType","forcedTimeZone"],J=["className","style","onChange","label","feedback","variant","prepend"],Q=["onChange","value"],X=a.forwardRef((function(t,n){var r=t.className,o=t.style,s=t.onChange,d=t.label,c=t.feedback,u=t.variant,m=t.prepend,p=D(t,J),f=e.useRandomId("eds-native-timepicker");return a.createElement(i.BaseFormControl,{style:o,className:l(r,"eds-native-timepicker"),prepend:m,label:d,feedback:c,variant:u,labelId:f,disableLabelAnimation:!0},a.createElement(ee,k({onChange:s,"aria-labelledby":f,ref:n},p)))})),ee=a.forwardRef((function(t,n){var r=t.onChange,l=t.value,o=D(t,Q),s=i.useVariant(),d=o.variant||s,c=i.useInputGroupContext(),u=c.isFilled,m=c.setFilled;return e.useOnMount((function(){m&&!u&&m(!0)})),a.useEffect((function(){l?m&&!u&&m(!0):m&&u&&m(!1)}),[l,m,u]),a.createElement("input",k({ref:n,"aria-invalid":"error"===d,type:"time",className:"eds-form-control",onChange:function(e){i.isFilled(e.target)?m&&!u&&m(!0):m&&u&&m(!1),r&&r(e)},value:l},o))})),ae=["append","className","disabled","feedback","showClockIcon","inputRef","label","labelTooltip","onChange","padding","prepend","readOnly","selectedTime","showSeconds","style","variant"],te=["onBlur","onClick","onDragStart","onFocus","onKeyDown","onKeyUp","onMouseDown","onPointerDown","onPointerUp"];!function(e){e[e.RESET_TIME=0]="RESET_TIME",e[e.INVALID=1]="INVALID"}(S||(S={})),e.warnAboutMissingStyles("datepicker","form","icons"),Object.defineProperty(exports,"CalendarDate",{enumerable:!0,get:function(){return o.CalendarDate}}),Object.defineProperty(exports,"CalendarDateTime",{enumerable:!0,get:function(){return o.CalendarDateTime}}),Object.defineProperty(exports,"Time",{enumerable:!0,get:function(){return o.Time}}),Object.defineProperty(exports,"ZonedDateTime",{enumerable:!0,get:function(){return o.ZonedDateTime}}),exports.Calendar=B,exports.DateField=x,exports.DatePicker=function(i){var o=i.selectedDate,s=i.onChange,d=i.locale,u=i.disabled,m=i.showTime,p=i.showTimeZone,h=void 0!==p&&p,y=i.classNameForDate,C=i.className,w=i.variant,_=i.feedback,N=i.validationVariant,I=i.validationFeedback,F=i.showWeekNumbers,S=i.weekNumberHeader,L=i.disableModal,P=void 0!==L&&L,O=i.labelTooltip,A=i.navigationDescription,M=i.minDate,V=i.maxDate,Z=i.modalTreshold,q=void 0===Z?1e3:Z,W=i.forcedReturnType,z=i.ariaLabelForDate,j=D(i,H),U=q,K=a.useRef(null),G=a.useRef(null),Y=a.useRef(null),$=e.useWindowDimensions().width,J=function(e){if(void 0!==W)return s(E({value:e,type:W,timezone:null!==e&&"timezone"in e?e.timezone:void 0}));s(e)},Q=t.useDatePickerState(k({},j,{minValue:M,maxValue:"hour"in(null!=V?V:{})?V:void 0!==V?T(V):void 0,value:o,onChange:J,granularity:m?"minute":j.granularity,isDisabled:u})),X=n.useDatePicker(k({},j),Q,K),ee=X.groupProps,ae=X.labelProps,te=X.fieldProps,ne=X.buttonProps,re=X.dialogProps,le=X.calendarProps,ie=f.useFloating({whileElementsMounted:f.autoUpdate,placement:"bottom-start",middleware:[f.offset(v.space.extraSmall),f.flip(),f.shift({padding:v.space.extraSmall})]}),oe=ie.x,se=ie.y,de=ie.reference,ce=ie.floating,ue=ie.strategy;e.useOnClickOutside([G],(function(){Q.setOpen(!1)})),e.useOnEscape(G,(function(){Q.setOpen(!1)}));var me=k({},re,le,{disabled:u,navigationDescription:A,onSelectedCellClick:function(){return Q.setOpen(!1)},selectedDate:o,onChange:J,minDate:M,maxDate:V,calendarRef:G,classNameForDate:y,ariaLabelForDate:z,showWeekNumbers:F,weekNumberHeader:S}),pe=void 0!==$&&$<=U&&!P,fe=a.createElement("div",{style:{position:ue,top:null!=se?se:0,left:null!=oe?oe:0,zIndex:v.zIndexes.popover},ref:function(e){ce(e)}},a.createElement(b,{disabled:!Q.isOpen||pe,returnFocus:!0},Q.isOpen&&a.createElement(B,k({},me)))),be=a.createElement(g.Modal,{size:"small",title:"",open:Q.isOpen,onDismiss:function(){return Q.setOpen(!1)},className:"eds-datepicker__calendar-modal"},a.createElement(B,k({},me)));return a.createElement(e.ConditionalWrapper,{condition:void 0!==d,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:d},e)}},a.createElement("div",{className:l("eds-datepicker",C)},a.createElement("div",k({},ee,{ref:function(e){K.current=e,de(e)},id:void 0,className:"eds-datepicker__datefield__wrapper"}),a.createElement(x,k({},te,{selectedDate:o,onChange:J,label:j.label,labelProps:ae,disabled:u,minDate:M,maxDate:V,showTime:m,showTimeZone:h,ref:Y,variant:w,feedback:_,validationVariant:N,validationFeedback:I,labelTooltip:O,className:l("eds-datepicker__datefield",{"eds-datepicker__datefield--disabled":u})})),!u&&a.createElement(R,k({},ne,{onPress:function(){return Q.setOpen(!Q.isOpen)},className:"eds-datepicker__open-calendar-button"}),a.createElement(c.CalendarIcon,null)),pe?be:fe)))},exports.NativeDatePicker=U,exports.NativeTimePicker=X,exports.SimpleTimePicker=function(s){var d=s.append,u=s.disabled,m=s.feedback,p=s.showClockIcon,f=void 0===p?"right":p,b=s.inputRef,v=s.label,g=s.labelTooltip,h=s.onChange,y=s.padding,C=void 0===y?"default":y,w=s.prepend,_=s.readOnly,T=s.selectedTime,E=s.showSeconds,N=s.style,I=s.variant,F=D(s,ae),L=a.useState(""),x=L[0],P=L[1],R=a.useRef(null),O=a.useState(null),A=O[0],M=O[1],V=r.useLocale().locale,Z=t.useTimeFieldState(k({onChange:h,label:v,locale:V,value:T,hideTimeZone:!0,isDisabled:u,isReadOnly:_},F)),q=n.useTimeField(k({},F,{label:v}),Z,R),B=q.labelProps,W=q.fieldProps;a.useEffect((function(){H(),null!==T&&M(T)}),[null==T?void 0:T.toString()]);var H=function(){var e=z(T);P(e);var a=document.activeElement===(null==R?void 0:R.current);""!==e||a||j()},z=function(e){if(null===e)return"";var a="day"in e?o.toTime(e):e;return E?a.toString().slice(0,8):a.toString().slice(0,5)},j=function(){P(E?"–– : –– : ––":"–– : ––")},U=function(){var e=K();if(e===S.INVALID)return H();(null==e?void 0:e.toString())!==(null==T?void 0:T.toString())&&(null==h||h(e))},K=function(){var e=G(x),a=Y(e);return a===S.INVALID?S.INVALID:a===S.RESET_TIME?null:$(a)},G=function(e){if(0===e.length)return S.RESET_TIME;if(e.length<3||e.length>8)return S.INVALID;var a=(e.match(new RegExp(":","g"))||[]).length,t=e.length;if(2===a&&t>=7)return e.padStart(8,"0");if(1===a)return e.padStart(5,"0");if(t>6)return S.INVALID;var n,r=t%2==0,l=e.slice(0,r?2:1),i=r?e.slice(2,4):e.slice(1,3),o=""===(n=r?e.slice(4,6):e.slice(3,5))?"00":n;return l.padStart(2,"0")+":"+i+(E?":"+o:"")},Y=function(e){if(e===S.INVALID)return S.INVALID;if(e===S.RESET_TIME)return S.RESET_TIME;var a=/^\d+$/,t=e.slice(0,2),n=e.slice(3,5),r=e.slice(6,8);if(t.match(a)&&n.match(a)&&(""===r||r.match(a)))try{return o.parseTime(e)}catch(e){return S.INVALID}return S.INVALID},$=function(e){return(null!=A?A:new o.Time).set({hour:e.hour,minute:e.minute,second:e.second})},J=D(W,te);return a.createElement(r.I18nProvider,{locale:V},a.createElement(i.TextField,k({append:d||(!0===f||"right"===f?a.createElement(c.ClockIcon,{onClick:function(){var e;return null==R||null==(e=R.current)?void 0:e.focus()}}):void 0),className:l("eds-simple-timepicker",{"eds-simple-timepicker--padding-large":"large"===C,"eds-simple-timepicker--show-seconds":E,"eds-simple-timepicker--hide-clock":!f}),disabled:u,disableLabelAnimation:!0,feedback:m,label:v,labelProps:B,labelTooltip:g,onBlur:function(){U(),null===T&&j()},onChange:function(e){return P(e.target.value)},onFocus:function(){null===T&&P("")},onKeyDown:function(e){"Enter"===e.key&&U()},placeholder:E?"–– : –– : ––":"–– : ––",prepend:w||("left"===f?a.createElement(c.ClockIcon,{onClick:function(){var e;return null==R||null==(e=R.current)?void 0:e.focus()}}):void 0),readOnly:_,ref:e.mergeRefs(R,b),style:N,value:x,variant:I},J)))},exports.TimePicker=function(s){var d=s.selectedTime,c=s.onChange,u=s.disabled,m=s.className,f=s.style,b=s.label,v=s.labelTooltip,g=s.feedback,h=s.granularity,C=s.variant,w=s.locale,_=s.showTimeZone,T=s.showSeconds,F=void 0!==T&&T,S=s.minuteIncrementForArrowButtons,L=void 0===S?30:S,x=s.leftArrowButtonAriaLabel,P=void 0===x?"Trekk fra "+L+" minutter":x,R=s.rightArrowButtonAriaLabel,O=void 0===R?"Legg til "+L+" minutter":R,A=s.inputRef,M=s.forcedReturnType,V=s.forcedTimeZone,Z=D(s,$),q=r.useLocale().locale;w&&(q=w);var B=e.useRandomId("eds-timepicker"),W=null!=V?V:null!==d&&"timezone"in d?d.timezone:"Europe/Oslo",H=function(e){if(void 0!==M)return c(E({value:e,type:M,timezone:W}));c(e)},z=t.useTimeFieldState(k({onChange:H,label:b,locale:q,value:d,granularity:(null!=h?h:F)?"second":"minute",hideTimeZone:!_,isDisabled:u,shouldForceLeadingZeros:!0},Z)),j=a.useRef(null),U=n.useTimeField(k({},Z,{label:b}),z,j),K=U.labelProps,G=U.fieldProps,J=e.useRandomId("timepicker"),Q=function(e){if(null===d)return H(E({value:o.now(W),type:null!=M?M:"ZonedDateTime"}));switch(e){case"add":return H(d.add({minutes:L-N(d.minute,L)}));case"subtract":return H(d.subtract({minutes:N(d.minute-1,L)+1}))}};return a.createElement(r.I18nProvider,{locale:q},a.createElement("div",{className:l(m,"eds-timepicker__wrapper")},a.createElement(i.BaseFormControl,k({style:f,className:l("eds-timepicker",{"eds-timepicker--disabled":u}),labelId:J,label:b,labelProps:k({},K,{"aria-describedby":B+"description"}),ref:e.mergeRefs(j,A),disabled:u,disableLabelAnimation:!0,labelTooltip:v},G,{variant:C,feedback:g,ariaAlertOnFeedback:!0,"aria-describedby":B+"description",prepend:a.createElement(Y,{direction:"left",disabled:u,"aria-label":P,onClick:function(){return Q("subtract")},onFocus:function(){return I(j,"first")}}),append:a.createElement(Y,{direction:"right",disabled:u,"aria-label":O,onClick:function(){return Q("add")},onFocus:function(){return I(j,"last")}})}),z.segments.map((function(e,t){return a.createElement(y,{segment:e,state:z,key:t,"aria-describedby":B+"description"})}))),a.createElement(p.VisuallyHidden,{id:B+"description"},null!==d?"valgt tid: "+d.hour.toString().padStart(2,"0")+":"+d.minute.toString().padStart(2,"0")+(F?":"+d.second.toString().padStart(2,"0"):""):"")))},exports.ariaLabelIfNorwegian=_,exports.convertValueToType=E,exports.createCalendar=w,exports.focusSegment=I,exports.getWeekNumberForDate=F,exports.lastMillisecondOfDay=T,exports.modulo=N,exports.nativeDateToDateValue=function(e,a,t,n){return void 0===a&&(a=!1),null===e?null:a?new o.CalendarDate(e.getFullYear(),e.getMonth()+1,e.getDate()):C(e,t,n)},exports.nativeDateToTimeValue=function(e,a,t,n){return void 0===a&&(a=!1),null===e?null:a?new o.Time(e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()):C(e,t,n)},exports.timeOrDateValueToNativeDate=function(e,a){if(null===e)return null;if(!("day"in e)){var t=new Date;return t.setHours(e.hour),t.setMinutes(e.minute),t.setSeconds(e.second),t.setMilliseconds(e.millisecond),t}return"hour"in e?"timeZone"in e?e.toDate():e.toDate(a||o.getLocalTimeZone()):e.toDate(null!=a?a:o.getLocalTimeZone())}; | ||
//# sourceMappingURL=datepicker.cjs.production.min.js.map |
@@ -69,7 +69,7 @@ import { useRandomId, ConditionalWrapper, mergeRefs, useWindowDimensions, useOnClickOutside, useOnEscape, useOnMount, warnAboutMissingStyles } from '@entur/utils'; | ||
if (offset) { | ||
return new ZonedDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate(), timeZone, offset, date.getHours(), date.getMinutes(), date.getSeconds()); | ||
return new ZonedDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate(), timeZone, offset, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()); | ||
} | ||
return parseAbsolute(date.toISOString(), timeZone); | ||
} | ||
return new CalendarDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()); | ||
return new CalendarDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()); | ||
}; | ||
@@ -105,3 +105,3 @@ /** | ||
if (date === null) return null; | ||
if (noDateOnlyTime) return new Time(date.getHours(), date.getMinutes(), date.getSeconds(), 0); | ||
if (noDateOnlyTime) return new Time(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()); | ||
return nativeDateToDateTime(date, timeZone, offset); | ||
@@ -123,2 +123,3 @@ } | ||
date.setSeconds(value.second); | ||
date.setMilliseconds(value.millisecond); | ||
return date; | ||
@@ -133,3 +134,3 @@ } | ||
if (timeZoneForCalendarDateTime) return value.toDate(timeZoneForCalendarDateTime); | ||
return new Date(value.year, value.month - 1, value.day, value.hour, value.minute, value.second); | ||
return value.toDate(getLocalTimeZone()); | ||
} | ||
@@ -536,2 +537,4 @@ // type is ZonedDateTime | ||
var handleOnChange = function handleOnChange(value) { | ||
// console.log(value && value.compare(parseDate('1000-01-01')) < 0); | ||
// if (value && value.compare(parseDate('1000-01-01')) < 0) return; | ||
if (forcedReturnType !== undefined) { | ||
@@ -538,0 +541,0 @@ return onChange(convertValueToType({ |
{ | ||
"name": "@entur/datepicker", | ||
"version": "9.3.3", | ||
"version": "9.3.4", | ||
"license": "EUPL-1.2", | ||
@@ -30,11 +30,11 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@entur/a11y": "^0.2.78", | ||
"@entur/button": "^3.2.14", | ||
"@entur/form": "^7.0.42", | ||
"@entur/icons": "^6.15.3", | ||
"@entur/modal": "^1.7.35", | ||
"@entur/tokens": "^3.13.2", | ||
"@entur/tooltip": "^2.6.51", | ||
"@entur/typography": "^1.8.27", | ||
"@entur/utils": "^0.10.0", | ||
"@entur/a11y": "^0.2.79", | ||
"@entur/button": "^3.2.15", | ||
"@entur/form": "^7.0.43", | ||
"@entur/icons": "^6.15.4", | ||
"@entur/modal": "^1.7.36", | ||
"@entur/tokens": "^3.13.3", | ||
"@entur/tooltip": "^2.6.52", | ||
"@entur/typography": "^1.8.28", | ||
"@entur/utils": "^0.10.1", | ||
"@floating-ui/react-dom": "^1.0.0", | ||
@@ -52,3 +52,3 @@ "@internationalized/date": "^3.4.0", | ||
}, | ||
"gitHead": "427e66ba68d33b8d1839714a48517b52afd5c2db" | ||
"gitHead": "89d5de6d31962e236a5c147e129bf915576166b4" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
488892
3241
Updated@entur/a11y@^0.2.79
Updated@entur/button@^3.2.15
Updated@entur/form@^7.0.43
Updated@entur/icons@^6.15.4
Updated@entur/modal@^1.7.36
Updated@entur/tokens@^3.13.3
Updated@entur/tooltip@^2.6.52
Updated@entur/typography@^1.8.28
Updated@entur/utils@^0.10.1