-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
AccordionV2
and CollapseV2
components to replace MUI's Acco…
…rdion and Collapse components (#3762) * Added component to replace MUI's Accordion component * minor ui fix * Added AccordionV2 and CollapseV2 * removed comments * patient registration fields alignment fix * fixed accordion max height issue
- Loading branch information
1 parent
0c00f1d
commit d3506fb
Showing
6 changed files
with
268 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { useState } from "react"; | ||
|
||
export default function AccordionV2(props: { | ||
children: JSX.Element | JSX.Element[]; | ||
expandIcon?: JSX.Element; | ||
title: JSX.Element | JSX.Element[] | string; | ||
className?: string; | ||
expanded?: boolean; | ||
}) { | ||
const [toggle, setToggle] = useState(props.expanded as boolean); | ||
const contentEl = React.useRef<HTMLDivElement>(null); | ||
|
||
return ( | ||
<div className={props.className}> | ||
<div className="flex justify-between"> | ||
<button | ||
type="button" | ||
className="w-full grid justify-start" | ||
onClick={() => { | ||
setToggle((prev) => !prev); | ||
}} | ||
> | ||
<>{props.title}</> | ||
</button> | ||
<button | ||
type="button" | ||
className={ | ||
toggle | ||
? "transition-all rotate-180 duration-300 ease-in-out" | ||
: "transition" | ||
} | ||
onClick={() => { | ||
setToggle((prev) => !prev); | ||
}} | ||
> | ||
{props.expandIcon ? ( | ||
props.expandIcon | ||
) : ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
strokeWidth={2} | ||
stroke="currentColor" | ||
className="w-5 h-5" | ||
> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
d="M19.5 8.25l-7.5 7.5-7.5-7.5" | ||
/> | ||
</svg> | ||
)} | ||
</button> | ||
</div> | ||
<div | ||
className="transition-all ease-in-out duration-500 overflow-hidden" | ||
ref={contentEl} | ||
style={ | ||
toggle | ||
? { | ||
maxHeight: contentEl.current | ||
? contentEl.current.scrollHeight * 2 | ||
: "0px", | ||
} | ||
: { maxHeight: "0px" } | ||
} | ||
> | ||
{props.children} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
export default function CollapseV2(props: { | ||
children: JSX.Element | JSX.Element[]; | ||
opened: boolean; | ||
className?: string; | ||
}) { | ||
const content = React.useRef<HTMLDivElement>(null); | ||
const [innerDivState, setInnerDivState] = useState(false); | ||
const [outerDivState, setOuterDivState] = useState(false); | ||
|
||
useEffect(() => { | ||
if (props.opened) { | ||
setOuterDivState(props.opened); | ||
setTimeout(() => { | ||
setInnerDivState(props.opened); | ||
}, 1); | ||
} else { | ||
setInnerDivState(props.opened); | ||
setTimeout(() => { | ||
setOuterDivState(props.opened); | ||
}, 300); | ||
} | ||
}, [props.opened]); | ||
|
||
return ( | ||
<div | ||
className="transition-all ease-in-out duration-300" | ||
style={ | ||
outerDivState | ||
? { | ||
display: "block", | ||
} | ||
: { display: "none" } | ||
} | ||
> | ||
<div | ||
className={`transition-all ease-in-out duration-300 overflow-hidden ${ | ||
props.className ? props.className : "" | ||
}`} | ||
ref={content} | ||
style={ | ||
innerDivState | ||
? { | ||
maxHeight: content.current?.scrollHeight, | ||
} | ||
: { maxHeight: "0px" } | ||
} | ||
> | ||
{props.children} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.