Skip to content

Commit

Permalink
feat: add method to get article variant
Browse files Browse the repository at this point in the history
  • Loading branch information
fbuireu committed Sep 7, 2024
1 parent baaeb94 commit adf611c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/ui/modules/contact/utils/changeTab/changeTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export function initTabs() {

for (const tab of tabs) {
tab.addEventListener("click", () => {
changeTab(tab.dataset.target || "");
changeTab(tab.dataset.target ?? "");
});
}
changeTab(tabs[0].dataset.target || "");
changeTab(tabs[0].dataset.target ?? "");
}
7 changes: 2 additions & 5 deletions src/ui/modules/core/components/articleCard/ArticleCard.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
import { Image } from "astro:assets";
import type { CollectionEntry } from "astro:content";
import { ArticleType } from "@application/dto/article/types";
import { PAGES_ROUTES } from "@const/index";
import { articleVariantToClass } from "@modules/core/utils/articleVariantToClass";
import { getLocation } from "@modules/core/utils/getLocation";
import clsx from "clsx";
import "./article-card.css";
Expand All @@ -17,10 +17,7 @@ const location = getLocation(Astro.url);
<article
class={clsx(
'article-card__item',
{
'--default-variant': article.data.variant === ArticleType.DEFAULT,
'--no-image-variant': article.data.variant === ArticleType.NO_IMAGE,
},
articleVariantToClass(article.data.variant),
location && `--is-${location}`,
)}
>
Expand Down
11 changes: 2 additions & 9 deletions src/ui/modules/core/components/articleCard/ArticleCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CollectionEntry } from "astro:content";
import { ArticleType } from "@application/dto/article/types";
import { PAGES_ROUTES } from "@const/index";
import type { ArticleCardAuthorProps } from "@modules/core/components/articleCard/atoms/articleCardAuthor";
import { ArticleCardAuthor } from "@modules/core/components/articleCard/atoms/articleCardAuthor";
Expand All @@ -17,6 +16,7 @@ import type { ArticleCardTagsListProps } from "@modules/core/components/articleC
import { ArticleCardTagsList } from "@modules/core/components/articleCard/atoms/articleCardTagsList";
import type { ArticleCardTitleProps } from "@modules/core/components/articleCard/atoms/articleCardTitle";
import { ArticleCardTitle } from "@modules/core/components/articleCard/atoms/articleCardTitle";
import { articleVariantToClass } from "@modules/core/utils/articleVariantToClass";
import { getLocation } from "@modules/core/utils/getLocation";
import clsx from "clsx";
import type { ReactNode } from "react";
Expand All @@ -36,14 +36,7 @@ export const ArticleCard = ({ children, location: origin, data }: ArticleCardPro
{" "}
</a>
<article
className={clsx(
"article-card__item",
{
"--default-variant": data.variant === ArticleType.DEFAULT,
"--no-image-variant": data.variant === ArticleType.NO_IMAGE,
},
location && `--is-${location}`,
)}
className={clsx("article-card__item", articleVariantToClass(data.variant), location && `--is-${location}`)}
>
{children}
</article>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
import { Image } from "astro:assets";
import type { CollectionEntry } from "astro:content";
import { ArticleType } from "@application/dto/article/types";
import { PAGES_ROUTES } from "@const/index";
import { articleVariantToClass } from "@modules/core/utils/articleVariantToClass";
import clsx from "clsx";
import "./related-article-card.css";
Expand All @@ -16,14 +16,11 @@ const relatedArticle = Astro.props as RelatedArticleCardProps;
<article
class={clsx(
'related-article-card__item',
{
'--default-variant': relatedArticle.data.variant === ArticleType.DEFAULT,
'--no-image-variant': relatedArticle.data.variant === ArticleType.NO_IMAGE,
},
articleVariantToClass(relatedArticle.data.variant)
)}
>
{relatedArticle.data.featuredImage && (
<Image
<Image
class="related-article-card__item__featured-image"
src={relatedArticle.data.featuredImage.url}
width={relatedArticle.data.featuredImage.details.width}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ArticleType } from "@application/dto/article/types.ts";

const variantClassMap = new Map<ArticleType, string>([
[ArticleType.DEFAULT, "--default-variant"],
[ArticleType.NO_IMAGE, "--no-image-variant"],
]);

export function articleVariantToClass(variant: ArticleType) {
return variantClassMap.get(variant) ?? "--default-variant";
}
1 change: 1 addition & 0 deletions src/ui/modules/core/utils/articleVariantToClass/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./articleVariantToClass";

0 comments on commit adf611c

Please sign in to comment.