From 20662e428742b6c76b36acee5c6df9dd9a171785 Mon Sep 17 00:00:00 2001 From: Jean-Marc Millet Date: Thu, 31 Oct 2024 16:53:41 +0100 Subject: [PATCH 1/4] Add preventDefault to avoid error when Accordion is inside Form Add story for custom style and add it in guideline --- .../accordion/Accordion.component.tsx | 14 +- stories/Accordion/accordion.guideline.mdx | 7 + stories/Accordion/accordion.stories.tsx | 30 ++- stories/form.stories.tsx | 179 ++++++++++++++++++ 4 files changed, 224 insertions(+), 6 deletions(-) diff --git a/src/lib/components/accordion/Accordion.component.tsx b/src/lib/components/accordion/Accordion.component.tsx index f3df820844..c647b14ef4 100644 --- a/src/lib/components/accordion/Accordion.component.tsx +++ b/src/lib/components/accordion/Accordion.component.tsx @@ -33,17 +33,25 @@ const AccordionContainer = styled.div<{ }>` overflow: hidden; opacity: ${(props) => (props.isOpen ? 1 : 0)}; - transition: height 0.3s ease-in, opacity 0.3s ease-in, visibility 0.3s; + transition: + height 0.3s ease-in, + opacity 0.3s ease-in, + visibility 0.3s; visibility: ${(props) => (props.isOpen ? 'visible' : 'hidden')}; `; const Wrapper = styled.div` - padding-block: ${spacing.r8}; + padding: ${spacing.r8} 0 ${spacing.r8} ${spacing.r16}; `; export const Accordion = ({ title, id, style, children }: AccordionProps) => { const [isOpen, setIsOpen] = useState(false); - const handleToggleContent = () => { + const handleToggleContent = ( + e: + | React.MouseEvent + | React.KeyboardEvent, + ) => { + e.preventDefault(); setIsOpen((prev) => !prev); }; diff --git a/stories/Accordion/accordion.guideline.mdx b/stories/Accordion/accordion.guideline.mdx index f19be488b6..5adae2612d 100644 --- a/stories/Accordion/accordion.guideline.mdx +++ b/stories/Accordion/accordion.guideline.mdx @@ -19,6 +19,13 @@ import * as Stories from './accordion.stories'; Accordions are used to toggle the visibility of content. It is used to hide non essential information or to reduce the amount of information displayed on the screen. +## Style + +Accordion component comes with a style prop that can be used to customize the appearance of the accordion content. +The default style of the accordion container only includes padding. + + + ## Playground diff --git a/stories/Accordion/accordion.stories.tsx b/stories/Accordion/accordion.stories.tsx index 9a1612b624..cc33f0f1ce 100644 --- a/stories/Accordion/accordion.stories.tsx +++ b/stories/Accordion/accordion.stories.tsx @@ -1,12 +1,14 @@ import { Meta, StoryObj } from '@storybook/react'; import React from 'react'; - +import { useTheme } from 'styled-components'; import { Accordion, AccordionProps, } from '../../src/lib/components/accordion/Accordion.component'; -import { Stack } from '../../src/lib/spacing'; import { Button } from '../../src/lib/components/buttonv2/Buttonv2.component'; +import { spacing, Stack } from '../../src/lib/spacing'; +import { margin } from 'styled-system'; +import { Text } from '../../src/lib'; type AccordionStory = StoryObj; @@ -59,7 +61,29 @@ export const Stacked: AccordionStory = { - + ), }; + +export const WithCustomStyle: AccordionStory = { + render: (args) => { + const { title } = args; + const theme = useTheme(); + console.log(theme); + const style = { + backgroundColor: theme.statusHealthy, + borderRadius: spacing.r4, + padding: spacing.r16, + margin: spacing.r8, + }; + return ( + + The container of this accordion has a custom style + + ); + }, + args: { + title: 'Accordion with custom style', + }, +}; diff --git a/stories/form.stories.tsx b/stories/form.stories.tsx index c2b2689eb4..573f179b8f 100644 --- a/stories/form.stories.tsx +++ b/stories/form.stories.tsx @@ -13,6 +13,7 @@ import { Text } from '../src/lib/components/text/Text.component'; import { Toggle } from '../src/lib/components/toggle/Toggle.component'; import { Stack } from '../src/lib/spacing'; import { iconArgType } from './controls'; +import { Accordion } from '../src/lib/next'; export default { title: 'Templates/Form', @@ -251,3 +252,181 @@ export const PageFormWithIcon = { }, }, }; + +export const FormWithAccordion = { + render: ({ kind, title, subTitle, icon, requireMode }) => { + const layout = { + kind, + title, + subTitle, + icon, + }; + const [toggle, setToggle] = useState(true); + return ( + <> +
+