@entur/datepicker 11.0.1 → 11.0.3

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.
@@ -1,2 +1,2 @@
1
- "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)({}).hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},k.apply(null,arguments)}function D(e,a){if(null==e)return{};var t={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(a.includes(n))continue;t[n]=e[n]}return t}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||":"===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())},T=function(e){if(void 0===e&&(e="gregory"),"gregory"===e)return new o.GregorianCalendar;throw new Error("Unsupported calendar "+e)},w=function(e,a,t){return"no-no"!==a.toLowerCase()?t["aria-label"]:e},E=function(e){return o.toCalendarDateTime(e.add({days:1})).add({milliseconds:-1})},_=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=_({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)}function S(e){var a=e.value,t=e.forcedReturnType,n=e.onChange;if(void 0!==t||!e.selectedDate)return null==n?void 0:n(_({value:a,type:null!=t?t:"ZonedDateTime",timezone:null!==a&&"timezone"in a?a.timezone:void 0}));null==n||n(a)}var R,L=["selectedDate","onChange","label","locale","showTimeZone","showTime","granularity","disabled","isDisabled","variant","feedback","validationVariant","validationFeedback","labelTooltip","minDate","maxDate","forcedReturnType","style","className","labelProps","append","prepend","dateFieldRef"],x=function(o){var s=o.selectedDate,d=o.onChange,c=o.label,u=o.locale,m=o.showTimeZone,p=o.granularity,f=void 0===p?o.showTime?"minute":"day":p,b=o.disabled,v=o.isDisabled,g=o.variant,h=o.feedback,C=o.validationVariant,w=void 0===C?"negative":C,_=o.validationFeedback,N=void 0===_?"Ugyldig dato":_,I=o.labelTooltip,F=o.minDate,R=o.maxDate,x=o.forcedReturnType,P=o.style,A=o.className,O=o.labelProps,M=o.append,V=o.prepend,Z=o.dateFieldRef,q=D(o,L),B=r.useLocale(),W=k({},q,{label:c,locale:null!=u?u:B.locale,createCalendar:T,value:s,onChange:function(e){return S({value:e,selectedDate:s,forcedReturnType:x,onChange:d})},hideTimeZone:!m,granularity:f,minValue:F,maxValue:"hour"in(null!=R?R:{})?R:void 0!==R?E(R):void 0,isDisabled:v||b,shouldForceLeadingZeros:!0}),z=t.useDateFieldState(W),H=a.useRef(null),j=n.useDateField(W,z,H),U=j.labelProps,K=j.fieldProps,G=e.useRandomId("datefield");return a.createElement(e.ConditionalWrapper,{condition:void 0!==u,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:u},e)}},a.createElement(i.BaseFormControl,k({append:M,ariaAlertOnFeedback:!0,className:l("eds-datefield",A,{"eds-datefield--has-tooltip":void 0!==I}),disabled:v||b,disableLabelAnimation:!0,feedback:null!=h?h:"invalid"===z.validationState?N:void 0,label:c,labelId:G,labelProps:null!=O?O:U,labelTooltip:I,prepend:V,ref:e.mergeRefs(Z,H),style:P,variant:null!=g?g:z.isInvalid?w:void 0},K),z.segments.map((function(e,t){return a.createElement(y,{segment:e,state:z,key:t})}))))},P=["children","className","style"],A=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"],M=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,T=h.isSelected,w=h.isOutsideVisibleRange,E=h.isDisabled,_=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":w,ref:g,hidden:w,className:l("eds-datepicker__calendar__grid__cell",(i={},i[null!=(n=null==f?void 0:f(c))?n:""]=!w,i["eds-datepicker__calendar__grid__cell--selected"]=T,i["eds-datepicker__calendar__grid__cell--disabled"]=E||_,i["eds-datepicker__calendar__grid__cell--outside-month"]=w,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),T&&m()},onKeyDown:function(e){C.onKeyDown&&C.onKeyDown(e),"Enter"!==e.key&&" "!==e.key||T&&m()}}),N))},V=["state","navigationDescription","onSelectedCellClick","showWeekNumbers","weekNumberHeader","classNameForDate","ariaLabelForDate"],Z=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,T=h.weekDays,w=o.getWeeksInMonth(n.visibleRange.start,g),E=Array.from(Array(w).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"===T[0])return["Mo","Tu","We","Th","Fr","Sa","Su"];if("S"===T[0])return["Su","Mo","Tu","We","Th","Fr","Sa"]}return T.map((function(e){return e.toLowerCase()}))}().map((function(e){return a.createElement("th",{key:e},e)})))),a.createElement("tbody",null,E.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(M,{key:e.month+"."+e.day,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")))},q=["locale"],B=["selectedDate","onChange","minDate","maxDate","showWeekNumbers","weekNumberHeader","forcedReturnType","style","className","navigationDescription","onSelectedCellClick","classNameForDate","ariaLabelForDate","calendarRef"],W=function(e){var t=e.locale,n=D(e,q),l=r.useLocale();return a.createElement(r.I18nProvider,{locale:null!=t?t:l.locale},a.createElement(z,k({},n)))},z=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.forcedReturnType,v=e.style,g=e.className,h=e.navigationDescription,y=e.onSelectedCellClick,C=void 0===y?function(){}:y,E=e.classNameForDate,_=e.ariaLabelForDate,N=e.calendarRef,I=D(e,B),F=r.useLocale().locale,R=k({},I,{value:t,onChange:function(e){return S({value:e,selectedDate:t,forcedReturnType:b,onChange:n})},locale:F,createCalendar:T,minValue:i,maxValue:o}),L=d.useCalendarState(R),x=s.useCalendar(R,L),P=x.prevButtonProps,O=x.nextButtonProps,M=x.title;return a.createElement("div",k({},x.calendarProps,{ref:N,className:l("eds-datepicker__calendar",g),style:v}),a.createElement("div",{className:"eds-datepicker__calendar__header"},a.createElement(A,k({},P,{"aria-label":w("Forrige måned",F,P)}),a.createElement(c.LeftArrowIcon,{size:20})),a.createElement("h2",null,M),a.createElement(A,k({},O,{"aria-label":w("Neste måned",F,O)}),a.createElement(c.RightArrowIcon,{size:20}))),a.createElement(Z,k({},I,{state:L,navigationDescription:h,onSelectedCellClick:C,classNameForDate:E,ariaLabelForDate:_,showWeekNumbers:m,weekNumberHeader:f})))},H=["selectedDate","locale","disabled","showTime","showTimeZone","classNameForDate","className","variant","feedback","validationVariant","validationFeedback","showWeekNumbers","weekNumberHeader","disableModal","labelTooltip","navigationDescription","minDate","maxDate","modalTreshold","forcedReturnType","ariaLabelForDate","append","prepend","granularity"],j=["className","style","label","onChange","feedback","variant","disableLabelAnimation","prepend"],U=["onChange","variant","value"],K=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,j),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(G,k({onChange:s,"aria-labelledby":v,ref:n,variant:u},b)))})),G=a.forwardRef((function(t,n){var r=t.onChange,l=t.variant,o=t.value,s=D(t,U),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))})),Y=["direction","onClick","disabled","aria-label"],$=function(e){var t=e.direction,n=e.onClick,r=e.disabled,i=e["aria-label"],o=D(e,Y);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))},J=["selectedTime","onChange","disabled","className","style","label","labelTooltip","feedback","granularity","variant","locale","showTimeZone","showSeconds","minuteIncrementForArrowButtons","leftArrowButtonAriaLabel","rightArrowButtonAriaLabel","inputRef","forcedReturnType","forcedTimeZone","append","prepend"],Q=["className","style","onChange","label","feedback","variant","prepend"],X=["onChange","value"],ee=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,Q),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(ae,k({onChange:s,"aria-labelledby":f,ref:n},p)))})),ae=a.forwardRef((function(t,n){var r=t.onChange,l=t.value,o=D(t,X),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))})),te=["append","className","disabled","feedback","showClockIcon","inputRef","label","labelTooltip","onChange","padding","prepend","readOnly","selectedTime","showSeconds","style","variant"],ne=["onBlur","onClick","onDragStart","onFocus","onKeyDown","onKeyUp","onMouseDown","onPointerDown","onPointerUp"];!function(e){e[e.RESET_TIME=0]="RESET_TIME",e[e.INVALID=1]="INVALID"}(R||(R={})),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=W,exports.DateField=x,exports.DatePicker=function(i){var o=i.selectedDate,s=i.locale,d=i.disabled,u=i.showTime,m=i.showTimeZone,p=void 0!==m&&m,h=i.classNameForDate,y=i.className,C=i.variant,T=i.feedback,w=i.validationVariant,_=i.validationFeedback,N=i.showWeekNumbers,I=i.weekNumberHeader,F=i.disableModal,S=void 0!==F&&F,R=i.labelTooltip,L=i.navigationDescription,P=i.minDate,O=i.maxDate,M=i.modalTreshold,V=void 0===M?1e3:M,Z=i.ariaLabelForDate,q=i.append,B=i.prepend,z=i.granularity,j=void 0===z?u?"minute":"day":z,U=D(i,H),K=V,G=a.useRef(null),Y=a.useRef(null),$=e.useWindowDimensions().width,J=k({},U,{minValue:P,maxValue:"hour"in(null!=O?O:{})?O:void 0!==O?E(O):void 0,value:o,granularity:j,isDisabled:d}),Q=t.useDatePickerState(J),X=n.useDatePicker(J,Q,G),ee=X.groupProps,ae=X.labelProps,te=X.fieldProps,ne=X.buttonProps,re=X.dialogProps,le=X.calendarProps,ie=f.useFloating({whileElementsMounted:function(e,a,t){return f.autoUpdate(e,a,t,{elementResize:!1})},placement:"bottom-start",middleware:[f.offset(v.space.extraSmall2),f.flip(),f.shift({padding:v.space.extraSmall})]}),oe=ie.refs,se=ie.floatingStyles,de=ie.update;e.useOnClickOutside([Y],(function(){Q.setOpen(!1)})),e.useOnEscape(Y,(function(){Q.setOpen(!1)}));var ce=k({},re,le,{onChange:U.onChange,disabled:d,navigationDescription:L,onSelectedCellClick:function(){return Q.setOpen(!1)},selectedDate:o,minDate:P,maxDate:O,calendarRef:Y,classNameForDate:h,ariaLabelForDate:Z,showWeekNumbers:N,weekNumberHeader:I}),ue=void 0!==$&&$<=K&&!S,me=a.createElement("div",{style:k({},se,{zIndex:v.zIndexes.popover}),ref:oe.setFloating},a.createElement(b,{disabled:!Q.isOpen||ue,returnFocus:!0},Q.isOpen&&a.createElement(W,k({},ce)))),pe=a.createElement(g.Modal,{size:"small",title:"",open:Q.isOpen,onDismiss:function(){return Q.setOpen(!1)},className:"eds-datepicker__calendar-modal"},a.createElement(W,k({},ce)));return a.createElement(e.ConditionalWrapper,{condition:void 0!==s,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:s},e)}},a.createElement(x,k({},ee,te,U,{append:!d&&a.createElement("div",{style:{display:"flex",alignItems:"center"}},q,a.createElement(A,k({},ne,{onPress:function(){Q.setOpen(!Q.isOpen),de()},className:"eds-datepicker__open-calendar-button"}),a.createElement(c.CalendarIcon,null))),prepend:B,className:l("eds-datepicker",y,{"eds-datepicker--disabled":d}),disabled:d,feedback:T,labelProps:ae,labelTooltip:R,maxDate:O,minDate:P,dateFieldRef:function(e){oe.setReference(e),G.current=e},selectedDate:o,showTime:u,showTimeZone:p,validationFeedback:_,validationVariant:w,variant:C})),ue?pe:me)},exports.NativeDatePicker=K,exports.NativeTimePicker=ee,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,T=s.prepend,w=s.readOnly,E=s.selectedTime,_=s.showSeconds,N=s.style,I=s.variant,F=D(s,te),S=a.useState(""),L=S[0],x=S[1],P=a.useRef(null),A=a.useState(null),O=A[0],M=A[1],V=r.useLocale().locale,Z=t.useTimeFieldState(k({onChange:h,label:v,locale:V,value:E,hideTimeZone:!0,isDisabled:u,isReadOnly:w},F)),q=n.useTimeField(k({},F,{label:v}),Z,P),B=q.labelProps,W=q.fieldProps;a.useEffect((function(){z(),null!==E&&M(E)}),[null==E?void 0:E.toString()]);var z=function(){var e=H(E);x(e);var a=document.activeElement===(null==P?void 0:P.current);""!==e||a||j()},H=function(e){if(null===e)return"";var a="day"in e?o.toTime(e):e;return _?a.toString().slice(0,8):a.toString().slice(0,5)},j=function(){x(_?"–– : –– : ––":"–– : ––")},U=function(){var e=K();if(e===R.INVALID)return z();(null==e?void 0:e.toString())!==(null==E?void 0:E.toString())&&(null==h||h(e))},K=function(){var e=G(L),a=Y(e);return a===R.INVALID?R.INVALID:a===R.RESET_TIME?null:$(a)},G=function(e){if(0===e.length)return R.RESET_TIME;if(e.length<3||e.length>8)return R.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 R.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+(_?":"+o:"")},Y=function(e){if(e===R.INVALID)return R.INVALID;if(e===R.RESET_TIME)return R.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 R.INVALID}return R.INVALID},$=function(e){return(null!=O?O:new o.Time).set({hour:e.hour,minute:e.minute,second:e.second})},J=D(W,ne);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==P||null==(e=P.current)?void 0:e.focus()},inline:!0}):void 0),className:l("eds-simple-timepicker",{"eds-simple-timepicker--padding-large":"large"===C,"eds-simple-timepicker--show-seconds":_,"eds-simple-timepicker--hide-clock":!f,"eds-simple-timepicker--has-tooltip":void 0!==g}),disabled:u,disableLabelAnimation:!0,feedback:m,label:v,labelProps:B,labelTooltip:g,onBlur:function(){U(),null===E&&j()},onChange:function(e){return x(e.target.value)},onFocus:function(){null===E&&x("")},onKeyDown:function(e){"Enter"===e.key&&U()},placeholder:_?"–– : –– : ––":"–– : ––",prepend:T||("left"===f?a.createElement(c.ClockIcon,{onClick:function(){var e;return null==P||null==(e=P.current)?void 0:e.focus()}}):void 0),readOnly:w,ref:e.mergeRefs(P,b),style:N,value:L,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,T=s.locale,w=s.showTimeZone,E=s.showSeconds,F=void 0!==E&&E,S=s.minuteIncrementForArrowButtons,R=void 0===S?30:S,L=s.leftArrowButtonAriaLabel,x=void 0===L?"Trekk fra "+R+" minutter":L,P=s.rightArrowButtonAriaLabel,A=void 0===P?"Legg til "+R+" minutter":P,O=s.inputRef,M=s.forcedReturnType,V=s.forcedTimeZone,Z=s.append,q=s.prepend,B=D(s,J),W=r.useLocale().locale;T&&(W=T);var z=e.useRandomId("eds-timepicker"),H=null!=V?V:null!==d&&"timezone"in d?d.timezone:"Europe/Oslo",j=function(e){if(void 0!==M||!d)return c(_({value:e,type:null!=M?M:"ZonedDateTime",timezone:H}));c(e)},U=t.useTimeFieldState(k({onChange:j,label:b,locale:W,value:d,granularity:(null!=h?h:F)?"second":"minute",hideTimeZone:!w,isDisabled:u,shouldForceLeadingZeros:!0},B)),K=a.useRef(null),G=n.useTimeField(k({},B,{label:b}),U,K),Y=G.labelProps,Q=G.fieldProps,X=e.useRandomId("timepicker"),ee=function(e){if(null===d)return j(_({value:o.now(H),type:null!=M?M:"ZonedDateTime"}));switch(e){case"add":return j(d.add({minutes:R-N(d.minute,R)}));case"subtract":return j(d.subtract({minutes:N(d.minute-1,R)+1}))}};return a.createElement(r.I18nProvider,{locale:W},a.createElement(i.BaseFormControl,{append:a.createElement("div",{style:{display:"flex",alignItems:"center"}},Z,a.createElement($,{direction:"right",disabled:u,"aria-label":A,onClick:function(){return ee("add")},onFocus:function(){return I(K,"last")}})),ariaAlertOnFeedback:!0,"aria-describedby":z+"description",className:l("eds-timepicker",m,{"eds-timepicker--disabled":u,"eds-timepicker--has-tooltip":void 0!==v}),disabled:u,disableLabelAnimation:!0,feedback:g,label:b,labelId:X,labelProps:k({},Y,{"aria-describedby":z+"description"}),labelTooltip:v,prepend:a.createElement("div",{style:{display:"flex",alignItems:"center"}},a.createElement($,{direction:"left",disabled:u,"aria-label":x,onClick:function(){return ee("subtract")},onFocus:function(){return I(K,"first")}}),q),ref:O,style:f,variant:C},a.createElement("span",k({ref:K},Q,{style:{display:"contents"}}),U.segments.map((function(e,t){return a.createElement(y,{segment:e,state:U,key:t,"aria-describedby":z+"description"})}))),a.createElement(p.VisuallyHidden,{id:z+"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=w,exports.convertValueToType=_,exports.createCalendar=T,exports.focusSegment=I,exports.getWeekNumberForDate=F,exports.handleOnChange=S,exports.lastMillisecondOfDay=E,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())};
1
+ "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"),d=require("@react-aria/calendar"),s=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)({}).hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},k.apply(null,arguments)}function y(e,a){if(null==e)return{};var t={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(a.includes(n))continue;t[n]=e[n]}return t}var D=["segment","state"],h=function(e){var t=e.segment,r=e.state,i=y(e,D),o=a.useRef(null),d=n.useDateSegment(t,r,o).segmentProps;return a.createElement("div",k({},d,{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||":"===t.text}),tabIndex:r.isDisabled?-1:d.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())},T=function(e){if(void 0===e&&(e="gregory"),"gregory"===e)return new o.GregorianCalendar;throw new Error("Unsupported calendar "+e)},w=function(e,a,t){return"no-no"!==a.toLowerCase()?t["aria-label"]:e},E=function(e){return o.toCalendarDateTime(e.add({days:1})).add({milliseconds:-1})},_=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=_({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)}function S(e){var a=e.value,t=e.forcedReturnType,n=e.onChange;if(void 0!==t||!e.selectedDate)return null==n?void 0:n(_({value:a,type:null!=t?t:"ZonedDateTime",timezone:null!==a&&"timezone"in a?a.timezone:void 0}));null==n||n(a)}var R,L=["selectedDate","onChange","label","locale","showTimeZone","showTime","granularity","disabled","readOnly","isDisabled","variant","feedback","validationVariant","validationFeedback","labelTooltip","minDate","maxDate","forcedReturnType","style","className","labelProps","append","prepend","dateFieldRef"],x=function(o){var d=o.selectedDate,s=o.onChange,c=o.label,u=o.locale,m=o.showTimeZone,p=o.granularity,f=void 0===p?o.showTime?"minute":"day":p,b=o.disabled,v=o.readOnly,g=o.isDisabled,D=o.variant,C=o.feedback,w=o.validationVariant,_=void 0===w?"negative":w,N=o.validationFeedback,I=void 0===N?"Ugyldig dato":N,F=o.labelTooltip,R=o.minDate,x=o.maxDate,P=o.forcedReturnType,O=o.style,A=o.className,M=o.labelProps,V=o.append,Z=o.prepend,q=o.dateFieldRef,B=y(o,L),W=r.useLocale(),z=k({},B,{label:c,locale:null!=u?u:W.locale,createCalendar:T,value:d,onChange:function(e){return S({value:e,selectedDate:d,forcedReturnType:P,onChange:s})},hideTimeZone:!m,granularity:f,minValue:R,maxValue:"hour"in(null!=x?x:{})?x:void 0!==x?E(x):void 0,isDisabled:g||b||v,shouldForceLeadingZeros:!0}),H=t.useDateFieldState(z),j=a.useRef(null),U=n.useDateField(z,H,j),K=U.labelProps,G=U.fieldProps,Y=e.useRandomId("datefield");return a.createElement(e.ConditionalWrapper,{condition:void 0!==u,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:u},e)}},a.createElement(i.BaseFormControl,k({append:V,ariaAlertOnFeedback:!0,className:l("eds-datefield",A,{"eds-datefield--has-tooltip":void 0!==F}),disabled:g||b,readOnly:v,disableLabelAnimation:!0,feedback:null!=C?C:"invalid"===H.validationState?I:void 0,label:c,labelId:Y,labelProps:null!=M?M:K,labelTooltip:F,prepend:Z,ref:e.mergeRefs(q,j),style:O,variant:null!=D?D:H.isInvalid?_:void 0},G),H.segments.map((function(e,t){return a.createElement(h,{segment:e,state:H,key:t})}))))},P=["children","className","style"],O=function(e){var t=e.children,n=e.className,r=e.style,l=y(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)},A=["state","date","onSelectedCellClick","weekNumberString","classNameForDate","ariaLabelForDate"],M=function(e){var t,n,r,i,s=e.state,c=e.date,u=e.onSelectedCellClick,m=void 0===u?function(){}:u,p=e.weekNumberString,f=e.classNameForDate,b=e.ariaLabelForDate,v=y(e,A),g=a.useRef(null),D=d.useCalendarCell({date:c},s,g),h=D.cellProps,C=D.buttonProps,T=D.isSelected,w=D.isOutsideVisibleRange,E=D.isDisabled,_=D.isUnavailable,N=D.formattedDate,I=""+C["aria-label"]+p+" "+(null!=(t=null==b?void 0:b(c))?t:"");return a.createElement("td",k({},h,{className:"eds-datepicker__calendar__grid__cell__td"}),a.createElement("div",k({},C,{"aria-label":I,"aria-hidden":w,ref:g,hidden:w,className:l("eds-datepicker__calendar__grid__cell",(i={},i[null!=(n=null==f?void 0:f(c))?n:""]=!w,i["eds-datepicker__calendar__grid__cell--selected"]=T,i["eds-datepicker__calendar__grid__cell--disabled"]=E||_,i["eds-datepicker__calendar__grid__cell--outside-month"]=w,i["eds-datepicker__calendar__grid__cell--today"]=o.isEqualDay(c,o.now(null!=(r=s.timeZone)?r:o.getLocalTimeZone())),i))},v,{onClick:function(e){C.onClick&&C.onClick(e),T&&m()},onKeyDown:function(e){C.onKeyDown&&C.onKeyDown(e),"Enter"!==e.key&&" "!==e.key||T&&m()}}),N))},V=["state","navigationDescription","onSelectedCellClick","showWeekNumbers","weekNumberHeader","classNameForDate","ariaLabelForDate"],Z=function(t){var n=t.state,l=t.navigationDescription,i=t.onSelectedCellClick,s=void 0===i?function(){}:i,c=t.showWeekNumbers,u=t.weekNumberHeader,m=t.classNameForDate,f=t.ariaLabelForDate,b=y(t,V),v=e.useRandomId("eds-calendar"),g=r.useLocale().locale,D=d.useCalendarGrid(b,n),h=D.gridProps,C=D.headerProps,T=D.weekDays,w=o.getWeeksInMonth(n.visibleRange.start,g),E=Array.from(Array(w).keys());return a.createElement(a.Fragment,null,a.createElement("table",k({},h,{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"===T[0])return["Mo","Tu","We","Th","Fr","Sa","Su"];if("S"===T[0])return["Su","Mo","Tu","We","Th","Fr","Sa"]}return T.map((function(e){return e.toLowerCase()}))}().map((function(e){return a.createElement("th",{key:e},e)})))),a.createElement("tbody",null,E.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(M,{key:e.month+"."+e.day,state:n,date:e,"aria-describedby":v+"description",weekNumberString:c?", "+u+" "+t+",":"",onSelectedCellClick:s,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")))},q=["locale"],B=["selectedDate","onChange","minDate","maxDate","showWeekNumbers","weekNumberHeader","forcedReturnType","style","className","navigationDescription","onSelectedCellClick","classNameForDate","ariaLabelForDate","calendarRef"],W=function(e){var t=e.locale,n=y(e,q),l=r.useLocale();return a.createElement(r.I18nProvider,{locale:null!=t?t:l.locale},a.createElement(z,k({},n)))},z=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.forcedReturnType,v=e.style,g=e.className,D=e.navigationDescription,h=e.onSelectedCellClick,C=void 0===h?function(){}:h,E=e.classNameForDate,_=e.ariaLabelForDate,N=e.calendarRef,I=y(e,B),F=r.useLocale().locale,R=k({},I,{value:t,onChange:function(e){return S({value:e,selectedDate:t,forcedReturnType:b,onChange:n})},locale:F,createCalendar:T,minValue:i,maxValue:o}),L=s.useCalendarState(R),x=d.useCalendar(R,L),P=x.prevButtonProps,A=x.nextButtonProps,M=x.title;return a.createElement("div",k({},x.calendarProps,{ref:N,className:l("eds-datepicker__calendar",g),style:v}),a.createElement("div",{className:"eds-datepicker__calendar__header"},a.createElement(O,k({},P,{"aria-label":w("Forrige måned",F,P)}),a.createElement(c.LeftArrowIcon,{size:20})),a.createElement("h2",null,M),a.createElement(O,k({},A,{"aria-label":w("Neste måned",F,A)}),a.createElement(c.RightArrowIcon,{size:20}))),a.createElement(Z,k({},I,{state:L,navigationDescription:D,onSelectedCellClick:C,classNameForDate:E,ariaLabelForDate:_,showWeekNumbers:m,weekNumberHeader:f})))},H=["selectedDate","locale","disabled","readOnly","showTime","showTimeZone","classNameForDate","className","variant","feedback","validationVariant","validationFeedback","showWeekNumbers","weekNumberHeader","disableModal","labelTooltip","navigationDescription","minDate","maxDate","modalTreshold","forcedReturnType","ariaLabelForDate","append","prepend","granularity"],j=["className","style","label","onChange","feedback","variant","disableLabelAnimation","prepend"],U=["onChange","variant","value"],K=a.forwardRef((function(t,n){var r=t.className,l=t.style,o=t.label,d=t.onChange,s=t.feedback,u=t.variant,m=t.disableLabelAnimation,p=t.prepend,f=void 0===p?a.createElement(c.DateIcon,{inline:!0}):p,b=y(t,j),v=e.useRandomId("eds-nativetimepicker");return a.createElement(i.BaseFormControl,{style:l,className:r,prepend:f,label:o,feedback:s,variant:u,labelId:v,disableLabelAnimation:m,isFilled:!0},a.createElement(G,k({onChange:d,"aria-labelledby":v,ref:n,variant:u},b)))})),G=a.forwardRef((function(t,n){var r=t.onChange,l=t.variant,o=t.value,d=y(t,U),s=i.useVariant(),c=l||s,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},d))})),Y=["direction","onClick","disabled","readonly","aria-label"],$=function(e){var t=e.direction,n=e.onClick,r=e.disabled,i=e["aria-label"],o=y(e,Y);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))},J=["selectedTime","onChange","disabled","readOnly","className","style","label","labelTooltip","feedback","granularity","variant","locale","showTimeZone","showSeconds","minuteIncrementForArrowButtons","leftArrowButtonAriaLabel","rightArrowButtonAriaLabel","inputRef","forcedReturnType","forcedTimeZone","append","prepend"],Q=["className","style","onChange","label","feedback","variant","prepend"],X=["onChange","value"],ee=a.forwardRef((function(t,n){var r=t.className,o=t.style,d=t.onChange,s=t.label,c=t.feedback,u=t.variant,m=t.prepend,p=y(t,Q),f=e.useRandomId("eds-native-timepicker");return a.createElement(i.BaseFormControl,{style:o,className:l(r,"eds-native-timepicker"),prepend:m,label:s,feedback:c,variant:u,labelId:f,disableLabelAnimation:!0},a.createElement(ae,k({onChange:d,"aria-labelledby":f,ref:n},p)))})),ae=a.forwardRef((function(t,n){var r=t.onChange,l=t.value,o=y(t,X),d=i.useVariant(),s=o.variant||d,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"===s,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))})),te=["append","className","disabled","feedback","showClockIcon","inputRef","label","labelTooltip","onChange","padding","prepend","readOnly","selectedTime","showSeconds","style","variant"],ne=["onBlur","onClick","onDragStart","onFocus","onKeyDown","onKeyUp","onMouseDown","onPointerDown","onPointerUp"];!function(e){e[e.RESET_TIME=0]="RESET_TIME",e[e.INVALID=1]="INVALID"}(R||(R={})),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=W,exports.DateField=x,exports.DatePicker=function(i){var o=i.selectedDate,d=i.locale,s=i.disabled,u=i.readOnly,m=i.showTime,p=i.showTimeZone,D=void 0!==p&&p,h=i.classNameForDate,C=i.className,T=i.variant,w=i.feedback,_=i.validationVariant,N=i.validationFeedback,I=i.showWeekNumbers,F=i.weekNumberHeader,S=i.disableModal,R=void 0!==S&&S,L=i.labelTooltip,P=i.navigationDescription,A=i.minDate,M=i.maxDate,V=i.modalTreshold,Z=void 0===V?1e3:V,q=i.ariaLabelForDate,B=i.append,z=i.prepend,j=i.granularity,U=void 0===j?m?"minute":"day":j,K=y(i,H),G=Z,Y=a.useRef(null),$=a.useRef(null),J=e.useWindowDimensions().width,Q=k({},K,{minValue:A,maxValue:"hour"in(null!=M?M:{})?M:void 0!==M?E(M):void 0,value:o,granularity:U,isDisabled:s||u}),X=t.useDatePickerState(Q),ee=n.useDatePicker(Q,X,Y),ae=ee.groupProps,te=ee.labelProps,ne=ee.fieldProps,re=ee.buttonProps,le=ee.dialogProps,ie=ee.calendarProps,oe=f.useFloating({whileElementsMounted:function(e,a,t){return f.autoUpdate(e,a,t,{elementResize:!1})},placement:"bottom-start",middleware:[f.offset(v.space.extraSmall2),f.flip(),f.shift({padding:v.space.extraSmall})]}),de=oe.refs,se=oe.floatingStyles,ce=oe.update;e.useOnClickOutside([$],(function(){X.setOpen(!1)})),e.useOnEscape($,(function(){X.setOpen(!1)}));var ue=k({},le,ie,{onChange:K.onChange,disabled:s,navigationDescription:P,onSelectedCellClick:function(){return X.setOpen(!1)},selectedDate:o,minDate:A,maxDate:M,calendarRef:$,classNameForDate:h,ariaLabelForDate:q,showWeekNumbers:I,weekNumberHeader:F}),me=void 0!==J&&J<=G&&!R,pe=a.createElement("div",{style:k({},se,{zIndex:v.zIndexes.popover}),ref:de.setFloating},a.createElement(b,{disabled:!X.isOpen||me,returnFocus:!0},X.isOpen&&a.createElement(W,k({},ue)))),fe=a.createElement(g.Modal,{size:"small",title:"",open:X.isOpen,onDismiss:function(){return X.setOpen(!1)},className:"eds-datepicker__calendar-modal"},a.createElement(W,k({},ue)));return a.createElement(e.ConditionalWrapper,{condition:void 0!==d,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:d},e)}},a.createElement(x,k({},ae,ne,K,{append:!s&&!u&&a.createElement("div",{style:{display:"flex",alignItems:"center"}},B,a.createElement(O,k({},re,{onPress:function(){X.setOpen(!X.isOpen),ce()},className:"eds-datepicker__open-calendar-button"}),a.createElement(c.CalendarIcon,null))),prepend:z,className:l("eds-datepicker",C,{"eds-datepicker--disabled":s}),disabled:s,readOnly:u,feedback:w,labelProps:te,labelTooltip:L,maxDate:M,minDate:A,dateFieldRef:function(e){de.setReference(e),Y.current=e},selectedDate:o,showTime:m,showTimeZone:D,validationFeedback:N,validationVariant:_,variant:T})),me?fe:pe)},exports.NativeDatePicker=K,exports.NativeTimePicker=ee,exports.SimpleTimePicker=function(d){var s=d.append,u=d.disabled,m=d.feedback,p=d.showClockIcon,f=void 0===p?"right":p,b=d.inputRef,v=d.label,g=d.labelTooltip,D=d.onChange,h=d.padding,C=void 0===h?"default":h,T=d.prepend,w=d.readOnly,E=d.selectedTime,_=d.showSeconds,N=d.style,I=d.variant,F=y(d,te),S=a.useState(""),L=S[0],x=S[1],P=a.useRef(null),O=a.useState(null),A=O[0],M=O[1],V=r.useLocale().locale,Z=t.useTimeFieldState(k({onChange:D,label:v,locale:V,value:E,hideTimeZone:!0,isDisabled:u,isReadOnly:w},F)),q=n.useTimeField(k({},F,{label:v}),Z,P),B=q.labelProps,W=q.fieldProps;a.useEffect((function(){z(),null!==E&&M(E)}),[null==E?void 0:E.toString()]);var z=function(){var e=H(E);x(e);var a=document.activeElement===(null==P?void 0:P.current);""!==e||a||j()},H=function(e){if(null===e)return"";var a="day"in e?o.toTime(e):e;return _?a.toString().slice(0,8):a.toString().slice(0,5)},j=function(){x(_?"–– : –– : ––":"–– : ––")},U=function(){var e=K();if(e===R.INVALID)return z();(null==e?void 0:e.toString())!==(null==E?void 0:E.toString())&&(null==D||D(e))},K=function(){var e=G(L),a=Y(e);return a===R.INVALID?R.INVALID:a===R.RESET_TIME?null:$(a)},G=function(e){if(0===e.length)return R.RESET_TIME;if(e.length<3||e.length>8)return R.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 R.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+(_?":"+o:"")},Y=function(e){if(e===R.INVALID)return R.INVALID;if(e===R.RESET_TIME)return R.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 R.INVALID}return R.INVALID},$=function(e){return(null!=A?A:new o.Time).set({hour:e.hour,minute:e.minute,second:e.second})},J=y(W,ne);return a.createElement(r.I18nProvider,{locale:V},a.createElement(i.TextField,k({append:s||(!0===f||"right"===f?a.createElement(c.ClockIcon,{onClick:function(){var e;return null==P||null==(e=P.current)?void 0:e.focus()},inline:!0}):void 0),className:l("eds-simple-timepicker",{"eds-simple-timepicker--padding-large":"large"===C,"eds-simple-timepicker--show-seconds":_,"eds-simple-timepicker--hide-clock":!f,"eds-simple-timepicker--has-tooltip":void 0!==g}),disabled:u,disableLabelAnimation:!0,feedback:m,label:v,labelProps:B,labelTooltip:g,onBlur:function(){U(),null===E&&j()},onChange:function(e){return x(e.target.value)},onFocus:function(){null===E&&x("")},onKeyDown:function(e){"Enter"===e.key&&U()},placeholder:_?"–– : –– : ––":"–– : ––",prepend:T||("left"===f?a.createElement(c.ClockIcon,{onClick:function(){var e;return null==P||null==(e=P.current)?void 0:e.focus()}}):void 0),readOnly:w,ref:e.mergeRefs(P,b),style:N,value:L,variant:I},J)))},exports.TimePicker=function(d){var s=d.selectedTime,c=d.onChange,u=d.disabled,m=d.readOnly,f=d.className,b=d.style,v=d.label,g=d.labelTooltip,D=d.feedback,C=d.granularity,T=d.variant,w=d.locale,E=d.showTimeZone,F=d.showSeconds,S=void 0!==F&&F,R=d.minuteIncrementForArrowButtons,L=void 0===R?30:R,x=d.leftArrowButtonAriaLabel,P=void 0===x?"Trekk fra "+L+" minutter":x,O=d.rightArrowButtonAriaLabel,A=void 0===O?"Legg til "+L+" minutter":O,M=d.inputRef,V=d.forcedReturnType,Z=d.forcedTimeZone,q=d.append,B=d.prepend,W=y(d,J),z=r.useLocale().locale;w&&(z=w);var H=e.useRandomId("eds-timepicker"),j=null!=Z?Z:null!==s&&"timezone"in s?s.timezone:"Europe/Oslo",U=function(e){if(void 0!==V||!s)return c(_({value:e,type:null!=V?V:"ZonedDateTime",timezone:j}));c(e)},K=t.useTimeFieldState(k({onChange:U,label:v,locale:z,value:s,granularity:(null!=C?C:S)?"second":"minute",hideTimeZone:!E,isDisabled:u||m,shouldForceLeadingZeros:!0},W)),G=a.useRef(null),Y=n.useTimeField(k({},W,{label:v}),K,G),Q=Y.labelProps,X=Y.fieldProps,ee=e.useRandomId("timepicker"),ae=function(e){if(null===s)return U(_({value:o.now(j),type:null!=V?V:"ZonedDateTime"}));switch(e){case"add":return U(s.add({minutes:L-N(s.minute,L)}));case"subtract":return U(s.subtract({minutes:N(s.minute-1,L)+1}))}};return a.createElement(r.I18nProvider,{locale:z},a.createElement(i.BaseFormControl,{append:a.createElement("div",{style:{display:"flex",alignItems:"center"}},q,a.createElement($,{direction:"right",disabled:u||m,"aria-label":A,onClick:function(){return ae("add")},onFocus:function(){return I(G,"last")}})),ariaAlertOnFeedback:!0,"aria-describedby":H+"description",className:l("eds-timepicker",f,{"eds-timepicker--disabled":u,"eds-timepicker--has-tooltip":void 0!==g,"eds-timepicker--readonly":m}),disabled:u,readOnly:m,disableLabelAnimation:!0,feedback:D,label:v,labelId:ee,labelProps:k({},Q,{"aria-describedby":H+"description"}),labelTooltip:g,prepend:a.createElement("div",{style:{display:"flex",alignItems:"center"}},a.createElement($,{direction:"left",disabled:u||m,"aria-label":P,onClick:function(){return ae("subtract")},onFocus:function(){return I(G,"first")}}),B),ref:M,style:b,variant:T},a.createElement("span",k({ref:G},X,{style:{display:"contents"}}),K.segments.map((function(e,t){return a.createElement(h,{segment:e,state:K,key:t,"aria-describedby":H+"description"})}))),a.createElement(p.VisuallyHidden,{id:H+"description"},null!==s?"valgt tid: "+s.hour.toString().padStart(2,"0")+":"+s.minute.toString().padStart(2,"0")+(S?":"+s.second.toString().padStart(2,"0"):""):"")))},exports.ariaLabelIfNorwegian=w,exports.convertValueToType=_,exports.createCalendar=T,exports.focusSegment=I,exports.getWeekNumberForDate=F,exports.handleOnChange=S,exports.lastMillisecondOfDay=E,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())};
2
2
  //# sourceMappingURL=datepicker.cjs.production.min.js.map