Lib: Add options to Card component to further customize the header image appearance

This commit is contained in:
2025-12-26 18:51:48 +01:00
parent a46a176d59
commit aa14ca6782

View File

@ -2,8 +2,9 @@
import type { Snippet } from "svelte"; import type { Snippet } from "svelte";
import { LazyImage } from "$lib/components"; import { LazyImage } from "$lib/components";
import { error } from "@sveltejs/kit"; import { error } from "@sveltejs/kit";
import type { HTMLAttributes } from "svelte/elements";
interface CardProps { interface CardProps extends HTMLAttributes<HTMLDivElement> {
children: Snippet; children: Snippet;
/** The URL for a possible header image. Leave undefined for no header image. Set to empty string for an image not yet loaded. */ /** The URL for a possible header image. Leave undefined for no header image. Set to empty string for an image not yet loaded. */
@ -24,6 +25,15 @@
/** If the header image is positioned at the left of the card */ /** If the header image is positioned at the left of the card */
imgleft?: boolean; imgleft?: boolean;
/** If the header image has a shadow */
imgshadow?: boolean;
/** Extra classes to pass to the card header image */
extraimgclass?: string;
/** Extra classes to pass to the card content div */
extraclass?: string;
/** The width class for the card, defaults to [w-auto] */ /** The width class for the card, defaults to [w-auto] */
width?: string; width?: string;
@ -39,6 +49,9 @@
imgid = undefined, imgid = undefined,
imghidden = false, imghidden = false,
imgleft = false, imgleft = false,
imgshadow = true,
extraimgclass = "",
extraclass = "",
width = "w-auto", width = "w-auto",
imgonclick = undefined, imgonclick = undefined,
...restProps ...restProps
@ -57,7 +70,7 @@
src={imgsrc} src={imgsrc}
alt="Card header" alt="Card header"
draggable="false" draggable="false"
class="select-none shadow" class="select-none {imgshadow ? 'shadow' : ''} {extraimgclass}"
hidden={imghidden} hidden={imghidden}
imgwidth={imgwidth ?? 0} imgwidth={imgwidth ?? 0}
imgheight={imgheight ?? 0} imgheight={imgheight ?? 0}
@ -65,7 +78,7 @@
/> />
{/if} {/if}
<div class="p-2" {...restProps}> <div class="p-2 {extraclass}" {...restProps}>
{@render children()} {@render children()}
</div> </div>
</div> </div>