Skip to content

Commit d251243

Browse files
authored
minor tweaks for card (#1755)
* minor tweaks for card * Add image error handling and lazy loading, fix small shadow and update CardProps typing
1 parent 11ec2a8 commit d251243

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/lib/card/Card.svelte

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,21 @@
2626

2727
{#snippet childSlot()}
2828
{#if img}
29-
<img class={image({ class: clsx(theme?.image, styling.image) })} src={img} alt={img} />
30-
{@render children()}
29+
<img
30+
class={image({ class: clsx(theme?.image, styling.image) })}
31+
src={img}
32+
alt=""
33+
loading="lazy"
34+
onerror={(e) => {
35+
const target = e.currentTarget as HTMLImageElement;
36+
if (target) {
37+
target.style.display = "none";
38+
}
39+
}}
40+
/>
41+
{@render children?.()}
3142
{:else}
32-
{@render children()}
43+
{@render children?.()}
3344
{/if}
3445
{/snippet}
3546

src/lib/card/theme.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ export const card = tv({
4141
rose: { base: "border-rose-200 bg-rose-400 dark:bg-rose-800 dark:border-rose-700" }
4242
},
4343
shadow: {
44-
sm: { base: "shadow-md" },
45-
normal: { base: "shadow-sm" },
44+
xs: { base: "shadow-xs" },
45+
sm: { base: "shadow-sm" },
46+
normal: { base: "shadow" },
4647
md: { base: "shadow-md" },
4748
lg: { base: "shadow-lg" },
4849
xl: { base: "shadow-xl" },

src/lib/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ export type CheckIconProps = SVGAttributes<SVGSVGElement>;
354354
// card
355355
export type CardProps = Omit<CardVariants, "href"> &
356356
AnchorDivAttributes & {
357-
children: Snippet;
358357
img?: string;
359358
imgClass?: ClassValue;
360359
contentClass?: string;

0 commit comments

Comments
 (0)