@entur/datepicker 10.1.3 → 11.0.1-beta.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/README.md +2 -2
- package/dist/DatePicker/Calendar.d.ts +5 -2
- package/dist/DatePicker/DateField.d.ts +31 -9
- package/dist/DatePicker/DatePicker.d.ts +4 -72
- package/dist/TimePicker/TimePicker.d.ts +1 -1
- package/dist/datepicker.cjs.development.js +72 -65
- 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 +73 -67
- package/dist/datepicker.esm.js.map +1 -1
- package/dist/shared/utils.d.ts +8 -1
- package/dist/styles.css +62 -56
- package/package.json +11 -11
|
@@ -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}),tabIndex:r.isDisabled?-1:s.tabIndex},i),t.text)},C=function(e,a,t){return a?t?new o.ZonedDateTime(e.getFullYear(),e.getMonth()+1,e.getDate(),a,t,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()):o.parseAbsolute(e.toISOString(),a):new o.CalendarDateTime(e.getFullYear(),e.getMonth()+1,e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())},w=function(e){if(void 0===e&&(e="gregory"),"gregory"===e)return new o.GregorianCalendar;throw new Error("Unsupported calendar "+e)},E=function(e,a,t){return"no-no"!==a.toLowerCase()?t["aria-label"]:e},T=function(e){return o.toCalendarDateTime(e.add({days:1})).add({milliseconds:-1})},_=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)}var S,P=["selectedDate","onChange","label","locale","showTimeZone","showTime","granularity","disabled","isDisabled","variant","feedback","validationVariant","validationFeedback","labelTooltip","minDate","maxDate","style","className","labelProps","fieldProps","groupProps","append","prepend","dateFieldRef"],L=function(o){var s=o.selectedDate,d=o.onChange,c=o.label,u=o.locale,m=o.showTimeZone,p=o.showTime,f=o.granularity,b=void 0===f?"day":f,v=o.disabled,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,S=o.minDate,L=o.maxDate,x=o.style,R=o.className,A=o.labelProps,O=o.fieldProps,M=o.groupProps,V=o.append,Z=o.prepend,q=o.dateFieldRef,B=D(o,P),W=r.useLocale(),z=t.useDateFieldState(k({},B,{locale:null!=u?u:W.locale,createCalendar:w,value:s,onChange:d,hideTimeZone:!m,granularity:p?"minute":b,minValue:S,maxValue:"hour"in(null!=L?L:{})?L:void 0!==L?T(L):void 0,isDisabled:g||v,shouldForceLeadingZeros:!0})),H=a.useRef(null),j=n.useDateField(k({},O,B,{label:c}),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:V,ariaAlertOnFeedback:!0,className:l("eds-datefield",R,{"eds-datefield--has-tooltip":void 0!==F}),disabled:g||v,disableLabelAnimation:!0,feedback:null!=C?C:"invalid"===z.validationState?I:void 0,label:c,labelId:G,labelProps:null!=A?A:U,labelTooltip:F,prepend:Z,ref:q,style:x,variant:null!=h?h:"invalid"===z.validationState?_:void 0},M),a.createElement("span",k({ref:H},K,{style:{display:"contents"}}),z.segments.map((function(e,t){return a.createElement(y,{segment:e,state:z,key:t})})))))},x=["children","className","style"],R=function(e){var t=e.children,n=e.className,r=e.style,l=D(e,x),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"],O=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,A),g=a.useRef(null),h=s.useCalendarCell({date:c},d,g),y=h.cellProps,C=h.buttonProps,w=h.isSelected,E=h.isOutsideVisibleRange,T=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":E,ref:g,hidden:E,className:l("eds-datepicker__calendar__grid__cell",(i={},i[null!=(n=null==f?void 0:f(c))?n:""]=!E,i["eds-datepicker__calendar__grid__cell--selected"]=w,i["eds-datepicker__calendar__grid__cell--disabled"]=T||_,i["eds-datepicker__calendar__grid__cell--outside-month"]=E,i["eds-datepicker__calendar__grid__cell--today"]=o.isEqualDay(c,o.now(null!=(r=d.timeZone)?r:o.getLocalTimeZone())),i))},v,{onClick:function(e){C.onClick&&C.onClick(e),w&&m()},onKeyDown:function(e){C.onKeyDown&&C.onKeyDown(e),"Enter"!==e.key&&" "!==e.key||w&&m()}}),N))},M=["state","navigationDescription","onSelectedCellClick","showWeekNumbers","weekNumberHeader","classNameForDate","ariaLabelForDate"],V=function(t){var n=t.state,l=t.navigationDescription,i=t.onSelectedCellClick,d=void 0===i?function(){}:i,c=t.showWeekNumbers,u=t.weekNumberHeader,m=t.classNameForDate,f=t.ariaLabelForDate,b=D(t,M),v=e.useRandomId("eds-calendar"),g=r.useLocale().locale,h=s.useCalendarGrid(b,n),y=h.gridProps,C=h.headerProps,w=h.weekDays,E=o.getWeeksInMonth(n.visibleRange.start,g),T=Array.from(Array(E).keys());return a.createElement(a.Fragment,null,a.createElement("table",k({},y,{cellSpacing:"0",className:"eds-datepicker__calendar__grid"}),a.createElement("thead",k({},C),a.createElement("tr",null,c&&a.createElement("th",{className:"eds-datepicker__calendar__grid__weeknumber-header"},u),function(){if(g.toLowerCase().includes("no"))return["ma","ti","on","to","fr","lø","sø"];if(g.toLowerCase().includes("en")){if("M"===w[0])return["Mo","Tu","We","Th","Fr","Sa","Su"];if("S"===w[0])return["Su","Mo","Tu","We","Th","Fr","Sa"]}return w.map((function(e){return e.toLowerCase()}))}().map((function(e,t){return a.createElement("th",{key:t},e)})))),a.createElement("tbody",null,T.map((function(e){var t=F(n.getDatesInWeek(e)[0]);return a.createElement("tr",{key:e},c&&a.createElement("th",{"aria-hidden":!0,className:"eds-datepicker__calendar__grid__weeknumber"},t),n.getDatesInWeek(e).map((function(e,r){return e?a.createElement(O,{key:r,state:n,date:e,"aria-describedby":v+"description",weekNumberString:c?", "+u+" "+t+",":"",onSelectedCellClick:d,classNameForDate:m,ariaLabelForDate:f}):a.createElement("td",{key:r})})))})))),a.createElement(p.VisuallyHidden,{id:v+"description"},l||(g.toLowerCase().includes("en")?"Use the arrow keys to navigate between dates":"Bruk piltastene til å navigere mellom datoer")))},Z=["locale"],q=["selectedDate","onChange","minDate","maxDate","showWeekNumbers","weekNumberHeader","style","className","navigationDescription","onSelectedCellClick","classNameForDate","ariaLabelForDate","calendarRef"],B=function(e){var t=e.locale,n=D(e,Z),l=r.useLocale();return a.createElement(r.I18nProvider,{locale:null!=t?t:l.locale},a.createElement(W,k({},n)))},W=function(e){var t=e.selectedDate,n=e.onChange,i=e.minDate,o=e.maxDate,u=e.showWeekNumbers,m=void 0!==u&&u,p=e.weekNumberHeader,f=void 0===p?"uke":p,b=e.style,v=e.className,g=e.navigationDescription,h=e.onSelectedCellClick,y=void 0===h?function(){}:h,C=e.classNameForDate,T=e.ariaLabelForDate,_=e.calendarRef,N=D(e,q),I=r.useLocale().locale,F=k({},N,{value:t,onChange:n,locale:I,createCalendar:w,minValue:i,maxValue:o}),S=d.useCalendarState(F),P=s.useCalendar(F,S),L=P.prevButtonProps,x=P.nextButtonProps,A=P.title;return a.createElement("div",k({},P.calendarProps,{ref:_,className:l("eds-datepicker__calendar",v),style:b}),a.createElement("div",{className:"eds-datepicker__calendar__header"},a.createElement(R,k({},L,{"aria-label":E("Forrige måned",I,L)}),a.createElement(c.LeftArrowIcon,{size:20})),a.createElement("h2",null,A),a.createElement(R,k({},x,{"aria-label":E("Neste måned",I,x)}),a.createElement(c.RightArrowIcon,{size:20}))),a.createElement(V,{state:S,navigationDescription:g,onSelectedCellClick:y,classNameForDate:C,ariaLabelForDate:T,showWeekNumbers:m,weekNumberHeader:f}))},z=["selectedDate","onChange","locale","disabled","showTime","showTimeZone","classNameForDate","className","style","variant","feedback","validationVariant","validationFeedback","showWeekNumbers","weekNumberHeader","disableModal","labelTooltip","navigationDescription","minDate","maxDate","modalTreshold","forcedReturnType","ariaLabelForDate","append","prepend"],H=["className","style","label","onChange","feedback","variant","disableLabelAnimation","prepend"],j=["onChange","variant","value"],U=a.forwardRef((function(t,n){var r=t.className,l=t.style,o=t.label,s=t.onChange,d=t.feedback,u=t.variant,m=t.disableLabelAnimation,p=t.prepend,f=void 0===p?a.createElement(c.DateIcon,{inline:!0}):p,b=D(t,H),v=e.useRandomId("eds-nativetimepicker");return a.createElement(i.BaseFormControl,{style:l,className:r,prepend:f,label:o,feedback:d,variant:u,labelId:v,disableLabelAnimation:m,isFilled:!0},a.createElement(K,k({onChange:s,"aria-labelledby":v,ref:n,variant:u},b)))})),K=a.forwardRef((function(t,n){var r=t.onChange,l=t.variant,o=t.value,s=D(t,j),d=i.useVariant(),c=l||d,u=i.useInputGroupContext(),m=u.isFilled,p=u.setFilled;return e.useOnMount((function(){p&&!m&&p(!0)})),a.useEffect((function(){o?p&&!m&&p(!0):p&&m&&p(!1)}),[o,p,m]),a.createElement("input",k({ref:n,"aria-invalid":"error"===c,type:"date",className:"eds-form-control eds-native-date-picker",onChange:function(e){i.isFilled(e.target)?p&&!m&&p(!0):p&&m&&p(!1),r&&r(e)},value:o},s))})),G=["direction","onClick","disabled","aria-label"],Y=function(e){var t=e.direction,n=e.onClick,r=e.disabled,i=e["aria-label"],o=D(e,G);return a.createElement(m.IconButton,k({className:l("eds-timepicker__arrowbutton","eds-timepicker__arrowbutton--"+t,{"eds-timepicker__arrowbutton--disabled":r}),type:"button",tabIndex:-1,onClick:n,"aria-label":i,disabled:r},o),a.createElement("left"===t?c.LeftArrowIcon:c.RightArrowIcon,null))},$=["selectedTime","onChange","disabled","className","style","label","labelTooltip","feedback","granularity","variant","locale","showTimeZone","showSeconds","minuteIncrementForArrowButtons","leftArrowButtonAriaLabel","rightArrowButtonAriaLabel","inputRef","forcedReturnType","forcedTimeZone","append","prepend"],J=["className","style","onChange","label","feedback","variant","prepend"],Q=["onChange","value"],X=a.forwardRef((function(t,n){var r=t.className,o=t.style,s=t.onChange,d=t.label,c=t.feedback,u=t.variant,m=t.prepend,p=D(t,J),f=e.useRandomId("eds-native-timepicker");return a.createElement(i.BaseFormControl,{style:o,className:l(r,"eds-native-timepicker"),prepend:m,label:d,feedback:c,variant:u,labelId:f,disableLabelAnimation:!0},a.createElement(ee,k({onChange:s,"aria-labelledby":f,ref:n},p)))})),ee=a.forwardRef((function(t,n){var r=t.onChange,l=t.value,o=D(t,Q),s=i.useVariant(),d=o.variant||s,c=i.useInputGroupContext(),u=c.isFilled,m=c.setFilled;return e.useOnMount((function(){m&&!u&&m(!0)})),a.useEffect((function(){l?m&&!u&&m(!0):m&&u&&m(!1)}),[l,m,u]),a.createElement("input",k({ref:n,"aria-invalid":"error"===d,type:"time",className:"eds-form-control",onChange:function(e){i.isFilled(e.target)?m&&!u&&m(!0):m&&u&&m(!1),r&&r(e)},value:l},o))})),ae=["append","className","disabled","feedback","showClockIcon","inputRef","label","labelTooltip","onChange","padding","prepend","readOnly","selectedTime","showSeconds","style","variant"],te=["onBlur","onClick","onDragStart","onFocus","onKeyDown","onKeyUp","onMouseDown","onPointerDown","onPointerUp"];!function(e){e[e.RESET_TIME=0]="RESET_TIME",e[e.INVALID=1]="INVALID"}(S||(S={})),e.warnAboutMissingStyles("datepicker","form","icons"),Object.defineProperty(exports,"CalendarDate",{enumerable:!0,get:function(){return o.CalendarDate}}),Object.defineProperty(exports,"CalendarDateTime",{enumerable:!0,get:function(){return o.CalendarDateTime}}),Object.defineProperty(exports,"Time",{enumerable:!0,get:function(){return o.Time}}),Object.defineProperty(exports,"ZonedDateTime",{enumerable:!0,get:function(){return o.ZonedDateTime}}),exports.Calendar=B,exports.DateField=L,exports.DatePicker=function(i){var o=i.selectedDate,s=i.onChange,d=i.locale,u=i.disabled,m=i.showTime,p=i.showTimeZone,h=void 0!==p&&p,y=i.classNameForDate,C=i.className,w=i.style,E=i.variant,N=i.feedback,I=i.validationVariant,F=i.validationFeedback,S=i.showWeekNumbers,P=i.weekNumberHeader,x=i.disableModal,A=void 0!==x&&x,O=i.labelTooltip,M=i.navigationDescription,V=i.minDate,Z=i.maxDate,q=i.modalTreshold,W=void 0===q?1e3:q,H=i.forcedReturnType,j=i.ariaLabelForDate,U=i.append,K=i.prepend,G=D(i,z),Y=W,$=a.useRef(null),J=a.useRef(null),Q=e.useWindowDimensions().width,X=function(e){if(void 0!==H)return s(_({value:e,type:H,timezone:null!==e&&"timezone"in e?e.timezone:void 0}));s(e)},ee=t.useDatePickerState(k({},G,{minValue:V,maxValue:"hour"in(null!=Z?Z:{})?Z:void 0!==Z?T(Z):void 0,value:o,onChange:X,granularity:m?"minute":G.granularity,isDisabled:u})),ae=n.useDatePicker(k({},G),ee,$),te=ae.groupProps,ne=ae.labelProps,re=ae.fieldProps,le=ae.buttonProps,ie=ae.dialogProps,oe=ae.calendarProps,se=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=se.refs,ce=se.floatingStyles,ue=se.update;e.useOnClickOutside([J],(function(){ee.setOpen(!1)})),e.useOnEscape(J,(function(){ee.setOpen(!1)}));var me=k({},ie,oe,{disabled:u,navigationDescription:M,onSelectedCellClick:function(){return ee.setOpen(!1)},selectedDate:o,onChange:X,minDate:V,maxDate:Z,calendarRef:J,classNameForDate:y,ariaLabelForDate:j,showWeekNumbers:S,weekNumberHeader:P}),pe=void 0!==Q&&Q<=Y&&!A,fe=a.createElement("div",{style:k({},ce,{zIndex:v.zIndexes.popover}),ref:de.setFloating},a.createElement(b,{disabled:!ee.isOpen||pe,returnFocus:!0},ee.isOpen&&a.createElement(B,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(B,k({},me)));return a.createElement(e.ConditionalWrapper,{condition:void 0!==d,wrapper:function(e){return a.createElement(r.I18nProvider,{locale:d},e)}},a.createElement(L,{append:!u&&a.createElement("div",{style:{display:"flex",alignItems:"center"}},U,a.createElement(R,k({},le,{onPress:function(){ee.setOpen(!ee.isOpen),ue()},className:"eds-datepicker__open-calendar-button"}),a.createElement(c.CalendarIcon,null))),prepend:K,className:l("eds-datepicker",C,{"eds-datepicker--disabled":u}),disabled:u,feedback:N,fieldProps:re,groupProps:te,label:G.label,labelProps:ne,labelTooltip:O,maxDate:Z,minDate:V,onChange:X,dateFieldRef:function(e){de.setReference(e),$.current=e},selectedDate:o,showTime:m,showTimeZone:h,style:w,validationFeedback:F,validationVariant:I,variant:E}),pe?be:fe)},exports.NativeDatePicker=U,exports.NativeTimePicker=X,exports.SimpleTimePicker=function(s){var d=s.append,u=s.disabled,m=s.feedback,p=s.showClockIcon,f=void 0===p?"right":p,b=s.inputRef,v=s.label,g=s.labelTooltip,h=s.onChange,y=s.padding,C=void 0===y?"default":y,w=s.prepend,E=s.readOnly,T=s.selectedTime,_=s.showSeconds,N=s.style,I=s.variant,F=D(s,ae),P=a.useState(""),L=P[0],x=P[1],R=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:T,hideTimeZone:!0,isDisabled:u,isReadOnly:E},F)),q=n.useTimeField(k({},F,{label:v}),Z,R),B=q.labelProps,W=q.fieldProps;a.useEffect((function(){z(),null!==T&&M(T)}),[null==T?void 0:T.toString()]);var z=function(){var e=H(T);x(e);var a=document.activeElement===(null==R?void 0:R.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===S.INVALID)return z();(null==e?void 0:e.toString())!==(null==T?void 0:T.toString())&&(null==h||h(e))},K=function(){var e=G(L),a=Y(e);return a===S.INVALID?S.INVALID:a===S.RESET_TIME?null:$(a)},G=function(e){if(0===e.length)return S.RESET_TIME;if(e.length<3||e.length>8)return S.INVALID;var a=(e.match(new RegExp(":","g"))||[]).length,t=e.length;if(2===a&&t>=7)return e.padStart(8,"0");if(1===a)return e.padStart(5,"0");if(t>6)return S.INVALID;var n,r=t%2==0,l=e.slice(0,r?2:1),i=r?e.slice(2,4):e.slice(1,3),o=""===(n=r?e.slice(4,6):e.slice(3,5))?"00":n;return l.padStart(2,"0")+":"+i+(_?":"+o:"")},Y=function(e){if(e===S.INVALID)return S.INVALID;if(e===S.RESET_TIME)return S.RESET_TIME;var a=/^\d+$/,t=e.slice(0,2),n=e.slice(3,5),r=e.slice(6,8);if(t.match(a)&&n.match(a)&&(""===r||r.match(a)))try{return o.parseTime(e)}catch(e){return S.INVALID}return S.INVALID},$=function(e){return(null!=O?O:new o.Time).set({hour:e.hour,minute:e.minute,second:e.second})},J=D(W,te);return a.createElement(r.I18nProvider,{locale:V},a.createElement(i.TextField,k({append:d||(!0===f||"right"===f?a.createElement(c.ClockIcon,{onClick:function(){var e;return null==R||null==(e=R.current)?void 0:e.focus()},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===T&&j()},onChange:function(e){return x(e.target.value)},onFocus:function(){null===T&&x("")},onKeyDown:function(e){"Enter"===e.key&&U()},placeholder:_?"–– : –– : ––":"–– : ––",prepend:w||("left"===f?a.createElement(c.ClockIcon,{onClick:function(){var e;return null==R||null==(e=R.current)?void 0:e.focus()}}):void 0),readOnly:E,ref:e.mergeRefs(R,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,w=s.locale,E=s.showTimeZone,T=s.showSeconds,F=void 0!==T&&T,S=s.minuteIncrementForArrowButtons,P=void 0===S?30:S,L=s.leftArrowButtonAriaLabel,x=void 0===L?"Trekk fra "+P+" minutter":L,R=s.rightArrowButtonAriaLabel,A=void 0===R?"Legg til "+P+" minutter":R,O=s.inputRef,M=s.forcedReturnType,V=s.forcedTimeZone,Z=s.append,q=s.prepend,B=D(s,$),W=r.useLocale().locale;w&&(W=w);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)return c(_({value:e,type:M,timezone:H}));c(e)},U=t.useTimeFieldState(k({onChange:j,label:b,locale:W,value:d,granularity:(null!=h?h:F)?"second":"minute",hideTimeZone:!E,isDisabled:u,shouldForceLeadingZeros:!0},B)),K=a.useRef(null),G=n.useTimeField(k({},B,{label:b}),U,K),J=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:P-N(d.minute,P)}));case"subtract":return j(d.subtract({minutes:N(d.minute-1,P)+1}))}};return a.createElement(r.I18nProvider,{locale:W},a.createElement(i.BaseFormControl,{append:a.createElement("div",{style:{display:"flex",alignItems:"center"}},Z,a.createElement(Y,{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({},J,{"aria-describedby":z+"description"}),labelTooltip:v,prepend:a.createElement("div",{style:{display:"flex",alignItems:"center"}},a.createElement(Y,{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=E,exports.convertValueToType=_,exports.createCalendar=w,exports.focusSegment=I,exports.getWeekNumberForDate=F,exports.lastMillisecondOfDay=T,exports.modulo=N,exports.nativeDateToDateValue=function(e,a,t,n){return void 0===a&&(a=!1),null===e?null:a?new o.CalendarDate(e.getFullYear(),e.getMonth()+1,e.getDate()):C(e,t,n)},exports.nativeDateToTimeValue=function(e,a,t,n){return void 0===a&&(a=!1),null===e?null:a?new o.Time(e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()):C(e,t,n)},exports.timeOrDateValueToNativeDate=function(e,a){if(null===e)return null;if(!("day"in e)){var t=new Date;return t.setHours(e.hour),t.setMinutes(e.minute),t.setSeconds(e.second),t.setMilliseconds(e.millisecond),t}return"hour"in e?"timeZone"in e?e.toDate():e.toDate(a||o.getLocalTimeZone()):e.toDate(null!=a?a:o.getLocalTimeZone())};
|
|
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())};
|
|
2
2
|
//# sourceMappingURL=datepicker.cjs.production.min.js.map
|