Skip to content

Commit

Permalink
Add preventDefault to avoid error when Accordion is inside Form
Browse files Browse the repository at this point in the history
Add story for custom style and add it in guideline
  • Loading branch information
JeanMarcMilletScality committed Oct 31, 2024
1 parent 0d31104 commit 20662e4
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/lib/components/accordion/Accordion.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLButtonElement>
| React.KeyboardEvent<HTMLButtonElement>,
) => {
e.preventDefault();
setIsOpen((prev) => !prev);
};

Expand Down
7 changes: 7 additions & 0 deletions stories/Accordion/accordion.guideline.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<Canvas of={Stories.WithCustomStyle} />

## Playground

<Canvas of={Stories.Playground} layout="fullscreen" />
Expand Down
30 changes: 27 additions & 3 deletions stories/Accordion/accordion.stories.tsx
Original file line number Diff line number Diff line change
@@ -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<AccordionProps>;

Expand Down Expand Up @@ -59,7 +61,29 @@ export const Stacked: AccordionStory = {
<Stack direction="vertical" gap="r8">
<Accordion {...args} />
<Accordion {...args} />
<Accordion {...args} style={{ backgroundColor: 'grey' }} />
<Accordion {...args} />
</Stack>
),
};

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 (
<Accordion {...args} style={style} title={title}>
<Text>The container of this accordion has a custom style</Text>
</Accordion>
);
},
args: {
title: 'Accordion with custom style',
},
};
179 changes: 179 additions & 0 deletions stories/form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 (
<>
<Form
layout={layout}
requireMode={requireMode}
rightActions={
<Stack gap={'r16'}>
<Button variant="outline" label="Cancel" />
<Button
variant="primary"
label="Save"
icon={<Icon name="Save" />}
/>
</Stack>
}
banner={
<Banner
variant="danger"
icon={<Icon name="Exclamation-circle" />}
title={'Error'}
>
There is an error
</Banner>
}
>
<FormSection
title={{
name: 'First part entity data',
helpTooltip: 'Tooltip of the first entity',
icon: 'Search',
}}
>
<FormGroup
direction="vertical"
label="Name"
id="name"
labelHelpTooltip="Name Tooltip"
content={<Input id="name" />}
help="Optional helper text"
required
disabled
></FormGroup>
<FormGroup
direction="horizontal"
label="Email"
id="email"
labelHelpTooltip="Email Tooltip"
content={<Input id="email" />}
error="Invalid email format. Try with a better format."
helpErrorPosition="right"
required
></FormGroup>
</FormSection>
<FormSection
title={{
name: 'Second part entity data',
helpTooltip: 'Tooltip of the Second entity',
icon: 'Search',
}}
>
<FormGroup
direction="horizontal"
label="Name"
id="name1"
labelHelpTooltip="Name Tooltip"
content={
<Toggle
onChange={() => {
setToggle(!toggle);
}}
toggle={toggle}
name="toggle"
/>
}
help="Optional helper text"
required={false}
></FormGroup>
<FormGroup
direction="horizontal"
label="Email"
id="email1"
labelHelpTooltip="Email Tooltip"
content={<Input id="email1" />}
error="Invalid email format. Try with a better format."
helpErrorPosition="right"
required={false}
></FormGroup>
<FormGroup
direction="horizontal"
label="Email long long long"
id="email-long1"
labelHelpTooltip="Email Tooltip"
content={<Input id="email-long1" />}
help="optional helper text"
helpErrorPosition="bottom"
required={false}
></FormGroup>
</FormSection>
<FormSection>
<Accordion title="Advanced Settings" id="advanced-settings">
<FormGroup
direction="vertical"
label="Object Lock Mode"
id="object_lock_mode"
labelHelpTooltip="S3 Object Lock Retention"
content={
<Stack direction="vertical">
<Stack direction="vertical">
<Stack>
<input
type="radio"
name="locktype"
id="locktype-governance"
value="governance"
/>
<label htmlFor="locktype-governance">Governance</label>
</Stack>
<Text isEmphazed color="textSecondary" variant="Smaller">
An user with a specific IAM permissions can
overwrite/delete protected object versions during the
retention period.
</Text>
</Stack>
<Stack>
<input
type="radio"
name="locktype"
id="locktype-compliance"
value="compliance"
/>
<label htmlFor="locktype-compliance">Compliance</label>
</Stack>
<Text isEmphazed color="textSecondary" variant="Smaller">
No one can overwrite protected object versions during the
retention period.
</Text>
</Stack>
}
required={true}
></FormGroup>
<FormGroup
id="value-example"
label="Choose a value"
helpErrorPosition="bottom"
required
content={
<Select
id="value-example"
placeholder="Select an option..."
onChange={() => {}}
value={'value-1'}
>
<Select.Option value={'value-1'}>Value 1</Select.Option>
<Select.Option value={'value-2'}>Value 2</Select.Option>
<Select.Option value={'value-3'}>Value 3</Select.Option>
</Select>
}
/>
</Accordion>
</FormSection>
</Form>
</>
);
},
args: {
requireMode: 'partial',
},
};

0 comments on commit 20662e4

Please sign in to comment.