Skip to content
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

feat(Tooltip): Rich tooltip #2040

Merged
merged 17 commits into from
Apr 3, 2024
2 changes: 1 addition & 1 deletion packages/core/src/components/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { withStaticProps } from "../../types";
import styles from "./Text.module.scss";

export interface TextProps extends TypographyProps {
type: TextType;
type?: TextType;
talkor marked this conversation as resolved.
Show resolved Hide resolved
weight?: TextWeight;
children: ReactNode;
}
Expand Down
34 changes: 27 additions & 7 deletions packages/core/src/components/Tooltip/Tooltip.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ $tooltip-z-index: 9999999999999999;

.tooltip {
position: relative;
display: inline-block;
border-radius: var(--tooltip-border-radius, var(--border-radius-small));
padding: var(--tooltip-padding, #{var(--spacing-small) var(--spacing-medium)});
box-shadow: var(--box-shadow-medium);
@include font-input();
max-width: var(--tooltip-max-width, 50vw);
Expand All @@ -15,12 +13,34 @@ $tooltip-z-index: 9999999999999999;
&.withMaxWidth {
--tooltip-max-width: 240px;
}
}

.tooltip.paddingSizeMd {
border-radius: var(--border-radius-medium);
padding: var(--spacing-medium);
@include font-input();
.image {
display: block;
position: relative;
border-top-right-radius: 2px;
border-top-left-radius: 2px;
padding: 2px 2px 0 2px;
object-fit: cover;
width: 100%;
height: 100%;
min-width: var(--tooltip-max-width);
z-index: 1;
}

.title {
talkor marked this conversation as resolved.
Show resolved Hide resolved
@include vibe-text(text2, bold);
}

.content {
display: inline-block;
padding: var(--tooltip-padding, #{var(--spacing-small) var(--spacing-medium)});
talkor marked this conversation as resolved.
Show resolved Hide resolved

&.paddingSizeMd {
border-radius: var(--border-radius-medium);
padding: var(--spacing-medium);
@include font-input();
}
}
}

.tooltip a.tooltipWhiteLink {
Expand Down
33 changes: 28 additions & 5 deletions packages/core/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { MoveBy } from "../../types/MoveBy";
import { getStyle } from "../../helpers/typesciptCssModulesHelper";
import styles from "./Tooltip.module.scss";
import { ComponentDefaultTestId, getTestId } from "../../tests/test-ids-utils";
import { SubIcon } from "../../types";
import Icon from "../Icon/Icon";
import Flex from "../Flex/Flex";

export type TooltipProps = TooltipBaseProps & (TooltipWithChildrenProps | TooltipWithoutChildrenProps);

Expand Down Expand Up @@ -100,7 +103,7 @@ interface TooltipBaseProps extends VibeComponentProps {
*/
showOnDialogEnter?: boolean;
/**
* A Classname to be added to <spam> element which wraps the children
* A Classname to be added to <span> element which wraps the children
talkor marked this conversation as resolved.
Show resolved Hide resolved
*/
referenceWrapperClassName?: string;
/**
Expand All @@ -115,11 +118,23 @@ interface TooltipBaseProps extends VibeComponentProps {
* Overwrites z-index of the tooltip
*/
zIndex?: number;
// TODO: make defualt next major
// TODO: make default next major
/**
* Limit tooltip to 240px
*/
withMaxWidth?: boolean;
/**
* The title of the tooltip
*/
title?: string;
/**
* The image of the tooltip
*/
image?: string;
talkor marked this conversation as resolved.
Show resolved Hide resolved
/**
* The icon of the tooltip next to the title
*/
icon?: SubIcon;
}
// When last tooltip was shown in the last 1.5 second - the next tooltip will be shown immediately
const IMMEDIATE_SHOW_THRESHOLD_MS = 1500;
Expand Down Expand Up @@ -175,7 +190,7 @@ export default class Tooltip extends PureComponent<TooltipProps> {
}

renderTooltipContent() {
const { theme, content, paddingSize, className, style, withMaxWidth } = this.props;
const { theme, content, paddingSize, className, style, withMaxWidth, title, image, icon } = this.props;
if (!content) {
// don't render empty tooltip
return null;
Expand All @@ -198,12 +213,20 @@ export default class Tooltip extends PureComponent<TooltipProps> {
className={cx(
styles.tooltip,
getStyle(styles, camelCase(theme)),
getStyle(styles, camelCase("padding-size-" + paddingSize)),
{ [styles.withMaxWidth]: withMaxWidth },
className
)}
>
{contentValue}
{image && <img className={styles.image} src={image} alt="" />}
<div className={cx(styles.content, getStyle(styles, camelCase("padding-size-" + paddingSize)))}>
talkor marked this conversation as resolved.
Show resolved Hide resolved
{title && (
<Flex gap={Flex.gaps.XS}>
{icon && <Icon iconSize="20" icon={icon} clickable={false} />}
<div className={styles.title}>{title}</div>
</Flex>
)}
{contentValue}
</div>
talkor marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading
Loading