refactor: improve props usage and dynamic rendering in LinkButton (#599)

- update LinkButton Props by using HTMLAttributes from astro/types
- use dynamic tags for rendering element dynamically
- improve a11y for pagination
This commit is contained in:
Sat Naing
2026-01-04 20:37:18 +07:00
committed by GitHub
parent ceb406314b
commit 312d1c3eed
3 changed files with 26 additions and 46 deletions
+2 -2
View File
@@ -97,8 +97,8 @@ const isActive = (path: string) => {
"active-nav [&>svg]:stroke-accent": isActive("/archives"), "active-nav [&>svg]:stroke-accent": isActive("/archives"),
}, },
]} ]}
ariaLabel="archives"
title="Archives" title="Archives"
aria-label="archives"
> >
<IconArchive class="hidden sm:inline-block" /> <IconArchive class="hidden sm:inline-block" />
<span class="sm:sr-only">Archives</span> <span class="sm:sr-only">Archives</span>
@@ -113,8 +113,8 @@ const isActive = (path: string) => {
"focus-outline flex p-3 sm:p-1", "focus-outline flex p-3 sm:p-1",
{ "[&>svg]:stroke-accent": isActive("/search") }, { "[&>svg]:stroke-accent": isActive("/search") },
]} ]}
ariaLabel="search"
title="Search" title="Search"
aria-label="search"
> >
<IconSearch /> <IconSearch />
<span class="sr-only">Search</span> <span class="sr-only">Search</span>
+12 -36
View File
@@ -1,45 +1,21 @@
--- ---
export interface Props { import type { HTMLAttributes } from "astro/types";
id?: string;
href: string;
class?: string;
ariaLabel?: string;
title?: string;
disabled?: boolean;
}
const { type Props = { disabled?: boolean } & HTMLAttributes<"a">;
id,
href, const { disabled, class: className, ...attrs } = Astro.props;
class: className = "",
ariaLabel, const Button = disabled ? "span" : "a";
title,
disabled = false,
} = Astro.props;
--- ---
{ <Button
disabled ? (
<span
id={id}
class:list={["group inline-flex items-center gap-1", className]}
title={title}
aria-disabled={disabled} aria-disabled={disabled}
>
<slot />
</span>
) : (
<a
id={id}
{href}
class:list={[ class:list={[
"group inline-flex items-center gap-1 hover:text-accent", "group inline-flex items-center gap-1",
{ "hover:text-accent": !disabled },
className, className,
]} ]}
aria-label={ariaLabel} {...attrs}
title={title} >
>
<slot /> <slot />
</a> </Button>
)
}
+7 -3
View File
@@ -14,12 +14,16 @@ const { page } = Astro.props;
{ {
page.lastPage > 1 && ( page.lastPage > 1 && (
<nav class="mt-auto mb-8 flex justify-center" aria-label="Pagination"> <nav
class="mt-auto mb-8 flex justify-center"
role="navigation"
aria-label="Pagination Navigation"
>
<LinkButton <LinkButton
disabled={!page.url.prev} disabled={!page.url.prev}
href={page.url.prev as string} href={page.url.prev as string}
class:list={["me-4 select-none", { "opacity-50": !page.url.prev }]} class:list={["me-4 select-none", { "opacity-50": !page.url.prev }]}
ariaLabel="Previous" aria-label="Goto Previous Page"
> >
<IconArrowLeft class="inline-block rtl:rotate-180" /> <IconArrowLeft class="inline-block rtl:rotate-180" />
Prev Prev
@@ -29,7 +33,7 @@ const { page } = Astro.props;
disabled={!page.url.next} disabled={!page.url.next}
href={page.url.next as string} href={page.url.next as string}
class:list={["ms-4 select-none", { "opacity-50": !page.url.next }]} class:list={["ms-4 select-none", { "opacity-50": !page.url.next }]}
ariaLabel="Next" aria-label="Goto Next Page"
> >
Next Next
<IconArrowRight class="inline-block rtl:rotate-180" /> <IconArrowRight class="inline-block rtl:rotate-180" />