Skip to content

Commit 5b37674

Browse files
committed
fix: Button - simplify tooltipProps typing and improve type safety
1 parent 7a91d91 commit 5b37674

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/Shared/Components/Button/Button.component.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import { MutableRefObject, PropsWithChildren, useEffect, useRef, useState } from
1818
import { Link } from 'react-router-dom'
1919

2020
import { Progressing } from '@Common/Progressing'
21-
import { Tooltip } from '@Common/Tooltip'
22-
import { TooltipProps } from '@Common/Tooltip/types'
21+
import { Tooltip, TooltipProps } from '@Common/Tooltip'
2322
import { ComponentSizeType } from '@Shared/constants'
2423

2524
import { ButtonComponentType, ButtonProps, ButtonStyleType, ButtonVariantType } from './types'
@@ -232,14 +231,13 @@ const Button = <ComponentType extends ButtonComponentType>({
232231
}
233232

234233
if (Object.hasOwn(tooltipProps, 'shortcutKeyCombo') && 'shortcutKeyCombo' in tooltipProps) {
235-
return tooltipProps
234+
return tooltipProps as TooltipProps
236235
}
237236

238237
return {
239-
// TODO: using some typing somersaults here, clean it up later
240-
alwaysShowTippyOnHover: showTooltip && !!(tooltipProps as Required<Pick<TooltipProps, 'content'>>)?.content,
241-
...(tooltipProps as Required<Pick<TooltipProps, 'content'>>),
242-
}
238+
alwaysShowTippyOnHover: showTooltip && !!tooltipProps?.content,
239+
...tooltipProps,
240+
} as TooltipProps
243241
}
244242

245243
return (

src/Shared/Components/Button/types.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,10 @@ export type ButtonProps<ComponentType extends ButtonComponentType = ButtonCompon
150150
/**
151151
* Props for tooltip
152152
*/
153-
// TODO: using some typing somersaults here, clean it up later
154153
tooltipProps:
155-
| Omit<TooltipProps, 'alwaysShowTippyOnHover' | 'showOnTruncate' | 'shortcutKeyCombo'>
156-
| (Omit<TooltipProps, 'alwaysShowTippyOnHover' | 'showOnTruncate' | 'content'> &
157-
Required<Pick<TooltipProps, 'shortcutKeyCombo'>>)
154+
| Omit<Extract<TooltipProps, { alwaysShowTippyOnHover: boolean }>, 'alwaysShowTippyOnHover'>
155+
| Omit<Extract<TooltipProps, { alwaysShowTippyOnHover?: boolean }>, 'alwaysShowTippyOnHover'>
156+
| Omit<Extract<TooltipProps, { alwaysShowTippyOnHover?: never }>, 'alwaysShowTippyOnHover'>
158157
}
159158
| {
160159
showTooltip?: never

0 commit comments

Comments
 (0)