From eb9dbecd96248ac10bfb9c0ff6b2742e174014a9 Mon Sep 17 00:00:00 2001 From: linhf123 Date: Mon, 29 Apr 2024 17:48:17 +0800 Subject: [PATCH] Revert "feat: Delete step interaction" This reverts commit 721e52dd5f6fc1859014cf8d93f1dd807cd2ee90. --- packages/ui/src/DateRanger/Ranger.tsx | 69 ++++++++++++++++++++-- packages/ui/src/DateRanger/demo/basic2.tsx | 37 ++++++++++++ packages/ui/src/DateRanger/index.md | 2 +- 3 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 packages/ui/src/DateRanger/demo/basic2.tsx diff --git a/packages/ui/src/DateRanger/Ranger.tsx b/packages/ui/src/DateRanger/Ranger.tsx index 436611ead..223a419c0 100644 --- a/packages/ui/src/DateRanger/Ranger.tsx +++ b/packages/ui/src/DateRanger/Ranger.tsx @@ -62,10 +62,13 @@ export interface DateRangerProps value?: RangeValue; defaultValue?: RangeValue; size?: 'small' | 'large' | 'middle'; + mode?: 'normal' | 'step'; tooltipProps?: TooltipProps; } const prefix = getPrefix('date-ranger'); +const STEP_QUICK = 0; +const STEP_CUSTOMIZE = 1; const Ranger = (props: DateRangerProps) => { const { @@ -93,6 +96,7 @@ const Ranger = (props: DateRangerProps) => { size, //固定 rangeName stickRangeName = false, + mode = 'normal', tooltipProps, ...rest } = props; @@ -118,12 +122,17 @@ const Ranger = (props: DateRangerProps) => { ?.range(isMoment ? moment() : dayjs()) as RangeValue) ); + const isStepMode = mode === 'step'; + const [step, setStep] = useState(STEP_QUICK); + const [open, setOpen] = useState(false); const [tooltipOpen, setTooltipOpen] = useState(false); const refState = useRef({ tooltipOpen, + step, }); refState.current.tooltipOpen = tooltipOpen; + refState.current.step = step; // 没有 selects 时,回退到普通 RangePicker, 当前时间选项为自定义时,应该显示 RangePicker const [isPlay, setIsPlay] = useState(rangeName !== CUSTOMIZE); @@ -299,14 +308,65 @@ const Ranger = (props: DateRangerProps) => { destroyPopupOnHide={true} // 存在缓存,会锁死里面的值 onOpenChange={o => { - if (o === false && refState.current.tooltipOpen) { + if ( + o === false && + (refState.current.tooltipOpen || refState.current.step === STEP_CUSTOMIZE) + ) { return; } setOpen(o); }} + dropdownRender={menu => { + if (step === STEP_CUSTOMIZE) { + return ( +
+ { + setStep(STEP_QUICK); + }} + > + 返回上一层 + + { + setIsPlay(false); + rangeChange( + vList.map(v => { + return isMoment ? moment(v) : dayjs(v); + }) as RangeValue + ); + setStep(STEP_QUICK); + closeTooltip(); + }} + onCancel={() => { + setStep(STEP_QUICK); + closeTooltip(); + }} + /> +
+ ); + } + return menu; + }} menu={{ onClick: ({ key, domEvent }) => { + if (key === CUSTOMIZE && isStepMode) { + // updateState 的修改会慢于 openChange 的判断,所以修改 refState.current.step 让 Dropdown 不要关闭 + refState.current.step = STEP_CUSTOMIZE; + return setStep(STEP_CUSTOMIZE); + } + const selected = NEAR_TIME_LIST.find(_item => _item.name === key); // 存在快捷选项切换为极简模式 if (selected?.range) { @@ -330,7 +390,7 @@ const Ranger = (props: DateRangerProps) => { return { key: item.name, label: - item.name === CUSTOMIZE ? ( + item.name === CUSTOMIZE && !isStepMode ? ( { } }} placement="right" - {...tooltipProps} overlayStyle={{ maxWidth: 'none', - ...tooltipProps?.overlayStyle, }} overlayInnerStyle={{ background: '#fff', maxHeight: 'none', - margin: 16, - ...tooltipProps?.overlayInnerStyle, }} title={ { }} /> } + {...tooltipProps} > {item.rangeLabel} diff --git a/packages/ui/src/DateRanger/demo/basic2.tsx b/packages/ui/src/DateRanger/demo/basic2.tsx new file mode 100644 index 000000000..2c06bcf81 --- /dev/null +++ b/packages/ui/src/DateRanger/demo/basic2.tsx @@ -0,0 +1,37 @@ +import React, { useState } from 'react'; +import { DateRanger } from '@oceanbase/ui'; +import { Checkbox, Divider, Flex } from '@oceanbase/design'; + +export default () => { + const options = [ + // { label: 'hasPlay', value: 'hasPlay' }, + { label: 'hasRewind', value: 'hasRewind' }, + { label: 'hasForward', value: 'hasForward' }, + // { label: 'hasZoomOut', value: 'hasZoomOut' }, + ]; + + const [state, setState] = useState(options.map(item => item.value)); + + const onChange = checkedValue => { + setState(checkedValue); + }; + const getValue = name => { + return state.some(v => v === name); + }; + + return ( +
+ + + + + +
+ ); +}; diff --git a/packages/ui/src/DateRanger/index.md b/packages/ui/src/DateRanger/index.md index cf72815ba..487e5d18d 100644 --- a/packages/ui/src/DateRanger/index.md +++ b/packages/ui/src/DateRanger/index.md @@ -7,7 +7,7 @@ nav: ## 代码演示 - +