-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
import { forwardRef } from 'react' | ||
|
||
import { Accordion as RAccordion, AccordionProps as RAccordionProps } from '@reach/accordion' | ||
import { Accordion as CAccordion } from '@chakra-ui/react' | ||
import { Flags } from '../../../common/helpers/datasetHelpers' | ||
|
||
export type AccordionProps = RAccordionProps & { | ||
id: string | ||
} | ||
export type CAccordionProps = { | ||
id: string | ||
children?: React.ReactNode | ||
} | ||
|
||
export const Accordion = forwardRef<HTMLDivElement, AccordionProps>(function Accordion({ id, children, ...rest }, ref) { | ||
return ( | ||
<RAccordion ref={ref} {...rest} id={id}> | ||
{children} | ||
</RAccordion> | ||
) | ||
}) | ||
export const Accordion = Flags.IS_DEV | ||
? forwardRef<HTMLDivElement, CAccordionProps>(function Accordion({ id, children }, ref) { | ||
return ( | ||
<CAccordion ref={ref} allowMultiple id={id}> | ||
{children} | ||
</CAccordion> | ||
) | ||
}) | ||
: forwardRef<HTMLDivElement, AccordionProps>(function Accordion({ id, children, ...rest }, ref) { | ||
return ( | ||
<RAccordion ref={ref} {...rest} id={id}> | ||
{children} | ||
</RAccordion> | ||
) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
import styled from 'styled-components' | ||
import { AccordionItem as RAccordionItem, AccordionItemProps as RAccordionItemProps } from '@reach/accordion' | ||
import { AccordionItem as CAccordionItem } from '@chakra-ui/react' | ||
import { Flags } from '../../../common/helpers/datasetHelpers' | ||
|
||
const StyledItem = styled(RAccordionItem)` | ||
border-bottom: 1px solid var(--grey-40); | ||
` | ||
const CStyledItem = styled(CAccordionItem)` | ||
border-bottom: 1px solid var(--grey-40); | ||
` | ||
|
||
export type AccordionItemProps = RAccordionItemProps & { | ||
id: number | ||
} | ||
|
||
export const Item = ({ id, children, ...rest }: AccordionItemProps) => { | ||
return ( | ||
<StyledItem {...rest} index={id}> | ||
{children} | ||
</StyledItem> | ||
) | ||
export type CAccordionItemProps = { | ||
id: number | ||
children: React.ReactNode | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
export const Item = Flags.IS_DEV | ||
? ({ id, children, ...rest }: CAccordionItemProps) => { | ||
return ( | ||
<CStyledItem {...rest} index={id}> | ||
{children} | ||
</CStyledItem> | ||
) | ||
} | ||
: ({ id, children, ...rest }: AccordionItemProps) => { | ||
return ( | ||
<StyledItem {...rest} index={id}> | ||
{children} | ||
</StyledItem> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,18 @@ import { | |
useAccordionItemContext, | ||
} from '@reach/accordion' | ||
import styled from 'styled-components' | ||
import { AccordionPanel as CAccordionPanel } from '@chakra-ui/react' | ||
import { Flags } from '../../../common/helpers/datasetHelpers' | ||
|
||
export type AccordionPanelProps = { | ||
animate?: boolean | ||
} & RAccordionPanelProps | ||
|
||
export type CAccordionPanelProps = { | ||
children?: React.ReactNode | ||
animate?: boolean | ||
} | ||
|
||
const AnimatedAccordionPanel = animated(RAccordionPanel) | ||
|
||
const StyledPanel = styled.div` | ||
|
@@ -27,32 +34,46 @@ const ContentWithBorder = styled.div` | |
padding-left: calc(var(--space-xLarge) / 2); | ||
` | ||
|
||
export const Panel = forwardRef<HTMLDivElement, AccordionPanelProps>(function Panel( | ||
{ animate = true, children, ...rest }, | ||
forwardedRef, | ||
) { | ||
const { isExpanded } = useAccordionItemContext() | ||
const { ref, height } = useDivHeight() | ||
const prefersReducedMotion = usePrefersReducedMotion() | ||
const animation = useSpring({ | ||
opacity: isExpanded ? 1 : 0, | ||
height: isExpanded ? height : 0, | ||
overflow: 'hidden', | ||
config: { duration: 150 }, | ||
immediate: prefersReducedMotion || !animate, | ||
}) | ||
export const Panel = Flags.IS_DEV | ||
? forwardRef<HTMLDivElement, CAccordionPanelProps>(function Panel( | ||
{ children, animate = true, ...rest }, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
fernandolucchesi
Contributor
|
||
forwardedRef, | ||
) { | ||
const { ref } = useDivHeight() | ||
return ( | ||
<CAccordionPanel ref={forwardedRef} {...rest}> | ||
<StyledPanel ref={ref}> | ||
<ContentWithBorder>{children}</ContentWithBorder> | ||
</StyledPanel> | ||
</CAccordionPanel> | ||
) | ||
}) | ||
: forwardRef<HTMLDivElement, AccordionPanelProps>(function Panel( | ||
{ animate = true, children, ...rest }, | ||
forwardedRef, | ||
) { | ||
const { isExpanded } = useAccordionItemContext() | ||
const { ref, height } = useDivHeight() | ||
const prefersReducedMotion = usePrefersReducedMotion() | ||
const animation = useSpring({ | ||
opacity: isExpanded ? 1 : 0, | ||
height: isExpanded ? height : 0, | ||
overflow: 'hidden', | ||
config: { duration: 150 }, | ||
immediate: prefersReducedMotion || !animate, | ||
}) | ||
|
||
return ( | ||
<AnimatedAccordionPanel | ||
style={animation} | ||
hidden={false} | ||
aria-hidden={!isExpanded || undefined} | ||
ref={forwardedRef} | ||
{...rest} | ||
> | ||
<StyledPanel ref={ref}> | ||
<ContentWithBorder>{children}</ContentWithBorder> | ||
</StyledPanel> | ||
</AnimatedAccordionPanel> | ||
) | ||
}) | ||
return ( | ||
<AnimatedAccordionPanel | ||
style={animation} | ||
hidden={false} | ||
aria-hidden={!isExpanded || undefined} | ||
ref={forwardedRef} | ||
{...rest} | ||
> | ||
<StyledPanel ref={ref}> | ||
<ContentWithBorder>{children}</ContentWithBorder> | ||
</StyledPanel> | ||
</AnimatedAccordionPanel> | ||
) | ||
}) |
1 comment
on commit 6f528ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is an extra space after "ReactNode" 😄 which makes me guess your prettier is not yet correctly setup