From c26fdac81353c4b203ff6fc3266666576daaae70 Mon Sep 17 00:00:00 2001 From: tmanyanov <2737310+darkwebdev@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:21:58 -0700 Subject: [PATCH] update types --- .../__tests__/index.stories.tsx | 6 +++--- src/ebay-segmented-buttons/button.tsx | 4 +++- src/ebay-segmented-buttons/index.ts | 2 +- src/ebay-segmented-buttons/segmented-buttons.tsx | 2 +- src/ebay-segmented-buttons/types.ts | 13 +++++++------ 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/ebay-segmented-buttons/__tests__/index.stories.tsx b/src/ebay-segmented-buttons/__tests__/index.stories.tsx index bfc77105..a5be3163 100644 --- a/src/ebay-segmented-buttons/__tests__/index.stories.tsx +++ b/src/ebay-segmented-buttons/__tests__/index.stories.tsx @@ -1,7 +1,7 @@ import React from 'react' import { Meta, StoryObj } from '@storybook/react' import { action } from '@storybook/addon-actions' -import { EbaySegmentedButtons, SegmentedButtonsProps, EbaySegmentedButton as Button } from '..' +import { EbaySegmentedButtons, EbaySegmentedButton as Button } from '..' import { EbayIcon } from '../../ebay-icon' export default { @@ -31,7 +31,7 @@ export default { } } as Meta -export const Default: StoryObj = { +export const Default: StoryObj = { render: args => ( @@ -42,7 +42,7 @@ export const Default: StoryObj = { ) } -export const WithIcons: StoryObj = { +export const WithIcons: StoryObj = { render: args => ( diff --git a/src/ebay-segmented-buttons/button.tsx b/src/ebay-segmented-buttons/button.tsx index 1a176219..f148eb69 100644 --- a/src/ebay-segmented-buttons/button.tsx +++ b/src/ebay-segmented-buttons/button.tsx @@ -7,7 +7,8 @@ import { SegmentedButtonProps } from './types' const SegmentedButton: FC = ({ selected, children, - onClick + onClick, + ...rest }) => { const icon = findComponent(children, EbayIcon) @@ -28,6 +29,7 @@ const SegmentedButton: FC = ({ className={classNames('segmented-buttons__button')} aria-current={selected || undefined} onClick={onClick} + {...rest} > {icon ? iconWithText() : children} diff --git a/src/ebay-segmented-buttons/index.ts b/src/ebay-segmented-buttons/index.ts index 0a49aab8..5c7fec87 100644 --- a/src/ebay-segmented-buttons/index.ts +++ b/src/ebay-segmented-buttons/index.ts @@ -1,3 +1,3 @@ export { default as EbaySegmentedButtons } from './segmented-buttons' export { default as EbaySegmentedButton } from './button' -export { SegmentedButtonsProps, SegmentedButtonProps } from './types' +export type { SegmentedButtonsProps, SegmentedButtonProps, SegmentedButtonSize } from './types' diff --git a/src/ebay-segmented-buttons/segmented-buttons.tsx b/src/ebay-segmented-buttons/segmented-buttons.tsx index 9bc2758c..aba544a4 100644 --- a/src/ebay-segmented-buttons/segmented-buttons.tsx +++ b/src/ebay-segmented-buttons/segmented-buttons.tsx @@ -16,7 +16,7 @@ const EbaySegmentedButtons: FC = ({ buttons.findIndex(button => button.props.selected) || 0 ) - const handleClick = (e: React.MouseEvent, index: number, value: string) => { + const handleClick = (e, index: number, value: string) => { setSelectedIndex(index) onChange(e, { index, value }) } diff --git a/src/ebay-segmented-buttons/types.ts b/src/ebay-segmented-buttons/types.ts index ed095348..54a7e415 100644 --- a/src/ebay-segmented-buttons/types.ts +++ b/src/ebay-segmented-buttons/types.ts @@ -1,14 +1,15 @@ import { ComponentProps } from 'react' -import { EbayMouseEventHandler } from '../common/event-utils/types' +import { EbayChangeEventHandler, EbayMouseEventHandler } from '../common/event-utils/types' -export interface SegmentedButtonProps extends Omit, 'onClick'> { +export type SegmentedButtonProps = Omit, 'onClick'> & { value?: string; selected?: boolean; onClick?: EbayMouseEventHandler; } -export interface SegmentedButtonsProps extends Omit, 'onChange'> { - buttons?: SegmentedButtonProps[]; - size?: 'large' | 'regular'; - onChange?: EbayMouseEventHandler; +export type SegmentedButtonSize = 'large' | 'regular' + +export type SegmentedButtonsProps = Omit, 'onChange'> & { + size?: SegmentedButtonSize; + onChange?: EbayChangeEventHandler; }