From 9b603a28d88fa56685a63f1eb71baa10c26bfbe2 Mon Sep 17 00:00:00 2001 From: ngorin Date: Mon, 8 Apr 2024 17:55:15 +0300 Subject: [PATCH 1/3] feat: userLabel depends on vars --- src/components/UserLabel/UserLabel.scss | 5 +++++ src/components/UserLabel/UserLabel.tsx | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/components/UserLabel/UserLabel.scss b/src/components/UserLabel/UserLabel.scss index 3ed49391ae..d0f57201fd 100644 --- a/src/components/UserLabel/UserLabel.scss +++ b/src/components/UserLabel/UserLabel.scss @@ -4,6 +4,9 @@ $block: '.#{variables.$ns}user-label'; #{$block} { + --_--font-size: var(--g-text-body-1-font-size); + --_--line-height: var(--g-text-body-1-line-height); + $transitionDuration: 0.1s; $transitionTimingFunction: ease-in-out; @@ -77,6 +80,8 @@ $block: '.#{variables.$ns}user-label'; } &__text { + font-size: var(--g-avatar-font-size, var(--_--font-size)); + line-height: var(--g-avatar-line-height, var(--_--line-height)); min-width: 0; margin-inline-end: 6px; white-space: nowrap; diff --git a/src/components/UserLabel/UserLabel.tsx b/src/components/UserLabel/UserLabel.tsx index d3e4e99f82..246c827835 100644 --- a/src/components/UserLabel/UserLabel.tsx +++ b/src/components/UserLabel/UserLabel.tsx @@ -41,9 +41,16 @@ export const UserLabel = React.forwardRef( let avatarProps; if (typeof avatar === 'string') { - avatarProps = { - imgUrl: avatar, - }; + if (!avatar && typeof children === 'string') { + avatarProps = { + imgUrl: avatar, + text: children, + }; + } else { + avatarProps = { + imgUrl: avatar, + }; + } } else if (avatar && !React.isValidElement(avatar)) { avatarProps = avatar; } else if (!avatar && typeof children === 'string') { From 3db4a3306d60bdd1da9ea7d9b4b42d832915843d Mon Sep 17 00:00:00 2001 From: ngorin Date: Tue, 9 Apr 2024 11:18:41 +0300 Subject: [PATCH 2/3] feat: add css api for user-label --- src/components/UserLabel/README.md | 7 +++++++ src/components/UserLabel/UserLabel.scss | 7 ++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/UserLabel/README.md b/src/components/UserLabel/README.md index 1f592f0f3f..191098bacc 100644 --- a/src/components/UserLabel/README.md +++ b/src/components/UserLabel/README.md @@ -97,3 +97,10 @@ 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` | | + +## CSS API + +| Name | Description | +| :--------------------------- | :--------------- | +| `--g-user-label-font-size` | Text font size | +| `--g-user-label-line-height` | Text line height | diff --git a/src/components/UserLabel/UserLabel.scss b/src/components/UserLabel/UserLabel.scss index d0f57201fd..0a44846819 100644 --- a/src/components/UserLabel/UserLabel.scss +++ b/src/components/UserLabel/UserLabel.scss @@ -4,9 +4,6 @@ $block: '.#{variables.$ns}user-label'; #{$block} { - --_--font-size: var(--g-text-body-1-font-size); - --_--line-height: var(--g-text-body-1-line-height); - $transitionDuration: 0.1s; $transitionTimingFunction: ease-in-out; @@ -80,8 +77,8 @@ $block: '.#{variables.$ns}user-label'; } &__text { - font-size: var(--g-avatar-font-size, var(--_--font-size)); - line-height: var(--g-avatar-line-height, var(--_--line-height)); + font-size: var(--g-user-label-font-size, inherit); + line-height: var(--g-user-label-line-height, inherit); min-width: 0; margin-inline-end: 6px; white-space: nowrap; From 80e153c41b848861ceb8b5d530ab371ef11d69d7 Mon Sep 17 00:00:00 2001 From: ngorin Date: Tue, 9 Apr 2024 16:52:33 +0300 Subject: [PATCH 3/3] feat: refactor --- src/components/UserLabel/UserLabel.tsx | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/components/UserLabel/UserLabel.tsx b/src/components/UserLabel/UserLabel.tsx index 246c827835..d3e4e99f82 100644 --- a/src/components/UserLabel/UserLabel.tsx +++ b/src/components/UserLabel/UserLabel.tsx @@ -41,16 +41,9 @@ export const UserLabel = React.forwardRef( let avatarProps; if (typeof avatar === 'string') { - if (!avatar && typeof children === 'string') { - avatarProps = { - imgUrl: avatar, - text: children, - }; - } else { - avatarProps = { - imgUrl: avatar, - }; - } + avatarProps = { + imgUrl: avatar, + }; } else if (avatar && !React.isValidElement(avatar)) { avatarProps = avatar; } else if (!avatar && typeof children === 'string') {