import React from "react"; import moment, { Moment } from "moment"; import Table, { CellStatus } from "./BaseTable"; import { useTranslation } from "../../i18n"; import { RangeDateType, CalendarTableType, DateChangeContext, } from "../DateProps"; import { noop } from "../../_util/noop"; import { getNow, isAfter, isBefore, isSame } from "../../datepicker/util"; export interface MonthTableProps { /** * 当前展示时间 */ current: Moment; /** * 允许选择的时间范围限制 */ range?: RangeDateType; cellStatus?: (date: Moment) => CellStatus; onSelect?: (value: Moment, context: DateChangeContext) => void; onTypeChange?: (type: CalendarTableType) => void; onCurrentChange?: (current: Moment) => void; hideCaption?: boolean; disabledMonth?: (date: Moment) => boolean; } export function MonthTable({ current, onCurrentChange = noop, range, onSelect = noop, disabledMonth, onTypeChange = noop, cellStatus = () => CellStatus.Common, hideCaption, }: MonthTableProps) { const t = useTranslation(); const year = current.year(); const now = getNow(current); function genTable(): number[][] { return [ [0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], ]; } function renderYear() { return ( onTypeChange("year")}> {current.format(t.yearFormat)} ); } const [rangeMin, rangeMax] = range || [null, null]; function isValid(date) { if (moment.isMoment(rangeMin) && isAfter(rangeMin, date, "month")) { return false; } if (moment.isMoment(rangeMax) && isBefore(rangeMax, date, "month")) { return false; } return disabledMonth(date); } return (