From 13a9a2159f15bf621106ad9283c6cb71dbb0b851 Mon Sep 17 00:00:00 2001
From: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>
Date: Thu, 5 Dec 2024 22:01:54 +0100
Subject: [PATCH] Refactor accordion stories (#3432)
---
.../react/src/accordion/accordion.stories.tsx | 125 ++++++------------
1 file changed, 40 insertions(+), 85 deletions(-)
diff --git a/@navikt/core/react/src/accordion/accordion.stories.tsx b/@navikt/core/react/src/accordion/accordion.stories.tsx
index 9ee5db211f..028ae894ac 100644
--- a/@navikt/core/react/src/accordion/accordion.stories.tsx
+++ b/@navikt/core/react/src/accordion/accordion.stories.tsx
@@ -1,37 +1,21 @@
-import { StoryObj } from "@storybook/react";
+import { Meta, StoryObj } from "@storybook/react";
import React, { useState } from "react";
import { Accordion, AccordionProps } from ".";
-import AccordionContent from "./AccordionContent";
-import AccordionHeader from "./AccordionHeader";
-import AccordionItem from "./AccordionItem";
export default {
title: "ds-react/Accordion",
component: Accordion,
- subcomponents: {
- AccordionItem,
- AccordionContent,
- AccordionHeader,
- },
parameters: {
chromatic: { disable: true },
},
decorators: [
(Story) => (
-
+
),
],
-};
+} satisfies Meta
;
type Story = StoryObj;
@@ -60,46 +44,21 @@ const SmallContent = () => (
);
-const Item = (props) => {
- const [open, setOpen] = useState(false);
-
- if (props.defaultOpen) {
- return (
-
- Accordion header text
-
-
- );
- }
-
- return props.controlled ? (
-
- setOpen(!open)}>
- Accordion header text
-
-
-
- ) : (
-
- Accordion header text
-
-
- );
-};
+const Item = ({ defaultOpen = false }) => (
+
+ Accordion header text
+ {defaultOpen ? : }
+
+);
export const Controls: Story = {
- render: ({ ...props }) => {
+ render: (props) => {
return (
-
-
- {[...Array(4)].map((_, y) => (
-
- ))}
-
-
+
+ {[...Array(4)].map((_, y) => (
+
+ ))}
+
);
},
argTypes: {
@@ -128,13 +87,11 @@ export const Controls: Story = {
export const DefaultOpen: Story = {
render: () => {
return (
-
-
- {[...Array(4)].map((_, y) => (
-
- ))}
-
-
+
+ {[...Array(4)].map((_, y) => (
+
+ ))}
+
);
},
};
@@ -142,7 +99,7 @@ export const DefaultOpen: Story = {
export const Variants: Story = {
render: () => {
return (
-
+
Default
{[...Array(2)].map((_, y) => (
@@ -166,22 +123,20 @@ export const ControlledState: Story = {
const [open2, setOpen2] = useState(false);
return (
-
-
-
- setOpen(!open)}>
- Accordion header text
-
-
-
-
- setOpen2(!open2)}>
- Accordion header text
-
-
-
-
-
+
+
+ setOpen(!open)}>
+ Accordion header text
+
+
+
+
+ setOpen2(!open2)}>
+ Accordion header text
+
+
+
+
);
},
};
@@ -216,7 +171,7 @@ const headingSizes: AccordionProps["headingSize"][] = [
export const Size: Story = {
render: () => (
-
+
{sizes.map((size) => (
))}
@@ -226,7 +181,7 @@ export const Size: Story = {
export const HeadingSize: Story = {
render: () => (
-
+
{headingSizes.map((size) => (
))}
@@ -237,14 +192,14 @@ export const HeadingSize: Story = {
export const Indent: Story = {
render: () => {
return (
-
-
No indent
+
+
Indent
{[...Array(2)].map((_, y) => (
))}
-
Indent
+
No indent
{[...Array(2)].map((_, y) => (