Skip to content

Commit

Permalink
feat(userLabel_size): add size property
Browse files Browse the repository at this point in the history
  • Loading branch information
rLukoyanov committed Jun 17, 2024
1 parent edf6473 commit 417a470
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 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 | UserLabel size | `'xs'` `'s'` `'m'` `'l'` `'xl'` | `'m'` |

## CSS API

Expand Down
8 changes: 8 additions & 0 deletions src/components/UserLabel/UserLabel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,12 @@ $block: '.#{variables.$ns}user-label';
outline: 2px solid var(--g-color-line-focus);
}
}

&_size {
@each $size-name, $size-value in variables.$sizes {
&_#{$size-name} {
height: #{$size-value};
}
}
}
}
13 changes: 10 additions & 3 deletions src/components/UserLabel/UserLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {UserLabelProps} from './types';
import './UserLabel.scss';

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

const b = block('user-label');
Expand All @@ -30,6 +30,7 @@ export const UserLabel = React.forwardRef<HTMLDivElement, UserLabelProps>(
className,
style,
qa,
size = COMMON_AVATAR_PROPS.size,
},
ref,
) => {
Expand All @@ -55,7 +56,12 @@ export const UserLabel = React.forwardRef<HTMLDivElement, UserLabelProps>(
switch (type) {
case 'email':
avatarView = (
<Avatar icon={Envelope} {...(avatarProps || {})} {...COMMON_AVATAR_PROPS} />
<Avatar
icon={Envelope}
{...(avatarProps || {})}
{...COMMON_AVATAR_PROPS}
size={size}
/>
);
break;
case 'empty':
Expand All @@ -66,7 +72,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} {...COMMON_AVATAR_PROPS} size={size} />;
}
break;
}
Expand All @@ -79,6 +85,7 @@ export const UserLabel = React.forwardRef<HTMLDivElement, UserLabelProps>(
empty: !avatarView,
clickable,
closeable,
size,
},
className,
)}
Expand Down
11 changes: 11 additions & 0 deletions src/components/UserLabel/_variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@use 'sass:map';

$sizes: (
'xs': 24px,
's': 28px,
'm': 32px,
'l': 42px,
'xl': 50px,
);

$default-size: map.get($sizes, 's');
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;
}
8 changes: 8 additions & 0 deletions src/components/variables.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
$ns: 'g-';

$sizes: (
'xs': 24px,
's': 28px,
'm': 32px,
'l': 42px,
'xl': 50px,
);

$xs-height: 20px;
$s-height: 24px;
$m-height: 28px;
Expand Down

0 comments on commit 417a470

Please sign in to comment.