@entur/datepicker 11.1.2 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DatePicker/Calendar.d.ts +2 -0
- package/dist/DatePicker/DateField.d.ts +3 -1
- package/dist/datepicker.cjs.development.js +8 -1
- package/dist/datepicker.cjs.development.js.map +1 -1
- package/dist/datepicker.cjs.production.min.js +1 -1
- package/dist/datepicker.cjs.production.min.js.map +1 -1
- package/dist/datepicker.esm.js +9 -2
- package/dist/datepicker.esm.js.map +1 -1
- package/dist/styles.css +26 -22
- package/package.json +2 -2
|
@@ -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"),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 h=["segment","state"],D=function(e){var t=e.segment,r=e.state,i=y(e,h),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,h=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),U=a.useRef(null),j=n.useDateField(z,H,U),K=j.labelProps,G=j.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,U),style:O,variant:null!=h?h:H.isInvalid?_:void 0},G),H.segments.map((function(e,t){return a.createElement(D,{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","onCellClick","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.onCellClick,f=void 0===p?function(){}:p,b=e.weekNumberString,v=e.classNameForDate,g=e.ariaLabelForDate,h=y(e,A),D=a.useRef(null),C=d.useCalendarCell({date:c},s,D),T=C.cellProps,w=C.buttonProps,E=C.isSelected,_=C.isOutsideVisibleRange,N=C.isDisabled,I=C.isUnavailable,F=C.formattedDate,S=""+w["aria-label"]+b+" "+(null!=(t=null==g?void 0:g(c))?t:""),R=!(_||N||I);return a.createElement("td",k({},T,{className:"eds-datepicker__calendar__grid__cell__td"}),a.createElement("div",k({},w,{"aria-label":S,"aria-hidden":_,ref:D,hidden:_,className:l("eds-datepicker__calendar__grid__cell",(i={},i[null!=(n=null==v?void 0:v(c))?n:""]=!_,i["eds-datepicker__calendar__grid__cell--selected"]=E,i["eds-datepicker__calendar__grid__cell--disabled"]=N||I,i["eds-datepicker__calendar__grid__cell--outside-month"]=_,i["eds-datepicker__calendar__grid__cell--today"]=o.isEqualDay(c,o.now(null!=(r=s.timeZone)?r:o.getLocalTimeZone())),i))},h,{onClick:function(e){w.onClick&&w.onClick(e),E&&m(),R&&f()},onKeyUp:function(e){w.onKeyUp&&w.onKeyUp(e),"Enter"===e.key&&(E&&m(),R&&f())}}),F))},V=["state","navigationDescription","onSelectedCellClick","onCellClick","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.onCellClick,u=void 0===c?function(){}:c,m=t.showWeekNumbers,f=t.weekNumberHeader,b=t.classNameForDate,v=t.ariaLabelForDate,g=y(t,V),h=e.useRandomId("eds-calendar"),D=r.useLocale().locale,C=d.useCalendarGrid(g,n),T=C.gridProps,w=C.headerProps,E=C.weekDays,_=o.getWeeksInMonth(n.visibleRange.start,D),N=Array.from(Array(_).keys());return a.createElement(a.Fragment,null,a.createElement("table",k({},T,{cellSpacing:"0",className:"eds-datepicker__calendar__grid"}),a.createElement("thead",k({},w),a.createElement("tr",null,m&&a.createElement("th",{className:"eds-datepicker__calendar__grid__weeknumber-header"},f),function(){if(D.toLowerCase().includes("no"))return["ma","ti","on","to","fr","lø","sø"];if(D.toLowerCase().includes("en")){if("M"===E[0])return["Mo","Tu","We","Th","Fr","Sa","Su"];if("S"===E[0])return["Su","Mo","Tu","We","Th","Fr","Sa"]}return E.map((function(e){return e.toLowerCase()}))}().map((function(e){return a.createElement("th",{key:e},e)})))),a.createElement("tbody",null,N.map((function(e){var t=F(n.getDatesInWeek(e)[0]);return a.createElement("tr",{key:e},m&&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":h+"description",weekNumberString:m?", "+f+" "+t+",":"",onSelectedCellClick:s,onCellClick:u,classNameForDate:b,ariaLabelForDate:v}):a.createElement("td",{key:r})})))})))),a.createElement(p.VisuallyHidden,{id:h+"description"},l||(D.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","onCellClick","classNameForDate","ariaLabelForDate","calendarRef"],W=function(e){var t=e.locale,n=y(e,q),l=k({isDisabled:n.disabled},n),i=r.useLocale();return a.createElement(r.I18nProvider,{locale:null!=t?t:i.locale},a.createElement(z,k({},l)))},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,D=e.onSelectedCellClick,C=void 0===D?function(){}:D,E=e.onCellClick,_=void 0===E?function(){}:E,N=e.classNameForDate,I=e.ariaLabelForDate,F=e.calendarRef,R=y(e,B),L=r.useLocale().locale,x=k({},R,{value:t,onChange:function(e){return S({value:e,selectedDate:t,forcedReturnType:b,onChange:n})},locale:L,createCalendar:T,minValue:i,maxValue:o}),P=s.useCalendarState(x),A=d.useCalendar(x,P),M=A.prevButtonProps,V=A.nextButtonProps,q=A.title;return a.createElement("div",k({},A.calendarProps,{ref:F,className:l("eds-datepicker__calendar",g),style:v}),a.createElement("div",{className:"eds-datepicker__calendar__header"},a.createElement(O,k({},M,{"aria-label":w("Forrige måned",L,M)}),a.createElement(c.LeftArrowIcon,{size:20})),a.createElement("h2",null,q),a.createElement(O,k({},V,{"aria-label":w("Neste måned",L,V)}),a.createElement(c.RightArrowIcon,{size:20}))),a.createElement(Z,k({},R,{state:P,navigationDescription:h,onSelectedCellClick:C,onCellClick:_,classNameForDate:N,ariaLabelForDate:I,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","ariaLabelForDate","append","prepend","granularity"],U=["className","style","label","onChange","feedback","variant","disableLabelAnimation","prepend"],j=["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,U),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,j),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,h=void 0!==p&&p,D=i.classNameForDate,C=i.className,T=i.variant,w=i.feedback,_=i.validationVariant,N=i.validationFeedback,I=i.showWeekNumbers,F=i.weekNumberHeader,R=i.disableModal,L=void 0!==R&&R,P=i.labelTooltip,A=i.navigationDescription,M=i.minDate,V=i.maxDate,Z=i.modalTreshold,q=void 0===Z?1e3:Z,B=i.ariaLabelForDate,z=i.append,U=i.prepend,j=i.granularity,K=void 0===j?m?"minute":"day":j,G=y(i,H),Y=q,$=a.useRef(null),J=a.useRef(null),Q=e.useWindowDimensions().width,X=k({},G,{onChange:function(e){return S({value:e,selectedDate:o,forcedReturnType:G.forcedReturnType,onChange:G.onChange})},minValue:M,maxValue:"hour"in(null!=V?V:{})?V:void 0!==V?E(V):void 0,value:o,granularity:K,isDisabled:s||u}),ee=t.useDatePickerState(X),ae=n.useDatePicker(X,ee,$),te=ae.groupProps,ne=ae.labelProps,re=ae.fieldProps,le=ae.buttonProps,ie=ae.dialogProps,oe=ae.calendarProps,de=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})]}),se=de.refs,ce=de.floatingStyles,ue=de.update;e.useOnClickOutside([J],(function(){return ee.setOpen(!1)})),e.useOnEscape(J,(function(){return ee.setOpen(!1)}));var me=k({},ie,oe,{onChange:G.onChange,forcedReturnType:G.forcedReturnType,disabled:s,navigationDescription:A,onSelectedCellClick:function(){return ee.setOpen(!1)},onCellClick:function(){return ee.setOpen(!1)},selectedDate:o,minDate:M,maxDate:V,calendarRef:J,classNameForDate:D,ariaLabelForDate:B,showWeekNumbers:I,weekNumberHeader:F}),pe=void 0!==Q&&Q<=Y&&!L,fe=a.createElement("div",{style:k({},ce,{zIndex:v.zIndexes.popover}),ref:se.setFloating},a.createElement(b,{disabled:!ee.isOpen||pe,returnFocus:!0},ee.isOpen&&a.createElement(W,k({},me)))),be=a.createElement(g.Modal,{size:"small",title:"",open:ee.isOpen,onDismiss:function(){return ee.setOpen(!1)},className:"eds-datepicker__calendar-modal"},a.createElement(W,k({},me)));return a.createElement(e.ConditionalWrapper,{condition:void 0!==d,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:d},e)}},a.createElement(x,k({},te,re,G,{append:!s&&!u&&a.createElement("div",{style:{display:"flex",alignItems:"center"}},z,a.createElement(O,k({},le,{onPress:function(){ee.setOpen(!ee.isOpen),ue()},className:"eds-datepicker__open-calendar-button"}),a.createElement(c.CalendarIcon,null))),prepend:U,className:l("eds-datepicker",C,{"eds-datepicker--disabled":s}),disabled:s,readOnly:u,feedback:w,labelProps:ne,labelTooltip:P,maxDate:V,minDate:M,dateFieldRef:function(e){se.setReference(e),$.current=e},selectedDate:o,showTime:m,showTimeZone:h,validationFeedback:N,validationVariant:_,variant:T})),pe?be:fe)},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,h=d.onChange,D=d.padding,C=void 0===D?"default":D,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: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||U()},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)},U=function(){x(_?"–– : –– : ––":"–– : ––")},j=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!=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(){j(),null===E&&U()},onChange:function(e){return x(e.target.value)},onFocus:function(){null===E&&x("")},onKeyDown:function(e){"Enter"===e.key&&j()},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,h=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"),U=null!=Z?Z:null!==s&&"timezone"in s?s.timezone:"Europe/Oslo",j=function(e){if(void 0!==V||!s)return c(_({value:e,type:null!=V?V:"ZonedDateTime",timezone:U}));c(e)},K=t.useTimeFieldState(k({onChange:j,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 j(_({value:o.now(U),type:null!=V?V:"ZonedDateTime"}));switch(e){case"add":return j(s.add({minutes:L-N(s.minute,L)}));case"subtract":return j(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:h,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(D,{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())};
|
|
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 h=["segment","state"],D=function(e){var t=e.segment,r=e.state,i=y(e,h),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)},E=function(e,a,t){return"no-no"!==a.toLowerCase()?t["aria-label"]:e},w=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","onValidate","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,h=o.variant,C=o.feedback,E=o.validationVariant,_=void 0===E?"negative":E,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,V=o.labelProps,M=o.append,Z=o.prepend,q=o.onValidate,B=o.dateFieldRef,W=y(o,L),z=r.useLocale(),H=k({},W,{label:c,locale:null!=u?u:z.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?w(x):void 0,isDisabled:g||b||v,shouldForceLeadingZeros:!0}),U=t.useDateFieldState(H),j=a.useRef(null),K=n.useDateField(H,U,j),G=K.labelProps,Y=K.fieldProps;a.useEffect((function(){return null==q?void 0:q(!U.isInvalid)}),[U.isInvalid]);var $=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!==F}),disabled:g||b,readOnly:v,disableLabelAnimation:!0,feedback:null!=C?C:"invalid"===U.validationState?I:void 0,label:c,labelId:$,labelProps:null!=V?V:G,labelTooltip:F,prepend:Z,ref:e.mergeRefs(B,j),style:O,variant:null!=h?h:U.isInvalid?_:void 0},Y),U.segments.map((function(e,t){return a.createElement(D,{segment:e,state:U,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","onCellClick","weekNumberString","classNameForDate","ariaLabelForDate"],V=function(e){var t,n,r,i,s=e.state,c=e.date,u=e.onSelectedCellClick,m=void 0===u?function(){}:u,p=e.onCellClick,f=void 0===p?function(){}:p,b=e.weekNumberString,v=e.classNameForDate,g=e.ariaLabelForDate,h=y(e,A),D=a.useRef(null),C=d.useCalendarCell({date:c},s,D),T=C.cellProps,E=C.buttonProps,w=C.isSelected,_=C.isOutsideVisibleRange,N=C.isDisabled,I=C.isUnavailable,F=C.formattedDate,S=""+E["aria-label"]+b+" "+(null!=(t=null==g?void 0:g(c))?t:""),R=!(_||N||I);return a.createElement("td",k({},T,{className:"eds-datepicker__calendar__grid__cell__td"}),a.createElement("div",k({},E,{"aria-label":S,"aria-hidden":_,ref:D,hidden:_,className:l("eds-datepicker__calendar__grid__cell",(i={},i[null!=(n=null==v?void 0:v(c))?n:""]=!_,i["eds-datepicker__calendar__grid__cell--selected"]=w,i["eds-datepicker__calendar__grid__cell--disabled"]=N||I,i["eds-datepicker__calendar__grid__cell--outside-month"]=_,i["eds-datepicker__calendar__grid__cell--today"]=o.isEqualDay(c,o.now(null!=(r=s.timeZone)?r:o.getLocalTimeZone())),i))},h,{onClick:function(e){E.onClick&&E.onClick(e),w&&m(),R&&f()},onKeyUp:function(e){E.onKeyUp&&E.onKeyUp(e),"Enter"===e.key&&(w&&m(),R&&f())}}),F))},M=["state","navigationDescription","onSelectedCellClick","onCellClick","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.onCellClick,u=void 0===c?function(){}:c,m=t.showWeekNumbers,f=t.weekNumberHeader,b=t.classNameForDate,v=t.ariaLabelForDate,g=y(t,M),h=e.useRandomId("eds-calendar"),D=r.useLocale().locale,C=d.useCalendarGrid(g,n),T=C.gridProps,E=C.headerProps,w=C.weekDays,_=o.getWeeksInMonth(n.visibleRange.start,D),N=Array.from(Array(_).keys());return a.createElement(a.Fragment,null,a.createElement("table",k({},T,{cellSpacing:"0",className:"eds-datepicker__calendar__grid"}),a.createElement("thead",k({},E),a.createElement("tr",null,m&&a.createElement("th",{className:"eds-datepicker__calendar__grid__weeknumber-header"},f),function(){if(D.toLowerCase().includes("no"))return["ma","ti","on","to","fr","lø","sø"];if(D.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){return a.createElement("th",{key:e},e)})))),a.createElement("tbody",null,N.map((function(e){var t=F(n.getDatesInWeek(e)[0]);return a.createElement("tr",{key:e},m&&a.createElement("th",{"aria-hidden":!0,className:"eds-datepicker__calendar__grid__weeknumber"},t),n.getDatesInWeek(e).map((function(e,r){return e?a.createElement(V,{key:e.month+"."+e.day,state:n,date:e,"aria-describedby":h+"description",weekNumberString:m?", "+f+" "+t+",":"",onSelectedCellClick:s,onCellClick:u,classNameForDate:b,ariaLabelForDate:v}):a.createElement("td",{key:r})})))})))),a.createElement(p.VisuallyHidden,{id:h+"description"},l||(D.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","onCellClick","classNameForDate","ariaLabelForDate","calendarRef"],W=function(e){var t=e.locale,n=y(e,q),l=k({isDisabled:n.disabled},n),i=r.useLocale();return a.createElement(r.I18nProvider,{locale:null!=t?t:i.locale},a.createElement(z,k({},l)))},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,D=e.onSelectedCellClick,C=void 0===D?function(){}:D,w=e.onCellClick,_=void 0===w?function(){}:w,N=e.classNameForDate,I=e.ariaLabelForDate,F=e.calendarRef,R=y(e,B),L=r.useLocale().locale,x=k({},R,{value:t,onChange:function(e){return S({value:e,selectedDate:t,forcedReturnType:b,onChange:n})},locale:L,createCalendar:T,minValue:i,maxValue:o}),P=s.useCalendarState(x),A=d.useCalendar(x,P),V=A.calendarProps,M=A.prevButtonProps,q=A.nextButtonProps,W=A.title;return a.useEffect((function(){return null==R.onValidate?void 0:R.onValidate(!P.isValueInvalid)}),[P.isValueInvalid]),a.createElement("div",k({},V,{ref:F,className:l("eds-datepicker__calendar",g),style:v}),a.createElement("div",{className:"eds-datepicker__calendar__header"},a.createElement(O,k({},M,{"aria-label":E("Forrige måned",L,M)}),a.createElement(c.LeftArrowIcon,{size:20})),a.createElement("h2",null,W),a.createElement(O,k({},q,{"aria-label":E("Neste måned",L,q)}),a.createElement(c.RightArrowIcon,{size:20}))),a.createElement(Z,k({},R,{state:P,navigationDescription:h,onSelectedCellClick:C,onCellClick:_,classNameForDate:N,ariaLabelForDate:I,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","ariaLabelForDate","append","prepend","granularity"],U=["className","style","label","onChange","feedback","variant","disableLabelAnimation","prepend"],j=["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,U),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,j),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,h=void 0!==p&&p,D=i.classNameForDate,C=i.className,T=i.variant,E=i.feedback,_=i.validationVariant,N=i.validationFeedback,I=i.showWeekNumbers,F=i.weekNumberHeader,R=i.disableModal,L=void 0!==R&&R,P=i.labelTooltip,A=i.navigationDescription,V=i.minDate,M=i.maxDate,Z=i.modalTreshold,q=void 0===Z?1e3:Z,B=i.ariaLabelForDate,z=i.append,U=i.prepend,j=i.granularity,K=void 0===j?m?"minute":"day":j,G=y(i,H),Y=q,$=a.useRef(null),J=a.useRef(null),Q=e.useWindowDimensions().width,X=k({},G,{onChange:function(e){return S({value:e,selectedDate:o,forcedReturnType:G.forcedReturnType,onChange:G.onChange})},minValue:V,maxValue:"hour"in(null!=M?M:{})?M:void 0!==M?w(M):void 0,value:o,granularity:K,isDisabled:s||u}),ee=t.useDatePickerState(X),ae=n.useDatePicker(X,ee,$),te=ae.groupProps,ne=ae.labelProps,re=ae.fieldProps,le=ae.buttonProps,ie=ae.dialogProps,oe=ae.calendarProps,de=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})]}),se=de.refs,ce=de.floatingStyles,ue=de.update;e.useOnClickOutside([J],(function(){return ee.setOpen(!1)})),e.useOnEscape(J,(function(){return ee.setOpen(!1)}));var me=k({},ie,oe,{onChange:G.onChange,forcedReturnType:G.forcedReturnType,disabled:s,navigationDescription:A,onSelectedCellClick:function(){return ee.setOpen(!1)},onCellClick:function(){return ee.setOpen(!1)},selectedDate:o,minDate:V,maxDate:M,calendarRef:J,classNameForDate:D,ariaLabelForDate:B,showWeekNumbers:I,weekNumberHeader:F}),pe=void 0!==Q&&Q<=Y&&!L,fe=a.createElement("div",{style:k({},ce,{zIndex:v.zIndexes.popover}),ref:se.setFloating},a.createElement(b,{disabled:!ee.isOpen||pe,returnFocus:!0},ee.isOpen&&a.createElement(W,k({},me)))),be=a.createElement(g.Modal,{size:"small",title:"",open:ee.isOpen,onDismiss:function(){return ee.setOpen(!1)},className:"eds-datepicker__calendar-modal"},a.createElement(W,k({},me)));return a.createElement(e.ConditionalWrapper,{condition:void 0!==d,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:d},e)}},a.createElement(x,k({},te,re,G,{append:!s&&!u&&a.createElement("div",{style:{display:"flex",alignItems:"center"}},z,a.createElement(O,k({},le,{onPress:function(){ee.setOpen(!ee.isOpen),ue()},className:"eds-datepicker__open-calendar-button"}),a.createElement(c.CalendarIcon,null))),prepend:U,className:l("eds-datepicker",C,{"eds-datepicker--disabled":s}),disabled:s,readOnly:u,feedback:E,labelProps:ne,labelTooltip:P,maxDate:M,minDate:V,dateFieldRef:function(e){se.setReference(e),$.current=e},selectedDate:o,showTime:m,showTimeZone:h,validationFeedback:N,validationVariant:_,variant:T})),pe?be:fe)},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,h=d.onChange,D=d.padding,C=void 0===D?"default":D,T=d.prepend,E=d.readOnly,w=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],V=O[1],M=r.useLocale().locale,Z=t.useTimeFieldState(k({onChange:h,label:v,locale:M,value:w,hideTimeZone:!0,isDisabled:u,isReadOnly:E},F)),q=n.useTimeField(k({},F,{label:v}),Z,P),B=q.labelProps,W=q.fieldProps;a.useEffect((function(){z(),null!==w&&V(w)}),[null==w?void 0:w.toString()]);var z=function(){var e=H(w);x(e);var a=document.activeElement===(null==P?void 0:P.current);""!==e||a||U()},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)},U=function(){x(_?"–– : –– : ––":"–– : ––")},j=function(){var e=K();if(e===R.INVALID)return z();(null==e?void 0:e.toString())!==(null==w?void 0:w.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!=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:M},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(){j(),null===w&&U()},onChange:function(e){return x(e.target.value)},onFocus:function(){null===w&&x("")},onKeyDown:function(e){"Enter"===e.key&&j()},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:E,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,h=d.feedback,C=d.granularity,T=d.variant,E=d.locale,w=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,V=d.inputRef,M=d.forcedReturnType,Z=d.forcedTimeZone,q=d.append,B=d.prepend,W=y(d,J),z=r.useLocale().locale;E&&(z=E);var H=e.useRandomId("eds-timepicker"),U=null!=Z?Z:null!==s&&"timezone"in s?s.timezone:"Europe/Oslo",j=function(e){if(void 0!==M||!s)return c(_({value:e,type:null!=M?M:"ZonedDateTime",timezone:U}));c(e)},K=t.useTimeFieldState(k({onChange:j,label:v,locale:z,value:s,granularity:(null!=C?C:S)?"second":"minute",hideTimeZone:!w,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 j(_({value:o.now(U),type:null!=M?M:"ZonedDateTime"}));switch(e){case"add":return j(s.add({minutes:L-N(s.minute,L)}));case"subtract":return j(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:h,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:V,style:b,variant:T},a.createElement("span",k({ref:G},X,{style:{display:"contents"}}),K.segments.map((function(e,t){return a.createElement(D,{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=E,exports.convertValueToType=_,exports.createCalendar=T,exports.focusSegment=I,exports.getWeekNumberForDate=F,exports.handleOnChange=S,exports.lastMillisecondOfDay=w,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
|