MonthPicker

Inline month, multiple months, and months range picker component.

Import

import { MonthPicker } from '@tidbcloud/uikit'

Basic Usage

import { useState } from 'react'
import { MonthPicker } from '@tidbcloud/uikit'
 
function Demo() {
  const [value, setValue] = useState<Date | null>(null)
  return <MonthPicker value={value} onChange={setValue} />
}

Multiple Dates

Select multiple months with type="multiple".

import { useState } from 'react'
import { MonthPicker } from '@tidbcloud/uikit'
 
function Demo() {
  const [value, setValue] = useState<Date[]>([])
  return <MonthPicker type="multiple" value={value} onChange={setValue} />
}

Date Range

Select a range of months with type="range".

import { useState } from 'react'
import { MonthPicker } from '@tidbcloud/uikit'
 
function Demo() {
  const [value, setValue] = useState<[Date | null, Date | null]>([null, null])
  return <MonthPicker type="range" value={value} onChange={setValue} />
}

Min and Max Date

import { useState } from 'react'
import { MonthPicker } from '@tidbcloud/uikit'
 
function Demo() {
  const [value, setValue] = useState<Date | null>(null)
  return <MonthPicker value={value} onChange={setValue} minDate={new Date(2022, 1, 1)} maxDate={new Date(2022, 8, 1)} />
}

Allow Deselect

Allow users to deselect the date by clicking on the selected item.

import { useState } from 'react'
import { MonthPicker } from '@tidbcloud/uikit'
 
function Demo() {
  const [value, setValue] = useState<Date | null>(null)
  return <MonthPicker allowDeselect value={value} onChange={setValue} />
}

Key Props

PropTypeDescription
valueDateValue | DateValue[] | DatesRangeValueSelected value
onChange(value) => voidCalled when value changes
type'default' | 'multiple' | 'range'Picker type
allowDeselectbooleanAllow deselecting date (default type only)
allowSingleDateInRangebooleanAllow single date as range
minDatestring | DateMinimum selectable date
maxDatestring | DateMaximum selectable date
defaultDatestring | DateInitial displayed date
numberOfColumnsnumberNumber of pickers side by side
maxLevel'month' | 'year' | 'decade'Max level user can navigate to
localestringdayjs locale
sizeMantineSizeComponent size