-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tooltip component #8
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,19 +5,25 @@ | |
import { classNames as cx, type ComponentProps } from '../../../util/componentUtil.ts'; | ||
import * as React from 'react'; | ||
|
||
import { Icon, IconProps } from '../../graphics/Icon/Icon.tsx'; | ||
|
||
import cl from './Tooltip.module.scss'; | ||
|
||
|
||
export { cl as TooltipClassNames }; | ||
|
||
export type TooltipSize = 'small' | 'medium' | 'large'; | ||
|
||
export type TooltipProps = React.PropsWithChildren<ComponentProps<'div'> & { | ||
/** Whether this component should be unstyled. */ | ||
unstyled?: undefined | boolean, | ||
/** Whether you want the component to have a fixed width. If unset, it will have dynamic size. */ | ||
size?: undefined | TooltipSize, | ||
}>; | ||
/** | ||
* A tooltip. Used by `TooltipProvider` to display a tooltip popover. | ||
*/ | ||
export const Tooltip = ({ unstyled = false, ...propsRest }: TooltipProps) => { | ||
export const Tooltip = ({ unstyled = false, size = undefined, ...propsRest }: TooltipProps) => { | ||
return ( | ||
<div | ||
role="tooltip" // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/tooltip_role | ||
|
@@ -26,7 +32,44 @@ export const Tooltip = ({ unstyled = false, ...propsRest }: TooltipProps) => { | |
bk: true, | ||
[cl['bk-tooltip']]: !unstyled, | ||
'bk-body-text': !unstyled, | ||
[cl['bk-tooltip--size-small']]: size === 'small', | ||
[cl['bk-tooltip--size-medium']]: size === 'medium', | ||
[cl['bk-tooltip--size-large']]: size === 'large', | ||
}, propsRest.className)} | ||
/> | ||
); | ||
}; | ||
|
||
export type TooltipTitleProps = React.PropsWithChildren<ComponentProps<'h1'>>; | ||
|
||
/** | ||
* Tooltip title. Can be optionally used as tooltip children. | ||
*/ | ||
export const TooltipTitle = ({ children }: TooltipTitleProps) => ( | ||
<h1 className={cl['bk-tooltip--title']}>{children}</h1> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think class name |
||
); | ||
|
||
export type TooltipItemProps = React.PropsWithChildren<ComponentProps<'h1'> & { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/** Whether the item is an alert */ | ||
alert?: undefined | boolean; | ||
}>; | ||
|
||
/** | ||
* Tooltip item. Can be optionally used as tooltip children. | ||
*/ | ||
export const TooltipItem = ({ alert = false, children }: TooltipItemProps) => ( | ||
<p | ||
className={cx({ | ||
[cl['bk-tooltip--alert']]: alert, | ||
})} | ||
> | ||
{children} | ||
</p> | ||
); | ||
|
||
/** | ||
* Tooltip icon. Can be optionally used as tooltip children. | ||
*/ | ||
export const TooltipIcon = (props: IconProps) => ( | ||
<Icon className={cl['bk-tooltip--icon']} {...props} /> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bk-tooltip--size-small
can bebk-tooltip--small
if we follow the same way as different components likebk-spinner--small
orbk-link--small
format.