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
// Generates array from 0 to N (inclusive) | |
type GenerateArr<N extends number, Acc extends number[] = []> = Acc['length'] extends N | |
? Acc | |
: GenerateArr<N, [...Acc, Acc['length']]> | |
type FlattenArr<A extends unknown[]> = A extends [infer X extends number[], ...infer R] ? [...X, ...FlattenArr<R>] : A; | |
type AbsoluteSquare<N extends number, Acc extends unknown[] = []> = | |
Acc['length'] extends N | |
? FlattenArr<Acc>['length'] |
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
import styled from "styled-components"; | |
import { ComponentType } from "./constants"; | |
export type Tree = { | |
name: string; | |
id: string; | |
style: { | |
top: number; | |
left: number; | |
width: number; |
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
const tree2 = { | |
id: "Parent 1", | |
name: "Parent 1", | |
children: [ | |
{ | |
id: "Child-1", | |
name: "Child-1", | |
icons: [<CiSquarePlus size={25} />, <CiSquareMinus size={25} />], | |
children: [ | |
{ |
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
const tree1 = { | |
id: "Parent 1", | |
name: "Parent 1", | |
children: [ | |
{ | |
id: "Child-1", | |
name: "Child-1", | |
children: [ | |
{ | |
id: "Inner-Child-1", |
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
const CustomDetails = (props: CustomDetailsProps) => { | |
const { icons, name, renderTree } = props; | |
const [isOpen, setIsOpen] = useState(false); | |
const hasIcons = icons && icons.length > 0; | |
const handleDrawerOpen = ( | |
e: React.SyntheticEvent<HTMLDetailsElement, ToggleEvent>, | |
) => { | |
// This stops event bubbling; |
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
tree.children.map((item) => ( | |
<li key={`key-${item.id}`}> | |
<CustomDetails | |
icons={item.icons} | |
name={item.name} | |
renderTree={<RecursiveTree tree={item} />} | |
/> | |
</li> | |
))} |
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
const StyledUnorderedList = styled.ul` | |
ul, | |
li { | |
list-style: none; | |
margin: 0; | |
padding: 0; | |
} | |
ul { | |
margin-left: 0.8rem; |
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
import styled from "styled-components"; | |
import { ReactElement, useState } from "react"; | |
type Tree = { | |
id: string; | |
name: string; | |
icons?: JSX.Element[]; | |
children?: Tree[]; | |
}; |
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
const tree = { | |
id: "Parent 1", | |
name: "Parent 1", | |
children: [ | |
{ | |
id: "Child-1", | |
name: "Child-1", | |
children: [ | |
{ | |
id: "Inner-Child-1", |
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
function factorial(n) { | |
if (n == 0) { | |
return 1; | |
} | |
else { | |
return n * factorial(n - 1); | |
} | |
} |
NewerOlder