diff --git a/src/lib/components/accordion/Accordion.component.tsx b/src/lib/components/accordion/Accordion.component.tsx index f3df820844..92652b23eb 100644 --- a/src/lib/components/accordion/Accordion.component.tsx +++ b/src/lib/components/accordion/Accordion.component.tsx @@ -20,30 +20,35 @@ const AccordionHeader = styled.button` -moz-appearance: none; appearance: none; border: none; - gap: ${spacing.r8}; width: 100%; cursor: pointer; background-color: transparent; color: ${(props) => props.theme.textPrimary}; - padding: ${spacing.r4}; - width: 100%; + padding: 0; `; const AccordionContainer = styled.div<{ isOpen: boolean; }>` 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.r20}; `; export const Accordion = ({ title, id, style, children }: AccordionProps) => { const [isOpen, setIsOpen] = useState(false); - const handleToggleContent = () => { + const handleToggleContent = ( + e: + | React.MouseEvent + | React.KeyboardEvent, + ) => { setIsOpen((prev) => !prev); }; @@ -51,6 +56,7 @@ export const Accordion = ({ title, id, style, children }: AccordionProps) => {

+ ## Playground diff --git a/stories/Accordion/accordion.stories.tsx b/stories/Accordion/accordion.stories.tsx index 9a1612b624..5d8046795f 100644 --- a/stories/Accordion/accordion.stories.tsx +++ b/stories/Accordion/accordion.stories.tsx @@ -1,12 +1,13 @@ 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 { Text } from '../../src/lib'; type AccordionStory = StoryObj; @@ -59,7 +60,29 @@ export const Stacked: AccordionStory = { - + ), }; + +export const WithCustomStyle: AccordionStory = { + render: (args) => { + const { title } = args; + const theme = useTheme(); + + 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 ( + <> +
+