|
1 |
| -import * as React from 'react'; |
2 | 1 | import classNames from 'classnames';
|
3 | 2 | import useMergedState from 'rc-util/lib/hooks/useMergedState';
|
4 |
| -import { composeRef } from 'rc-util/lib/ref'; |
5 | 3 | import omit from 'rc-util/lib/omit';
|
| 4 | +import { composeRef } from 'rc-util/lib/ref'; |
| 5 | +import * as React from 'react'; |
6 | 6 |
|
7 | 7 | import MotionThumb from './MotionThumb';
|
8 | 8 |
|
9 | 9 | export type SegmentedValue = string | number;
|
10 | 10 |
|
11 | 11 | export type SegmentedRawOption = SegmentedValue;
|
12 | 12 |
|
13 |
| -export interface SegmentedLabeledOption { |
| 13 | +export interface SegmentedLabeledOption<ValueType = SegmentedRawOption> { |
14 | 14 | className?: string;
|
15 | 15 | disabled?: boolean;
|
16 | 16 | label: React.ReactNode;
|
17 |
| - value: SegmentedRawOption; |
| 17 | + value: ValueType; |
18 | 18 | /**
|
19 | 19 | * html `title` property for label
|
20 | 20 | */
|
21 | 21 | title?: string;
|
22 | 22 | }
|
23 | 23 |
|
24 |
| -type SegmentedOptions = (SegmentedRawOption | SegmentedLabeledOption)[]; |
25 |
| - |
26 |
| -export interface SegmentedProps |
27 |
| - extends Omit<React.HTMLProps<HTMLDivElement>, 'onChange'> { |
28 |
| - options: SegmentedOptions; |
29 |
| - defaultValue?: SegmentedValue; |
30 |
| - value?: SegmentedValue; |
31 |
| - onChange?: (value: SegmentedValue) => void; |
| 24 | +type SegmentedOptions<T = SegmentedRawOption> = ( |
| 25 | + | T |
| 26 | + | SegmentedLabeledOption<T> |
| 27 | +)[]; |
| 28 | + |
| 29 | +export interface SegmentedProps<ValueType = SegmentedValue> |
| 30 | + extends Omit< |
| 31 | + React.HTMLProps<HTMLDivElement>, |
| 32 | + 'defaultValue' | 'value' | 'onChange' |
| 33 | + > { |
| 34 | + options: SegmentedOptions<ValueType>; |
| 35 | + defaultValue?: ValueType; |
| 36 | + value?: ValueType; |
| 37 | + onChange?: (value: ValueType) => void; |
32 | 38 | disabled?: boolean;
|
33 | 39 | prefixCls?: string;
|
34 | 40 | direction?: 'ltr' | 'rtl';
|
@@ -219,6 +225,14 @@ const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>(
|
219 | 225 | },
|
220 | 226 | );
|
221 | 227 |
|
222 |
| -Segmented.displayName = 'Segmented'; |
| 228 | +if (process.env.NODE_ENV !== 'production') { |
| 229 | + Segmented.displayName = 'Segmented'; |
| 230 | +} |
| 231 | + |
| 232 | +const TypedSegmented = Segmented as <ValueType>( |
| 233 | + props: SegmentedProps<ValueType> & { |
| 234 | + ref?: React.ForwardedRef<HTMLDivElement>; |
| 235 | + }, |
| 236 | +) => ReturnType<typeof Segmented>; |
223 | 237 |
|
224 |
| -export default Segmented; |
| 238 | +export default TypedSegmented; |
0 commit comments