Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2483 from teamleadercrm/avatar-custom-tooltip
Browse files Browse the repository at this point in the history
Add `tooltipProps` to `Avatar` to allow a custom tooltip
  • Loading branch information
BeirlaenAaron authored Dec 9, 2022
2 parents c28d460 + 0b89385 commit fd9f4db
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

### Dependency updates

## [18.2.0] - 2022-12-08

### Added

- `Avatar`: Add a prop `tooltipProps` to allow a custom tooltip ([@BeirlaenAaron](https://github.com/BeirlaenAaron)) in ([#2483](https://github.com/teamleadercrm/ui/pull/2483))

## [18.1.2] - 2022-12-07

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@teamleader/ui",
"description": "Teamleader UI library",
"version": "18.1.2",
"version": "18.2.0",
"author": "Teamleader <[email protected]>",
"bugs": {
"url": "https://github.com/teamleadercrm/ui/issues"
Expand Down
10 changes: 7 additions & 3 deletions src/components/avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface AvatarProps extends Omit<BoxProps, 'size' | 'ref'> {
team?: boolean;
/** If true, the name will be shown in a tooltip on hover. */
tooltip?: boolean;
/** The tooltip props for the avatar */
tooltipProps?: TooltipProps;
}

type AvatarInternalComponentProps = { size: Exclude<typeof SIZES[number], 'fullscreen' | 'smallest'> } & Pick<
Expand Down Expand Up @@ -138,6 +140,7 @@ const Avatar = ({
id,
onImageChange,
team,
tooltipProps,
...others
}: AvatarProps) => {
const avatarClassNames = cx(
Expand All @@ -151,23 +154,24 @@ const Avatar = ({
className,
);

const enableTooltip = tooltip && typeof fullName === 'string' && fullName.length > 0;
const enableTooltip = tooltip && ((typeof fullName === 'string' && fullName.length > 0) || tooltipProps?.tooltip);

const Component = enableTooltip ? TooltippedBox : Box;
const tooltipProps = enableTooltip
const defaultToolTipProps = enableTooltip
? {
tooltip: <TextBodyCompact>{fullName}</TextBodyCompact>,
tooltipColor: 'white',
tooltipPosition: 'top',
tooltipSize: 'small',
...tooltipProps,
}
: {};

return (
<Component
{...others}
{...(selectable && { boxSizing: 'content-box', padding: size === 'hero' ? 2 : 1 })}
{...(tooltipProps as TooltipProps)}
{...(defaultToolTipProps as TooltipProps)}
className={avatarClassNames}
>
<AvatarInternalComponent
Expand Down
12 changes: 11 additions & 1 deletion src/components/avatar/avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { Avatar, Bullet } from '../../index';
import { Avatar, Bullet, TextBodyCompact } from '../../index';
import avatars from '../../static/data/avatar';
import { addStoryInGroup, MID_LEVEL_BLOCKS } from '../../../.storybook/utils';

Expand Down Expand Up @@ -29,3 +29,13 @@ export const WithBullet = () => (
<Bullet borderColor="neutral" borderTint="lightest" color="ruby" />
</Avatar>
);

export const WithCustomTooltip: ComponentStory<typeof Avatar> = (args) => <Avatar {...args} />;

WithCustomTooltip.args = {
tooltip: true,
tooltipProps: {
tooltip: <TextBodyCompact>Unassigned</TextBodyCompact>,
tooltipSize: 'small',
},
};

0 comments on commit fd9f4db

Please sign in to comment.