Created
May 9, 2021 16:57
-
-
Save thesabbir/369a3d79a20941d2100363f81e93fe57 to your computer and use it in GitHub Desktop.
Editorjs Nested List render
This file contains hidden or 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
import React from "react"; | |
const NestedListRenderer = ({ data }) => { | |
const ListType = ({ children, style }) => | |
style === "unordered" ? <ul>{children}</ul> : <ol>{children}</ol>; | |
const renderWalk = (items) => | |
!!items.length && ( | |
<ListType style={data.style}> | |
{items.map((item) => ( | |
<React.Fragment key={item.content}> | |
<li>{item.content}</li> | |
{renderWalk(item.items)} | |
</React.Fragment> | |
))} | |
</ListType> | |
); | |
return <div className="nested-list"> {renderWalk(data.items)}</div>; | |
}; | |
export default NestedListRenderer; |
This file contains hidden or 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
.nested-list ol { | |
counter-reset: item | |
} | |
.nested-list li { | |
display: block | |
} | |
.nested-list li:before { | |
content: counters(item, ".") " "; | |
counter-increment: item | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment