Skip to content

Commit 4c04e0f

Browse files
committed
fix(Img): add children for enhanded:img
1 parent f68823a commit 4c04e0f

28 files changed

+775
-781
lines changed

package.json

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@
4141
"@eslint/compat": "^1.4.0",
4242
"@eslint/js": "^9.36.0",
4343
"@flowbite-svelte-plugins/chart": "^0.2.4",
44-
"@flowbite-svelte-plugins/datatable": "^0.4.0",
44+
"@flowbite-svelte-plugins/datatable": "^0.4.1",
4545
"@flowbite-svelte-plugins/texteditor": "^0.25.5",
4646
"@playwright/test": "^1.55.1",
4747
"@resvg/resvg-js": "^2.6.2",
48-
"@sveltejs/adapter-auto": "^6.1.0",
49-
"@sveltejs/adapter-vercel": "^5.10.2",
48+
"@sveltejs/adapter-auto": "^6.1.1",
49+
"@sveltejs/adapter-vercel": "^5.10.3",
5050
"@sveltejs/enhanced-img": "0.6.1",
51-
"@sveltejs/kit": "^2.43.2",
51+
"@sveltejs/kit": "^2.43.8",
5252
"@sveltejs/package": "^2.5.4",
53-
"@sveltejs/vite-plugin-svelte": "^6.2.0",
53+
"@sveltejs/vite-plugin-svelte": "^6.2.1",
5454
"@svitejs/changesets-changelog-github-compact": "^1.2.0",
55-
"@tailwindcss/vite": "^4.1.13",
56-
"@testing-library/jest-dom": "^6.8.0",
55+
"@tailwindcss/vite": "^4.1.14",
56+
"@testing-library/jest-dom": "^6.9.1",
5757
"@testing-library/svelte": "^5.2.8",
5858
"@testing-library/user-event": "^14.6.1",
5959
"@tiptap/core": "3.4.4",
@@ -83,19 +83,18 @@
8383
"runes-meta-tags": "^0.4.5",
8484
"satori": "^0.18.3",
8585
"satori-html": "^0.3.2",
86-
"simple-datatables": "^10.0.0",
8786
"super-sitemap": "^1.0.5",
88-
"svelte": "^5.39.5",
87+
"svelte": "^5.39.8",
8988
"svelte-check": "^4.3.2",
9089
"svelte-doc-llm": "^0.4.1",
9190
"svelte-lib-helpers": "^0.4.31",
9291
"svelte-meta-tags": "^4.4.1",
9392
"svelte-rune-highlight": "^0.7.1",
94-
"tailwindcss": "^4.1.13",
95-
"tsx": "^4.20.5",
96-
"typescript": "^5.9.2",
97-
"typescript-eslint": "^8.44.1",
98-
"vite": "^7.1.7",
93+
"tailwindcss": "^4.1.14",
94+
"tsx": "^4.20.6",
95+
"typescript": "^5.9.3",
96+
"typescript-eslint": "^8.45.0",
97+
"vite": "^7.1.9",
9998
"vite-plugin-devtools-json": "^1.0.0",
10099
"vitest": "^3.2.4"
101100
},

pnpm-lock.yaml

Lines changed: 506 additions & 508 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1934,13 +1934,15 @@ export interface Picture {
19341934
}
19351935
// export type EnhancedImgAttributes = Omit<HTMLImgAttributes, "src"> & { src: string };
19361936

