From f95ad3416c9328caf71030dc4b8e23254d567109 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrian=20R=C3=B8stg=C3=A5rd=20Flatner?=
<42931448+adrianflatner@users.noreply.github.com>
Date: Tue, 8 Aug 2023 08:39:23 +0200
Subject: [PATCH] Legger til dokumentasjon for Image (#380)
---
.../stories/components/image/Image.mdx | 24 ++-
.../components/image/Image.stories.tsx | 172 ++++++++++++++++++
2 files changed, 193 insertions(+), 3 deletions(-)
create mode 100644 apps/storybook/stories/components/image/Image.stories.tsx
diff --git a/apps/storybook/stories/components/image/Image.mdx b/apps/storybook/stories/components/image/Image.mdx
index 8ae937f8b6..f0186c566c 100644
--- a/apps/storybook/stories/components/image/Image.mdx
+++ b/apps/storybook/stories/components/image/Image.mdx
@@ -1,13 +1,31 @@
-import { Meta } from "@storybook/blocks";
+import { Meta, Canvas, Story, Controls } from "@storybook/blocks";
+import * as ImageStories from "./Image.stories";
-
+
# Image
-Se [https://chakra-ui.com/docs/components/image](https://chakra-ui.com/docs/components/image) for eksempler og dokumentasjon.
+Image brukes til å vise frem bilder med støtte for fallback.
## Ta i bruk
```jsx
import { Image } from "@kvib/react";
```
+
+## Props
+
+
+
+
+## Størrelser
+
+
+
+## Image med border radius
+
+
+
+## Fallback
+
+
diff --git a/apps/storybook/stories/components/image/Image.stories.tsx b/apps/storybook/stories/components/image/Image.stories.tsx
new file mode 100644
index 0000000000..d7d9825d03
--- /dev/null
+++ b/apps/storybook/stories/components/image/Image.stories.tsx
@@ -0,0 +1,172 @@
+import { Image as KvibImage, Stack as KvibStack } from "@kvib/react/src";
+import { Meta, StoryObj } from "@storybook/react";
+
+const meta: Meta = {
+ title: "Komponenter/Image",
+ component: KvibImage,
+ parameters: {
+ docs: {
+ story: { inline: true },
+ canvas: { sourceState: "shown" },
+ },
+ },
+ argTypes: {
+ align: {
+ description: "How to align the image within its bounds. It maps to css `object-position` property.",
+ table: {
+ type: { summary: "ResponsiveValue>" },
+ },
+ control: "text",
+ },
+ crossOrigin: {
+ description:
+ "The key used to set the crossOrigin on the HTMLImageElement into which the image will be loaded. This tells the browser to request cross-origin access when trying to download the image data.",
+ table: {
+ type: { summary: `"" | "anonymous" | "use-credentials"` },
+ },
+ control: "text",
+ },
+ fallback: {
+ description: "Fallback element to show if image is loading or image fails.",
+ table: {
+ type: { summary: "ReactElement>" },
+ },
+ control: "text",
+ },
+ fallbackSrc: {
+ description:
+ "Fallback image src to show if image is loading or image fails. Note 🚨: We recommend you use a local image",
+ table: {
+ type: { summary: "string" },
+ },
+ control: "text",
+ },
+ fallbackStrategy: {
+ description:
+ "- beforeLoadOrError(default): loads the fallbackImage while loading the src - onError: loads the fallbackImage only if there is an error fetching the src",
+ table: {
+ type: { summary: "FallbackStrategy" },
+ defaultValue: { summary: "beforeLoadOrError" },
+ },
+ control: "text",
+ },
+ fit: {
+ description: "How the image to fit within its bounds. It maps to css `object-fit` property.",
+ table: {
+ type: { summary: "ResponsiveValue" },
+ },
+ control: "text",
+ },
+ htmlHeight: {
+ description: "The native HTML height attribute to the passed to the img",
+ table: {
+ type: { summary: "string | number" },
+ },
+ control: "text",
+ },
+ htmlWidth: {
+ description: "The native HTML width attribute to the passed to the img",
+ table: {
+ type: { summary: "string | number" },
+ },
+ control: "text",
+ },
+ ignoreFallback: {
+ description: "If true, opt out of the fallbackSrc logic and use as img.",
+ table: {
+ type: { summary: "boolean" },
+ defaultValue: { summary: false },
+ },
+ control: "boolean",
+ },
+ loading: {
+ table: {
+ type: { summary: "eager | lazy" },
+ },
+ options: ["eager", "lazy"],
+ control: { type: "radio" },
+ },
+ onError: {
+ description: "A callback for when there was an error loading the image src",
+ table: {
+ type: { summary: "ReactEventHandler" },
+ },
+ control: "text",
+ },
+ onLoad: {
+ description: "A callback for when the image src has been loaded",
+ table: {
+ type: { summary: "ReactEventHandler" },
+ },
+ control: "text",
+ },
+ sizes: {
+ description: "The image sizes attribute",
+ table: {
+ type: { summary: "string" },
+ },
+ control: "text",
+ },
+ src: {
+ description: "The image src attribute",
+ table: {
+ type: { summary: "string" },
+ },
+ control: "text",
+ },
+ srcSet: {
+ description: "The image srcset attribute",
+ table: {
+ type: { summary: "string" },
+ },
+ control: "text",
+ },
+ },
+ args: {
+ onError: undefined,
+ onLoad: undefined,
+ },
+};
+
+export default meta;
+type Story = StoryObj;
+
+export const Image: Story = {
+ args: {
+ boxSize: "400px",
+ fit: "contain",
+ src: "https://images.unsplash.com/photo-1619468129361-605ebea04b44?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2942&q=80",
+ },
+ render: (args) => ,
+};
+
+export const ImageSizes: Story = {
+ args: {
+ fit: "cover",
+ src: "https://images.unsplash.com/photo-1619468129361-605ebea04b44?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2942&q=80",
+ },
+ render: (args) => (
+
+
+
+
+
+ ),
+};
+
+export const ImageBorderRadius: Story = {
+ args: {
+ boxSize: "150px",
+ borderRadius: "full",
+ fit: "cover",
+ src: "https://images.unsplash.com/photo-1619468129361-605ebea04b44?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2942&q=80",
+ },
+ render: (args) => ,
+};
+
+export const ImageFallback: Story = {
+ args: {},
+ render: (args) => (
+
+ ),
+};