UNPKG

@undp/design-system-react

Version:

React based design system for UNDP

2 lines 2.84 kB
const e=require("./utils-Dd9-5CFr.cjs"),t=require("./dist-BZMXZCSu.cjs"),n=require("./arrow-right-Cxlbw8LS.cjs"),r=require("./calendar-D3DI6jL5.cjs"),i=require("./popover-UvMqvZhZ.cjs"),a=require("./calendar-card-BmXmnASy.cjs");let o=require("react"),s=require("react/jsx-runtime");function c(e,t,n){return a.i(e,-t,n)}var l=t.t(`w-full h-auto bg-background rounded-base text-content-primary text-base transition-colors focus-visible:outline-hidden focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-disabled placeholder:text-content-placeholder`,{variants:{variant:{light:`border border-stroke`,normal:`border-2 border-foreground`},rounded:{base:`rounded`,sm:`rounded-sm`,md:`rounded-md`,lg:`rounded-lg`,xl:`rounded-xl`,"2xl":`rounded-2xl`,full:`rounded-full`},inputSize:{sm:`px-2.5 py-1`,base:`p-2.5`}},defaultVariants:{inputSize:`base`,variant:`normal`,rounded:`base`}});function u({onValueChange:t,value:u,defaultValue:d,disablePopover:f,classNames:p,variant:m,inputSize:h,numberOfMonths:g=2,..._}){let[v,y]=(0,o.useState)({from:u?.from||d?.from||void 0,to:u?.to||d?.to||void 0}),[b,x]=(0,o.useState)(!0),[S,C]=(0,o.useState)(!1),w=e=>{e&&(b?(y({from:e,to:void 0}),x(!1)):(v.from&&e<v.from?y({from:e,to:v.from}):y(t=>({...t,to:e})),x(!0),C(!1)))};return(0,o.useEffect)(()=>{t?.({from:v.from,to:v.to})},[v.from,v.to,t]),(0,s.jsxs)(i.t,{open:S,onOpenChange:C,children:[(0,s.jsxs)(i.i,{className:e.t(l({inputSize:h,variant:m}),p?.popOverTrigger),children:[(0,s.jsx)(r.t,{className:e.t(`size-4 text-content-placeholder`,p?.popOverTriggerIcon)}),v.from?(0,s.jsxs)(`div`,{className:`flex grow items-center gap-4`,children:[(0,s.jsx)(`p`,{className:`mt-1 grow p-0 text-left font-body text-content-primary`,children:a.r(v.from,`MMM d, yyyy`)}),(0,s.jsx)(n.t,{size:14,className:`text-content-primary`}),v.to?(0,s.jsx)(`p`,{className:`mt-1 grow p-0 text-left font-body text-content-primary`,children:a.r(v.to,`MMM d, yyyy`)}):(0,s.jsx)(`div`,{className:`grow text-left text-content-placeholder`,children:b?`Start date`:`End date`})]}):(0,s.jsxs)(`div`,{className:`flex grow items-center gap-4`,children:[(0,s.jsx)(`p`,{className:`mt-1 grow p-0 text-left font-body text-content-placeholder`,children:`Start date`}),(0,s.jsx)(n.t,{size:14,className:`text-content-primary`}),(0,s.jsx)(`p`,{className:`mt-1 grow p-0 text-left font-body text-content-placeholder`,children:`End date`})]})]}),(0,s.jsx)(i.r,{className:e.t(`w-auto p-0`,p?.popOverContent),align:`start`,children:(0,s.jsx)(a.t,{mode:`single`,numberOfMonths:g,selected:b?v.from:v.to,modifiers:{range_start:v.from?[v.from]:[],range_middle:v.from&&v.to?{from:v.from,to:c(v.to,1)}:void 0,range_end:v.to?[v.to]:[]},onSelect:e=>{w(e)},..._})})]})}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return u}}); //# sourceMappingURL=date-range-picker-BmxdqrRq.cjs.map