Skip to content

๐Ÿ“… Make your DatePicker from calendar-components

License

Notifications You must be signed in to change notification settings

faustienf/datepicker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

18 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โš›๏ธ Modular DatePicker

Make your DatePicker from calendar-components ๐Ÿ“… Demo

Usage

Simple datepicker

// write a facade-component
const DatepickerSimple: FC<Props> = (props) => {
  const {
    selected = 0 as Timestamp,
    onSelect,
  } = props;

  // use hooks for manage states, e.g. switching a month
  const {
    currentMonthTimestamp,
    onPrevMonth,
    onNextMonth,
  } = useCalendarMonth(selected || Date.now() as Timestamp);

  return (
    <Calendar
      // pass states and callbacks from logic hooks
      monthTimestamp={currentMonthTimestamp}
      onPrevMonth={onPrevMonth}
      onNextMonth={onNextMonth}
    >
      {(dayTimestamp) => (
        <CalendarDay
          // highlight the selected day
          isSelected={selected === dayTimestamp}
          // select the clicked day
          onClick={() => onSelect(dayTimestamp)}
        >
          {/* display a date */}
          {(new Date(dayTimestamp)).getDate()}
        </CalendarDay>
      )}
    </Calendar>
  );
};

Datepicker with 2 calendars

const BigDatepicker: FC<Props> = () => {
  ...

  return (
    <>
      {/* 1st calendar */}
      <Calendar monthTimestamp={currentMonthTimestamp}>
        ...
      </Calendar>
      {/* 2nd calendar */}
      <Calendar monthTimestamp={nextMonthTimestamp}>
        ...
      </Calendar>
    </>
  );
};

License

MIT