theme.keycloak.v2.admin.resources.assets.DatePicker-DTJHSI7E.js Maven / Gradle / Ivy
import{_ as ke,bU as xe,m as P,i as Me,cb as Ae,bb as we,bc as oe,V as Oe,K as Le,W as He,U as Ye,am as _e,n as je,o as Ve,a9 as $e,aM as be,cc as Se,b_ as qe,b$ as ze}from"./main-C7ps2lmX.js";import*as o from"react";import n,{useEffect as Ee,useImperativeHandle as Be}from"react";const f=r=>!!(r&&!isNaN(r)),s={calendarMonth:"pf-v5-c-calendar-month",calendarMonthCalendar:"pf-v5-c-calendar-month__calendar",calendarMonthDate:"pf-v5-c-calendar-month__date",calendarMonthDatesCell:"pf-v5-c-calendar-month__dates-cell",calendarMonthDatesRow:"pf-v5-c-calendar-month__dates-row",calendarMonthDay:"pf-v5-c-calendar-month__day",calendarMonthDays:"pf-v5-c-calendar-month__days",calendarMonthHeader:"pf-v5-c-calendar-month__header",calendarMonthHeaderMonth:"pf-v5-c-calendar-month__header-month",calendarMonthHeaderNavControl:"pf-v5-c-calendar-month__header-nav-control",calendarMonthHeaderYear:"pf-v5-c-calendar-month__header-year",dirRtl:"pf-v5-m-dir-rtl",modifiers:{prevMonth:"pf-m-prev-month",nextMonth:"pf-m-next-month",current:"pf-m-current",inRange:"pf-m-in-range",startRange:"pf-m-start-range",endRange:"pf-m-end-range",adjacentMonth:"pf-m-adjacent-month",selected:"pf-m-selected",disabled:"pf-m-disabled",hover:"pf-m-hover",focus:"pf-m-focus"},themeDark:"pf-v5-theme-dark"};var Fe;(function(r){r[r.Sunday=0]="Sunday",r[r.Monday=1]="Monday",r[r.Tuesday=2]="Tuesday",r[r.Wednesday=3]="Wednesday",r[r.Thursday=4]="Thursday",r[r.Friday=5]="Friday",r[r.Saturday=6]="Saturday"})(Fe||(Fe={}));const Ke=(r,l,C,T)=>{const D=new Date(r,l),c=new Date(D);c.setDate(c.getDate()-c.getDay()+C);const S=[];c.getMonth()===D.getMonth()&&c.getDate()!==1&&c.setDate(c.getDate()-7);for(let E=0;E<6;E++){const y=[];for(let F=0;F<7;F++){const x=new Date(c);y.push({date:x,isValid:T.every(k=>k(x))}),c.setDate(c.getDate()+1)}if(S.push(y),c.getMonth()!==D.getMonth())break}return S},_=(r,l)=>r.getFullYear()===l.getFullYear()&&r.getMonth()===l.getMonth()&&r.getDate()===l.getDate(),ge=new Date,Ce=r=>{var{date:l,locale:C=void 0,monthFormat:T=a=>a.toLocaleDateString(C,{month:"long"}),weekdayFormat:D=a=>a.toLocaleDateString(C,{weekday:"narrow"}),longWeekdayFormat:c=a=>a.toLocaleDateString(C,{weekday:"long"}),dayFormat:S=a=>a.getDate(),weekStart:E=0,onChange:y=()=>{},validators:F=[()=>!0],className:x,onSelectToggle:k=()=>{},onMonthChange:j=()=>{},rangeStart:p,prevMonthAriaLabel:m="Previous month",nextMonthAriaLabel:X="Next month",yearInputAriaLabel:se="Select year",cellAriaLabel:J,isDateFocused:Q=!1,inlineProps:w}=r,le=ke(r,["date","locale","monthFormat","weekdayFormat","longWeekdayFormat","dayFormat","weekStart","onChange","validators","className","onSelectToggle","onMonthChange","rangeStart","prevMonthAriaLabel","nextMonthAriaLabel","yearInputAriaLabel","cellAriaLabel","isDateFocused","inlineProps"]);const ce=[0,1,2,3,4,5,6,7,8,9,10,11].map(a=>new Date(1990,a)).map(T),[V,A]=n.useState(!1),ie=f(l)?l:f(p)?p:ge,[i,M]=n.useState(ie),h=a=>a.getFullYear(),O=h(i),[L,R]=n.useState(O.toString()),[g,u]=n.useState(new Date(i)),v=n.useRef(),[b]=n.useState(xe("hidden-month-span")),[W,I]=n.useState(!1),N=a=>F.every(e=>e(a)),$=N(i);Ee(()=>{f(l)&&!_(i,l)?M(l):l||M(ge)},[l]),Ee(()=>{(W||Q)&&$&&v.current&&v.current.focus()},[i,Q,$,v]);const Z=(a,e)=>{M(e),u(e),I(!1),j(a,e),R(h(e).toString())},ee=a=>{const e=new Date(i);a.key==="ArrowUp"?e.setDate(e.getDate()-7):a.key==="ArrowRight"?e.setDate(e.getDate()+1):a.key==="ArrowDown"?e.setDate(e.getDate()+7):a.key==="ArrowLeft"&&e.setDate(e.getDate()-1),e.getTime()!==i.getTime()&&N(e)&&(a.preventDefault(),M(e),u(e),I(!0))},de=a=>q(i.getMonth(),a),q=(a,e)=>new Date(e??i.getFullYear(),a,1),z=1900,me=2100,te=(a,e)=>{if(/^\d{0,4}$/.test(e)&&(R(e),e.length===4)){const t=Number(e);if(t>=z&&t<=me){const d=de(t);M(d),u(d),I(!1),a.target.focus(),j(a,d)}else R(O.toString())}},ae=a=>{let e=i.getMonth()+a,t=i.getFullYear();return e===-1?(e=11,t--):e===12&&(e=0,t++),q(e,t)},B=ae(-1),H=ae(1),ne=i.getFullYear(),K=i.getMonth(),U=n.useMemo(()=>Ke(ne,K,E,F),[ne,K,E,F]);if(!$){const a=U.reduce((e,t)=>[...e,...t],[]).filter(({date:e,isValid:t})=>t&&e.getMonth()===K).map(({date:e})=>({date:e,days:Math.abs(i.getTime()-e.getTime())})).sort((e,t)=>e.days-t.days).map(({date:e})=>e)[0];a&&(M(a),u(a))}const ue=N(g),Y=T(i),re=n.createElement("div",Object.assign({className:P(s.calendarMonth,x)},le),n.createElement("div",{className:s.calendarMonthHeader},n.createElement("div",{className:P(s.calendarMonthHeaderNavControl,s.modifiers.prevMonth)},n.createElement(Me,{variant:"plain","aria-label":m,onClick:a=>Z(a,B)},n.createElement(Ae,{"aria-hidden":!0}))),n.createElement(we,null,n.createElement(oe,{isFill:!0},n.createElement("div",{className:s.calendarMonthHeaderMonth},n.createElement("span",{id:b,hidden:!0},"Month"),n.createElement(Oe,{toggle:a=>n.createElement(Le,{ref:a,onClick:()=>A(!V),isExpanded:V,style:{width:"140px"}},Y),"aria-labelledby":b,isOpen:V,onOpenChange:a=>{A(a),k(a)},onSelect:(a,e)=>{setTimeout(()=>{A(!1),k(!1);const t=q(Number(e));M(t),u(t),I(!1),j(a,t)},0)},selected:Y},n.createElement(He,null,ce.map((a,e)=>n.createElement(Ye,{key:e,value:e,isSelected:a===Y},a)))))),n.createElement(oe,null,n.createElement("div",{className:s.calendarMonthHeaderYear},n.createElement(_e,{"aria-label":se,type:"number",value:L,onChange:te})))),n.createElement("div",{className:P(s.calendarMonthHeaderNavControl,s.modifiers.nextMonth)},n.createElement(Me,{variant:"plain","aria-label":X,onClick:a=>Z(a,H)},n.createElement(je,{"aria-hidden":!0})))),n.createElement("table",{className:s.calendarMonthCalendar},n.createElement("thead",{className:s.calendarMonthDays},n.createElement("tr",null,U[0].map(({date:a},e)=>n.createElement("th",{key:e,className:s.calendarMonthDay,scope:"col"},n.createElement("span",{className:"pf-v5-screen-reader"},c(a)),n.createElement("span",{"aria-hidden":!0},D(a)))))),n.createElement("tbody",{onKeyDown:ee},U.map((a,e)=>n.createElement("tr",{key:e,className:s.calendarMonthDatesRow},a.map(({date:t,isValid:d},he)=>{const Te=S(t),Re=_(t,ge),Ie=f(l)&&_(t,l),ye=_(t,i),Ne=t.getMonth()!==i.getMonth(),pe=f(p)&&_(t,p);let fe=!1,G=!1;return f(p)&&f(l)?(fe=t>p&&tp||_(g,p))&&(fe=t>p&&ty(Pe,t),onMouseOver:()=>u(t),tabIndex:ye?0:-1,disabled:!d,"aria-label":J?J(t):`${S(t)} ${T(t)} ${h(t)}`},ye&&{ref:v}),Te))}))))));if(w!==void 0){const a=w.component?w.component:"article";return n.createElement(a,Object.assign({},w.ariaLabelledby&&{"aria-labelledby":w.ariaLabelledby}),w.title,re)}return re};Ce.displayName="CalendarMonth";const ve={datePicker:"pf-v5-c-date-picker",datePickerCalendar:"pf-v5-c-date-picker__calendar",datePickerHelperText:"pf-v5-c-date-picker__helper-text",datePickerInput:"pf-v5-c-date-picker__input",formControl:"pf-v5-c-form-control",modifiers:{alignRight:"pf-m-align-right",top:"pf-m-top",static:"pf-m-static"},themeDark:"pf-v5-theme-dark"},Ue={name:"OutlinedCalendarAltIcon",height:512,width:448,svgPath:"M148 288h-40c-6.6 0-12-5.4-12-12v-40c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12zm108-12v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm96 0v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm-96 96v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm-96 0v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm192 0v-40c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12zm96-260v352c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V112c0-26.5 21.5-48 48-48h48V12c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v52h128V12c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v52h48c26.5 0 48 21.5 48 48zm-48 346V160H48v298c0 3.3 2.7 6 6 6h340c3.3 0 6-2.7 6-6z",yOffset:0,xOffset:0},Ge=Ve(Ue),Xe={name:"--pf-v5-c-date-picker__input--c-form-control--width-chars",value:"10",var:"var(--pf-v5-c-date-picker__input--c-form-control--width-chars)"},Je=r=>`${r.getFullYear()}-${(r.getMonth()+1).toString().padStart(2,"0")}-${r.getDate().toString().padStart(2,"0")}`,Qe=(r,l)=>{var{className:C,locale:T=void 0,dateFormat:D=Je,dateParse:c=e=>e.split("-").length===3?new Date(`${e}T00:00:00`):new Date(void 0),isDisabled:S=!1,placeholder:E="YYYY-MM-DD",value:y="","aria-label":F="Date picker",buttonAriaLabel:x="Toggle date picker",onChange:k=()=>{},onBlur:j=()=>{},invalidFormatText:p="Invalid date",requiredDateOptions:m,helperText:X,appendTo:se="inline",popoverProps:J,monthFormat:Q,weekdayFormat:w,longWeekdayFormat:le,dayFormat:ce,weekStart:V,validators:A=[],rangeStart:De,style:ie={},inputProps:i={}}=r,M=ke(r,["className","locale","dateFormat","dateParse","isDisabled","placeholder","value","aria-label","buttonAriaLabel","onChange","onBlur","invalidFormatText","requiredDateOptions","helperText","appendTo","popoverProps","monthFormat","weekdayFormat","longWeekdayFormat","dayFormat","weekStart","validators","rangeStart","style","inputProps"]);const[h,O]=o.useState(y),[L,R]=o.useState(c(h)),[g,u]=o.useState(""),[v,b]=o.useState(!1),[W,I]=o.useState(!1),[N,$]=o.useState(!0),[Z,ee]=o.useState(!1),de=o.useMemo(()=>Math.max(D(new Date).length,E.length),[D]),q=Object.assign({[Xe.name]:de},ie),z=o.useRef(),me=o.useRef(),te=o.useRef(),ae=m?.isRequired||!1,B=m?.emptyDateText||"Date cannot be blank";o.useEffect(()=>{O(y),R(c(y))},[y]),o.useEffect(()=>{$(!h);const e=c(h);g&&f(e)&&H(e),h===""&&!N&&!Z&&u(ae?B:"")},[h]);const H=e=>{u(A.map(t=>t(e)).join(`
`)||"")},ne=(e,t)=>{O(t),u("");const d=c(t);R(d),f(d)?k(e,t,new Date(d)):k(e,t)},K=e=>{ee(!1);const t=c(h),d=f(t),he=d?new Date(t):void 0;j(e,h,he),d&&H(t),!d&&!N&&u(p),!d&&N&&m?.isRequired&&u(B)},U=(e,t)=>{const d=D(t);O(d),R(t),H(t),b(!1),k(null,d,new Date(t))},ue=e=>{e.key==="Enter"&&h&&(f(L)?H(L):u(p))};Be(l,()=>({setCalendarOpen:e=>b(e),toggleCalendar:e=>{b(t=>e!==void 0?e:!t)},isCalendarOpen:v}),[b,v,W]);const Y=e=>`.${s.calendarMonthDatesCell}.${e} .${s.calendarMonthDate}`,re=Y(s.modifiers.selected),a=Y(s.modifiers.current);return o.createElement("div",Object.assign({className:P(ve.datePicker,C),ref:me,style:q},M),o.createElement($e,Object.assign({elementToFocus:f(L)?re:a,position:"bottom",bodyContent:o.createElement(Ce,{date:L,onChange:U,locale:T,validators:A.map(e=>t=>!e(t)),onSelectToggle:e=>I(e),monthFormat:Q,weekdayFormat:w,longWeekdayFormat:le,dayFormat:ce,weekStart:V,rangeStart:De}),showClose:!1,isVisible:v,shouldClose:(e,t)=>(e=e,e.key===be.Escape&&W?(e.stopPropagation(),I(!1),!1):z.current&&z.current.contains(e.target)?!1:(v&&(e.stopPropagation(),b(!1),t(),m?.isRequired&&!h&&u(B)),e.key===be.Escape&&v&&e.stopPropagation(),!0)),withFocusTrap:!0,hasNoPadding:!0,hasAutoWidth:!0,appendTo:se,triggerRef:te},J),o.createElement("div",{className:ve.datePickerInput,ref:te},o.createElement(we,null,o.createElement(oe,null,o.createElement(_e,Object.assign({isDisabled:S,isRequired:m?.isRequired,"aria-label":F,placeholder:E,validated:g.trim()?"error":"default",value:h,onChange:ne,onBlur:K,onFocus:()=>ee(!0),onKeyPress:ue},i))),o.createElement(oe,null,o.createElement("button",{ref:z,className:P(Se.button,Se.modifiers.control),"aria-label":x,type:"button",onClick:()=>b(!v),disabled:S},o.createElement(Ge,null)))))),(g||X)&&o.createElement("div",{className:ve.datePickerHelperText},g?o.createElement(qe,null,o.createElement(ze,{variant:"error"},g)):X))},We=o.forwardRef(Qe);We.displayName="DatePicker";export{We as D,ve as d};
//# sourceMappingURL=DatePicker-DTJHSI7E.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy