Skip to content

Commit

Permalink
feat(ref): fix for init collapse state
Browse files Browse the repository at this point in the history
  • Loading branch information
TrofimovAnton85 committed Oct 4, 2024
1 parent f771b9b commit f9ddecb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/components/ParserOpenRPC/CollapseBox/CollapseBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ interface CollapseBoxProps {

export const CollapseBox = ({
children,
isInitCollapsed = false,
isInitCollapsed = true,
}: CollapseBoxProps) => {
const { collapsed, toggleCollapsed } = useCollapsible({ initialState: true });
const { collapsed, setCollapsed } = useCollapsible({ initialState: isInitCollapsed });
const { colorMode } = useColorMode();
useEffect(() => {
if (isInitCollapsed) {
toggleCollapsed();
}
setCollapsed(isInitCollapsed);
}, [isInitCollapsed]);
return (
<div
Expand All @@ -36,7 +34,7 @@ export const CollapseBox = ({
!collapsed && styles.collapsedBtnView,
colorMode === "light" && styles.collapsedBtnLightHover,
)}
onClick={toggleCollapsed}
onClick={() => setCollapsed((expanded) => !expanded)}
>
{collapsed ? "Show child attributes" : "Hide child attributes"}
<div
Expand Down
2 changes: 1 addition & 1 deletion src/components/ParserOpenRPC/DetailsBox/RenderParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const renderSchema = (schemaItem, schemas, name) => {
description={item.description || item.title || ""}
/>
<div className="padding-bottom--md">
<CollapseBox isInitCollapsed={!!name}>
<CollapseBox>
<>
{Object.entries(item.properties).map(([key, value]) => (
<div key={key} className={styles.paramItemWrapper}>
Expand Down

0 comments on commit f9ddecb

Please sign in to comment.