/* eslint-disable jsx-a11y/no-static-element-interactions,jsx-a11y/click-events-have-key-events */ import React, { PureComponent } from 'react'; import classNames from 'classnames'; import PropTypes from 'prop-types'; import { cssClasses, strings } from '@douyinfe/semi-foundation/datePicker/constants'; import Button from '../button/index'; import Typography from '../typography/index'; import { noop } from '@douyinfe/semi-foundation/utils/function'; import { PresetsType, PresetType } from '@douyinfe/semi-foundation/datePicker/foundation'; const prefixCls = cssClasses.PREFIX; const { Text } = Typography; export interface QuickControlProps { presets: PresetsType; presetPosition: typeof strings.PRESET_POSITION_SET[number]; onPresetClick: (preset: PresetType, e: React.MouseEvent) => void; type: string; insetInput: boolean; } class QuickControl extends PureComponent { static propTypes = { presets: PropTypes.array, presetPosition: PropTypes.oneOf(strings.PRESET_POSITION_SET), onPresetClick: PropTypes.func, type: PropTypes.string, insetInput: PropTypes.bool }; static defaultProps = { presets: [] as PresetsType, presetPosition: 'bottom', onPresetClick: noop, }; render() { const { presets, onPresetClick, type, presetPosition, insetInput } = this.props; const isTypeRange = type === 'dateRange' || type === 'dateTimeRange'; const isPanelTopAndBottom = presetPosition === 'top' || presetPosition === 'bottom'; const isMonth = type === 'month'; const isTopAndBottomRange = isPanelTopAndBottom && isTypeRange; const isTopAndBottomMonth = isPanelTopAndBottom && isMonth; const wrapperCls = classNames(`${prefixCls}-quick-control`, { [`${prefixCls}-quick-control-${type}`]: type, [`${prefixCls}-quick-control-${presetPosition}`]: true, }); const headerCls = classNames({ [`${prefixCls}-quick-control-header`]: true, }); const contentWrapperCls = classNames({ [`${prefixCls}-quick-control-${presetPosition}-content-wrapper`]: true, }); const contentCls = classNames({ [`${prefixCls}-quick-control-${presetPosition}-content`]: !isTopAndBottomRange && !isTopAndBottomMonth, [`${prefixCls}-quick-control-${presetPosition}-range-content`]: isTopAndBottomRange, [`${prefixCls}-quick-control-${presetPosition}-month-content`]: isTopAndBottomMonth, }); const itemCls = classNames({ [`${prefixCls}-quick-control-${presetPosition}-content-item`]: !isTopAndBottomRange && !isTopAndBottomMonth, [`${prefixCls}-quick-control-${presetPosition}-range-content-item`]: isTopAndBottomRange, [`${prefixCls}-quick-control-${presetPosition}-month-content-item`]: isTopAndBottomMonth, }); const ellipsisCls = classNames({ [`${prefixCls}-quick-control-${presetPosition}-content-item-ellipsis`]: !isTopAndBottomRange && !isTopAndBottomMonth, [`${prefixCls}-quick-control-${presetPosition}-range-content-item-ellipsis`]: isTopAndBottomRange, [`${prefixCls}-quick-control-${presetPosition}-month-content-item-ellipsis`]: isTopAndBottomMonth, }); if (!presets.length) { return null; } return (
{ !isPanelTopAndBottom &&
快捷选择
}
{presets.map((item, index) => { const _item: PresetType = typeof item === 'function' ? item() : item; return ( ); })}
); } } export default QuickControl;