Skip to content

Commit edc31e7

Browse files
authored
feat(react): add DropDownTree component (#48)
1 parent dc403e9 commit edc31e7

22 files changed

+502
-118
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ArrowRight } from "@/icons";
2+
import { withAs } from "@/utils/hoc";
3+
import { PropsWithChildren } from "react";
4+
5+
type DropdownTreeEndProps = {
6+
title: string;
7+
} & PropsWithChildren;
8+
9+
export const DropdownTreeEnd = withAs(
10+
(Component, props: DropdownTreeEndProps) => {
11+
const { title, children, ...rest } = props;
12+
return (
13+
<Component className="dropdown-tree-end" {...rest}>
14+
<span className="text-h5">
15+
{title} <ArrowRight width={24} height={24} />
16+
</span>
17+
<span className="text-paragraph-1">{children}</span>
18+
</Component>
19+
);
20+
}
21+
);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { PropsWithChildren } from "react";
2+
import { ArrowDown } from "@/icons";
3+
import { Badge } from "../badge";
4+
import { Level } from "../level";
5+
import { TopicElement } from "./dropdown-tree.types";
6+
import { cn } from "@/utils/tw-merge";
7+
8+
const DROPDOWN_TREE_START_VARIANT = {
9+
default: "rustlanges-dropdown-tree-start--default",
10+
extended: "rustlanges-dropdown-tree-start--extended",
11+
};
12+
13+
type StartProps = {
14+
variant: keyof typeof DROPDOWN_TREE_START_VARIANT;
15+
} & PropsWithChildren &
16+
TopicElement;
17+
18+
export const DropdownTreeStart = ({
19+
level,
20+
variant,
21+
title,
22+
state,
23+
children,
24+
}: StartProps) => {
25+
return (
26+
<details
27+
className={cn([
28+
"rustlanges-dropdown-tree-start",
29+
DROPDOWN_TREE_START_VARIANT[variant],
30+
])}
31+
>
32+
<summary>
33+
<Badge type="text" variant={state} />
34+
<Level as="span" variant={level} />
35+
<span className="text-h5 rustlanges-dropdown-tree-start__title">
36+
{title}
37+
</span>
38+
<ArrowDown width={24} height={24} />
39+
</summary>
40+
<div>{children}</div>
41+
</details>
42+
);
43+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { InputHTMLAttributes, PropsWithChildren } from "react";
2+
import { ArrowDown } from "@/icons";
3+
import { Badge } from "../badge";
4+
import { Level } from "../level";
5+
import { TopicElement } from "./dropdown-tree.types";
6+
import { Radio } from "../radio";
7+
8+
type SubjectProps = PropsWithChildren &
9+
TopicElement &
10+
InputHTMLAttributes<HTMLInputElement>;
11+
export const DropdownTreeSubject = ({
12+
level,
13+
title,
14+
state,
15+
children,
16+
...rest
17+
}: SubjectProps) => {
18+
return (
19+
<details className="rustlanges-dropdown-tree-subject">
20+
<summary>
21+
<Badge type="text" variant={state} />
22+
<Level as="span" variant={level} />
23+
<span className="text-h5 rustlanges-dropdown-tree-subject__title">
24+
{title}
25+
</span>
26+
<ArrowDown width={24} height={24} />
27+
<Radio {...rest} />
28+
</summary>
29+
30+
<div>{children}</div>
31+
</details>
32+
);
33+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Badge } from "../badge";
2+
import { Level } from "../level";
3+
import { withAs } from "@/utils/hoc";
4+
import { TopicElement } from "./dropdown-tree.types";
5+
6+
export const DropdownTreeSubTopic = withAs(
7+
(Component, { level, state, title, ...rest }: TopicElement) => {
8+
return (
9+
<Component
10+
{...rest}
11+
tabIndex={0}
12+
className="rustlanges-dropdown-tree-subtopic"
13+
>
14+
<Level variant={level} />
15+
<span className="rustlanges-dropdown-tree-subtopic__title">
16+
{title}
17+
</span>
18+
<Badge type="default" variant={state} />
19+
</Component>
20+
);
21+
}
22+
);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { PropsWithChildren } from "react";
2+
import { ArrowDown } from "@/icons";
3+
import { Badge } from "../badge";
4+
import { Level } from "../level";
5+
import { TopicElement } from "./dropdown-tree.types";
6+
7+
type DropdownTreeTopicProps = PropsWithChildren & TopicElement;
8+
9+
export const DropdownTreeTopic = ({
10+
level,
11+
title,
12+
state,
13+
children,
14+
}: DropdownTreeTopicProps) => {
15+
return (
16+
<details className="rustlanges-dropdown-tree-topic">
17+
<summary>
18+
<Level as="span" variant={level} />
19+
<span className="text-h6 rustlanges-dropdown-tree-topic__title">
20+
{title}
21+
</span>
22+
<Badge type="default" variant={state} />
23+
<ArrowDown width={24} height={24} />
24+
</summary>
25+
<div>{children}</div>
26+
</details>
27+
);
28+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { DropdownTreeStart } from "./dropdown-tree.start";
2+
import { DropdownTreeSubject } from "./dropdown-tree.subject";
3+
import { DropdownTreeTopic } from "./dropdown-tree.topic";
4+
import { DropdownTreeSubTopic } from "./dropdown-tree.subtopic";
5+
import { DropdownTreeEnd } from "./dropdown-tree.end";
6+
7+
export const DropdownTree = {
8+
Start: DropdownTreeStart,
9+
Subject: DropdownTreeSubject,
10+
Topic: DropdownTreeTopic,
11+
SubTopic: DropdownTreeSubTopic,
12+
End: DropdownTreeEnd,
13+
};

js/react/lib/components/topic/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

js/react/lib/components/topic/subtopic.component.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

js/react/lib/components/topic/topic.component.tsx

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)