-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(theme): extend Button with tooltip
- Loading branch information
Showing
4 changed files
with
65 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Button as ButtonMantine, createPolymorphicComponent, Tooltip} from '@mantine/core'; | ||
import type {ButtonProps as ButtonPropsMantine, TooltipProps} from '@mantine/core/lib/components'; | ||
import {forwardRef} from 'react'; | ||
|
||
// See boilerpate at: https://mantine.dev/guides/polymorphic/#wrapping-polymorphic-components | ||
|
||
export interface ButtonProps extends ButtonPropsMantine { | ||
tooltip?: React.ReactNode; | ||
tooltipProps?: Partial<Omit<TooltipProps, 'label'>>; | ||
} | ||
|
||
const Button = forwardRef<HTMLButtonElement, ButtonProps>(({tooltip, tooltipProps, ...others}, ref) => { | ||
if (!tooltip) { | ||
return ( | ||
<ButtonMantine {...others} ref={ref} /> | ||
); | ||
} | ||
|
||
return ( | ||
<Tooltip label={tooltip} {...tooltipProps}> | ||
<ButtonMantine {...others} ref={ref} /> | ||
</Tooltip> | ||
); | ||
}); | ||
Button.displayName = 'Button'; | ||
|
||
export default createPolymorphicComponent<'button', ButtonProps>(Button); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {Tooltip} from '@mantine/core'; | ||
|
||
export const TooltipThemeKobo = Tooltip.extend({ | ||
defaultProps: { | ||
offset: {mainAxis: -4}, | ||
position: 'bottom', | ||
withArrow: true, | ||
arrowSize: 8, | ||
// arrowPosition: 'center', | ||
}, | ||
vars: (theme, props) => { | ||
Check failure on line 11 in jsapp/js/theme/kobo/Tooltip.ts GitHub Actions / npm-test / build (16.15.0)
Check failure on line 11 in jsapp/js/theme/kobo/Tooltip.ts GitHub Actions / npm-test / build (20.17.0)
Check failure on line 11 in jsapp/js/theme/kobo/Tooltip.ts GitHub Actions / npm-test / build (20)
|
||
return { | ||
tooltip: { | ||
'--tooltip-bg': theme.colors.gray[2], | ||
'--tooltip-color': 'var(--mantine-color-white)', | ||
'--tooltip-radius': theme.radius.xs, | ||
}, | ||
}; | ||
}, | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters