Skip to content

Commit

Permalink
Add new-link icon to cards with external links (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashachabin authored Aug 26, 2024
1 parent 9f75498 commit 568665d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/components/MainPage/Card/Card.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
}

.CardTitle {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
position: relative;
font-size: 16px;
font-weight: 500;
Expand All @@ -124,6 +128,7 @@
}

.CardTitle.CardTitle_Bg {
width: auto;
padding: .5em .75em;
color: white;
text-decoration-color: rgba(255, 255, 255, 0.3);
Expand Down Expand Up @@ -154,12 +159,17 @@
line-height: 1.35;
}

.CardExternalLink {
margin-left: 16px;
flex-shrink: 0;
}

@media screen and (min-width: 375px) {
.Card {
padding: 24px;
}

.CardTitle {
.CardTitle {
font-size: max(16px, 4vw);
}

Expand Down
6 changes: 6 additions & 0 deletions client/components/MainPage/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { useSmoothCorners } from './useSmoothCorners';

import { CardProps } from './Card.types';

import NewLink from './icon-external-link.svg';

import styles from './Card.module.css';

const CARD_TYPES_CLASSNAMES = {
Expand All @@ -32,6 +34,8 @@ export function Card({
}: CardProps) {
const cardRef = useRef<HTMLAnchorElement>(null);
const cardTitleRef = useRef<HTMLDivElement>(null);
const isExternalUrl = url.includes('http');

useSmoothCorners(cardRef);

if (titleBackgroundColor) {
Expand All @@ -44,6 +48,7 @@ export function Card({
href={url}
onClick={onClick}
ref={cardRef}
target={isExternalUrl ? '_blank' : ''}
style={
{
'--CardTitleBgColor': titleBackgroundColor,
Expand All @@ -61,6 +66,7 @@ export function Card({
ref={cardTitleRef}
>
{t(title)}
{isExternalUrl && <NewLink className={cn(styles.CardExternalLink)} />}
</div>
)}
{headerCaption && <p className={cn(styles.CardHeaderCaption)}>{t(headerCaption)}</p>}
Expand Down
1 change: 1 addition & 0 deletions client/components/MainPage/Card/icon-external-link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 568665d

Please sign in to comment.