From 70e084c0db73398deff1f66f941d7c8c374108ab Mon Sep 17 00:00:00 2001 From: Ilya Y <75578537+ilya-bkv@users.noreply.github.com> Date: Mon, 25 Dec 2023 14:35:04 +0300 Subject: [PATCH] aspect ratio in Expo (#347) --- .../Feed/ArticleCard/ArticleCard.module.scss | 20 ++++++++++++++++++- .../Feed/ArticleCard/ArticleCard.tsx | 19 +++++++++++++++++- src/components/Views/Expo/Expo.tsx | 4 +++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/components/Feed/ArticleCard/ArticleCard.module.scss b/src/components/Feed/ArticleCard/ArticleCard.module.scss index 3c5b70b4..9775243c 100644 --- a/src/components/Feed/ArticleCard/ArticleCard.module.scss +++ b/src/components/Feed/ArticleCard/ArticleCard.module.scss @@ -107,7 +107,7 @@ height: 0; margin-bottom: 1.6rem; overflow: hidden; - padding-bottom: 56.2%; + padding-bottom: 56.2%; //16:9 position: relative; transform-origin: 50% 50%; transition: transform 1s ease-in-out; @@ -267,6 +267,24 @@ } } +.aspectRatio1x1 { + .shoutCardCover { + padding-bottom: 100%; + } +} + +.aspectRatio4x3 { + .shoutCardCover { + padding-bottom: 75%; + } +} + +.aspectRatio16x9 { + .shoutCardCover { + padding-bottom: 56.25%; + } +} + .shoutCardType { height: 3.2rem; position: absolute; diff --git a/src/components/Feed/ArticleCard/ArticleCard.tsx b/src/components/Feed/ArticleCard/ArticleCard.tsx index f656c8a7..951ea08c 100644 --- a/src/components/Feed/ArticleCard/ArticleCard.tsx +++ b/src/components/Feed/ArticleCard/ArticleCard.tsx @@ -46,6 +46,7 @@ export type ArticleCardProps = { withViewed?: boolean noAuthorLink?: boolean } + withAspectRatio?: boolean desktopCoverSize?: 'XS' | 'S' | 'M' | 'L' article: Shout } @@ -112,6 +113,22 @@ export const ArticleCard = (props: ArticleCardProps) => { const [isCoverImageLoading, setIsCoverImageLoading] = createSignal(true) const description = getDescription(props.article.body) + + const aspectRatio = () => { + switch (props.article.layout) { + case 'music': { + return styles.aspectRatio1x1 + } + case 'image': { + return styles.aspectRatio4x3 + } + case 'video': + case 'literature': { + return styles.aspectRatio16x9 + } + } + } + return (
{ [styles.shoutCardSingle]: props.settings?.isSingle, [styles.shoutCardBeside]: props.settings?.isBeside, [styles.shoutCardNoImage]: !props.article.cover, + [aspectRatio()]: props.withAspectRatio, })} > @@ -154,7 +172,6 @@ export const ArticleCard = (props: ArticleCardProps) => { -
{ const handleLoadMoreClick = () => { loadMoreWithoutScrolling(LOAD_MORE_PAGE_SIZE) } - return (
0} fallback={}> @@ -206,6 +205,7 @@ export const Expo = (props: Props) => { article={shout} settings={{ nodate: true, nosubtitle: true, noAuthorLink: true }} desktopCoverSize="XS" + withAspectRatio={true} />
)} @@ -220,6 +220,7 @@ export const Expo = (props: Props) => { article={shout} settings={{ nodate: true, nosubtitle: true, noAuthorLink: true }} desktopCoverSize="XS" + withAspectRatio={true} />
)} @@ -236,6 +237,7 @@ export const Expo = (props: Props) => { article={shout} settings={{ nodate: true, nosubtitle: true, noAuthorLink: true }} desktopCoverSize="XS" + withAspectRatio={true} /> )}