Skip to content

Commit 5e95b22

Browse files
committed
feat: add support for tippy in button
1 parent cfa69ab commit 5e95b22

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Progressing } from '@Common/Progressing'
2+
import { Tooltip } from '@Common/Tooltip'
23
import { ComponentSizeType } from '@Shared/constants'
34
import { ButtonProps, ButtonStyleType, ButtonVariantType } from './types'
45
import { BUTTON_SIZE_TO_ICON_CLASS_NAME_MAP, BUTTON_SIZE_TO_LOADER_SIZE_MAP } from './constants'
@@ -15,23 +16,29 @@ const Button = ({
1516
endIcon,
1617
disabled,
1718
isLoading,
19+
showTippy,
20+
tippyContent,
1821
}: ButtonProps) => {
22+
const isDisabled = disabled || isLoading
1923
const iconClass = `dc__no-shrink flex dc__fill-available-space ${BUTTON_SIZE_TO_ICON_CLASS_NAME_MAP[size]}`
2024

2125
return (
22-
<button
23-
{...buttonProps}
24-
disabled={disabled || isLoading}
25-
// eslint-disable-next-line react/button-has-type
26-
type={buttonProps.type || 'button'}
27-
className={`br-4 flex cursor dc__mnw-100 dc__tab-focus dc__position-rel dc__capitalize ${getButtonDerivedClass({ size, variant, style, isLoading })} ${disabled ? 'dc__disabled' : ''} ${buttonProps.className || ''}`}
28-
>
29-
{startIcon && <span className={iconClass}>{startIcon}</span>}
30-
<span className="dc__mxw-150 dc__align-left dc__truncate">{text}</span>
31-
{endIcon && <span className={iconClass}>{endIcon}</span>}
32-
{isLoading && <Progressing size={BUTTON_SIZE_TO_LOADER_SIZE_MAP[size]} />}
33-
</button>
26+
<Tooltip content={tippyContent} alwaysShowTippyOnHover={showTippy && !!tippyContent}>
27+
<div>
28+
<button
29+
{...buttonProps}
30+
disabled={isDisabled}
31+
// eslint-disable-next-line react/button-has-type
32+
type={buttonProps.type || 'button'}
33+
className={`br-4 flex cursor dc__mnw-100 dc__tab-focus dc__position-rel dc__capitalize ${getButtonDerivedClass({ size, variant, style, isLoading })} ${isDisabled ? 'dc__disabled' : ''} ${buttonProps.className || ''}`}
34+
>
35+
{startIcon && <span className={iconClass}>{startIcon}</span>}
36+
<span className="dc__mxw-150 dc__align-left dc__truncate">{text}</span>
37+
{endIcon && <span className={iconClass}>{endIcon}</span>}
38+
{isLoading && <Progressing size={BUTTON_SIZE_TO_LOADER_SIZE_MAP[size]} />}
39+
</button>
40+
</div>
41+
</Tooltip>
3442
)
3543
}
36-
3744
export default Button

src/Shared/Components/Button/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ProgressingProps } from '@Common/Types'
33
import { ButtonProps } from './types'
44

55
export const BUTTON_SIZE_TO_CLASS_NAME_MAP: Record<ButtonProps['size'], string> = {
6-
[ComponentSizeType.xs]: 'px-9 py-1 fs-14 lh-20 fw-6 dc__gap-6',
6+
[ComponentSizeType.xs]: 'px-9 py-1 fs-12 lh-20 fw-6 dc__gap-6',
77
[ComponentSizeType.small]: 'px-9 py-3 fs-12 lh-20 fw-6 dc__gap-6',
88
[ComponentSizeType.medium]: 'px-11 py-5 fs-13 lh-20 fw-6 dc__gap-8',
99
[ComponentSizeType.large]: 'px-13 py-7 fs-13 lh-20 fw-6 dc__gap-10',

src/Shared/Components/Button/types.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TooltipProps } from '@Common/Tooltip/types'
12
import { ComponentSizeType } from '@Shared/constants'
23
import { ButtonHTMLAttributes, ReactElement } from 'react'
34

@@ -16,7 +17,7 @@ export enum ButtonStyleType {
1617
neutral = 'neutral',
1718
}
1819

19-
export interface ButtonProps {
20+
export type ButtonProps = {
2021
buttonProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'disabled'>
2122
variant?: ButtonVariantType
2223
size?: ComponentSizeType
@@ -26,4 +27,13 @@ export interface ButtonProps {
2627
endIcon?: ReactElement
2728
disabled?: boolean
2829
isLoading?: boolean
29-
}
30+
} & (
31+
| {
32+
showTippy: boolean
33+
tippyContent: TooltipProps['content']
34+
}
35+
| {
36+
showTippy?: never
37+
tippyContent?: never
38+
}
39+
)

0 commit comments

Comments
 (0)