MCPcopy Index your code
hub / github.com/aboveyunhai/chakra-dayzed-datepicker

github.com/aboveyunhai/chakra-dayzed-datepicker @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
81 symbols 158 edges 24 files 8 documented · 10%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

A Simple Chakra Datepicker based on Dayzed.

npm version Downloads

Every individual component is using Chakra UI. So it should respect all Chakra UI Configs without problem.

The componenent itself has to use some date library

Highly recommend just copy/paste the source code from /src to customize however you want.

Install the dependency

Npm

npm i date-fns dayzed
npm i chakra-dayzed-datepicker

Yarn:

yarn add date-fns dayzed
yarn add chakra-dayzed-datepicker

Basic usage

Single


  import { SingleDatepicker } from "chakra-dayzed-datepicker";

  const [date, setDate] = useState(new Date());

  <SingleDatepicker
    name="date-input"
    date={date}
    onDateChange={setDate}
  />

Range:

Note that this list will have one value during the selection process. Your system won't work if you try to control this directly as [startDate, endDate] because we'll try to set selectedDates to [intermediateSelection] and the length of the resulting selectedDates is meaningful to the datepicker.


  import { RangeDatepicker } from "chakra-dayzed-datepicker";

  const [selectedDates, setSelectedDates] = useState<Date[]>([new Date(), new Date()]);

  <RangeDatepicker
    selectedDates={selectedDates}
    onDateChange={setSelectedDates}
  />

propsConfigs:

dateNavBtnProps extends from ButtonProps of Chakra-UI This allows you to override the default behavior however your want as long as supported by Chakra-UI.

dayOfMonthBtnProps = {
  defaultBtnProps,
  isInRangeBtnProp,
  selectedBtnProps,
  todayBtnProps
}

dayOfMonthBtnProps allows you to customzie date btn style based on the state.

Style precedence: default < isInRange < seleted < today.

popoverCompProps might be useful when you want to setup some simple styles like text color globally

popoverCompProps = {
  popoverContentProps,
  popoverBodyProps
}

To sum them up:

  propsConfigs={{
    dateNavBtnProps: {},
    dayOfMonthBtnProps: {
      defaultBtnProps: {},
      isInRangeBtnProps: {},
      selectedBtnProps: {},
      todayBtnProps: {}
    },
    inputProps: {},
    popoverCompProps: {
      popoverContentProps: {},
      popoverBodyProps: {}
    },
    calendarPanelProps: {
      wrapperProps: {},
      contentProps: {},
      headerProps: {},
      dividerProps: {},
    },
    weekdayLabelProps: {},
    dateHeadingProps: {}
  }}

Example:

  propsConfigs={{
    dateNavBtnProps: {
      colorScheme: "blue",
      variant: "outline"
    },
    dayOfMonthBtnProps: {
      defaultBtnProps: {
        borderColor: "red.300",
        _hover: {
          background: 'blue.400',
        }
      },
      isInRangeBtnProps: {
        color: "yellow",
      },
      selectedBtnProps: {
        background: "blue.200",
        color: "green",
      },
      todayBtnProps: {
        background: "teal.400",
      }
    },
    inputProps: {
      size: "sm"
    },
    popoverCompProps: {
      popoverContentProps: {
        background: "gray.700",
        color: "white",
      },
    },
    calendarPanelProps: {
      wrapperProps: {
        borderColor: 'green',
      },
      contentProps: {
        borderWidth: 0,
      },
      headerProps: {
        padding: '5px',
      },
      dividerProps: {
        display: "none",
      },
    },
    weekdayLabelProps: {
      fontWeight: 'normal'
    },
    dateHeadingProps: {
      fontWeight: 'semibold'
    }
  }}

configs:

Non Chakra-related configurations :

  configs={{
    dateFormat: 'yyyy-MM-dd',
    dayNames: 'abcdefg'.split(''), // length of 7
    monthNames: 'ABCDEFGHIJKL'.split(''), // length of 12
    firstDayOfWeek: 2, // default is 0, the dayNames[0], which is Sunday if you don't specify your own dayNames,
  }}

other props:

Name single/range Type Default value Description
name both string undefined name attribute for <input /> element
usePortal both boolean undefined to prevent parent styles from clipping or hiding content
defaultIsOpen both boolean false open the date panel at the beginning
closeOnSelect both boolean true close the date panel upon the complete selection
minDate both Date undefined minimum date
maxDate both Date undefined maximum date
disabledDates single Set undefined for single datepicker only, uses startOfDay as comparison, e.g., disabledDates={new Set([startOfDay(new Date()).getTime()}

For version < npm@0.1.6:

dayOfMonthBtnProps extends from ButtonProps and has only selectedBg support,

  dayOfMonthBtnProps: {
    borderColor: "red.300",
    selectedBg: "blue.200",
    _hover: {
      bg: 'blue.400',
    }
  },

Extension points exported contracts — how you extend this code

DialogContentProps (Interface)
(no doc)
example/snippet/dialog.tsx
RangeCalendarPanelProps (Interface)
(no doc)
src/range.tsx
SingleProps (Interface)
(no doc)
src/single.tsx
CalendarPanelProps (Interface)
(no doc)
src/components/calendarPanel.tsx
ArrowKeysReactConfig (Interface)
(no doc)
src/utils/reactKeysArrow.ts
SwitchProps (Interface)
(no doc)
example/snippet/switch.tsx
RangeProps (Interface)
(no doc)
src/range.tsx
DayOfMonthProps (Interface)
(no doc)
src/components/dayOfMonth.tsx

Core symbols most depended-on inside this repo

composeEventHandlers
called by 3
src/utils/dayzed/utils.ts
isSelected
called by 3
src/utils/dayzed/utils.ts
isSelectable
called by 3
src/utils/dayzed/utils.ts
useColorMode
called by 2
example/snippet/color-mode.tsx
isOffsetControlled
called by 2
src/utils/dayzed/dayzed.ts
getBackProps
called by 2
src/utils/dayzed/dayzed.ts
getForwardProps
called by 2
src/utils/dayzed/dayzed.ts
onMouseEnterHighlight
called by 1
src/range.tsx

Shape

Function 46
Interface 29
Method 4
Class 2

Languages

TypeScript100%

Modules by API surface

src/utils/dayzed/utils.ts24 symbols
src/utils/dayzed/dayzed.ts8 symbols
src/range.tsx8 symbols
src/utils/commonTypes.ts7 symbols
example/index.tsx6 symbols
src/utils/reactKeysArrow.ts5 symbols
example/snippet/color-mode.tsx5 symbols
src/components/dateNavBtns.tsx4 symbols
src/components/button.tsx4 symbols
src/single.tsx2 symbols
src/components/dayOfMonth.tsx2 symbols
src/components/calendarPanel.tsx2 symbols

For agents

$ claude mcp add chakra-dayzed-datepicker \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page