Skip to content

Commit

Permalink
feat: add view transitions for card on search page (#118)
Browse files Browse the repository at this point in the history
* feat: use predictable slug for card transition

* feat: enable view transitions in search card

* refactor: use Card.tsx instead of Card.astro

* refactor: handle card styling in component

* refactor: remove unused class name

---------

Co-authored-by: Sat Naing <satnaingdev@gmail.com>
  • Loading branch information
tanishqmanuja and satnaing authored Sep 18, 2023
1 parent fdabb82 commit b873ed5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 40 deletions.
22 changes: 0 additions & 22 deletions src/components/Card.astro

This file was deleted.

20 changes: 18 additions & 2 deletions src/components/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { slugifyStr } from "@utils/slugify";
import Datetime from "./Datetime";
import type { BlogFrontmatter } from "@content/_schemas";

Expand All @@ -9,9 +10,24 @@ export interface Props {

export default function Card({ href, frontmatter, secHeading = true }: Props) {
const { title, pubDatetime, description } = frontmatter;

const headerProps = {
style: { viewTransitionName: slugifyStr(title) },
className: "text-lg font-medium decoration-dashed hover:underline",
};

return (
<li className="list-card">
<a href={href}>{secHeading ? <h2>{title}</h2> : <h3>{title}</h3>}</a>
<li className="my-6">
<a
href={href}
className="inline-block text-lg font-medium text-skin-accent decoration-dashed underline-offset-4 focus-visible:no-underline focus-visible:underline-offset-0"
>
{secHeading ? (
<h2 {...headerProps}>{title}</h2>
) : (
<h3 {...headerProps}>{title}</h3>
)}
</a>
<Datetime datetime={pubDatetime} />
<p>{description}</p>
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/PostDetails.astro
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const ogUrl = new URL(ogImage ? ogImage : `${post.slug}.png`, Astro.url.origin)
</button>
</div>
<main id="main-content">
<h1 transition:name={title} class="post-title">{title}</h1>
<h1 transition:name={slugifyStr(title)} class="post-title">{title}</h1>
<Datetime datetime={pubDatetime} size="lg" className="my-2" />
<article id="article" role="article" class="prose mx-auto mt-8 max-w-3xl">
<Content />
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/Posts.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Layout from "@layouts/Layout.astro";
import Main from "@layouts/Main.astro";
import Header from "@components/Header.astro";
import Footer from "@components/Footer.astro";
import Card from "@components/Card.astro";
import Card from "@components/Card";
import LinkButton from "@components/LinkButton.astro";
import slugify from "@utils/slugify";
import type { CollectionEntry } from "astro:content";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Header from "@components/Header.astro";
import Footer from "@components/Footer.astro";
import LinkButton from "@components/LinkButton.astro";
import Hr from "@components/Hr.astro";
import Card from "@components/Card.astro";
import Card from "@components/Card";
import Socials from "@components/Socials.astro";
import getSortedPosts from "@utils/getSortedPosts";
import slugify from "@utils/slugify";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tags/[tag].astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Layout from "@layouts/Layout.astro";
import Main from "@layouts/Main.astro";
import Header from "@components/Header.astro";
import Footer from "@components/Footer.astro";
import Card from "@components/Card.astro";
import Card from "@components/Card";
import getUniqueTags from "@utils/getUniqueTags";
import getPostsByTag from "@utils/getPostsByTag";
import slugify from "@utils/slugify";
Expand Down
12 changes: 0 additions & 12 deletions src/styles/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,4 @@
.focus-outline {
@apply outline-2 outline-offset-1 outline-skin-fill focus-visible:no-underline focus-visible:outline-dashed;
}

/* Card */
.list-card {
@apply my-6;
}
.list-card > a {
@apply inline-block text-lg font-medium text-skin-accent decoration-dashed underline-offset-4 focus-visible:no-underline focus-visible:underline-offset-0;
}
.list-card h2,
.list-card h3 {
@apply text-lg font-medium decoration-dashed hover:underline;
}
}

0 comments on commit b873ed5

Please sign in to comment.