11import React , { ReactNode } from "react" ;
2- import styled from "styled-components" ;
32import { useElementSize } from "../../hooks/useElementSize" ;
43import Plus from "../../assets/svgs/accordion/plus.svg" ;
54import Minus from "../../assets/svgs/accordion/minus.svg" ;
6- import {
7- svg ,
8- button ,
9- hoverMediumBlue ,
10- hoverShortTransitionTiming ,
11- } from "../../styles/common-style" ;
125
13- const StyledDiv = styled . div `
14- margin: 8px 0px;
15- .accordion-button {
16- ${ button }
17- ${ hoverMediumBlue }
18- ${ hoverShortTransitionTiming }
19- width: 100%;
20- background-color: ${ ( { theme } ) => theme . klerosUIComponentsWhiteBackground } ;
21- border: 1px solid ${ ( { theme } ) => theme . klerosUIComponentsStroke } ;
22- border-radius: 3px;
23- padding: 11.5px 32px;
24- display: flex;
25- justify-content: space-between;
26- align-items: center;
27-
28- .accordion-svg {
29- ${ svg }
30- height: 16px;
31- width: 16px;
32- fill: ${ ( { theme } ) => theme . klerosUIComponentsPrimaryText } ;
33- }
34- }
35- ` ;
36-
37- interface CollapsibleProps {
38- expanded ?: boolean ;
39- totalHeight : number ;
40- }
41-
42- const Collapsible = styled . div < CollapsibleProps > `
43- height: ${ ( props ) => ( props . expanded ? props . totalHeight . toString ( ) : "0" ) } px;
44- overflow: ${ ( props ) => ( props . expanded ? "visible" : "hidden" ) } ;
45- transition: height ease
46- ${ ( { theme } ) => theme . klerosUIComponentsTransitionSpeed } ;
47- ` ;
48-
49- const Body = styled . div `
50- padding: 32px;
51- ` ;
6+ import clsx from "clsx" ;
7+ import { Button } from "react-aria-components" ;
528
539interface AccordionItemProps {
5410 setExpanded : React . Dispatch < React . SetStateAction < number > > ;
@@ -67,22 +23,39 @@ const AccordionItem: React.FC<AccordionItemProps> = ({
6723} ) => {
6824 const [ ref , { height } ] = useElementSize ( ) ;
6925 return (
70- < StyledDiv >
71- < button
72- className = "accordion-button"
73- onClick = { ( ) => setExpanded ( expanded ? - 1 : index ) }
26+ < div className = "my-2" >
27+ < Button
28+ className = { clsx (
29+ "bg-klerosUIComponentsWhiteBackground border-klerosUIComponentsStroke border" ,
30+ "hover-medium-blue hover-short-transition hover:cursor-pointer" ,
31+ "rounded-[3px] px-8 py-[11.5px]" ,
32+ "flex w-full items-center justify-between" ,
33+ ) }
34+ onPress = { ( ) => setExpanded ( expanded ? - 1 : index ) }
7435 >
7536 { title }
7637 { expanded ? (
77- < Minus className = "accordion-svg" />
38+ < Minus
39+ className = { clsx ( "fill-klerosUIComponentsPrimaryText h-4 w-4" ) }
40+ />
7841 ) : (
79- < Plus className = "accordion-svg" />
42+ < Plus
43+ className = { clsx ( "fill-klerosUIComponentsPrimaryText h-4 w-4" ) }
44+ />
8045 ) }
81- </ button >
82- < Collapsible expanded = { expanded } totalHeight = { height } >
83- < Body ref = { ref } > { body } </ Body >
84- </ Collapsible >
85- </ StyledDiv >
46+ </ Button >
47+ < div
48+ style = { { height : expanded ? `${ height . toString ( ) } px` : 0 } }
49+ className = { clsx (
50+ expanded ? `overflow-visible` : "overflow-hidden" ,
51+ "transition-[height] duration-(--klerosUIComponentsTransitionSpeed) ease-initial" ,
52+ ) }
53+ >
54+ < div className = "p-8" ref = { ref } >
55+ { body }
56+ </ div >
57+ </ div >
58+ </ div >
8659 ) ;
8760} ;
8861
0 commit comments