Skip to content

Commit a801f56

Browse files
committed
fix: fix
2 parents 2936952 + c46c015 commit a801f56

File tree

3 files changed

+30
-57
lines changed

3 files changed

+30
-57
lines changed

.github/workflows/codeql.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-segmented",
3-
"version": "2.2.2",
3+
"version": "2.3.0",
44
"description": "React segmented controls used in ant.design",
55
"keywords": [
66
"react",
@@ -78,7 +78,7 @@
7878
"react": "^18.0.0",
7979
"react-dom": "^18.0.0",
8080
"ts-node": "^10.9.1",
81-
"typescript": "^4.9.4"
81+
"typescript": "^5.3.0"
8282
},
8383
"peerDependencies": {
8484
"react": ">=16.0.0",

src/index.tsx

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
1-
import * as React from 'react';
21
import classNames from 'classnames';
32
import useMergedState from 'rc-util/lib/hooks/useMergedState';
4-
import { composeRef } from 'rc-util/lib/ref';
53
import omit from 'rc-util/lib/omit';
4+
import { composeRef } from 'rc-util/lib/ref';
5+
import * as React from 'react';
66

77
import MotionThumb from './MotionThumb';
88

99
export type SegmentedValue = string | number;
1010

1111
export type SegmentedRawOption = SegmentedValue;
1212

13-
export interface SegmentedLabeledOption {
13+
export interface SegmentedLabeledOption<ValueType = SegmentedRawOption> {
1414
className?: string;
1515
disabled?: boolean;
1616
label: React.ReactNode;
17-
value: SegmentedRawOption;
17+
value: ValueType;
1818
/**
1919
* html `title` property for label
2020
*/
2121
title?: string;
2222
}
2323

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;
3238
disabled?: boolean;
3339
prefixCls?: string;
3440
direction?: 'ltr' | 'rtl';
@@ -219,6 +225,14 @@ const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>(
219225
},
220226
);
221227

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>;
223237

224-
export default Segmented;
238+
export default TypedSegmented;

0 commit comments

Comments
 (0)