Skip to content

Commit 6b0d04e

Browse files
committed
update
1 parent 0bd457b commit 6b0d04e

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

apps/dashboard/src/@/components/blocks/Img.stories.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Meta, StoryObj } from "@storybook/react";
22
import { ImageIcon } from "lucide-react";
33
import { useState } from "react";
4-
import { BadgeContainer, mobileViewport } from "../../../stories/utils";
4+
import { BadgeContainer } from "../../../stories/utils";
55
import { Spinner } from "../ui/Spinner/Spinner";
66
import { Button } from "../ui/button";
77
import { Img } from "./Img";
@@ -19,28 +19,21 @@ export const Desktop: Story = {
1919
args: {},
2020
};
2121

22-
export const Mobile: Story = {
23-
args: {},
24-
parameters: {
25-
viewport: mobileViewport("iphone14"),
26-
},
27-
};
28-
2922
function Story() {
3023
return (
3124
<div className="flex flex-col gap-10 p-10">
3225
<p> All images below are set with size-20 className </p>
3326

3427
<BadgeContainer label="No Src - pending">
35-
<Img className="size-20" />
28+
<Img className="size-20" src={undefined} />
3629
</BadgeContainer>
3730

3831
<BadgeContainer label="Failed to load - fallback">
3932
<Img className="size-20" src="invalid-src" />
4033
</BadgeContainer>
4134

4235
<BadgeContainer label="No Src, pending - rounded-full">
43-
<Img className="size-20 rounded-full" />
36+
<Img className="size-20 rounded-full" src={undefined} />
4437
</BadgeContainer>
4538

4639
<BadgeContainer label="Failed to load - fallback - rounded-full">
@@ -59,6 +52,7 @@ function Story() {
5952

6053
<BadgeContainer label="Custom Skeleton">
6154
<Img
55+
src={undefined}
6256
skeleton={
6357
<div className="flex items-center justify-center rounded-lg border">
6458
<Spinner className="size-6" />

apps/dashboard/src/@/components/blocks/Img.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ type imgElementProps = React.DetailedHTMLProps<
99
> & {
1010
skeleton?: React.ReactNode;
1111
fallback?: React.ReactNode;
12+
src: string | undefined;
1213
};
1314

1415
export function Img(props: imgElementProps) {
1516
const [_status, setStatus] = useState<"pending" | "fallback" | "loaded">(
1617
"pending",
1718
);
18-
const status = props.src ? _status : "pending";
19+
const status = props.src === undefined ? "pending" : _status;
1920
const { className, ...restProps } = props;
2021
const defaultSkeleton = <div className="animate-pulse bg-accent" />;
2122
const defaultFallback = <div className="bg-muted" />;

0 commit comments

Comments
 (0)