Skip to content

Commit

Permalink
feat: optional Accordion prop to tweak padding
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyEPhipps committed Nov 1, 2024
1 parent 3655ca1 commit a74154b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/components/Molecules/Accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ const Copy = styled.div`
padding: 0 ${spacing('lg')};
}
${({ isOpen }) => (isOpen && css`
${({ isOpen, contentPadding }) => (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 (${contentPadding} || ${spacing('l')}) (${contentPadding} || ${spacing('l')});
@media ${({ theme }) => theme.allBreakpoints('M')} {
padding: 0 ${spacing('lg')} ${spacing('l')};
Expand All @@ -73,7 +73,7 @@ const Copy = styled.div`
`;

const Accordion = ({
children, title, ...rest
children, title, contentPadding, ...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} contentPadding={contentPadding}>
{children}
</Copy>
</Container>
);
};

Accordion.propTypes = {
contentPadding: 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
contentPadding="666px"
title={
<Text family="Anton" size="l" uppercase>
I am the title
</Text>
}
>
<Text tag="p">Tweaked padding here</Text>
</Accordion>
```

0 comments on commit a74154b

Please sign in to comment.