PageSourceSearch

https://portal.commoninterest.com/assets/DatePicker-CHF9-gLW.js

js commoninterest.com collected 2026-09-24 13:28:38 UTC 5,334 bytes, 1 lines download raw bytes

1import{r as s,a as V,j as n,q as j,F as L,dU as G,dV as U,b7 as K}from"./elements-DVh2jUIM.js";import{D as J}from"./datepicker-B9D4iLeH.js";import{i as Q}from"./isSameDay-CQTDJwZ-.js";import"./startOfDay-AazlW55I.js";const W="datepicker-day-recommended",X=()=>{const f=[];for(let a=0;a<24;a++)for(let e=0;e<60;e+=15){const w=a,y=e,l=a>=12?"PM":"AM",i=`${a%12||12}:${String(e).padStart(2,"0")} ${l}`,x=`${String(a).padStart(2,"0")}:${String(e).padStart(2,"0")}`;f.push({value:x,display:i,hours:w,minutes:y})}return f},Y=X(),Z=(f,a)=>{const e=f>=12?"PM":"AM";return`${f%12||12}:${String(a).padStart(2,"0")} ${e}`},st=({className:f,label:a,value:e,placeholder:w,error:y,minDate:l,onChange:o,disabled:i=!1,beforeShowDay:x,highlightDate:k,useMinDate:N=!0,showTimePicker:m=!1,id:$,popupContainer:b,"data-qa":T="date-input"})=>{const S=s.useRef(null),c=s.useRef(null),g=s.useRef(null),h=s.useRef(null),[p,v]=s.useState(!1),[I,P]=s.useState({top:0,left:0}),[A,M]=s.useState(()=>{if(e){const t=e.getHours(),r=Math.floor(e.getMinutes()/15)*15;return`${String(t).padStart(2,"0")}:${String(r).padStart(2,"0")}`}return"12:00"}),E=s.useCallback(t=>{const r=k&&Q(t,k)?W:"",u=x==null?void 0:x(t);if(u==null)return r?{classes:r}:!0;const d=typeof u=="boolean"?{enabled:u}:typeof u=="string"?{classes:u}:u,O=[r,d.classes].filter(Boolean).join(" ");return{...d,...O&&{classes:O}}},[k,x]),D=s.useCallback(t=>{if(!t.target||!(t.target instanceof HTMLInputElement)||typeof t.target.value!="string")return;if(t.target.value===""){o==null||o(void 0);return}const r=new Date(t.target.value);m&&e&&r.setHours(e.getHours(),e.getMinutes(),0,0),o==null||o(r)},[o,m,e]),R=t=>{t.key==="Enter"&&t.preventDefault()},q=t=>{t.stopPropagation(),!i&&c.current&&c.current.show()},H=s.useCallback(()=>{if(g.current){const t=g.current.getBoundingClientRect();P({top:t.bottom+4,left:t.right-128})}},[]),B=t=>{t.stopPropagation(),!i&&(H(),v(!p))},F=(t,r)=>{const u=`${String(t).padStart(2,"0")}:${String(r).padStart(2,"0")}`;if(M(u),v(!1),e){const d=new Date(e);d.setHours(t,r,0,0),o==null||o(d)}else{const d=new Date;d.setHours(t,r,0,0),o==null||o(d)}};s.useEffect(()=>{const t=r=>{h.current&&!h.current.contains(r.target)&&g.current&&!g.current.contains(r.target)&&v(!1)};return p&&document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t)}},[p]),s.useEffect(()=>{if(!p)return;const t=()=>{H()};return window.addEventListener("scroll",t,!0),window.addEventListener("resize",t),()=>{window.removeEventListener("scroll",t,!0),window.removeEventListener("resize",t)}},[p,H]),s.useEffect(()=>{if(e&&m){const t=e.getHours(),r=Math.floor(e.getMinutes()/15)*15;M(`${String(t).padStart(2,"0")}:${String(r).padStart(2,"0")}`)}},[e,m]),s.useEffect(()=>{if(!S.current||!(S.current instanceof HTMLInputElement))return;const t=S.current;return c.current||(c.current=new J(t,{autohide:!0,showOnFocus:!1,minDate:l,beforeShowDay:E,...b?{container:b}:{}}),t.addEventListener("changeDate",D),t.addEventListener("keydown",R)),()=>{c.current&&(t.removeEventListener("changeDate",D),t.removeEventListener("keydown",R),c.current.destroy(),c.current=null)}},[E,D,l,b]),s.useEffect(()=>{c.current&&(c.current.setOptions({minDate:l,beforeShowDay:E}),c.current.refresh())},[l,E]),s.useEffect(()=>{if(!c.current)return;const t=c.current.getDate(),r=e||(N?l:void 0);t!==r&&c.current.setDate(r)},[e,l,N]);const _=()=>e?Z(e.getHours(),e.getMinutes()):"",z=p?V.createPortal(n.jsx("div",{ref:h,className:"fixed bg-white border border-base-border rounded-lg shadow-lg max-h-60 overflow-y-auto w-32",style:{top:I.top,left:I.left,zIndex:9999},children:Y.map(t=>n.jsx("button",{type:"button",onClick:()=>F(t.hours,t.minutes),className:j("w-full px-3 py-2 text-sm text-left hover:bg-base-hover transition-colors",A===t.value&&"bg-primary/10 text-primary font-medium"),children:t.display},t.value))}),b&&document.querySelector(b)||document.body):null;return n.jsxs("div",{className:f,children:[a&&n.jsx("label",{htmlFor:$,className:"block text-sm font-medium text-base-header mb-1",children:a}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{id:$,ref:S,"data-qa":T,type:"text",placeholder:w,defaultValue:e==null?void 0:e.toLocaleDateString(),disabled:i,className:j("block w-full appearance-none rounded-md border-input-border shadow-sm","sm:text-sm bg-input-bg focus:border-input-active","focus:ring-input-active",m?"pr-16":"pr-9")}),n.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 mt-0.5 flex items-center gap-1",children:[n.jsx("button",{type:"button",onClick:q,disabled:i,className:j("p-1 rounded hover:bg-base-hover transition-colors",i?"cursor-not-allowed opacity-50":"cursor-pointer"),"aria-label":"Open date picker",children:n.jsx(L,{icon:G,className:"w-4 h-4 text-base-icon"})}),m&&n.jsx("button",{ref:g,type:"button",onClick:B,disabled:i,className:j("p-1 rounded hover:bg-base-hover transition-colors",i?"cursor-not-allowed opacity-50":"cursor-pointer",p&&"bg-base-hover"),"aria-label":"Open time picker",children:n.jsx(L,{icon:U,className:"w-4 h-4 text-base-icon"})})]})]}),m&&e&&n.jsx("p",{className:"mt-1 text-xs text-base-fg/60",children:_()}),y&&n.jsxs("p",{className:"mt-1 text-xs text-error inline-flex items-center",children:[n.jsx(L,{icon:K,className:"w-3 h-3 mr-1"}),n.jsx("span",{children:y})]}),z]})};export{st as DatePicker};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.