Skip to content

Commit ea3d0d6

Browse files
committed
refactor: cleanup
1 parent 46f24a2 commit ea3d0d6

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

packages/slice-machine/src/features/customTypes/customTypesBuilder/ReuseExistingSlicesDialog/ReuseExistingSlicesDialog.tsx

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
Tab,
1111
} from "@prismicio/editor-ui";
1212
import { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
13-
import { useState } from "react";
13+
import { ReactNode, useState } from "react";
1414

1515
import { ComponentUI } from "@/legacy/lib/models/common/ComponentUI";
1616

@@ -96,22 +96,12 @@ function ReuseExistingSlicesDialogContent(
9696
</Box>
9797
{selectedTab === "library" && "<repo-select>"}
9898
</Box>
99-
<Box
100-
minHeight={0}
101-
{...(selectedTab === "local"
102-
? { display: "flex", flexDirection: "column", flexGrow: 1 }
103-
: { display: "none" })}
104-
>
99+
<TabContent selected={selectedTab === "local"}>
105100
<LocalSlicesTab availableSlices={availableSlices} />
106-
</Box>
107-
<Box
108-
minHeight={0}
109-
{...(selectedTab === "library"
110-
? { display: "flex", flexDirection: "column", flexGrow: 1 }
111-
: { display: "none" })}
112-
>
101+
</TabContent>
102+
<TabContent selected={selectedTab === "library"}>
113103
<LibrarySlicesTab />
114-
</Box>
104+
</TabContent>
115105
</Box>
116106

117107
<DialogActions>
@@ -130,6 +120,25 @@ function ReuseExistingSlicesDialogContent(
130120
);
131121
}
132122

123+
interface TabContentProps {
124+
children: ReactNode;
125+
selected: boolean;
126+
}
127+
128+
function TabContent(args: TabContentProps) {
129+
const { children, selected } = args;
130+
131+
if (!selected) {
132+
return <Box display="none">{children}</Box>;
133+
}
134+
135+
return (
136+
<Box display="flex" flexDirection="column" flexGrow={1}>
137+
{children}
138+
</Box>
139+
);
140+
}
141+
133142
export function ReuseExistingSlicesDialog(
134143
props: ReuseExistingSlicesDialogProps,
135144
) {

0 commit comments

Comments
 (0)