1937-
export interface ImgProps extends ImgVariants, HTMLImgAttributes {
1937+
export interface ImgProps extends ImgVariants, Omit<HTMLImgAttributes, 'children'> {
1938+
children?: Snippet<[{ class: string; restProps: any }]>;
19381939
size?: ImgVariants["size"];
19391940
effect?: ImgVariants["effect"];
19401941
caption?: string;
19411942
figClass?: string;
19421943
captionClass?: string;
19431944
href?: HTMLAnchorElement["href"];
1945+
align?: ImgVariants["align"];
19441946
}
19451947

19461948
export interface EnhandedImgProps extends ImgVariants, Omit<HTMLImgAttributes, "src"> {

src/lib/typography/img/EnhancedImg.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
const theme = getTheme("img");
2323
2424
let { base, figure, caption: figureCaption } = $derived(img({ size }));
25+
console.warn("EnhancedImg is deprecated. Please use Img instead.");
2526
</script>
2627

2728
{#snippet imageSlot()}

src/lib/typography/img/Img.svelte

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,50 @@
44
import type { ImgProps } from "$lib/types";
55
import { getTheme, warnThemeDeprecation } from "$lib/theme/themeUtils";
66
7-
let { size = "none", effect = "none", caption, class: className, classes, figClass, captionClass, href, ...restProps }: ImgProps = $props();
7+
let { children, size, effect, align, caption, class: className, classes, figClass, captionClass, href, ...restProps }: ImgProps = $props();
88
99
warnThemeDeprecation(
1010
"Img",
1111
{ figClass, captionClass },
1212
{
13-
figClass: "fig",
13+
figClass: "figure",
1414
captionClass: "caption"
1515
}
1616
);
17+
1718
const styling = $derived({
18-
fig: figClass,
19-
caption: captionClass
19+
figure: figClass || classes?.figure,
20+
caption: captionClass || classes?.caption
2021
});
2122
2223
const theme = getTheme("img");
2324
24-
let { base, figure, caption: figureCaption } = $derived(img({ size, effect }));
25+
let { base, figure, caption: figureCaption } = $derived(img({ size, effect, align }));
26+
27+
// Determine if using slot or traditional props
28+
const useSlot = $derived(!!children);
29+
// Compute the final class string to pass to children
30+
const imgClass = $derived(base({ class: clsx(theme?.base, className) }));
2531
</script>
2632

2733
{#snippet imageSlot()}
2834
{#if caption}
29-
<figure class={figure({ class: clsx(theme?.figure, styling.fig) })}>
30-
<img {...restProps} class={base({ class: clsx(theme?.base, className) })} />
35+
<figure class={figure({ class: clsx(theme?.figure, styling.figure) })}>
36+
{#if useSlot}
37+
{@render children?.({ class: imgClass, restProps })}
38+
{:else}
39+
<img {...restProps} class={imgClass} />
40+
{/if}
3141
<figcaption class={figureCaption({ class: clsx(theme?.caption, styling.caption) })}>
3242
{@html caption}
3343
</figcaption>
3444
</figure>
3545
{:else}
36-
<img {...restProps} class={base({ class: clsx(theme?.base, className) })} />
46+
{#if useSlot}
47+
{@render children?.({ class: imgClass, restProps })}
48+
{:else}
49+
<img {...restProps} class={imgClass} />
50+
{/if}
3751
{/if}
3852
{/snippet}
3953

src/lib/typography/img/theme.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ export const img = tv({
1818
lg: { base: "max-w-lg", figure: "max-w-lg" },
1919
xl: { base: "max-w-xl", figure: "max-w-xl" },
2020
"2xl": { base: "max-w-2xl", figure: "max-w-2xl" },
21-
full: { base: "max-w-full", figure: "max-w-full" },
22-
none: { base: "", figure: "" }
21+
full: { base: "max-w-full", figure: "max-w-full" }
2322
},
2423
effect: {
2524
grayscale: {
@@ -37,10 +36,12 @@ export const img = tv({
3736
},
3837
"hue-rotate": {
3938
base: "hue-rotate-60 filter transition-all duration-300 hover:hue-rotate-0"
40-
},
41-
none: {
42-
base: "transition-all duration-300"
4339
}
40+
},
41+
align: {
42+
left: { base: "mx-0" },
43+
center: { base: "mx-auto" },
44+
right: { base: "ml-auto mr-0" }
4445
}
4546
}
4647
});

src/routes/builder/image/+page.svelte

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
let dir = "builder";
1414
1515
const sizes = Object.keys(img.variants.size);
16-
let imgSize: ImgProps["size"] = $state("none");
16+
let imgSize: ImgProps["size"] = $state(undefined);
1717
// const alignments = Object.keys(img.variants.alignment);
1818
// let imgAlignment: ImgProps['alignment'] = $state('left');
1919
const effects = Object.keys(img.variants.effect);
20-
let imgEffect: ImgProps["effect"] = $state("none");
20+
let imgEffect: ImgProps["effect"] = $state(undefined);
2121
2222
// const shadows = Object.keys(img.variants.shadow);
2323
// let imgShadow: ImgProps['shadow'] = $state('none');
@@ -33,8 +33,8 @@
3333
imgHref = imgHref === "" ? "/" : "";
3434
};
3535
$effect(() => {
36-
if (imgSize !== "none") {
37-
imgEffect = "none";
36+
if (imgSize !== undefined) {
37+
imgEffect = undefined;
3838
}
3939
});
4040
@@ -43,13 +43,13 @@
4343
(() => {
4444
// size, alignment, effect, shadow, rounded, caption, imgClass, figClass, captionClass,
4545
let props = [];
46-
if (imgSize !== "none") props.push(` size="${imgSize}"`);
46+
if (imgSize !== undefined) props.push(` size="${imgSize}"`);
4747
// if (imgAlignment !== 'left') props.push(` alignment="${imgAlignment}"`);
48-
if (imgEffect !== "none") props.push(` effect="${imgEffect}"`);
48+
if (imgEffect !== undefined) props.push(` effect="${imgEffect}"`);
4949
// if (imgShadow !== 'none') props.push(` shadow="${imgShadow}"`);
5050
// if (imgRounded !== 'none') props.push(` rounded="${imgRounded}"`);
51-
if (imgEffect !== "none" && imgCaption) props.push(` figClass="relative max-w-sm transition-all duration-300 cursor-pointer filter grayscale hover:grayscale-0"`);
52-
if (imgEffect !== "none" && imgCaption) props.push(` captionClass="absolute bottom-6 px-4 text-lg text-white"`);
51+
if (imgEffect !== undefined && imgCaption) props.push(` figClass="relative max-w-sm transition-all duration-300 cursor-pointer filter grayscale hover:grayscale-0"`);
52+
if (imgEffect !== undefined && imgCaption) props.push(` captionClass="absolute bottom-6 px-4 text-lg text-white"`);
5353
if (imgCaption) props.push(` caption="Image caption"`);
5454
if (imgHref) props.push(` href="/"`);
5555
@@ -82,7 +82,7 @@
8282
<H1>Image Builder</H1>
8383
<CodeWrapper>
8484
<div class="relative mb-4 overflow-y-auto md:h-[700px]">
85-
<Img src={imgEffect !== "none" ? "/images/examples/content-gallery-3.png" : imgClass.includes("full") ? "/images/examples/[email protected]" : "/images/examples/[email protected]"} size={imgSize} class={imgClass} alt="sample 1" effect={imgEffect} figClass={imgEffect !== "none" && imgCaption ? "relative max-w-sm transition-all duration-300 cursor-pointer filter grayscale hover:grayscale-0" : ""} captionClass={imgEffect !== "none" && imgCaption ? "absolute bottom-6 px-4 text-lg text-white mx-auto" : ""} caption={imgEffect !== "none" ? "Do you want to get notified when a new component is added to Flowbite?" : imgCaption ? "Image caption" : ""} href={imgHref} />
85+
<Img src={imgEffect !== undefined ? "/images/examples/content-gallery-3.png" : imgClass.includes("full") ? "/images/examples/[email protected]" : "/images/examples/[email protected]"} size={imgSize} class={imgClass} alt="sample 1" effect={imgEffect} figClass={imgEffect !== undefined && imgCaption ? "relative max-w-sm transition-all duration-300 cursor-pointer filter grayscale hover:grayscale-0" : ""} captionClass={imgEffect !== undefined && imgCaption ? "absolute bottom-6 px-4 text-lg text-white mx-auto" : ""} caption={imgEffect !== undefined ? "Do you want to get notified when a new component is added to Flowbite?" : imgCaption ? "Image caption" : ""} href={imgHref} />
8686
</div>
8787
<div class="mb-4 flex flex-wrap space-x-2">
8888
<Label class="mb-4 w-full font-bold">Size</Label>

src/routes/docs-examples/typography/image/Alignment.svelte

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script lang="ts">
2+
import { Img, img, Radio, Label, type ImgProps } from "$lib";
3+
4+
const alignments = Object.keys(img.variants.align);
5+
let imgAlign: ImgProps["align"] = $state(undefined);
6+
</script>
7+
8+
<div class="flex flex-col">
9+
<Img src="/images/examples/[email protected]" size="sm" align={imgAlign} alt="sample 1" />
10+
11+
<div class="mt-4 flex flex-wrap space-x-2">
12+
<Label class="mb-4 w-full font-bold">Alignment</Label>
13+
{#each alignments as option}
14+
<Radio class="my-1" classes={{ label: "w-16" }} name="alignment" bind:group={imgAlign} value={option}>{option}</Radio>
15+
{/each}
16+
</div>
17+
</div>

src/routes/docs-examples/typography/image/Card.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
import { Img } from "flowbite-svelte";
33
</script>
44

5-
<Img src="/images/examples/content-gallery-3.png" alt="sample 1" class="rounded-lg" figClass="relative max-w-sm transition-all duration-300 cursor-pointer filter grayscale hover:grayscale-0" captionClass="absolute bottom-6 px-4 text-lg text-white" caption="Do you want to get notified when a new component is added to Flowbite?" />
5+
<Img src="/images/examples/content-gallery-3.png" alt="sample 1" class="rounded-lg" classes={{ figure:"relative", caption:"absolute bottom-6 px-4 text-lg text-white"}} caption="Do you want to get notified when a new component is added to Flowbite?" effect="grayscale" size="sm"/>

0 commit comments

Comments
 (0)