Skip to content

Commit

Permalink
feat: string number boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyair committed Jan 2, 2024
1 parent 37b4bb3 commit 004f80a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/MotionThumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import CSSMotion from 'rc-motion';
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
import { composeRef } from 'rc-util/lib/ref';
import * as React from 'react';
import type { SegmentedValue } from '.';

type ThumbReact = {
left: number;
right: number;
width: number;
} | null;

export interface MotionThumbInterface<Value = any> {
export interface MotionThumbInterface<Value = SegmentedValue> {
containerRef: React.RefObject<HTMLDivElement>;
value: Value;
getValueIndex: (value: Value) => number;
Expand Down
15 changes: 10 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import * as React from 'react';

import MotionThumb from './MotionThumb';

export interface SegmentedLabeledOption<Value = any> {
export type SegmentedValue = string | number | boolean;

export interface SegmentedLabeledOption<Value = SegmentedValue> {
className?: string;
disabled?: boolean;
label: React.ReactNode;
Expand All @@ -17,9 +19,12 @@ export interface SegmentedLabeledOption<Value = any> {
title?: string;
}

type SegmentedOptions<Value = any> = (Value | SegmentedLabeledOption<Value>)[];
type SegmentedOptions<Value = SegmentedValue> = (
| Value
| SegmentedLabeledOption<Value>
)[];

export interface SegmentedProps<Value = any>
export interface SegmentedProps<Value = SegmentedValue>
extends Omit<
React.HTMLProps<HTMLDivElement>,
'value' | 'defaultValue' | 'onChange'
Expand Down Expand Up @@ -192,7 +197,7 @@ const InternalSegmented: React.ForwardRefRenderFunction<
{segmentedOptions.map((segmentedOption) => (
<InternalSegmentedOption
{...segmentedOption}
key={segmentedOption.value}
key={segmentedOption.value as any}
prefixCls={prefixCls}
className={classNames(
segmentedOption.className,
Expand All @@ -214,7 +219,7 @@ const InternalSegmented: React.ForwardRefRenderFunction<

const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>(
InternalSegmented,
) as (<Value = any>(
) as (<Value = SegmentedValue>(
props: SegmentedProps<Value> & { ref?: React.Ref<HTMLDivElement> },
) => React.ReactElement) & { displayName?: string };

Expand Down

0 comments on commit 004f80a

Please sign in to comment.