From 39cd8ada02a66e43ff4c9a1afa6d4b384c8000b6 Mon Sep 17 00:00:00 2001 From: Ruslan Lukoyanov <105169805+rLukoyanov@users.noreply.github.com> Date: Mon, 24 Jun 2024 19:28:52 +0300 Subject: [PATCH] feat(UserLabel): add `size` property (#1658) Co-authored-by: Andrey Morozov --- src/components/UserLabel/README.md | 1 + src/components/UserLabel/UserLabel.scss | 12 ++++++++++++ src/components/UserLabel/UserLabel.tsx | 13 ++++--------- src/components/UserLabel/types.ts | 3 ++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/components/UserLabel/README.md b/src/components/UserLabel/README.md index 191098bacc..bc3a610712 100644 --- a/src/components/UserLabel/README.md +++ b/src/components/UserLabel/README.md @@ -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 diff --git a/src/components/UserLabel/UserLabel.scss b/src/components/UserLabel/UserLabel.scss index 0a44846819..f01d582877 100644 --- a/src/components/UserLabel/UserLabel.scss +++ b/src/components/UserLabel/UserLabel.scss @@ -1,5 +1,6 @@ @use '../../../styles/mixins'; @use '../variables'; +@use '../Avatar/variables' as avatar-variables; $block: '.#{variables.$ns}user-label'; @@ -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; + } + } + } } diff --git a/src/components/UserLabel/UserLabel.tsx b/src/components/UserLabel/UserLabel.tsx index d3e4e99f82..69eb3eaeb2 100644 --- a/src/components/UserLabel/UserLabel.tsx +++ b/src/components/UserLabel/UserLabel.tsx @@ -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'; @@ -12,10 +11,6 @@ import type {UserLabelProps} from './types'; import './UserLabel.scss'; -const COMMON_AVATAR_PROPS: Partial = { - size: 's', -}; - const b = block('user-label'); export const UserLabel = React.forwardRef( @@ -30,6 +25,7 @@ export const UserLabel = React.forwardRef( className, style, qa, + size = 's', }, ref, ) => { @@ -54,9 +50,7 @@ export const UserLabel = React.forwardRef( switch (type) { case 'email': - avatarView = ( - - ); + avatarView = ; break; case 'empty': avatarView = null; @@ -66,7 +60,7 @@ export const UserLabel = React.forwardRef( if (React.isValidElement(avatar)) { avatarView = avatar; } else if (avatarProps) { - avatarView = ; + avatarView = ; } break; } @@ -79,6 +73,7 @@ export const UserLabel = React.forwardRef( empty: !avatarView, clickable, closeable, + size, }, className, )} diff --git a/src/components/UserLabel/types.ts b/src/components/UserLabel/types.ts index fc79942654..2bee2a95ca 100644 --- a/src/components/UserLabel/types.ts +++ b/src/components/UserLabel/types.ts @@ -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'; @@ -17,4 +17,5 @@ export interface UserLabelProps extends DOMProps, QAProps { view?: UserLabelView; onClick?: React.MouseEventHandler; onCloseClick?: React.MouseEventHandler; + size?: AvatarSize; }