mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 11:32:52 +08:00
chore(slider): optimize type definition (#26884)
This commit is contained in:
parent
aac1d4e434
commit
006abe5e92
@ -1,7 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RcSlider from 'rc-slider/lib/Slider';
|
import RcSlider, { Range as RcRange, Handle as RcHandle } from 'rc-slider';
|
||||||
import RcRange from 'rc-slider/lib/Range';
|
|
||||||
import RcHandle from 'rc-slider/lib/Handle';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { TooltipPlacement } from '../tooltip';
|
import { TooltipPlacement } from '../tooltip';
|
||||||
import SliderTooltip from './SliderTooltip';
|
import SliderTooltip from './SliderTooltip';
|
||||||
@ -18,16 +16,15 @@ export interface SliderMarks {
|
|||||||
|
|
||||||
interface HandleGeneratorInfo {
|
interface HandleGeneratorInfo {
|
||||||
value?: number;
|
value?: number;
|
||||||
dragging: boolean;
|
dragging?: boolean;
|
||||||
index: number;
|
index: number;
|
||||||
rest: any[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type HandleGeneratorFn = (config: {
|
export type HandleGeneratorFn = (config: {
|
||||||
tooltipPrefixCls?: string;
|
tooltipPrefixCls?: string;
|
||||||
prefixCls?: string;
|
prefixCls?: string;
|
||||||
info: HandleGeneratorInfo;
|
info: HandleGeneratorInfo;
|
||||||
}) => React.ReactNode;
|
}) => React.ReactElement;
|
||||||
|
|
||||||
export interface SliderBaseProps {
|
export interface SliderBaseProps {
|
||||||
prefixCls?: string;
|
prefixCls?: string;
|
||||||
@ -35,7 +32,7 @@ export interface SliderBaseProps {
|
|||||||
reverse?: boolean;
|
reverse?: boolean;
|
||||||
min?: number;
|
min?: number;
|
||||||
max?: number;
|
max?: number;
|
||||||
step?: number | null;
|
step?: number;
|
||||||
marks?: SliderMarks;
|
marks?: SliderMarks;
|
||||||
dots?: boolean;
|
dots?: boolean;
|
||||||
included?: boolean;
|
included?: boolean;
|
||||||
@ -70,7 +67,8 @@ export interface SliderRangeProps extends SliderBaseProps {
|
|||||||
|
|
||||||
export type Visibles = { [index: number]: boolean };
|
export type Visibles = { [index: number]: boolean };
|
||||||
|
|
||||||
const Slider = React.forwardRef<unknown, SliderSingleProps | SliderRangeProps>((props, ref) => {
|
const Slider = React.forwardRef<unknown, SliderSingleProps | SliderRangeProps>(
|
||||||
|
(props, ref: any) => {
|
||||||
const { getPrefixCls, direction, getPopupContainer } = React.useContext(ConfigContext);
|
const { getPrefixCls, direction, getPopupContainer } = React.useContext(ConfigContext);
|
||||||
const [visibles, setVisibles] = React.useState<Visibles>({});
|
const [visibles, setVisibles] = React.useState<Visibles>({});
|
||||||
|
|
||||||
@ -144,7 +142,7 @@ const Slider = React.forwardRef<unknown, SliderSingleProps | SliderRangeProps>((
|
|||||||
if (range) {
|
if (range) {
|
||||||
return (
|
return (
|
||||||
<RcRange
|
<RcRange
|
||||||
{...restProps}
|
{...(restProps as SliderRangeProps)}
|
||||||
className={cls}
|
className={cls}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
handle={(info: HandleGeneratorInfo) =>
|
handle={(info: HandleGeneratorInfo) =>
|
||||||
@ -155,13 +153,12 @@ const Slider = React.forwardRef<unknown, SliderSingleProps | SliderRangeProps>((
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
prefixCls={prefixCls}
|
prefixCls={prefixCls}
|
||||||
tooltipPrefixCls={tooltipPrefixCls}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<RcSlider
|
<RcSlider
|
||||||
{...restProps}
|
{...(restProps as SliderSingleProps)}
|
||||||
className={cls}
|
className={cls}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
handle={(info: HandleGeneratorInfo) =>
|
handle={(info: HandleGeneratorInfo) =>
|
||||||
@ -172,10 +169,10 @@ const Slider = React.forwardRef<unknown, SliderSingleProps | SliderRangeProps>((
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
prefixCls={prefixCls}
|
prefixCls={prefixCls}
|
||||||
tooltipPrefixCls={tooltipPrefixCls}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
Slider.displayName = 'Slider';
|
Slider.displayName = 'Slider';
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@
|
|||||||
"rc-rate": "~2.8.2",
|
"rc-rate": "~2.8.2",
|
||||||
"rc-resize-observer": "^0.2.3",
|
"rc-resize-observer": "^0.2.3",
|
||||||
"rc-select": "~11.3.2",
|
"rc-select": "~11.3.2",
|
||||||
"rc-slider": "~9.4.1",
|
"rc-slider": "~9.5.1",
|
||||||
"rc-steps": "~4.1.0",
|
"rc-steps": "~4.1.0",
|
||||||
"rc-switch": "~3.2.0",
|
"rc-switch": "~3.2.0",
|
||||||
"rc-table": "~7.9.2",
|
"rc-table": "~7.9.2",
|
||||||
|
8
typings/custom-typings.d.ts
vendored
8
typings/custom-typings.d.ts
vendored
@ -46,14 +46,6 @@ declare module 'rc-rate';
|
|||||||
|
|
||||||
declare module 'rc-queue-anim';
|
declare module 'rc-queue-anim';
|
||||||
|
|
||||||
declare module 'rc-slider';
|
|
||||||
|
|
||||||
declare module 'rc-slider/lib/Slider';
|
|
||||||
|
|
||||||
declare module 'rc-slider/lib/Range';
|
|
||||||
|
|
||||||
declare module 'rc-slider/lib/Handle';
|
|
||||||
|
|
||||||
declare module 'rc-steps';
|
declare module 'rc-steps';
|
||||||
|
|
||||||
declare module 'rc-switch';
|
declare module 'rc-switch';
|
||||||
|
Loading…
Reference in New Issue
Block a user