Skip to content

Commit

Permalink
feat(on-this-page): add height and with animation
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardoAnjos16 committed Aug 2, 2022
1 parent edde134 commit d229bd3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/components/on-this-page/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react'
import { Box, Flex, Text } from '@vtex/brand-ui'
import AnimateHeight from 'react-animate-height'

import MenuIcon from 'components/icons/menu-icon'
import CloseIcon from 'components/icons/close-icon'
Expand All @@ -12,20 +13,20 @@ const OnThisPage = () => {

return (
<Flex sx={styles.container}>
{open && (
<AnimateHeight duration={300} height={open ? 'auto' : 0}>
<Box sx={styles.contentContainer}>
<Text sx={styles.onThisPageTitle}>On this page</Text>
<Box>
<TableOfContents />
</Box>
</Box>
)}
</AnimateHeight>

<Flex
sx={styles.buttonContainer}
onClick={() => setOpen((open) => !open)}
>
{!open && <Text sx={styles.title}>On this page</Text>}
<Text sx={styles.title(open)}>On this page</Text>
<Box sx={styles.iconContainer}>
{!open ? <MenuIcon size={32} /> : <CloseIcon size={32} />}
</Box>
Expand Down
13 changes: 9 additions & 4 deletions src/components/on-this-page/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { SxStyleProp } from '@vtex/brand-ui'

const container: SxStyleProp = {
right: '20px',
bottom: '20px',
position: 'fixed',
alignItems: 'flex-end',
display: ['flex', 'flex', 'flex', 'flex', 'none'],
Expand Down Expand Up @@ -44,13 +45,17 @@ const iconContainer: SxStyleProp = {
borderLeft: '1px solid #CCCED8',
}

const title: SxStyleProp = {
padding: '8px',
const title: (open: boolean) => SxStyleProp = (open) => ({
color: 'black',
fontSize: '12px',
fontWeight: '400',
lineHeight: '16px',
color: 'black',
}
padding: open ? '0px' : '8px',
overflow: 'hidden',
whiteSpace: 'nowrap',
width: open ? '0px' : '84px',
transition: 'width 0.3s ease-in-out',
})

export default {
container,
Expand Down

0 comments on commit d229bd3

Please sign in to comment.