Skip to content

Commit

Permalink
feat(User): add html titles for elements (#1982)
Browse files Browse the repository at this point in the history
  • Loading branch information
DakEnviy authored Dec 6, 2024
1 parent 55737b5 commit 105d43b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/components/User/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ import React from 'react';
import {Avatar} from '../Avatar';
import {block} from '../utils/cn';

import {COMPACT_SIZES, DEFAULT_SIZE} from './constants';
import {COMPACT_SIZES, DEFAULT_SIZE, UserQa} from './constants';
import type {UserProps} from './types';

import './User.scss';

const b = block('user');

export const UserQa = {
NAME: 'user-name',
DESCRIPTION: 'user-description',
};

export const User = React.forwardRef<HTMLDivElement, UserProps>(
(
{
Expand All @@ -30,7 +25,10 @@ export const User = React.forwardRef<HTMLDivElement, UserProps>(
},
ref,
) => {
const showDescription = Boolean(description && !COMPACT_SIZES.includes(size));
const showDescription = Boolean(description && !COMPACT_SIZES.has(size));

const nameTitle = typeof name === 'string' ? name : undefined;
const descriptionTitle = typeof description === 'string' ? description : undefined;

return (
<div
Expand All @@ -43,18 +41,26 @@ export const User = React.forwardRef<HTMLDivElement, UserProps>(
>
{avatar ? (
<div className={b('avatar')}>
{React.isValidElement(avatar) ? avatar : <Avatar {...avatar} size={size} />}
{React.isValidElement(avatar) ? (
avatar
) : (
<Avatar {...avatar} size={size} title={avatar.title || nameTitle} />
)}
</div>
) : null}
{name || showDescription ? (
<div className={b('info')}>
{name ? (
<span className={b('name')} data-qa={UserQa.NAME}>
<span className={b('name')} title={nameTitle} data-qa={UserQa.NAME}>
{name}
</span>
) : null}
{showDescription ? (
<span className={b('description')} data-qa={UserQa.DESCRIPTION}>
<span
className={b('description')}
title={descriptionTitle}
data-qa={UserQa.DESCRIPTION}
>
{description}
</span>
) : null}
Expand Down
7 changes: 6 additions & 1 deletion src/components/User/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type {UserSize} from './types';

export const COMPACT_SIZES: UserSize[] = ['xs', '2xs'];
export const COMPACT_SIZES: Set<UserSize> = new Set(['xs', '2xs']);
export const DEFAULT_SIZE: UserSize = 'm';

export const UserQa = {
NAME: 'user-name',
DESCRIPTION: 'user-description',
};
1 change: 1 addition & 0 deletions src/components/User/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export type {UserSize, UserProps} from './types';
export {UserQa} from './constants';
export {User} from './User';

0 comments on commit 105d43b

Please sign in to comment.