Skip to content

Commit 2786c81

Browse files
authored
feat: alt attributes and titles, fix yfm plugins bug (#655)
* feat: alt attributes for Quote block and Author avatar * feat: share links with labels and titles * feat: alt attributes are not present at all by default * fix: yfm plugins paramter bug
1 parent 053b469 commit 2786c81

File tree

17 files changed

+63
-41
lines changed

17 files changed

+63
-41
lines changed

src/blocks/Share/Share.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const Share = ({items, title}: ShareBlockProps) => {
4444
const url = getAbsolutePath(hostname, pathname);
4545
const socialUrl = getShareLink(url, type);
4646
const icon = icons[type];
47+
const urlTitle = i18n(`${type}-title`);
48+
const buttonLabel = i18n(`${type}-label`);
4749

4850
return (
4951
<Button
@@ -54,6 +56,10 @@ const Share = ({items, title}: ShareBlockProps) => {
5456
href={socialUrl}
5557
className={b('item', {type: type.toLowerCase()})}
5658
onClick={handleButtonClick}
59+
title={urlTitle}
60+
extraProps={{
61+
'aria-label': buttonLabel,
62+
}}
5763
>
5864
{icon && <Icon data={icon} size={24} className={b('icon', {type})} />}
5965
</Button>

src/blocks/Share/i18n/en.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
{
2-
"constructor-share": "Share"
2+
"constructor-share": "Share",
3+
"facebook-title": "Opens in a new tab",
4+
"twitter-title": "Opens in a new tab",
5+
"linkedin-title": "Opens in a new tab",
6+
"vk-title": "Opens in a new tab",
7+
"telegram-title": "Opens in a new tab",
8+
"facebook-label": "Facebook logo",
9+
"twitter-label": "Twitter logo",
10+
"linkedin-label": "LinkedIn logo",
11+
"vk-label": "VK logo",
12+
"telegram-label": "Telegram logo"
313
}

src/blocks/Share/i18n/ru.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
{
2-
"constructor-share": "Поделиться"
2+
"constructor-share": "Поделиться",
3+
"facebook-title": "Откроется в новой вкладке",
4+
"twitter-title": "Откроется в новой вкладке",
5+
"linkedin-title": "Откроется в новой вкладке",
6+
"vk-title": "Откроется в новой вкладке",
7+
"telegram-title": "Откроется в новой вкладке",
8+
"facebook-label": "Facebook лого",
9+
"twitter-label": "Twitter лого",
10+
"linkedin-label": "LinkedIn лого",
11+
"vk-label": "VK лого",
12+
"telegram-label": "Telegram лого"
313
}

src/components/Author/Author.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22

3-
import {AuthorProps, AuthorType, WithChildren} from '../../models';
3+
import {AuthorProps, AuthorType, ImageProps, WithChildren} from '../../models';
44
import {block} from '../../utils';
5+
import {getMediaImage} from '../Media/Image/utils';
56
import {Image} from '../index';
67

78
import './Author.scss';
@@ -13,12 +14,17 @@ const Author = (props: WithChildren<AuthorProps>) => {
1314
const {firstName, secondName, description, avatar} = author;
1415

1516
const name = secondName ? `${firstName} ${secondName}` : firstName;
17+
const isAvatarJSX = React.isValidElement(avatar);
18+
let avatarProps = {};
19+
if (!isAvatarJSX && avatar) {
20+
avatarProps = getMediaImage(avatar as ImageProps);
21+
}
1622

1723
return (
1824
<div className={b({type}, className)} data-qa={qa}>
1925
{avatar && (
2026
<div className={b('avatar', authorContainerClassName)}>
21-
{typeof avatar === 'string' ? <Image src={avatar} /> : avatar}
27+
{isAvatarJSX ? avatar : <Image {...avatarProps} />}
2228
</div>
2329
)}
2430
<div className={b('label')}>

src/components/CardBase/CardBase.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface CardBaseProps extends AnalyticsEventsBase, CardBaseParams {
3030
metrikaGoals?: MetrikaGoal;
3131
pixelEvents?: ButtonPixel;
3232
qa?: string;
33+
extraProps?: React.HTMLAttributes<HTMLElement>;
3334
}
3435

3536
export interface CardHeaderBaseProps {
@@ -61,6 +62,7 @@ export const Layout = (props: CardBaseProps) => {
6162
border = 'shadow',
6263
urlTitle,
6364
qa,
65+
extraProps = {},
6466
} = props;
6567
const handleMetrika = useMetrika();
6668
const handleAnalytics = useAnalytics(DefaultEventNames.CardBase, url);
@@ -133,14 +135,15 @@ export const Layout = (props: CardBaseProps) => {
133135
extraProps={{
134136
draggable: false,
135137
onDragStart: (e: React.DragEvent<HTMLAnchorElement>) => e.preventDefault(),
138+
...extraProps,
136139
}}
137140
qa={qa}
138141
>
139142
{cardContent}
140143
</Link>
141144
</RouterLink>
142145
) : (
143-
<div className={fullClassName} data-qa={qa}>
146+
<div className={fullClassName} data-qa={qa} {...extraProps}>
144147
{cardContent}
145148
</div>
146149
);

src/components/Image/Image.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {getQaAttrubutes} from '../../utils';
77
import {isCompressible} from '../../utils/imageCompress';
88
import ImageBase from '../ImageBase/ImageBase';
99

10-
import i18n from './i18n';
11-
1210
export interface ImageProps extends Partial<ImageObjectProps>, Partial<ImageDeviceProps>, QAProps {
1311
style?: CSSProperties;
1412
className?: string;
@@ -49,7 +47,7 @@ const Image = (props: ImageProps) => {
4947
const projectSettings = useContext(ProjectSettingsContext);
5048
const {
5149
src: imageSrc,
52-
alt = i18n('img-alt'),
50+
alt,
5351
disableCompress,
5452
tablet,
5553
desktop,

src/components/Image/__tests__/Image.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from '../../../../test-utils/shared/common';
1010
import {testSourceProps} from '../../../../test-utils/shared/image';
1111
import Image, {ImageProps} from '../Image';
12-
import i18n from '../i18n';
1312

1413
const qaId = 'image-component';
1514

@@ -106,11 +105,11 @@ describe('Image', () => {
106105
});
107106
});
108107

109-
test('render default "alt"', () => {
108+
test('render without attribute "alt" if not provided', () => {
110109
render(<Image src={imageSrc} qa={qaId} />);
111110

112111
const component = screen.getByRole('img');
113-
expect(component).toHaveAttribute('alt', i18n('img-alt'));
112+
expect(component).not.toHaveAttribute('alt');
114113
});
115114

116115
test('render custom "alt"', () => {

src/components/Image/i18n/en.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/components/Image/i18n/index.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/components/Image/i18n/ru.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)