UNPKG

@cameratajs/react-date-range-input

Version:

A lightweight, customizable React Date Range Input component with popup calendar(s). Built with TypeScript and Pure CSS.

12 lines (11 loc) 33.8 kB
import*as e from"react";import t,{useState as n,useEffect as r,useRef as a}from"react";var o,i={exports:{}},s={};var c,u,l={}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */function d(){return c||(c=1,"production"!==process.env.NODE_ENV&&function(){function e(t){if(null==t)return null;if("function"==typeof t)return t.$$typeof===D?null:t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case m:return"Fragment";case p:return"Profiler";case g:return"StrictMode";case v:return"Suspense";case k:return"SuspenseList";case S:return"Activity"}if("object"==typeof t)switch("number"==typeof t.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case h:return"Portal";case b:return(t.displayName||"Context")+".Provider";case y:return(t._context.displayName||"Context")+".Consumer";case w:var n=t.render;return(t=t.displayName)||(t=""!==(t=n.displayName||n.name||"")?"ForwardRef("+t+")":"ForwardRef"),t;case x:return null!==(n=t.displayName||null)?n:e(t.type)||"Memo";case M:n=t._payload,t=t._init;try{return e(t(n))}catch(e){}}return null}function n(e){return""+e}function r(e){try{n(e);var t=!1}catch(e){t=!0}if(t){var r=(t=console).error,a="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return r.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",a),n(e)}}function a(t){if(t===m)return"<>";if("object"==typeof t&&null!==t&&t.$$typeof===M)return"<...>";try{var n=e(t);return n?"<"+n+">":"<...>"}catch(e){return"<...>"}}function o(){return Error("react-stack-top-frame")}function i(){var t=e(this.type);return O[t]||(O[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(t=this.props.ref)?t:null}function s(t,n,a,o,s,l,d,h){var m,g=n.children;if(void 0!==g)if(o)if(C(g)){for(o=0;o<g.length;o++)c(g[o]);Object.freeze&&Object.freeze(g)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else c(g);if(P.call(n,"key")){g=e(t);var p=Object.keys(n).filter((function(e){return"key"!==e}));o=0<p.length?"{key: someKey, "+p.join(": ..., ")+": ...}":"{key: someKey}",W[g+o]||(p=0<p.length?"{"+p.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',o,g,p,g),W[g+o]=!0)}if(g=null,void 0!==a&&(r(a),g=""+a),function(e){if(P.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(n)&&(r(n.key),g=""+n.key),"key"in n)for(var y in a={},n)"key"!==y&&(a[y]=n[y]);else a=n;return g&&function(e,t){function n(){u||(u=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(a,"function"==typeof t?t.displayName||t.name||"Unknown":t),function(e,t,n,r,a,o,s,c){return n=o.ref,e={$$typeof:f,type:e,key:t,props:o,_owner:a},null!==(void 0!==n?n:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:i}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:s}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:c}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(t,g,l,0,null===(m=j.A)?null:m.getOwner(),a,d,h)}function c(e){"object"==typeof e&&null!==e&&e.$$typeof===f&&e._store&&(e._store.validated=1)}var u,d=t,f=Symbol.for("react.transitional.element"),h=Symbol.for("react.portal"),m=Symbol.for("react.fragment"),g=Symbol.for("react.strict_mode"),p=Symbol.for("react.profiler"),y=Symbol.for("react.consumer"),b=Symbol.for("react.context"),w=Symbol.for("react.forward_ref"),v=Symbol.for("react.suspense"),k=Symbol.for("react.suspense_list"),x=Symbol.for("react.memo"),M=Symbol.for("react.lazy"),S=Symbol.for("react.activity"),D=Symbol.for("react.client.reference"),j=d.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=Object.prototype.hasOwnProperty,C=Array.isArray,N=console.createTask?console.createTask:function(){return null},O={},T=(d={"react-stack-bottom-frame":function(e){return e()}})["react-stack-bottom-frame"].bind(d,o)(),E=N(a(o)),W={};l.Fragment=m,l.jsx=function(e,t,n,r,o){var i=1e4>j.recentlyCreatedOwnerStacks++;return s(e,t,n,!1,0,o,i?Error("react-stack-top-frame"):T,i?N(a(e)):E)},l.jsxs=function(e,t,n,r,o){var i=1e4>j.recentlyCreatedOwnerStacks++;return s(e,t,n,!0,0,o,i?Error("react-stack-top-frame"):T,i?N(a(e)):E)}}()),l}var f=(u||(u=1,"production"===process.env.NODE_ENV?i.exports=function(){if(o)return s;o=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(t,n,r){var a=null;if(void 0!==r&&(a=""+r),void 0!==n.key&&(a=""+n.key),"key"in n)for(var o in r={},n)"key"!==o&&(r[o]=n[o]);else r=n;return n=r.ref,{$$typeof:e,type:t,key:a,ref:void 0!==n?n:null,props:r}}return s.Fragment=t,s.jsx=n,s.jsxs=n,s}():i.exports=d()),i.exports);const h=6048e5,m=Symbol.for("constructDateFrom");function g(e,t){return"function"==typeof e?e(t):e&&"object"==typeof e&&m in e?e[m](t):e instanceof Date?new e.constructor(t):new Date(t)}function p(e,t){return g(t||e,e)}function y(e,t,n){const r=p(e,n?.in);if(isNaN(t))return g(e,NaN);if(!t)return r;const a=r.getDate(),o=g(e,r.getTime());o.setMonth(r.getMonth()+t+1,0);return a>=o.getDate()?o:(r.setFullYear(o.getFullYear(),o.getMonth(),a),r)}let b={};function w(){return b}function v(e,t){const n=w(),r=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,a=p(e,t?.in),o=a.getDay(),i=(o<r?7:0)+o-r;return a.setDate(a.getDate()-i),a.setHours(0,0,0,0),a}function k(e,t){return v(e,{...t,weekStartsOn:1})}function x(e,t){const n=p(e,t?.in),r=n.getFullYear(),a=g(n,0);a.setFullYear(r+1,0,4),a.setHours(0,0,0,0);const o=k(a),i=g(n,0);i.setFullYear(r,0,4),i.setHours(0,0,0,0);const s=k(i);return n.getTime()>=o.getTime()?r+1:n.getTime()>=s.getTime()?r:r-1}function M(e){const t=p(e),n=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return n.setUTCFullYear(t.getFullYear()),+e-+n}function S(e,...t){const n=g.bind(null,t.find((e=>"object"==typeof e)));return t.map(n)}function D(e,t){const n=p(e,t?.in);return n.setHours(0,0,0,0),n}function j(e,t,n){const[r,a]=S(0,e,t);return+D(r)==+D(a)}function P(e){return!(!((t=e)instanceof Date||"object"==typeof t&&"[object Date]"===Object.prototype.toString.call(t))&&"number"!=typeof e||isNaN(+p(e)));var t}const C={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};function N(e){return(t={})=>{const n=t.width?String(t.width):e.defaultWidth;return e.formats[n]||e.formats[e.defaultWidth]}}const O={date:N({formats:{full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},defaultWidth:"full"}),time:N({formats:{full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},defaultWidth:"full"}),dateTime:N({formats:{full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},T={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"};function E(e){return(t,n)=>{let r;if("formatting"===(n?.context?String(n.context):"standalone")&&e.formattingValues){const t=e.defaultFormattingWidth||e.defaultWidth,a=n?.width?String(n.width):t;r=e.formattingValues[a]||e.formattingValues[t]}else{const t=e.defaultWidth,a=n?.width?String(n.width):e.defaultWidth;r=e.values[a]||e.values[t]}return r[e.argumentCallback?e.argumentCallback(t):t]}}function W(e){return(t,n={})=>{const r=n.width,a=r&&e.matchPatterns[r]||e.matchPatterns[e.defaultMatchWidth],o=t.match(a);if(!o)return null;const i=o[0],s=r&&e.parsePatterns[r]||e.parsePatterns[e.defaultParseWidth],c=Array.isArray(s)?function(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return n;return}(s,(e=>e.test(i))):function(e,t){for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t(e[n]))return n;return}(s,(e=>e.test(i)));let u;u=e.valueCallback?e.valueCallback(c):c,u=n.valueCallback?n.valueCallback(u):u;return{value:u,rest:t.slice(i.length)}}}var Y;const F={code:"en-US",formatDistance:(e,t,n)=>{let r;const a=C[e];return r="string"==typeof a?a:1===t?a.one:a.other.replace("{{count}}",t.toString()),n?.addSuffix?n.comparison&&n.comparison>0?"in "+r:r+" ago":r},formatLong:O,formatRelative:(e,t,n,r)=>T[e],localize:{ordinalNumber:(e,t)=>{const n=Number(e),r=n%100;if(r>20||r<10)switch(r%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},era:E({values:{narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},defaultWidth:"wide"}),quarter:E({values:{narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},defaultWidth:"wide",argumentCallback:e=>e-1}),month:E({values:{narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},defaultWidth:"wide"}),day:E({values:{narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},defaultWidth:"wide"}),dayPeriod:E({values:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},defaultWidth:"wide",formattingValues:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},defaultFormattingWidth:"wide"})},match:{ordinalNumber:(Y={matchPattern:/^(\d+)(th|st|nd|rd)?/i,parsePattern:/\d+/i,valueCallback:e=>parseInt(e,10)},(e,t={})=>{const n=e.match(Y.matchPattern);if(!n)return null;const r=n[0],a=e.match(Y.parsePattern);if(!a)return null;let o=Y.valueCallback?Y.valueCallback(a[0]):a[0];return o=t.valueCallback?t.valueCallback(o):o,{value:o,rest:e.slice(r.length)}}),era:W({matchPatterns:{narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^b/i,/^(a|c)/i]},defaultParseWidth:"any"}),quarter:W({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},defaultMatchWidth:"wide",parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:"any",valueCallback:e=>e+1}),month:W({matchPatterns:{narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},defaultParseWidth:"any"}),day:W({matchPatterns:{narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},defaultParseWidth:"any"}),dayPeriod:W({matchPatterns:{narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},defaultParseWidth:"any"})},options:{weekStartsOn:0,firstWeekContainsDate:1}};function R(e,t){const n=p(e,t?.in),r=function(e,t){const[n,r]=S(0,e,t),a=D(n),o=D(r),i=+a-M(a),s=+o-M(o);return Math.round((i-s)/864e5)}(n,function(e,t){const n=p(e,t?.in);return n.setFullYear(n.getFullYear(),0,1),n.setHours(0,0,0,0),n}(n));return r+1}function H(e,t){const n=p(e,t?.in),r=+k(n)-+function(e,t){const n=x(e,t),r=g(e,0);return r.setFullYear(n,0,4),r.setHours(0,0,0,0),k(r)}(n);return Math.round(r/h)+1}function q(e,t){const n=p(e,t?.in),r=n.getFullYear(),a=w(),o=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??a.firstWeekContainsDate??a.locale?.options?.firstWeekContainsDate??1,i=g(t?.in||e,0);i.setFullYear(r+1,0,o),i.setHours(0,0,0,0);const s=v(i,t),c=g(t?.in||e,0);c.setFullYear(r,0,o),c.setHours(0,0,0,0);const u=v(c,t);return+n>=+s?r+1:+n>=+u?r:r-1}function z(e,t){const n=p(e,t?.in),r=+v(n,t)-+function(e,t){const n=w(),r=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??n.firstWeekContainsDate??n.locale?.options?.firstWeekContainsDate??1,a=q(e,t),o=g(t?.in||e,0);return o.setFullYear(a,0,r),o.setHours(0,0,0,0),v(o,t)}(n,t);return Math.round(r/h)+1}function A(e,t){return(e<0?"-":"")+Math.abs(e).toString().padStart(t,"0")}const L={y(e,t){const n=e.getFullYear(),r=n>0?n:1-n;return A("yy"===t?r%100:r,t.length)},M(e,t){const n=e.getMonth();return"M"===t?String(n+1):A(n+1,2)},d:(e,t)=>A(e.getDate(),t.length),a(e,t){const n=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];default:return"am"===n?"a.m.":"p.m."}},h:(e,t)=>A(e.getHours()%12||12,t.length),H:(e,t)=>A(e.getHours(),t.length),m:(e,t)=>A(e.getMinutes(),t.length),s:(e,t)=>A(e.getSeconds(),t.length),S(e,t){const n=t.length,r=e.getMilliseconds();return A(Math.trunc(r*Math.pow(10,n-3)),t.length)}},_="midnight",B="noon",$="morning",X="afternoon",Q="evening",G="night",I={G:function(e,t,n){const r=e.getFullYear()>0?1:0;switch(t){case"G":case"GG":case"GGG":return n.era(r,{width:"abbreviated"});case"GGGGG":return n.era(r,{width:"narrow"});default:return n.era(r,{width:"wide"})}},y:function(e,t,n){if("yo"===t){const t=e.getFullYear(),r=t>0?t:1-t;return n.ordinalNumber(r,{unit:"year"})}return L.y(e,t)},Y:function(e,t,n,r){const a=q(e,r),o=a>0?a:1-a;if("YY"===t){return A(o%100,2)}return"Yo"===t?n.ordinalNumber(o,{unit:"year"}):A(o,t.length)},R:function(e,t){return A(x(e),t.length)},u:function(e,t){return A(e.getFullYear(),t.length)},Q:function(e,t,n){const r=Math.ceil((e.getMonth()+1)/3);switch(t){case"Q":return String(r);case"QQ":return A(r,2);case"Qo":return n.ordinalNumber(r,{unit:"quarter"});case"QQQ":return n.quarter(r,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(r,{width:"narrow",context:"formatting"});default:return n.quarter(r,{width:"wide",context:"formatting"})}},q:function(e,t,n){const r=Math.ceil((e.getMonth()+1)/3);switch(t){case"q":return String(r);case"qq":return A(r,2);case"qo":return n.ordinalNumber(r,{unit:"quarter"});case"qqq":return n.quarter(r,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(r,{width:"narrow",context:"standalone"});default:return n.quarter(r,{width:"wide",context:"standalone"})}},M:function(e,t,n){const r=e.getMonth();switch(t){case"M":case"MM":return L.M(e,t);case"Mo":return n.ordinalNumber(r+1,{unit:"month"});case"MMM":return n.month(r,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(r,{width:"narrow",context:"formatting"});default:return n.month(r,{width:"wide",context:"formatting"})}},L:function(e,t,n){const r=e.getMonth();switch(t){case"L":return String(r+1);case"LL":return A(r+1,2);case"Lo":return n.ordinalNumber(r+1,{unit:"month"});case"LLL":return n.month(r,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(r,{width:"narrow",context:"standalone"});default:return n.month(r,{width:"wide",context:"standalone"})}},w:function(e,t,n,r){const a=z(e,r);return"wo"===t?n.ordinalNumber(a,{unit:"week"}):A(a,t.length)},I:function(e,t,n){const r=H(e);return"Io"===t?n.ordinalNumber(r,{unit:"week"}):A(r,t.length)},d:function(e,t,n){return"do"===t?n.ordinalNumber(e.getDate(),{unit:"date"}):L.d(e,t)},D:function(e,t,n){const r=R(e);return"Do"===t?n.ordinalNumber(r,{unit:"dayOfYear"}):A(r,t.length)},E:function(e,t,n){const r=e.getDay();switch(t){case"E":case"EE":case"EEE":return n.day(r,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(r,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(r,{width:"short",context:"formatting"});default:return n.day(r,{width:"wide",context:"formatting"})}},e:function(e,t,n,r){const a=e.getDay(),o=(a-r.weekStartsOn+8)%7||7;switch(t){case"e":return String(o);case"ee":return A(o,2);case"eo":return n.ordinalNumber(o,{unit:"day"});case"eee":return n.day(a,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(a,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(a,{width:"short",context:"formatting"});default:return n.day(a,{width:"wide",context:"formatting"})}},c:function(e,t,n,r){const a=e.getDay(),o=(a-r.weekStartsOn+8)%7||7;switch(t){case"c":return String(o);case"cc":return A(o,t.length);case"co":return n.ordinalNumber(o,{unit:"day"});case"ccc":return n.day(a,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(a,{width:"narrow",context:"standalone"});case"cccccc":return n.day(a,{width:"short",context:"standalone"});default:return n.day(a,{width:"wide",context:"standalone"})}},i:function(e,t,n){const r=e.getDay(),a=0===r?7:r;switch(t){case"i":return String(a);case"ii":return A(a,t.length);case"io":return n.ordinalNumber(a,{unit:"day"});case"iii":return n.day(r,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(r,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(r,{width:"short",context:"formatting"});default:return n.day(r,{width:"wide",context:"formatting"})}},a:function(e,t,n){const r=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(r,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(r,{width:"narrow",context:"formatting"});default:return n.dayPeriod(r,{width:"wide",context:"formatting"})}},b:function(e,t,n){const r=e.getHours();let a;switch(a=12===r?B:0===r?_:r/12>=1?"pm":"am",t){case"b":case"bb":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(a,{width:"narrow",context:"formatting"});default:return n.dayPeriod(a,{width:"wide",context:"formatting"})}},B:function(e,t,n){const r=e.getHours();let a;switch(a=r>=17?Q:r>=12?X:r>=4?$:G,t){case"B":case"BB":case"BBB":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(a,{width:"narrow",context:"formatting"});default:return n.dayPeriod(a,{width:"wide",context:"formatting"})}},h:function(e,t,n){if("ho"===t){let t=e.getHours()%12;return 0===t&&(t=12),n.ordinalNumber(t,{unit:"hour"})}return L.h(e,t)},H:function(e,t,n){return"Ho"===t?n.ordinalNumber(e.getHours(),{unit:"hour"}):L.H(e,t)},K:function(e,t,n){const r=e.getHours()%12;return"Ko"===t?n.ordinalNumber(r,{unit:"hour"}):A(r,t.length)},k:function(e,t,n){let r=e.getHours();return 0===r&&(r=24),"ko"===t?n.ordinalNumber(r,{unit:"hour"}):A(r,t.length)},m:function(e,t,n){return"mo"===t?n.ordinalNumber(e.getMinutes(),{unit:"minute"}):L.m(e,t)},s:function(e,t,n){return"so"===t?n.ordinalNumber(e.getSeconds(),{unit:"second"}):L.s(e,t)},S:function(e,t){return L.S(e,t)},X:function(e,t,n){const r=e.getTimezoneOffset();if(0===r)return"Z";switch(t){case"X":return U(r);case"XXXX":case"XX":return V(r);default:return V(r,":")}},x:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"x":return U(r);case"xxxx":case"xx":return V(r);default:return V(r,":")}},O:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"O":case"OO":case"OOO":return"GMT"+J(r,":");default:return"GMT"+V(r,":")}},z:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"z":case"zz":case"zzz":return"GMT"+J(r,":");default:return"GMT"+V(r,":")}},t:function(e,t,n){return A(Math.trunc(+e/1e3),t.length)},T:function(e,t,n){return A(+e,t.length)}};function J(e,t=""){const n=e>0?"-":"+",r=Math.abs(e),a=Math.trunc(r/60),o=r%60;return 0===o?n+String(a):n+String(a)+t+A(o,2)}function U(e,t){if(e%60==0){return(e>0?"-":"+")+A(Math.abs(e)/60,2)}return V(e,t)}function V(e,t=""){const n=e>0?"-":"+",r=Math.abs(e);return n+A(Math.trunc(r/60),2)+t+A(r%60,2)}const K=(e,t)=>{switch(e){case"P":return t.date({width:"short"});case"PP":return t.date({width:"medium"});case"PPP":return t.date({width:"long"});default:return t.date({width:"full"})}},Z=(e,t)=>{switch(e){case"p":return t.time({width:"short"});case"pp":return t.time({width:"medium"});case"ppp":return t.time({width:"long"});default:return t.time({width:"full"})}},ee={p:Z,P:(e,t)=>{const n=e.match(/(P+)(p+)?/)||[],r=n[1],a=n[2];if(!a)return K(e,t);let o;switch(r){case"P":o=t.dateTime({width:"short"});break;case"PP":o=t.dateTime({width:"medium"});break;case"PPP":o=t.dateTime({width:"long"});break;default:o=t.dateTime({width:"full"})}return o.replace("{{date}}",K(r,t)).replace("{{time}}",Z(a,t))}},te=/^D+$/,ne=/^Y+$/,re=["D","DD","YY","YYYY"];const ae=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,oe=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,ie=/^'([^]*?)'?$/,se=/''/g,ce=/[a-zA-Z]/;function ue(e,t,n){const r=w(),a=r.locale??F,o=r.firstWeekContainsDate??r.locale?.options?.firstWeekContainsDate??1,i=r.weekStartsOn??r.locale?.options?.weekStartsOn??0,s=p(e,n?.in);if(!P(s))throw new RangeError("Invalid time value");let c=t.match(oe).map((e=>{const t=e[0];if("p"===t||"P"===t){return(0,ee[t])(e,a.formatLong)}return e})).join("").match(ae).map((e=>{if("''"===e)return{isToken:!1,value:"'"};const t=e[0];if("'"===t)return{isToken:!1,value:le(e)};if(I[t])return{isToken:!0,value:e};if(t.match(ce))throw new RangeError("Format string contains an unescaped latin alphabet character `"+t+"`");return{isToken:!1,value:e}}));a.localize.preprocessor&&(c=a.localize.preprocessor(s,c));const u={firstWeekContainsDate:o,weekStartsOn:i,locale:a};return c.map((n=>{if(!n.isToken)return n.value;const r=n.value;(function(e){return ne.test(e)}(r)||function(e){return te.test(e)}(r))&&function(e,t,n){const r=function(e,t,n){const r="Y"===e[0]?"years":"days of the month";return`Use \`${e.toLowerCase()}\` instead of \`${e}\` (in \`${t}\`) for formatting ${r} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}(e,t,n);if(console.warn(r),re.includes(e))throw new RangeError(r)}(r,t,String(e));return(0,I[r[0]])(s,r,a.localize,u)})).join("")}function le(e){const t=e.match(ie);return t?t[1].replace(se,"'"):e}function de({title:t,titleId:n,...r},a){return e.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":n},r),t?e.createElement("title",{id:n},t):null,e.createElement("path",{fillRule:"evenodd",d:"M11.03 3.97a.75.75 0 0 1 0 1.06l-6.22 6.22H21a.75.75 0 0 1 0 1.5H4.81l6.22 6.22a.75.75 0 1 1-1.06 1.06l-7.5-7.5a.75.75 0 0 1 0-1.06l7.5-7.5a.75.75 0 0 1 1.06 0Z",clipRule:"evenodd"}))}const fe=e.forwardRef(de);function he({title:t,titleId:n,...r},a){return e.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":n},r),t?e.createElement("title",{id:n},t):null,e.createElement("path",{fillRule:"evenodd",d:"M12.97 3.97a.75.75 0 0 1 1.06 0l7.5 7.5a.75.75 0 0 1 0 1.06l-7.5 7.5a.75.75 0 1 1-1.06-1.06l6.22-6.22H3a.75.75 0 0 1 0-1.5h16.19l-6.22-6.22a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const me=e.forwardRef(he);function ge({title:t,titleId:n,...r},a){return e.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:a,"aria-labelledby":n},r),t?e.createElement("title",{id:n},t):null,e.createElement("path",{fillRule:"evenodd",d:"M5.47 5.47a.75.75 0 0 1 1.06 0L12 10.94l5.47-5.47a.75.75 0 1 1 1.06 1.06L13.06 12l5.47 5.47a.75.75 0 1 1-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 0 1-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const pe=e.forwardRef(ge);function ye(e){var t,n,r="";if("string"==typeof e||"number"==typeof e)r+=e;else if("object"==typeof e)if(Array.isArray(e)){var a=e.length;for(t=0;t<a;t++)e[t]&&(n=ye(e[t]))&&(r&&(r+=" "),r+=n)}else for(n in e)e[n]&&(r&&(r+=" "),r+=n);return r}function be(){for(var e,t,n=0,r="",a=arguments.length;n<a;n++)(e=arguments[n])&&(t=ye(e))&&(r&&(r+=" "),r+=t);return r}function we(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===n&&r.firstChild?r.insertBefore(a,r.firstChild):r.appendChild(a),a.styleSheet?a.styleSheet.cssText=e:a.appendChild(document.createTextNode(e))}}we(".calendar{text-align:center;width:18.75rem}.calendar-header{font-size:1.125rem;font-weight:700;margin-bottom:.5rem}.calendar-weekdays{color:#666;display:grid;font-weight:700;grid-template-columns:repeat(7,1fr)}.calendar-weekday{padding:.3125rem}.calendar-days{display:grid;gap:.25rem;grid-template-columns:repeat(7,1fr)}.calendar-day{border-radius:.25rem;cursor:pointer;padding:.625rem;transition:background .2s}.calendar-day:hover{background:#f0f0f0}.calendar-day-today{border:.125rem solid #007bff;font-weight:700}.calendar-day-selected{background:#007bff;color:#fff}.calendar-day-in-range{background:#cce5ff;color:#004085}.calendar-day-outside{color:#bbb;pointer-events:none}");const ve=e=>ue(e,"MM/dd/yyyy"),ke=(e,t,n,r,a)=>e?{backgroundColor:n,borderColor:n,color:a}:t?{backgroundColor:r,borderColor:r,color:a}:{borderColor:n},xe=({month:e,startDate:t,endDate:n,onDateSelect:r,highlightColor:a="#007bff",highlightRangeColor:o="#cce5ff",renderDay:i,color:s="#fff"})=>{const c=function(e,t){const n=p(e,t?.in);return n.setDate(1),n.setHours(0,0,0,0),n}(e),u=v(c),l=Array.from({length:42},((e,t)=>new Date(u.getFullYear(),u.getMonth(),u.getDate()+t)));return f.jsxs("div",{className:"calendar",children:[f.jsx("h2",{className:"calendar-header",children:ue(c,"MMMM yyyy")}),f.jsx("div",{className:"calendar-weekdays",children:["S","M","T","W","T","F","S"].map(((e,t)=>f.jsx("div",{className:"calendar-weekday",children:e},t)))}),f.jsx("div",{className:"calendar-days",children:l.map((c=>{const u=!function(e,t){const[n,r]=S(0,e,t);return n.getFullYear()===r.getFullYear()&&n.getMonth()===r.getMonth()}(c,e),l=!u&&(t&&j(c,t)||n&&j(c,n)),d=!u&&t&&n&&(h=t,+p(c)>+p(h))&&function(e,t){return+p(e)<+p(t)}(c,n);var h;const m=be("calendar-day",j(c,new Date)&&"calendar-day-today",l&&"calendar-day-selected",d&&"calendar-day-in-range",u&&"calendar-day-outside");return f.jsx("div",{className:m,onClick:()=>!u&&r(c),style:ke(l,d,a,o,s),children:i?i(c,!!l,!!d):ue(c,"d")},c.toString())}))})]})};we(".date-range-input{align-items:center;background:#fff;border:1px solid #ccc;border-radius:.375rem;cursor:pointer;display:flex;font-size:1rem;height:100%;text-align:left;transition:border .2s ease-in-out;button{all:unset;padding:.8rem 1rem;width:90%}.close-container{padding:.4rem 0}.close-container,.close-icon{align-items:center;display:flex;justify-content:center}.close-icon{background-color:transparent;border:none;border-radius:100%;cursor:pointer;height:2.5rem;margin:0 .25rem;width:2.5rem}.separator{background:#ddd;height:100%;min-height:2.5rem;width:.0625rem}.close-icon:hover{background:rgba(0,0,0,.1);border-radius:100%;cursor:pointer}}.date-range-input:focus,.date-range-input:hover{border-color:#007bff;outline:none}");const Me=({inputRef:e,togglePopup:t,startDate:n,endDate:r,handleClear:a,startDatePlaceholder:o="Start Date",endDatePlaceholder:i="End Date"})=>f.jsxs("div",{className:"date-range-input",children:[f.jsxs("button",{ref:e,onClick:t,children:[n?ve(n):o," -"," ",r?ve(r):i]}),f.jsxs("div",{className:"close-container",children:[f.jsx("div",{className:"separator"}),f.jsx("div",{className:"close-icon",onClick:a,"data-testid":"close-icon",children:f.jsx(pe,{width:20})})]})]});we(".date-range-container{position:relative;width:17.5rem}.calendar-container{display:flex;gap:1.25rem;justify-content:space-between;max-width:90vw;overflow-x:auto}.date-range-popup{background:#fff;border:.0625rem solid #ccc;box-shadow:0 .25rem .375rem rgba(0,0,0,.1);padding:.625rem;position:absolute;z-index:1000}.anchor-bottom{left:0;top:110%}.anchor-top{bottom:110%;left:0}.anchor-left{right:110%;top:0}.anchor-right{left:110%;top:0}.calendar-separator{background-color:#ddd;min-height:100%;width:.0625rem}.navigation-icon-left{all:unset;left:1rem;position:absolute;top:1rem}.navigation-icon-right{all:unset;position:absolute;right:1rem;top:1rem}.navigation{align-items:center;background-color:transparent;border:none;border-radius:100%;cursor:pointer;display:flex;height:1.875rem;justify-content:center;width:1.875rem}.navigation:hover{background:#ddd}");const Se=({startDate:e,endDate:t,onChange:o,initialMonth:i=new Date,isOpen:s,onToggle:c,anchor:u="bottom",calendars:l=2,highlightColor:d,highlightRangeColor:h,renderDay:m,className:g,popupClassName:p,calendarContainerClassName:b,navigationButtonClassName:w,color:v,startDatePlaceholder:k,endDatePlaceholder:x})=>{const[M,S]=n(!1),[D,j]=n(i),P=a(null),C=a(null),N=null!=s?s:M,O=(({anchor:e,isOpen:t,inputRef:a,popupRef:o})=>{const[i,s]=n(e);return r((()=>{if(!t||!o.current||!a.current)return;const n=o.current,r=a.current.getBoundingClientRect(),i=window.innerWidth,c=window.innerHeight;let u=e;"left"===e&&r.left<n.offsetWidth?u="right":"right"===e&&r.right+n.offsetWidth>i?u="left":"top"===e&&r.top<n.offsetHeight?u="bottom":"bottom"===e&&r.bottom+n.offsetHeight>c&&(u="top"),s(u)}),[t,e]),i})({anchor:u,inputRef:C,isOpen:N,popupRef:P}),T=n=>{o(!e||e&&t?{startDate:n,endDate:null}:n<e?{startDate:n,endDate:e}:{startDate:e,endDate:n})};return r((()=>{const e=e=>{const t=e.target;N&&P.current&&C.current&&!P.current.contains(t)&&!C.current.contains(t)&&(void 0===s&&S(!1),null==c||c(!1))};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}}),[N,s,c]),f.jsxs("div",{className:be("date-range-container",g),children:[f.jsx(Me,{inputRef:C,startDate:e,endDate:t,handleClear:()=>{S(!1),o({startDate:null,endDate:null})},togglePopup:()=>{const e=!N;S(e),null==c||c(e)},startDatePlaceholder:k,endDatePlaceholder:x}),N&&f.jsx("div",{ref:P,className:be("date-range-popup",`anchor-${O}`,p),children:f.jsxs("div",{className:be("calendar-container",b),children:[f.jsx("button",{className:be("navigation-icon-left","navigation",w),onClick:()=>j(y(D,-1)),"data-testid":"left-arrow",children:f.jsx(fe,{width:20})}),Array.from({length:l}).map(((n,r)=>f.jsx("div",{children:f.jsx(xe,{month:y(D,r),startDate:e,endDate:t,onDateSelect:T,highlightColor:d,highlightRangeColor:h,renderDay:m,color:v})},r))),f.jsx("button",{className:be("navigation-icon-right","navigation",w),onClick:()=>j(y(D,1)),"data-testid":"right-arrow",children:f.jsx(me,{width:20})})]})})]})};export{Se as DateRangeInput}; //# sourceMappingURL=index.esm.js.map