import React, { PureComponent } from 'react'; // import cls from 'classnames'; import PropTypes from 'prop-types'; import { noop } from 'lodash'; import IconButton from '../iconButton'; import Button from '../button'; import { cssClasses, strings } from '@douyinfe/semi-foundation/datePicker/constants'; import { IconChevronLeft, IconChevronRight, IconDoubleChevronLeft, IconDoubleChevronRight } from '@douyinfe/semi-icons'; import { PanelType } from '@douyinfe/semi-foundation/datePicker/monthsGridFoundation'; const prefixCls = cssClasses.NAVIGATION; interface NavigationProps { forwardRef?: React.Ref; monthText?: string; density?: string; onMonthClick?: (e: React.MouseEvent) => void; onNextMonth?: () => void; onPrevMonth?: () => void; onNextYear?: () => void; onPrevYear?: () => void; navPrev?: React.ReactNode; navNext?: React.ReactNode; // Whether to switch synchronously for two panels shouldBimonthSwitch?: boolean; // Panel type, divided into left panel and right panel panelType?: PanelType; } export default class Navigation extends PureComponent { static propTypes = { monthText: PropTypes.string, density: PropTypes.string, onMonthClick: PropTypes.func, onNextMonth: PropTypes.func, onPrevMonth: PropTypes.func, onNextYear: PropTypes.func, onPrevYear: PropTypes.func, navPrev: PropTypes.node, navNext: PropTypes.node, // Whether to switch synchronously for two panels shouldBimonthSwitch: PropTypes.bool, // Panel type, divided into left panel and right panel panelType: PropTypes.oneOf([strings.PANEL_TYPE_LEFT, strings.PANEL_TYPE_RIGHT]) }; static defaultProps = { monthText: '', onMonthClick: noop, onNextMonth: noop, onPrevMonth: noop, onNextYear: noop, onPrevYear: noop, }; navRef: React.RefObject; constructor(props: NavigationProps) { super(props); this.navRef = React.createRef(); } render() { const { forwardRef, monthText, onMonthClick, onNextMonth, onPrevMonth, onPrevYear, onNextYear, density, shouldBimonthSwitch, panelType } = this.props; const btnTheme = 'borderless'; const iconBtnSize = density === 'compact' ? 'default' : 'large'; const btnNoHorizontalPadding = true; const buttonSize = density === 'compact' ? 'small' : 'default'; const isLeftPanel = panelType === strings.PANEL_TYPE_LEFT; const isRightPanel = panelType === strings.PANEL_TYPE_RIGHT; // syncSwitchMonth and the current panel is the left const hiddenLeftPanelRightButtons = shouldBimonthSwitch && isLeftPanel; // syncSwitchMonth and the current panel is the right const hiddenRightPanelLeftButtons = shouldBimonthSwitch && isRightPanel; // `visibility: hidden` will keep the icon in position const leftButtonStyle: React.CSSProperties = {}; const rightButtonStyle: React.CSSProperties = {}; if (hiddenRightPanelLeftButtons) { leftButtonStyle.visibility = 'hidden'; } if (hiddenLeftPanelRightButtons) { rightButtonStyle.visibility = 'hidden'; } const ref = forwardRef || this.navRef; return (
} size={buttonSize} theme={btnTheme} noHorizontalPadding={btnNoHorizontalPadding} onClick={onPrevYear} style={leftButtonStyle} /> } size={buttonSize} onClick={onPrevMonth} theme={btnTheme} noHorizontalPadding={btnNoHorizontalPadding} style={leftButtonStyle} />
} size={buttonSize} onClick={onNextMonth} theme={btnTheme} noHorizontalPadding={btnNoHorizontalPadding} style={rightButtonStyle} /> } size={buttonSize} theme={btnTheme} noHorizontalPadding={btnNoHorizontalPadding} onClick={onNextYear} style={rightButtonStyle} />
); } }