@guruhotel/aura-ui
Version:
⚛️ React UI library by GuruHotel
1 lines • 3.43 kB
JavaScript
var e=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports.YearSelector=exports.MonthSelector=void 0;e(require("react"));var o=require("@react-aria/i18n"),r=require("../icons"),t=require("../select"),l=require("../box"),c=require("./utils"),n=require("./calendar-props.provider"),s=require("react/jsx-runtime");exports.MonthSelector=({state:e})=>{const{monthDateFormat:{month:a},rounded:i,colorScheme:u,size:d}=(0,n.useCalendarProps)(),h=[],x=(0,o.useDateFormatter)({month:a,timeZone:e.timeZone}),S=e.focusedDate.calendar.getMonthsInYear(e.focusedDate);for(let o=1;o<=S;o++){const r=e.focusedDate.set({month:o});h.push((0,c.capitalizeFirstLetter)(x.format(r.toDate(e.timeZone))))}const m=(0,c.increaseResponsiveValue)(d,"fontSize");return(0,s.jsxs)(t.Select,{onValueChange:o=>{const r=Number(o),t=e.focusedDate.set({month:r});e.setFocusedDate(t)},value:e.focusedDate.month.toString(),size:d,children:[(0,s.jsxs)(t.SelectTrigger,{"aria-label":"Month",rounded:i,colorScheme:u,css:{boxShadow:"none",fontWeight:700,color:`$${u}12`,"&:hover":{backgroundColor:`$${u}4`},"&:focus":{boxShadow:`0 0 0 2px $colors$${u}12`},...m},children:[(0,s.jsx)(t.SelectValue,{}),(0,s.jsx)(t.SelectIcon,{children:(0,s.jsx)(l.Box,{css:{mb:"$1"},children:(0,s.jsx)(r.ChevronDownRegular,{label:"",color:"currentcolor"})})})]}),(0,s.jsxs)(t.SelectContent,{rounded:i,colorScheme:u,children:[(0,s.jsx)(t.SelectScrollUpButton,{children:(0,s.jsx)(r.ChevronUpRegular,{label:"",color:"currentcolor"})}),(0,s.jsx)(t.SelectViewport,{children:h.map(((e,o)=>(0,s.jsxs)(t.SelectItem,{value:(o+1).toString(),children:[(0,s.jsx)(t.SelectItemText,{children:e}),(0,s.jsx)(t.SelectItemIndicator,{children:(0,s.jsx)(r.CheckSolid,{label:"",color:"currentcolor"})})]},`${e}-${o}`)))}),(0,s.jsx)(t.SelectScrollDownButton,{children:(0,s.jsx)(r.ChevronDownRegular,{label:"",color:"currentcolor"})})]})]})};exports.YearSelector=({state:e})=>{const{monthDateFormat:{year:a},rounded:i,colorScheme:u,size:d}=(0,n.useCalendarProps)(),h=[],x=(0,o.useDateFormatter)({year:a,timeZone:e.timeZone});for(let o=-10;o<=10;o++){const r=e.focusedDate.add({years:o});h.push({value:r,formatted:x.format(r.toDate(e.timeZone))})}const S=(0,c.increaseResponsiveValue)(d,"fontSize");return(0,s.jsxs)(t.Select,{onValueChange:o=>{var r;const t=Number(o),l=null==(r=h[t])?void 0:r.value;l&&e.setFocusedDate(l)},value:"10",size:d,children:[(0,s.jsxs)(t.SelectTrigger,{"aria-label":"Year",rounded:i,colorScheme:u,css:{boxShadow:"none",fontWeight:700,color:`$${u}12`,"&:hover":{backgroundColor:`$${u}4`},"&:focus":{boxShadow:`0 0 0 2px $colors$${u}12`},...S},children:[(0,s.jsx)(t.SelectValue,{}),(0,s.jsx)(t.SelectIcon,{children:(0,s.jsx)(l.Box,{css:{mb:"$1"},children:(0,s.jsx)(r.ChevronDownRegular,{label:"",color:"currentcolor"})})})]}),(0,s.jsxs)(t.SelectContent,{rounded:i,colorScheme:u,children:[(0,s.jsx)(t.SelectScrollUpButton,{children:(0,s.jsx)(r.ChevronUpRegular,{label:"",color:"currentcolor"})}),(0,s.jsx)(t.SelectViewport,{children:h.map(((e,o)=>(0,s.jsxs)(t.SelectItem,{value:o.toString(),css:{rounded:i?"$base":"$none",fontSize:"$md",color:`$${u}11`},children:[(0,s.jsx)(t.SelectItemText,{children:e.formatted}),(0,s.jsx)(t.SelectItemIndicator,{children:(0,s.jsx)(r.CheckSolid,{label:"",color:"currentcolor"})})]},`${e.formatted}-${o}`)))}),(0,s.jsx)(t.SelectScrollDownButton,{children:(0,s.jsx)(r.ChevronDownRegular,{label:"",color:"currentcolor"})})]})]})};