Skip to content

Commit 514c988

Browse files
authored
feat: ability to add titles for the links (#549)
1 parent 2047dd6 commit 514c988

File tree

15 files changed

+48
-11
lines changed

15 files changed

+48
-11
lines changed

src/components/CardBase/CardBase.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface CardBaseProps extends AnalyticsEventsBase, CardBaseParams {
2222
contentClassName?: string;
2323
children: ReactElement | ReactElement[];
2424
url?: string;
25+
urlTitle?: string;
2526
target?: HTMLAttributeAnchorTarget;
2627
metrikaGoals?: MetrikaGoal;
2728
pixelEvents?: ButtonPixel;
@@ -55,6 +56,7 @@ export const Layout = (props: CardBaseProps) => {
5556
url,
5657
target,
5758
border = 'shadow',
59+
urlTitle,
5860
qa,
5961
} = props;
6062
const handleMetrika = useMetrika();
@@ -126,6 +128,7 @@ export const Layout = (props: CardBaseProps) => {
126128
draggable={false}
127129
onDragStart={(e) => e.preventDefault()}
128130
onClick={onClick}
131+
title={urlTitle}
129132
data-qa={qa}
130133
>
131134
{cardContent}

src/components/FileLink/FileLink.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const FileLink = (props: WithChildren<FileLinkProps>) => {
5656
theme = 'default',
5757
onClick,
5858
tabIndex,
59+
urlTitle,
5960
} = props;
6061
const fileExt = getFileExt(href) as FileExtension;
6162
const labelTheme = (FileExtensionThemes[fileExt] || 'unknown') as LabelProps['theme'];
@@ -71,6 +72,7 @@ const FileLink = (props: WithChildren<FileLinkProps>) => {
7172
href={href}
7273
onClick={onClick}
7374
tabIndex={tabIndex}
75+
title={urlTitle}
7476
{...getLinkProps(href, hostname)}
7577
>
7678
{text}

src/components/Link/Link.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const LinkBlock = (props: WithChildren<LinkFullProps>) => {
5757
children,
5858
tabIndex,
5959
qa,
60+
urlTitle,
6061
} = props;
6162
const qaAttributes = getQaAttrubutes(qa, ['normal']);
6263

@@ -105,6 +106,7 @@ const LinkBlock = (props: WithChildren<LinkFullProps>) => {
105106
href={href}
106107
onClick={onClick}
107108
tabIndex={tabIndex}
109+
title={urlTitle}
108110
{...linkProps}
109111
data-qa={qaAttributes.normal}
110112
>

src/components/Title/TitleItem.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const TitleItem = (props: TitleItemFullProps) => {
4646
className,
4747
qa,
4848
resetMargin = true,
49+
urlTitle,
4950
} = props;
5051

5152
const {hostname} = useContext(LocationContext);
@@ -80,13 +81,19 @@ const TitleItem = (props: TitleItemFullProps) => {
8081
content = textMarkup;
8182
} else if (url) {
8283
content = (
83-
<a className={b('link')} href={url} {...getLinkProps(url, hostname)} onClick={onClick}>
84+
<a
85+
className={b('link')}
86+
href={url}
87+
{...getLinkProps(url, hostname)}
88+
onClick={onClick}
89+
title={urlTitle}
90+
>
8491
{insideClickableContent}
8592
</a>
8693
);
8794
} else if (onClick) {
8895
content = (
89-
<span className={b('link')} onClick={onClick}>
96+
<span className={b('link')} onClick={onClick} title={urlTitle}>
9097
{insideClickableContent}
9198
</span>
9299
);

src/components/Title/__stories__/data.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
"title": {
1111
"text": "Lorem ipsum",
1212
"url": "https://example.com",
13-
"custom": "Some react node"
13+
"custom": "Some react node",
14+
"urlTitle": "Example website. Opens in a new window"
1415
}
1516
}
1617
},
1718
"titleLink": {
1819
"content": {
1920
"title": {
2021
"text": "Lorem ipsum",
21-
"url": "https://example.com"
22+
"url": "https://example.com",
23+
"urlTitle": "Example website. Opens in a new window"
2224
}
2325
}
2426
},

src/models/constructor-items/common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export interface MediaVideoProps extends AnalyticsEventsBase {
159159
// links
160160
export interface LinkProps extends AnalyticsEventsBase, Stylable, Tabbable {
161161
url: string;
162+
urlTitle?: string;
162163
text?: string;
163164
textSize?: TextSize;
164165
theme?: LinkTheme;
@@ -175,6 +176,7 @@ export interface FileLinkProps extends ClassNameProps, Tabbable {
175176
type?: FileLinkType;
176177
textSize?: TextSize;
177178
theme?: ContentTheme;
179+
urlTitle?: string;
178180
onClick?: () => void;
179181
}
180182

@@ -347,6 +349,7 @@ export interface TitleItemBaseProps {
347349
text: string;
348350
textSize?: TextSize;
349351
url?: string;
352+
urlTitle?: string;
350353
custom?: string | ReactNode;
351354
onClick?: () => void;
352355
}

src/models/constructor-items/sub-blocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export interface BackgroundCardProps
103103
AnalyticsEventsBase,
104104
Omit<ContentBlockProps, 'colSizes' | 'centered'> {
105105
url?: string;
106+
urlTitle?: string;
106107
background?: ThemeSupporting<ImageObjectProps>;
107108
paddingBottom?: 's' | 'm' | 'l' | 'xl';
108109
backgroundColor?: string;

src/models/navigation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export enum NavigationGithubButtonIcon {
3535
export interface NavigationGithubButton extends Omit<NavigationItemBase, 'icon'> {
3636
type: NavigationItemType.GithubButton;
3737
url: string;
38+
urlTitle?: string;
3839
label?: string;
3940
icon?: keyof typeof NavigationGithubButtonIcon;
4041
size?: string;
@@ -43,6 +44,7 @@ export interface NavigationGithubButton extends Omit<NavigationItemBase, 'icon'>
4344
export interface NavigationLinkItem extends Omit<NavigationItemBase, 'url'> {
4445
type: NavigationItemType.Link;
4546
url: string;
47+
urlTitle?: string;
4648
arrow?: boolean;
4749
target?: string;
4850
}
@@ -62,6 +64,7 @@ export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
6264
type: NavigationItemType.Social;
6365
icon: ImageProps;
6466
url: string;
67+
urlTitle?: string;
6568
}
6669

6770
export type NavigationItemModel =

src/navigation/__stories__/data.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
"type": "link",
7272
"text": "Link with arrow",
7373
"url": "https://example.com",
74-
"arrow": true
74+
"arrow": true,
75+
"urlTitle": "External website. Opens in a new window"
7576
},
7677
{
7778
"type": "link",
@@ -106,7 +107,8 @@
106107
"type": "github-button",
107108
"text": "Star",
108109
"label": "Star @gravity-ui/page-constructor on GitHub",
109-
"url": "https://github.com/gravity-ui/page-constructor"
110+
"url": "https://github.com/gravity-ui/page-constructor",
111+
"urlTitle": "Page Constructor GitHub page. Opens in a new window"
110112
},
111113
{
112114
"type": "link",

src/navigation/components/NavigationItem/components/GithubButton/GithubButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const GithubButton = ({
2020
label,
2121
size,
2222
icon,
23+
urlTitle,
2324
}: NavigationGithubButtonProps) => {
2425
const containerRef = useRef<HTMLSpanElement>(null);
2526
const linkRef = useRef<HTMLAnchorElement>(null);
@@ -63,6 +64,7 @@ export const GithubButton = ({
6364
<a
6465
href={url}
6566
ref={linkRef}
67+
title={urlTitle}
6668
data-show-count="true"
6769
aria-label={label || DEFAULT_LABEL}
6870
{...(icon && {'data-icon': NavigationGithubButtonIcon[icon]})}

0 commit comments

Comments
 (0)