Skip to content

Commit

Permalink
feat(UserLabel): add size property (#1658)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrey Morozov <[email protected]>
  • Loading branch information
rLukoyanov and amje authored Jun 24, 2024
1 parent ea320f7 commit 39cd8ad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/components/UserLabel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ LANDING_BLOCK-->
| className | Custom CSS class for root element | `string` | |
| style | HTML style attribute | `React.CSSProperties` | |
| qa | HTML `data-qa` attribute, used in tests | `string` | |
| size | Avatar size | `'xs'` `'s'` `'m'` `'l'` `'xl'` | `'s'` |

## CSS API

Expand Down
12 changes: 12 additions & 0 deletions src/components/UserLabel/UserLabel.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use '../../../styles/mixins';
@use '../variables';
@use '../Avatar/variables' as avatar-variables;

$block: '.#{variables.$ns}user-label';

Expand Down Expand Up @@ -114,4 +115,15 @@ $block: '.#{variables.$ns}user-label';
outline: 2px solid var(--g-color-line-focus);
}
}

&_size {
@each $size-name, $size-value in avatar-variables.$sizes {
&_#{$size-name} {
height: #{$size-value};
}
&_xl::after {
border-radius: 150px;
}
}
}
}
13 changes: 4 additions & 9 deletions src/components/UserLabel/UserLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import {Envelope, Xmark} from '@gravity-ui/icons';

import {Avatar} from '../Avatar';
import type {AvatarProps} from '../Avatar';
import {Icon} from '../Icon';
import {block} from '../utils/cn';

Expand All @@ -12,10 +11,6 @@ import type {UserLabelProps} from './types';

import './UserLabel.scss';

const COMMON_AVATAR_PROPS: Partial<AvatarProps> = {
size: 's',
};

const b = block('user-label');

export const UserLabel = React.forwardRef<HTMLDivElement, UserLabelProps>(
Expand All @@ -30,6 +25,7 @@ export const UserLabel = React.forwardRef<HTMLDivElement, UserLabelProps>(
className,
style,
qa,
size = 's',
},
ref,
) => {
Expand All @@ -54,9 +50,7 @@ export const UserLabel = React.forwardRef<HTMLDivElement, UserLabelProps>(

switch (type) {
case 'email':
avatarView = (
<Avatar icon={Envelope} {...(avatarProps || {})} {...COMMON_AVATAR_PROPS} />
);
avatarView = <Avatar icon={Envelope} {...(avatarProps || {})} size={size} />;
break;
case 'empty':
avatarView = null;
Expand All @@ -66,7 +60,7 @@ export const UserLabel = React.forwardRef<HTMLDivElement, UserLabelProps>(
if (React.isValidElement(avatar)) {
avatarView = avatar;
} else if (avatarProps) {
avatarView = <Avatar {...avatarProps} {...COMMON_AVATAR_PROPS} />;
avatarView = <Avatar {...avatarProps} size={size} />;
}
break;
}
Expand All @@ -79,6 +73,7 @@ export const UserLabel = React.forwardRef<HTMLDivElement, UserLabelProps>(
empty: !avatarView,
clickable,
closeable,
size,
},
className,
)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/UserLabel/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type React from 'react';

import type {DistributiveOmit} from '../../types/utils';
import type {AvatarProps} from '../Avatar';
import type {AvatarProps, AvatarSize} from '../Avatar';
import type {DOMProps, QAProps} from '../types';

export type UserLabelType = 'person' | 'email' | 'empty';
Expand All @@ -17,4 +17,5 @@ export interface UserLabelProps extends DOMProps, QAProps {
view?: UserLabelView;
onClick?: React.MouseEventHandler<HTMLElement>;
onCloseClick?: React.MouseEventHandler<HTMLButtonElement>;
size?: AvatarSize;
}

0 comments on commit 39cd8ad

Please sign in to comment.