Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Update stories, fix bug

istarkovfbf8babd62c3
diff --git a/packages/react-sdk/src/components/image-dev.stories.tsx b/packages/react-sdk/src/components/image-dev.stories.tsx
index aaf54898af..0aa54a543e 100644
--- a/packages/react-sdk/src/components/image-dev.stories.tsx
+++ b/packages/react-sdk/src/components/image-dev.stories.tsx
@@ -2,9 +2,10 @@
import React, { type ComponentProps, type HTMLAttributes } from "react";
import type { ComponentMeta, ComponentStory } from "@storybook/react";
+import warnOnce from "warn-once";
import { Image as ImagePrimitive } from "./image";
+import imageMeta from "./image.ws";
import { type ImageLoader } from "../component-utils/image";
-import argTypes from "./image.props.json";
// to not allow include local assets everywhere, just enable it for this file
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -13,8 +14,6 @@ import localLogoImage from "../../storybook-assets/logo.webp";
export default {
title: "Components/ImageDev",
- component: ImagePrimitive,
- argTypes,
} as ComponentMeta<typeof ImagePrimitive>;
type ImageProps = ComponentProps<typeof ImagePrimitive>;
@@ -61,12 +60,29 @@ const imageLoader = USE_CLOUDFLARE_IMAGE_TRANSFORM
? cloudflareImageLoader
: localImageLoader;
-const ImageTemplate: ComponentStory<
+const ImageBase: ComponentStory<
React.ForwardRefExoticComponent<
- ImageProps & { style: HTMLAttributes<"img">["style"] }
+ ImageProps & { style?: HTMLAttributes<"img">["style"] }
>
> = (args) => {
- const style = { maxWidth: "100%", ...args.style };
+ warnOnce(
+ !(
+ imageMeta.defaultStyle?.maxWidth?.value === 100 &&
+ imageMeta.defaultStyle?.maxWidth?.unit === "%"
+ ),
+ "We expect that the image default style has maxWidth: 100%"
+ );
+
+ warnOnce(
+ imageMeta.defaultStyle?.display?.value !== "block",
+ "We expect that the image default style has display: block"
+ );
+
+ const style = {
+ maxWidth: "100%",
+ display: "block",
+ ...args.style,
+ };
return (
<ImagePrimitive
@@ -78,121 +94,76 @@ const ImageTemplate: ComponentStory<
);
};
-export const FixedWidthImage = ImageTemplate.bind({});
-
-FixedWidthImage.parameters = {
- docs: {
- description: {
- story: "Load images depending on image width and device per pixel ratio.",
- },
- },
-};
-
-FixedWidthImage.args = {
- src: imageSrc,
- width: 300,
- height: 400,
-};
-
-export const FixedWidthImageCover = ImageTemplate.bind({});
-
-FixedWidthImageCover.parameters = {
- docs: {
- description: {
- story:
- "Preserve ratio using object-fit: cover. Load images depending on image width and device per pixel ratio.",
- },
- },
-};
-
-FixedWidthImageCover.args = {
- src: imageSrc,
- width: 300,
- height: 400,
- style: { objectFit: "cover" },
-};
-
-export const UnknownWidthImage = ImageTemplate.bind({});
-
-UnknownWidthImage.parameters = {
- docs: {
- description: {
- story: `Load images depending on the viewport width.`,
- },
- },
-};
-
-UnknownWidthImage.args = {
- src: imageSrc,
-};
-
-export const AspectRatioImage = ImageTemplate.bind({});
-
-AspectRatioImage.parameters = {
- docs: {
- description: {
- story: `Fit width of the parent container, has own aspect-ratio and object-fit=cover. Load images depending on the viewport width.`,
- },
- },
-};
-
-AspectRatioImage.decorators = [
- (Story) => <div style={{ maxWidth: "400px" }}>{<Story />}</div>,
-];
+/**
+ * Load images depending on image width and device per pixel ratio.
+ **/
+export const FixedWidthImage: ComponentStory<React.FunctionComponent> = () => (
+ <ImageBase src={imageSrc} width="300" height="400" />
+);
-AspectRatioImage.args = {
- src: imageSrc,
- style: { aspectRatio: "2/1", objectFit: "cover", width: "100%" },
-};
+/**
+ * Preserve ratio using object-fit: cover. Load images depending on image width and device per pixel ratio.
+ **/
+export const FixedWidthImageCover: ComponentStory<
+ React.FunctionComponent
+> = () => (
+ <ImageBase
+ src={imageSrc}
+ width="300"
+ height="400"
+ style={{ objectFit: "cover" }}
+ />
+);
-export const FillParentImage = ImageTemplate.bind({});
+/**
+ * Load images depending on the viewport width.
+ **/
+export const UnknownWidthImage: ComponentStory<
+ React.FunctionComponent
+> = () => <ImageBase src={imageSrc} />;
-FillParentImage.parameters = {
- docs: {
- description: {
- story: `Fill width and height of the relative parent container, object-fit=cover. Load images depending on the viewport width.`,
- },
- },
-};
+/**
+ * Fit width of the parent container, has own aspect-ratio and object-fit=cover.
+ * Load images depending on the viewport width.
+ **/
+export const AspectRatioImage: ComponentStory<React.FunctionComponent> = () => (
+ <div style={{ width: "50%" }}>
+ <ImageBase
+ src={imageSrc}
+ style={{ aspectRatio: "2/1", objectFit: "cover", width: "100%" }}
+ />
+ </div>
+);
-FillParentImage.decorators = [
- (Story) => (
- <div
+/**
+ * Fill width and height of the relative parent container, object-fit=cover. Load images depending on the viewport width.
+ **/
+export const FillParentImage: ComponentStory<React.FunctionComponent> = () => (
+ <div style={{ width: "50%", aspectRatio: "2/1", position: "relative" }}>
+ <ImageBase
+ src={imageSrc}
style={{
- maxWidth: "400px",
- aspectRatio: "2/1",
- position: "relative",
- border: "1px solid red",
+ objectFit: "cover",
+ position: "absolute",
+ width: "100%",
+ height: "100%",
}}
- >
- {<Story />}
- </div>
- ),
-];
-
-FillParentImage.args = {
- src: imageSrc,
- style: {
- position: "absolute",
- inset: 0,
- width: "100%",
- height: "100%",
- objectFit: "cover",
- },
-};
-
-export const HeroImage = ImageTemplate.bind({});
-
-HeroImage.parameters = {
- docs: {
- description: {
- story: `"sizes" attribute explicitly equal to 100vw allowing to skip the default behavior. See DEFAULT_SIZES in the Image component. Load images depending on the viewport width.`,
- },
- },
-};
+ />
+ </div>
+);
-HeroImage.args = {
- src: imageSrc,
- sizes: "100vw",
- style: { aspectRatio: "3/4", objectFit: "cover", width: "100%" },
-};
+/**
+ * "sizes" attribute explicitly equal to 100vw allowing to skip the default behavior.
+ * See DEFAULT_SIZES in the Image component. Load images depending on the viewport width.
+ **/
+export const HeroImage: ComponentStory<React.FunctionComponent> = () => (
+ <ImageBase
+ src={imageSrc}
+ sizes="100vw"
+ style={{
+ aspectRatio: "3/1",
+ objectFit: "cover",
+ width: "100%",
+ }}
+ />
+);
diff --git a/packages/react-sdk/src/components/image.ws.tsx b/packages/react-sdk/src/components/image.ws.tsx
index afa6b02367..27e8fae0bf 100644
--- a/packages/react-sdk/src/components/image.ws.tsx
+++ b/packages/react-sdk/src/components/image.ws.tsx
@@ -3,11 +3,18 @@ import type { WsComponentMeta } from "./component-type";
import { Image } from "./image";
const defaultStyle = {
+ // Otherwise on new image insert onto canvas it can overfit screen size multiple times
maxWidth: {
type: "unit",
unit: "%",
value: 100,
},
+ // inline | inline-block is not suitable because without line-height: 0 on the parent you get unsuitable spaces/margins
+ // see https://stackoverflow.com/questions/24771194/is-the-margin-of-inline-block-4px-is-static-for-all-browsers
+ display: {
+ type: "keyword",
+ value: "block",
+ },
} as const;
const meta: WsComponentMeta<typeof Image> = {