MCPcopy Index your code
hub / github.com/simstudioai/sim / SingleCalendarView

Function SingleCalendarView

packages/emcn/src/components/calendar/calendar.tsx:292–347  ·  view source on GitHub ↗
({ value, onChange, className }: CalendarSingleProps)

Source from the content-addressed store, hash-verified

290}
291
292function SingleCalendarView({ value, onChange, className }: CalendarSingleProps) {
293 const selected = useMemo(() => parseDateValue(value), [value])
294 const { today, view, setView, goToPrevMonth, goToNextMonth, cells } = useCalendarView(selected)
295
296 useEffect(() => {
297 if (selected) setView({ month: selected.getMonth(), year: selected.getFullYear() })
298 }, [selected, setView])
299
300 const selectDay = (day: number) => onChange?.(toDateString(view.year, view.month, day))
301
302 const goToToday = () => {
303 setView({ month: today.getMonth(), year: today.getFullYear() })
304 onChange?.(toDateString(today.getFullYear(), today.getMonth(), today.getDate()))
305 }
306
307 return (
308 <div className={cn('flex w-[256px] flex-col p-2', className)}>
309 <CalendarHeader
310 month={view.month}
311 year={view.year}
312 onPrev={goToPrevMonth}
313 onNext={goToNextMonth}
314 />
315 <WeekdayRow />
316
317 <div className='grid grid-cols-7'>
318 {cells.map((day, index) => {
319 if (day === null) return <div key={`empty-${index}`} className='h-[34px]' />
320
321 const cellDate = new Date(view.year, view.month, day)
322 const isSelected = selected ? isSameDay(cellDate, selected) : false
323 const isToday = isSameDay(cellDate, today)
324
325 return (
326 <div key={day} className='flex h-[34px] items-center justify-center'>
327 <CalendarDayCell selected={isSelected} today={isToday} onClick={() => selectDay(day)}>
328 {day}
329 </CalendarDayCell>
330 </div>
331 )
332 })}
333 </div>
334
335 <button
336 type='button'
337 onClick={goToToday}
338 className={cn(
339 chipVariants({ variant: 'filled', fullWidth: true, flush: true }),
340 'mt-1 justify-center'
341 )}
342 >
343 <span className={chipContentLabelClass}>Today</span>
344 </button>
345 </div>
346 )
347}
348
349function RangeCalendarView({

Callers

nothing calls this directly

Calls 5

cnFunction · 0.90
useCalendarViewFunction · 0.85
isSameDayFunction · 0.85
selectDayFunction · 0.85
parseDateValueFunction · 0.70

Tested by

no test coverage detected