Skip to content

Commit

Permalink
feat: optional Accordion prop to tweak padding (#680)
Browse files Browse the repository at this point in the history
* feat: optional Accordion prop to tweak padding

* Only override bottom padding

* Specify tests now we've got 2 exampels
  • Loading branch information
AndyEPhipps authored Nov 1, 2024
1 parent 3655ca1 commit 75d1180
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
9 changes: 4 additions & 5 deletions playwright/components/molecules/accordian.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ const { test, expect } = require('@playwright/test');

test.describe('accordian component', () => {
test('accordian', async ({ page, context }) => {

await page.goto('/#accordion');

// accordian elements should be visible
await expect(page.locator('[data-testid="Accordion-example-1"]')).toBeVisible();
await expect(page.locator('[data-preview="Accordion"]')).toBeVisible();
await expect(page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"]')).toBeVisible();
// dropdown svg icon should be visible
await expect(page.locator('[data-preview="Accordion"] svg')).toBeVisible();
await expect(page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"] svg')).toBeVisible();

// clicking the accordian should show the paragraph
await page.locator('[data-preview="Accordion"] svg').click();
await expect(page.locator('[data-preview="Accordion"] p')).toBeVisible();
await page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"] svg').click();
await expect(page.locator('[data-testid="Accordion-example-1"] [data-preview="Accordion"] p')).toBeVisible();

await page.close();
});
Expand Down
11 changes: 6 additions & 5 deletions src/components/Molecules/Accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ const Copy = styled.div`
padding: 0 ${spacing('lg')};
}
${({ isOpen }) => (isOpen && css`
${({ isOpen, contentBottomPadding }) => (isOpen && css`
height: auto;
visibility: visible;
transition: all 0.2s cubic-bezier(0.21, 1.7, 0.83, 0.68) 0s;
padding: 0 ${spacing('l')} ${spacing('l')};
padding: 0 ${spacing('lg')} ${contentBottomPadding || spacing('l')};
@media ${({ theme }) => theme.allBreakpoints('M')} {
padding: 0 ${spacing('lg')} ${spacing('l')};
padding: 0 ${spacing('lg')} ${contentBottomPadding || spacing('l')};
}
`)}
`;

const Accordion = ({
children, title, ...rest
children, title, contentBottomPadding, ...rest
}) => {
const [isOpen, setIsOpen] = useState(false);

Expand All @@ -89,14 +89,15 @@ const Accordion = ({
<Chevron colour="black" direction={isOpen ? 'up' : 'down'} />
</Icon>
</Button>
<Copy isOpen={isOpen}>
<Copy isOpen={isOpen} contentBottomPadding={contentBottomPadding}>
{children}
</Copy>
</Container>
);
};

Accordion.propTypes = {
contentBottomPadding: PropTypes.string,
children: PropTypes.node.isRequired,
title: PropTypes.oneOfType([
PropTypes.string,
Expand Down
15 changes: 15 additions & 0 deletions src/components/Molecules/Accordion/Accordion.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ import Text from '../../Atoms/Text/Text';
<Text tag="p">Name, surname, email and billing address We need these to process your payment, create a receipt and send it to you. Establishment information We use this information to understand which institutions (e.g. schools, companies) raise money for us. Your details will be kept safe and never shared with other organisations; see our Privacy Policy for more information</Text>
</Accordion>
```

```js
import Text from '../../Atoms/Text/Text';

<Accordion
contentBottomPadding="15px"
title={
<Text family="Anton" size="l" uppercase>
I am the title
</Text>
}
>
<Text tag="p">Customised bottom padding here!</Text>
</Accordion>
```

0 comments on commit 75d1180

Please sign in to comment.