UNPKG

dgz-ui-shared

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library

7 lines (6 loc) 3.49 kB
"use strict";const s=require("./jsx-runtime-DUiatUiq.cjs"),a=require("react"),m=require("./timepicker-CVwZY2bQ-BCnAd1SD.cjs"),n=require("./dayjs.min-BoFVZSwB.cjs"),p=require("./check-DE-1lGDl-C_ZPlJ0c.cjs"),d=require("./popover-DDxpKohG-lwQEtZjs.cjs"),y=require("./utils-D0f6bOsw-BmDOeWKv.cjs"),g=require("./useTranslation-CZf20ucv.cjs"),E=require("./createLucideIcon-BnAj0RnC.cjs");/** * @license lucide-react v0.511.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const k=[["path",{d:"M11 14h1v4",key:"fy54vd"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}],["rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",key:"12vinp"}]],v=E.createLucideIcon("calendar-1",k),q=({className:j,format:i=m.no,selected:x,timezone:u,onRangeSelected:b=()=>{},placeholder:D})=>{const{t:o}=g.useTranslation(),[R,f]=a.useState(!1),[t,c]=a.useState();a.useEffect(()=>{c(x)},[x]);const O=a.useMemo(()=>{const e=n.dayjs().endOf("day");return[{from:e.startOf("week").toDate(),to:e.endOf("week").toDate(),label:o("This week")},{from:e.startOf("month").toDate(),to:e.endOf("month").toDate(),label:o("This month")},{from:e.startOf("year").toDate(),to:e.endOf("year").toDate(),label:o("This year")},{from:e.subtract(7,"day").startOf("day").toDate(),to:e.toDate(),label:o("Last 7 days")},{from:e.subtract(30,"day").startOf("day").toDate(),to:e.toDate(),label:o("Last 30 days")},{from:e.subtract(3,"month").startOf("day").toDate(),to:e.toDate(),label:o("Last 3 months")},{from:e.subtract(6,"month").startOf("day").toDate(),to:e.toDate(),label:o("Last 6 months")},{from:e.subtract(12,"month").startOf("day").toDate(),to:e.toDate(),label:o("Last 12 months")}]},[o]),h=e=>{const{from:r,to:l}=e;c({from:r,to:l}),r&&l&&(b({from:r,to:l}),f(!1))};return s.jsxRuntimeExports.jsx("div",{className:y.mo("grid gap-2",j),children:s.jsxRuntimeExports.jsxs(d.Oe,{open:R,onOpenChange:f,children:[s.jsxRuntimeExports.jsx(d._e,{asChild:!0,children:s.jsxRuntimeExports.jsxs(p.u,{id:"date",size:"sm",variant:"secondary",className:y.mo("min-w-[170px] text-body-xs-regular justify-between",!t&&"text-primary"),children:[t!=null&&t.from?t.to?s.jsxRuntimeExports.jsxs(s.jsxRuntimeExports.Fragment,{children:[n.dayjs(t.from).format(i)," -"," ",n.dayjs(t.to).format(i)]}):n.dayjs(t.from).format(i):s.jsxRuntimeExports.jsx("span",{className:"text-secondary",children:D}),s.jsxRuntimeExports.jsx(v,{className:"text-secondary"})]})}),s.jsxRuntimeExports.jsxs(d.ue,{className:"w-auto p-0 flex",align:"end",side:"bottom",children:[s.jsxRuntimeExports.jsx("div",{className:"space-y-1 flex flex-col p-2 border-e border-border-alpha-light",children:O.map((e,r)=>s.jsxRuntimeExports.jsx(p.u,{size:"xs",variant:"ghost",className:"justify-start",onClick:()=>h(e),children:e.label},r))}),s.jsxRuntimeExports.jsx(m.Gs,{className:"border-e border-border-alpha-light",mode:"single",endMonth:t==null?void 0:t.to,selected:t==null?void 0:t.from,selectedToDate:t==null?void 0:t.to,selectedFromDate:t==null?void 0:t.from,timeZone:u,disabled:t!=null&&t.to?{after:t.to}:void 0,onSelect:e=>{c({...t,from:e})}}),s.jsxRuntimeExports.jsx(m.Gs,{mode:"single",startMonth:t==null?void 0:t.from,selected:t==null?void 0:t.to,timeZone:u,disabled:t!=null&&t.from?{before:t.from}:void 0,selectedToDate:t==null?void 0:t.to,selectedFromDate:t==null?void 0:t.from,onSelect:e=>{t&&h({...t,to:e})}})]})]})})};exports.DateRangePicker=q;