Skip to content

Commit 14c2e88

Browse files
committed
fix: ts error
1 parent 9562fc3 commit 14c2e88

5 files changed

Lines changed: 28 additions & 25 deletions

File tree

packages/components/date-picker/panel/PanelContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default function PanelContent(props: PanelContentProps) {
132132
position={partial}
133133
format={timeFormat}
134134
value={time || defaultTime}
135-
onChange={onTimePickerChange}
135+
onChange={(value) => onTimePickerChange?.(value)}
136136
isShowPanel={props.popupVisible}
137137
{...timePickerProps}
138138
/>

packages/components/form/FormItem.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
122122

123123
const { defaultInitialData } = useFormItemInitialData(name, fullPath, initialData, children);
124124

125+
// eslint-disable-next-line @eslint-react/use-state
125126
const [, forceUpdate] = useState({}); // custom render state
126127
const [freeShowErrorMessage, setFreeShowErrorMessage] = useState(undefined);
127128
const [errorList, setErrorList] = useState([]);
@@ -214,7 +215,7 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
214215
return null;
215216
};
216217

217-
if (React.isValidElement(statusIcon)) {
218+
if (React.isValidElement<Record<string, any>>(statusIcon)) {
218219
// @ts-ignore
219220
return resultIcon(
220221
React.cloneElement(statusIcon, {
@@ -495,7 +496,7 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
495496
if (!child) return null;
496497

497498
// Fragment can only have `key` and `children` props, skip props injection
498-
if (!React.isValidElement(child) || child.type === React.Fragment) return child;
499+
if (!React.isValidElement<Record<string, any>>(child) || child.type === React.Fragment) return child;
499500

500501
const childType = child.type;
501502
const isCustomComp = typeof childType === 'object' || typeof childType === 'function';
@@ -512,7 +513,7 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
512513
});
513514
}
514515

515-
const childProps = child.props as any;
516+
const childProps = child.props;
516517
const commonProps = {
517518
disabled: disabledFromContext,
518519
readOnly: readOnlyFromContext,

packages/components/time-picker/TimePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const TimePicker = forwardRefWithStatics(
111111

112112
const handlePanelChange: TimePickerPanelProps['onChange'] = (v, ctx) => {
113113
setCurrentValue(v);
114-
onPick?.(v, ctx);
114+
onPick?.(v, { e: ctx as unknown as React.MouseEvent<HTMLDivElement> });
115115
};
116116

117117
return (

packages/components/time-picker/TimeRangePicker.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import TimePickerPanel from './panel/TimePickerPanel';
1919
import type { FC } from 'react';
2020
import type { StyledProps } from '../common';
2121
import type { RangeInputPopupProps, RangeInputPosition } from '../range-input';
22+
import type { TimePickerPanelProps } from './panel/TimePickerPanel';
2223
import type { TdTimeRangePickerProps, TimeRangePickerPartial, TimeRangeValue } from './type';
2324

2425
export interface TimeRangePickerProps extends TdTimeRangePickerProps, StyledProps {}
@@ -57,7 +58,7 @@ const TimeRangePicker: FC<TimeRangePickerProps> = (originalProps) => {
5758
const { TimeIcon } = useGlobalIcon({
5859
TimeIcon: TdTimeIcon,
5960
});
60-
const [isPanelShowed, setPanelShow] = useState(false);
61+
const [isPanelShowed, setIsPanelShowed] = useState(false);
6162
const [currentPanelIdx, setCurrentPanelIdx] = useState(undefined);
6263
const [currentValue, setCurrentValue] = useState(['', '']);
6364

@@ -69,10 +70,10 @@ const TimeRangePicker: FC<TimeRangePickerProps> = (originalProps) => {
6970

7071
const handleShowPopup: RangeInputPopupProps['onPopupVisibleChange'] = (visible, { trigger }) => {
7172
if (trigger === 'trigger-element-click') {
72-
setPanelShow(true);
73+
setIsPanelShowed(true);
7374
return;
7475
}
75-
setPanelShow(visible);
76+
setIsPanelShowed(visible);
7677
};
7778

7879
function handlePickerValue(pickValue: string | string[], currentValue: string[]) {
@@ -105,10 +106,10 @@ const TimeRangePicker: FC<TimeRangePickerProps> = (originalProps) => {
105106
setCurrentPanelIdx(position === 'first' ? 0 : 1);
106107
};
107108

108-
const handleTimeChange = (newValue: string | string[], context: { e: React.MouseEvent }) => {
109+
const handleTimeChange = (newValue: string | string[], e?: MouseEvent | UIEvent) => {
109110
const nextCurrentValue = handlePickerValue(newValue, currentValue);
110111
setCurrentValue(nextCurrentValue);
111-
handleOnPick(nextCurrentValue, context);
112+
handleOnPick(nextCurrentValue, { e: e as unknown as React.MouseEvent });
112113
};
113114

114115
const autoSwapTime = (valueBeforeConfirm: Array<string>) => {
@@ -145,7 +146,7 @@ const TimeRangePicker: FC<TimeRangePickerProps> = (originalProps) => {
145146
const handleClickConfirm = () => {
146147
const isValidTime = !currentValue.find((v) => !validateInputValue(v, format));
147148
if (isValidTime) onChange(props.autoSwap ? autoSwapTime(currentValue) : currentValue);
148-
setPanelShow(false);
149+
setIsPanelShowed(false);
149150
};
150151

151152
const handleFocus = (
@@ -206,7 +207,7 @@ const TimeRangePicker: FC<TimeRangePickerProps> = (originalProps) => {
206207
hideDisabledTime={hideDisabledTime}
207208
isFooterDisplay={true}
208209
value={currentValue[currentPanelIdx || 0]}
209-
onChange={handleTimeChange}
210+
onChange={handleTimeChange as TimePickerPanelProps['onChange']}
210211
handleConfirmClick={handleClickConfirm}
211212
position={currentPanelIdx === 0 ? 'start' : 'end'}
212213
activeIndex={currentPanelIdx}

packages/components/time-picker/panel/TimePickerPanel.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import type { TimePickerProps } from '../TimePicker';
1313
import type { TimeRangePickerProps } from '../TimeRangePicker';
1414
import type { SinglePanelProps } from './SinglePanel';
1515

16-
export interface TimePickerPanelProps extends SinglePanelProps {
16+
export interface TimePickerPanelProps extends Omit<SinglePanelProps, 'onChange'> {
1717
isShowPanel?: boolean;
1818
isFooterDisplay?: boolean; // 是否展示footer
1919
handleConfirmClick?: (defaultValue: dayjs.Dayjs | string) => void;
2020
presets?: TimePickerProps['presets'] | TimeRangePickerProps['presets'];
2121
activeIndex?: number;
22+
onChange?: (value: string, e?: MouseEvent | UIEvent) => void;
2223
}
2324

2425
type PresetValue = TimePickerPanelProps['presets'][keyof TimePickerPanelProps['presets']];
@@ -34,7 +35,7 @@ const TimePickerPanel: FC<TimePickerPanelProps> = (props) => {
3435
isShowPanel = true,
3536
presets = null,
3637
} = props;
37-
const [triggerScroll, toggleTriggerScroll] = useState(false); // 触发滚动
38+
const [triggerScroll, setTriggerScroll] = useState(false); // 触发滚动
3839
const { classPrefix } = useConfig();
3940

4041
const TEXT_CONFIG = useTimePickerTextConfig();
@@ -52,23 +53,23 @@ const TimePickerPanel: FC<TimePickerPanelProps> = (props) => {
5253
}, [value, format]);
5354

5455
useEffect(() => {
55-
if (isShowPanel) toggleTriggerScroll(true);
56+
if (isShowPanel) setTriggerScroll(true);
5657
}, [isShowPanel]);
5758

5859
const resetTriggerScroll = useCallback(() => {
59-
toggleTriggerScroll(false);
60-
}, [toggleTriggerScroll]);
60+
setTriggerScroll(false);
61+
}, [setTriggerScroll]);
6162

62-
const handlePresetClick = (presetValue: PresetValue) => {
63+
const handlePresetClick = (presetValue: PresetValue, e: React.MouseEvent) => {
6364
const presetVal = typeof presetValue === 'function' ? presetValue() : presetValue;
6465
if (typeof props.activeIndex === 'number') {
6566
if (Array.isArray(presetVal)) {
66-
props.onChange?.(presetVal[props.activeIndex]);
67+
props.onChange?.(presetVal[props.activeIndex], e.nativeEvent);
6768
} else {
6869
log.error('TimePicker', `preset: ${presets} 预设值必须是数组!`);
6970
}
7071
} else {
71-
props.onChange?.(presetVal);
72+
props.onChange?.(presetVal as string, e.nativeEvent);
7273
}
7374
};
7475

@@ -80,8 +81,8 @@ const TimePickerPanel: FC<TimePickerPanelProps> = (props) => {
8081
theme="primary"
8182
size="small"
8283
variant="text"
83-
onClick={() => {
84-
handlePresetClick(presets[preset]);
84+
onClick={(e) => {
85+
handlePresetClick(presets[preset], e);
8586
}}
8687
>
8788
{preset}
@@ -94,8 +95,8 @@ const TimePickerPanel: FC<TimePickerPanelProps> = (props) => {
9495
theme="primary"
9596
variant="text"
9697
size="small"
97-
onClick={() => {
98-
onChange?.(dayjs().format(format));
98+
onClick={(e) => {
99+
onChange?.(dayjs().format(format), e.nativeEvent);
99100
}}
100101
>
101102
{TEXT_CONFIG.nowTime}
@@ -108,7 +109,7 @@ const TimePickerPanel: FC<TimePickerPanelProps> = (props) => {
108109
<div className={`${panelClassName}-section-body`}>
109110
<SinglePanel
110111
{...props}
111-
onChange={onChange}
112+
onChange={onChange as unknown as SinglePanelProps['onChange']}
112113
format={format}
113114
steps={steps}
114115
value={dayjs(value, format).isValid() ? value : defaultValue}

0 commit comments

Comments
 (0)