fix: avoid undefined when passing class-name as prop (#270)

- avoid `undefined` when passing class-name as prop
- use built-in `class:list` directive
This commit is contained in:
87xie
2024-07-14 16:21:49 +08:00
committed by GitHub
parent 8fbb0b4d85
commit e252506493
2 changed files with 13 additions and 5 deletions
+4 -2
View File
@@ -14,10 +14,12 @@ export default function Datetime({
pubDatetime,
modDatetime,
size = "sm",
className,
className = "",
}: Props) {
return (
<div className={`flex items-center space-x-2 opacity-80 ${className}`}>
<div
className={`flex items-center space-x-2 opacity-80 ${className}`.trim()}
>
<svg
xmlns="http://www.w3.org/2000/svg"
className={`${
+9 -3
View File
@@ -7,13 +7,19 @@ export interface Props {
disabled?: boolean;
}
const { href, className, ariaLabel, title, disabled = false } = Astro.props;
const {
href,
className = "",
ariaLabel,
title,
disabled = false,
} = Astro.props;
---
{
disabled ? (
<span
class={`group inline-block ${className}`}
class:list={["group inline-block", className]}
aria-label={ariaLabel}
title={title}
aria-disabled={disabled}
@@ -23,7 +29,7 @@ const { href, className, ariaLabel, title, disabled = false } = Astro.props;
) : (
<a
{href}
class={`group inline-block hover:text-skin-accent ${className}`}
class:list={["group inline-block hover:text-skin-accent", className]}
aria-label={ariaLabel}
title={title}
>