refactor: kanban block render

This commit is contained in:
lawvs
2022-08-24 18:54:30 +08:00
parent 9633ebd486
commit aa62599d13

View File

@@ -25,32 +25,64 @@ const OneLevelBlockRender = ({ blockId }: RenderBlockProps) => {
); );
}; };
export const KanbanBlockRender = ({ blockId }: RenderBlockProps) => { export const KanbanParentBlockRender = ({
blockId,
active,
}: RenderBlockProps & { active?: boolean }) => {
return (
<BlockBorder active={active}>
<BlockWithoutChildrenRender blockId={blockId} />
</BlockBorder>
);
};
const KanbanChildrenRender = ({
blockId,
activeBlock,
}: RenderBlockProps & { activeBlock?: string | null }) => {
const { block } = useBlock(blockId); const { block } = useBlock(blockId);
if (!block) { if (!block) {
return ( return null;
<BlockRenderProvider blockRender={NullBlockRender}>
<RenderBlock blockId={blockId} />
</BlockRenderProvider>
);
} }
return ( return (
<BlockRenderProvider blockRender={NullBlockRender}> <BlockRenderProvider blockRender={NullBlockRender}>
<RenderBlock blockId={blockId} />
{block?.childrenIds.map(childId => ( {block?.childrenIds.map(childId => (
<StyledBorder key={childId}> <ChildBorder key={childId} active={activeBlock === childId}>
<RenderBlock blockId={childId} /> <RenderBlock blockId={childId} />
</StyledBorder> </ChildBorder>
))} ))}
</BlockRenderProvider> </BlockRenderProvider>
); );
}; };
const StyledBorder = styled('div')({ export const KanbanBlockRender = ({
border: '1px solid #E0E6EB', blockId,
borderRadius: '5px', activeBlock,
margin: '4px', }: RenderBlockProps & { activeBlock?: string | null }) => {
padding: '0 4px', return (
}); <BlockRenderProvider blockRender={NullBlockRender}>
<KanbanParentBlockRender
blockId={blockId}
active={activeBlock === blockId}
/>
<KanbanChildrenRender blockId={blockId} activeBlock={activeBlock} />
</BlockRenderProvider>
);
};
const BlockBorder = styled('div')<{ active?: boolean }>(
({ theme, active }) => ({
borderRadius: '5px',
padding: '0 4px',
border: `1px solid ${
active ? theme.affine.palette.primary : 'transparent'
}`,
})
);
const ChildBorder = styled(BlockBorder)(({ active, theme }) => ({
border: `1px solid ${active ? theme.affine.palette.primary : '#E0E6EB'}`,
margin: '4px 0',
}));