@@ -7,25 +7,23 @@ import omit from 'rc-util/lib/omit';
7
7
8
8
export type SegmentedValue = string | number ;
9
9
10
- type RawOption = SegmentedValue ;
10
+ type SegmentedRawOption = SegmentedValue ;
11
11
12
- interface LabeledOption {
12
+ interface SegmentedLabeledOption {
13
13
className ?: string ;
14
14
disabled ?: boolean ;
15
15
label : React . ReactNode ;
16
- value : RawOption ;
16
+ value : SegmentedRawOption ;
17
17
}
18
18
19
- type Option = RawOption | LabeledOption ;
20
-
21
- type Options = Option [ ] ;
19
+ type SegmentedOptions = ( SegmentedRawOption | SegmentedLabeledOption ) [ ] ;
22
20
23
21
type ExtendedHTMLInputElement = Omit < HTMLInputElement , 'value' > & {
24
22
value : SegmentedValue ;
25
23
} ;
26
24
27
25
export interface SegmentedProps extends React . HTMLProps < HTMLDivElement > {
28
- options : Options ;
26
+ options : SegmentedOptions ;
29
27
defaultValue ?: SegmentedValue ;
30
28
value ?: SegmentedValue ;
31
29
onChange ?: ( e : React . ChangeEvent < ExtendedHTMLInputElement > ) => void ;
@@ -35,7 +33,7 @@ export interface SegmentedProps extends React.HTMLProps<HTMLDivElement> {
35
33
motionName ?: string ;
36
34
}
37
35
38
- function normalizeOptions ( options : Options ) : LabeledOption [ ] {
36
+ function normalizeOptions ( options : SegmentedOptions ) : SegmentedLabeledOption [ ] {
39
37
return options . map ( ( option ) => {
40
38
if ( typeof option === 'object' ) {
41
39
return option || { } ;
@@ -52,14 +50,17 @@ const calcThumbStyle = (targetElement: HTMLElement): React.CSSProperties => ({
52
50
width : targetElement . clientWidth ,
53
51
} ) ;
54
52
55
- const SegmentedOption : React . FC < {
53
+ const InternalSegmentedOption : React . FC < {
56
54
prefixCls : string ;
57
55
className ?: string ;
58
56
disabled ?: boolean ;
59
57
checked : boolean ;
60
58
label : React . ReactNode ;
61
- value : RawOption ;
62
- onChange : ( e : React . ChangeEvent < HTMLInputElement > , value : RawOption ) => void ;
59
+ value : SegmentedRawOption ;
60
+ onChange : (
61
+ e : React . ChangeEvent < HTMLInputElement > ,
62
+ value : SegmentedRawOption ,
63
+ ) => void ;
63
64
} > = ( { prefixCls, className, disabled, checked, label, value, onChange } ) => {
64
65
const handleChange = ( event : React . ChangeEvent < HTMLInputElement > ) => {
65
66
if ( disabled ) {
@@ -119,7 +120,7 @@ const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>(
119
120
) ;
120
121
121
122
const [ visualSelected , setVisualSelected ] = React . useState <
122
- RawOption | undefined
123
+ SegmentedRawOption | undefined
123
124
> ( selected ) ;
124
125
125
126
const [ thumbShow , setThumbShow ] = React . useState ( false ) ;
@@ -143,7 +144,7 @@ const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>(
143
144
144
145
const handleChange = (
145
146
event : React . ChangeEvent < HTMLInputElement > ,
146
- value : RawOption ,
147
+ value : SegmentedRawOption ,
147
148
) => {
148
149
if ( disabled ) {
149
150
return ;
@@ -231,7 +232,7 @@ const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>(
231
232
} }
232
233
</ CSSMotion >
233
234
{ segmentedOptions . map ( ( segmentedOption ) => (
234
- < SegmentedOption
235
+ < InternalSegmentedOption
235
236
key = { segmentedOption . value }
236
237
prefixCls = { prefixCls }
237
238
className = { classNames ( segmentedOption . className , {
0 commit comments