Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

282-feat: Standardize links designation #467

Merged
merged 37 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c966ab6
feat: 282 - change text link appearance
Wystov Aug 29, 2024
d2e4619
feat: 282 - conditionally add attributes and icon for external links
Wystov Aug 29, 2024
5ddd027
refactor: 282 - change LinkCustom component use in accordance to new …
Wystov Aug 29, 2024
cbb6b4d
refactor: 282 - change Link component to LinkCustom where applicable
Wystov Aug 29, 2024
dbea28d
fix: 282 - remove text-link font size so it can inherit
Wystov Aug 29, 2024
4b46b0c
feat: 282 - set smaller external icon size
Wystov Aug 29, 2024
6345706
fix: 282 - empty links rendering
Wystov Aug 29, 2024
b77c140
refactor: 282 - change data file extension to tsx
Wystov Aug 29, 2024
dc88914
feat: 282 - set jsx from data insted of setting innerhtml
Wystov Aug 29, 2024
a7c4271
feat: 282 - use LinkCustom in study path
Wystov Aug 29, 2024
7094cbb
fix: 282 - old tests to work with implemented changes to links
Wystov Aug 29, 2024
f88097d
test: 282 - add test case for internal link
Wystov Aug 29, 2024
c87f85c
refactor: 282 - remove tsx extension from import
Wystov Aug 30, 2024
9b8bb1a
refactor: 282 - change two more links in data to jsx with LinkCustom
Wystov Aug 30, 2024
21a34b6
refactor: 282 - remove default variant from variants as it sets in co…
Wystov Aug 30, 2024
8ba694a
refactor: 282 - use render with router util in tests
Wystov Aug 30, 2024
218f2ad
refactor: 282 - use ReactNode type instead of JSX.Element
Wystov Aug 30, 2024
37b266c
feat: 282 - set default icons for LinkCustom variants
Wystov Aug 30, 2024
1ad5551
refactor: 282 - delete passing of redundant default icon prop
Wystov Aug 30, 2024
5d68991
feat: 282 - use LinkCustom in SocialMedia component
Wystov Aug 31, 2024
acf5b0b
fix: 282 - tests to render with router
Wystov Aug 31, 2024
ada4fa1
test: 282 - add test cases for icons resolving in LinkCustom
Wystov Aug 31, 2024
5cbfc45
chore: 282 - merge main
Wystov Aug 31, 2024
7fd9554
fix: 282 - merge main conflicts
Wystov Sep 6, 2024
ac4077d
refactor: 282 - review suggestions implemented
Wystov Sep 6, 2024
a64e1d1
fix: 282 - skip failing test
Wystov Sep 6, 2024
ce0d53e
fix: 282 - angular course youtube link style
Wystov Sep 6, 2024
e1d2921
fix: 282 - merge main
Wystov Sep 8, 2024
4e7ab8e
refactor: 282 - remove comment
Wystov Sep 9, 2024
e16ed53
chore: 282 - merge main
SpaNb4 Sep 12, 2024
cc65f86
chore: 282 - merge main
SpaNb4 Sep 12, 2024
b9246f8
chore: merge main
SpaNb4 Sep 12, 2024
2226cc8
chore: 282 - merge main
SpaNb4 Sep 12, 2024
24d3380
chore: merge main
SpaNb4 Sep 12, 2024
bd91582
chore: 282 - merge main
SpaNb4 Sep 13, 2024
96b4128
refactor: 282 - delete redundant link styles
Wystov Sep 13, 2024
7180e9f
refactor: 282 - classname to kebabcase
Wystov Sep 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app/styles/_constants.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ $color-gray-400: hsl(0deg 0% 69%); // #afafaf
$color-gray-200: hsl(0deg 0% 90%); // #e6e6e6
$color-gray-100: hsl(0deg 0% 95%); // #f2f2f2

// Link color
$color-blue: hsl(202deg 89% 65%);

// OPACITY
$opacity-100: 1;
$opacity-80: 0.8;
Expand Down
11 changes: 0 additions & 11 deletions src/entities/courses/ui/general/general.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@
padding: 0;
font-size: 18px;
line-height: 28px;

