Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan committed Mar 1, 2024
2 parents 2936952 + c46c015 commit a801f56
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 57 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/codeql.yml

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-segmented",
"version": "2.2.2",
"version": "2.3.0",
"description": "React segmented controls used in ant.design",
"keywords": [
"react",
Expand Down Expand Up @@ -78,7 +78,7 @@
"react": "^18.0.0",
"react-dom": "^18.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
"typescript": "^5.3.0"
},
"peerDependencies": {
"react": ">=16.0.0",
Expand Down
42 changes: 28 additions & 14 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
import * as React from 'react';
import classNames from 'classnames';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import { composeRef } from 'rc-util/lib/ref';
import omit from 'rc-util/lib/omit';
import { composeRef } from 'rc-util/lib/ref';
import * as React from 'react';

import MotionThumb from './MotionThumb';

export type SegmentedValue = string | number;

export type SegmentedRawOption = SegmentedValue;

export interface SegmentedLabeledOption {
export interface SegmentedLabeledOption<ValueType = SegmentedRawOption> {
className?: string;
disabled?: boolean;
label: React.ReactNode;
value: SegmentedRawOption;
value: ValueType;
/**
* html `title` property for label
*/
title?: string;
}

type SegmentedOptions = (SegmentedRawOption | SegmentedLabeledOption)[];

export interface SegmentedProps
extends Omit<React.HTMLProps<HTMLDivElement>, 'onChange'> {
options: SegmentedOptions;
defaultValue?: SegmentedValue;
value?: SegmentedValue;
onChange?: (value: SegmentedValue) => void;
type SegmentedOptions<T = SegmentedRawOption> = (
| T
| SegmentedLabeledOption<T>
)[];

export interface SegmentedProps<ValueType = SegmentedValue>
extends Omit<
React.HTMLProps<HTMLDivElement>,
'defaultValue' | 'value' | 'onChange'
> {
options: SegmentedOptions<ValueType>;
defaultValue?: ValueType;
value?: ValueType;
onChange?: (value: ValueType) => void;
disabled?: boolean;
prefixCls?: string;
direction?: 'ltr' | 'rtl';
Expand Down Expand Up @@ -219,6 +225,14 @@ const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>(
},
);

Segmented.displayName = 'Segmented';
if (process.env.NODE_ENV !== 'production') {
Segmented.displayName = 'Segmented';
}

const TypedSegmented = Segmented as <ValueType>(
props: SegmentedProps<ValueType> & {
ref?: React.ForwardedRef<HTMLDivElement>;
},
) => ReturnType<typeof Segmented>;

export default Segmented;
export default TypedSegmented;

0 comments on commit a801f56

Please sign in to comment.