a {
@extend %transition-all;

color: $color-gray-600;
text-decoration: underline;

&:hover {
color: $color-gray-400;
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/entities/courses/ui/general/general.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link } from 'react-router-dom';
import { LinkCustom } from '@/shared/ui/link-custom';
import { WidgetTitle } from '@/shared/ui/widget-title';

import './general.scss';
Expand All @@ -13,9 +13,9 @@ export const General = () => {
<h2 className="title">Materials</h2>
<ul className="description">
<li>
<Link to="https://docs.rs.school" target="_blank" rel="noopener noreferrer">
<LinkCustom href="https://docs.rs.school" external>
School documentation
</Link>
</LinkCustom>
</li>
<li>All materials are publicly available on YouTube and GitHub</li>
<li>
Expand Down
2 changes: 1 addition & 1 deletion src/entities/events/ui/event-card/event-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const EventCard = ({
<br />
{city}
</address>
<LinkCustom href={href} variant="rounded" target="_blank">
<LinkCustom href={href} variant="rounded" external>
View details
</LinkCustom>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/shared/icons/text-link-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import textLinkIcon from '@/shared/assets/svg/text-link.svg';
import { Image } from '@/shared/ui/image';

export const TextLinkIcon = () => {
return <Image src={textLinkIcon} width="25px" height="25px" alt="external link icon" />;
return <Image src={textLinkIcon} width="20px" height="20px" alt="external link icon" />;
};
11 changes: 3 additions & 8 deletions src/shared/ui/link-custom/link-custom.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,10 @@
.text-link {
@extend %transition-all;

@include media-tablet {
font-size: 16px;
}

font-size: 20px;
font-weight: 600;
color: $color-gray-600;
color: $color-blue;
text-decoration: underline;

&:hover {
color: $color-black;
text-decoration: none;
}
}
12 changes: 10 additions & 2 deletions src/shared/ui/link-custom/link-custom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ describe('LinkCustom', () => {
expect(link.textContent).toContain(label);
});

it('should have attribute', () => {
const { getByRole } = renderWithRouter(<LinkCustom href={href}>{label}</LinkCustom>);
it('should be external', () => {
const { getByRole } = renderWithRouter(<LinkCustom href={href} external>{label}</LinkCustom>);
const link = getByRole('link');

expect(link).toHaveAttribute('rel', 'noopener noreferrer');
expect(link).toHaveTextContent('Click me');
expect(link).toHaveAttribute('target', '_blank');
});

it('should be inner', () => {
const { getByRole } = renderWithRouter(<LinkCustom href={href}>{label}</LinkCustom>);
const link = getByRole('link');

expect(link).not.toHaveAttribute('rel', 'noopener noreferrer');
expect(link).not.toHaveAttribute('target', '_blank');
});

Expand Down
19 changes: 14 additions & 5 deletions src/shared/ui/link-custom/link-custom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import { AnchorHTMLAttributes, ReactNode } from 'react';
import { type VariantProps, cva } from 'class-variance-authority';
import classNames from 'classnames/bind';
import { Link } from 'react-router-dom';
import { TextLinkIcon } from '@/shared/icons';

import styles from './link-custom.module.scss';

export const cx = classNames.bind(styles);

type LinkCustomProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'rel'> &
type LinkCustomProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'rel' | 'target'> &
VariantProps<typeof linkCustomVariants> &
LinkCustomAdditionalProps;

type LinkCustomAdditionalProps = {
href: string;
icon?: ReactNode;
external?: boolean;
};

const linkCustomVariants = cva('', {
Expand All @@ -25,17 +27,24 @@ const linkCustomVariants = cva('', {
textLink: cx('textLink'),
},
},
defaultVariants: { variant: 'textLink' },
});

const externalLinkAttributes = {
target: '_blank',
rel: 'noopener noreferrer',
};

export const LinkCustom = ({
children,
href,
icon = <></>,
className = '',
variant,
variant = 'textLink',
external = false,
...props
}: LinkCustomProps) => {
const iconElement = external && variant === 'textLink' ? <TextLinkIcon /> : icon;

return (
<Link
className={linkCustomVariants({
Expand All @@ -44,10 +53,10 @@ export const LinkCustom = ({
})}
to={href}
{...props}
rel="noopener noreferrer"
{...(external && externalLinkAttributes)}
>
{children}
{icon}
{iconElement}
</Link>
);
};
3 changes: 0 additions & 3 deletions src/shared/ui/text-with-link/text-with-link.scss

This file was deleted.

8 changes: 2 additions & 6 deletions src/shared/ui/text-with-link/text-with-link.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Fragment } from 'react/jsx-runtime';
import { Link } from 'react-router-dom';
import { LinkCustom } from '../link-custom';
import { LinkList } from '@/widgets/required/required.types';

import './text-with-link.scss';

interface TextWithLinkProps {
data: LinkList;
}
Expand All @@ -12,9 +10,7 @@ export const TextWithLink = ({ data }: TextWithLinkProps) => {
return data.map(({ id, text, link, title }) => (
<Fragment key={id}>
{text && <span>{text}</span>}
<Link className="required-link" to={link}>
{title}
</Link>
{link && <LinkCustom href={link} external>{title}</LinkCustom>}
</Fragment>
));
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import personIcon from '@/shared/assets/icons/person-icon.webp';
import planetIcon from '@/shared/assets/icons/planet.webp';
import type { CourseNames } from '@/shared/data/communication.data';
import { DISCORD_LINKS } from '@/shared/data/communication.data';
import { LinkCustom } from '@/shared/ui/link-custom';

type AboutInfo = {
id: number;
title: string;
info: string;
info: string | JSX.Element;
icon: string;
};

Expand Down Expand Up @@ -66,7 +67,15 @@ const javaScriptEN: () => AboutInfo[] = () => {
{
id: 2,
title: 'Worldwide mentors and trainers',
info: 'The Mentors and trainers of our school are front-end and javascript developers from different companies/countries. How to become a <a href="/courses#mentors-wanted">mentor</a>?',
info: (
<p>
The Mentors and trainers of our school are front-end and javascript developers from
different companies/countries. How to
{' '}
<LinkCustom href="/courses#mentors-wanted">become a mentor</LinkCustom>
?
</p>
),
icon: planetIcon,
},
{
Expand Down Expand Up @@ -146,14 +155,30 @@ const reactEn: AboutInfo[] = javaScriptEN().map((item) => {
return {
...item,
title: 'Materials',
info: `<li>School <a href='https://docs.rs.school'>documentation</a></li><li>All materials are publicly available on the YouTube channel and GitHub</li>`,
info: (
<ul>
<li>
School
{' '}
<LinkCustom href="https://docs.rs.school" external>documentation</LinkCustom>
</li>
<li>All materials are publicly available on the YouTube channel and GitHub</li>
</ul>
),
icon: paperIcon,
};
}
if (item.id === 5) {
return {
...item,
info: `Throughout the course, we mostly use <a href=${DISCORD_LINKS['react']}>Discord chat</a>.`,
info: (
<p>
Throughout the course, we mostly use
{' '}
<LinkCustom href={DISCORD_LINKS['react']} external>Discord chat</LinkCustom>
.
</p>
),
};
}
return item;
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/about/ui/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const About = ({ courseName, type = 'en' }: AboutProps) => {
<Paragraph>{localizedContent[type].paragraph}</Paragraph>
)}
<InfoGrid items={infoList} hasTitle />
<LinkCustom href={course.enroll} icon={<ArrowIcon />} variant="primary" target="_blank">
<LinkCustom href={course.enroll} icon={<ArrowIcon />} variant="primary" external>
{localizedContent[type].linkLabel}
</LinkCustom>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/about/ui/info-grid/info-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface InfoGridProps {
items: {
id: number;
title: string;
info: string;
info: string | JSX.Element;
icon: string;
}[];
hasTitle?: boolean;
Expand All @@ -21,7 +21,7 @@ export const InfoGrid = ({ items }: InfoGridProps) => {
<Image src={icon} alt={title} />
<h2>{title}</h2>
</div>
<p dangerouslySetInnerHTML={{ __html: info }} />
{ typeof info === 'string' ? <p>{info}</p> : info }
</div>
))}
</div>
Expand Down
8 changes: 3 additions & 5 deletions src/widgets/communication/ui/communication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
RS_DOCS_COMMUNICATION_LINK,
RS_DOCS_TELEGRAM_CHATS_LINK,
} from '@/shared/data/communication.data';
import { TextLinkIcon } from '@/shared/icons';
import { DiscordLogo } from '@/shared/icons/discord-logo';
import { LinkCustom } from '@/shared/ui/link-custom';
import { Paragraph } from '@/shared/ui/paragraph';
Expand Down Expand Up @@ -64,7 +63,7 @@ export const Communication = ({ courseName, lang = 'en' }: RequiredProps) => {
<Subtitle text={localizedContent[lang].subTitle} />
<Paragraph>
{localizedContent[lang].firstParagraphFirstHalf}{' '}
<LinkCustom href={DISCORD_LINKS[courseName]} icon={<TextLinkIcon />} target="_blank">
<LinkCustom href={DISCORD_LINKS[courseName]} external>
{localizedContent[lang].discordLink}
</LinkCustom>
{localizedContent[lang].firstParagraphSecondHalf}
Expand All @@ -73,16 +72,15 @@ export const Communication = ({ courseName, lang = 'en' }: RequiredProps) => {
{localizedContent[lang].secondParagraphFirstHalf}{' '}
<LinkCustom
href={RS_DOCS_TELEGRAM_CHATS_LINK}
icon={<TextLinkIcon />}
target="_blank"
external
>
{localizedContent[lang].telegramLink}
</LinkCustom>
{localizedContent[lang].secondParagraphSecondHalf}
</Paragraph>
<Paragraph>
{localizedContent[lang].thirdParagraphFirstHalf}{' '}
<LinkCustom href={RS_DOCS_COMMUNICATION_LINK} icon={<TextLinkIcon />} target="_blank">
<LinkCustom href={RS_DOCS_COMMUNICATION_LINK} external>
{localizedContent[lang].rsDocsLink}
</LinkCustom>
{localizedContent[lang].thirdParagraphSecondHalf}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/course-main/course-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const CourseMain = ({ courseName, lang = 'en', type }: CourseMainProps) =
<WidgetTitle>{`${altTitle || title} Course`}</WidgetTitle>
{type && <Subtitle text={type} type="course-main" />}
<DateLang startDate={date} language={language} mode={mode} withMargin />
<LinkCustom href={enroll} icon={<ArrowIcon />} variant="secondary" target="_blank">
<LinkCustom href={enroll} icon={<ArrowIcon />} variant="secondary" external>
{localizedContent[lang].linkLabel}
</LinkCustom>
</div>
Expand Down
5 changes: 0 additions & 5 deletions src/widgets/mentors-wanted/ui/mentors-wanted.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
text-align: left;
}

.link {
font-size: 18px;
text-decoration: underline;
}

.content {
display: flex;
align-items: start;
Expand Down
12 changes: 5 additions & 7 deletions src/widgets/mentors-wanted/ui/mentors-wanted.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import classNames from 'classnames';
import classNamesBind from 'classnames/bind';
import { Link } from 'react-router-dom';
import mentorImg from '@/shared/assets/mentors-wanted-poster.webp';
import { Image } from '@/shared/ui/image';
import { LinkCustom } from '@/shared/ui/link-custom';
import { Paragraph } from '@/shared/ui/paragraph';
import { WidgetTitle } from '@/shared/ui/widget-title';

Expand All @@ -11,7 +11,6 @@ import styles from './mentors-wanted.module.scss';
const cx = classNamesBind.bind(styles);

export const MentorsWanted = () => {
// todo use custom link
return (
<section className={cx('mentors-wanted', 'container')}>
<article className={classNames('content', cx('content'))}>
Expand All @@ -20,13 +19,12 @@ export const MentorsWanted = () => {
<Paragraph>
If&nbsp;you are interested in mentoring our students, please go through the
{' '}
<Link
className={cx('link')}
to="https://github.com/rolling-scopes-school/tasks/tree/master/angular/mentoring"
target="blank"
<LinkCustom
href="https://github.com/rolling-scopes-school/tasks/tree/master/angular/mentoring"
external
>
Mentoring Documentation
</Link>
</LinkCustom>
{' '}
for&nbsp;the Angular Course.
</Paragraph>
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/mentors/ui/mentors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Mentors = () => {
href={LINKS.BECOME_MENTOR}
icon={<ArrowIcon />}
variant="primary"
target="_blank"
external
>
Become a mentor
</LinkCustom>
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/merch/ui/merch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Merch = () => (
assets where you will find all merch collections and can print your own Rolling Scopes
t-shirts, stickers etc.
</Paragraph>
<LinkCustom href={LINKS.MERCH} icon={<ArrowIcon />} variant="primary" target="_blank">
<LinkCustom href={LINKS.MERCH} icon={<ArrowIcon />} variant="primary" external>
Discover merch assets
</LinkCustom>
</div>
Expand Down
Loading
Loading