Skip to content

Commit dc403e9

Browse files
authored
feat(react): add Topic component (#47)
* feat(styles): add Topic & SubTopic styles * feat(react): add Topic & SubTopic components * chore: scoped styles for svg in summary & remove unused subtopic prop type
1 parent ed7fab8 commit dc403e9

File tree

8 files changed

+120
-0
lines changed

8 files changed

+120
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./topic.component";
2+
export * from "./subtopic.component";
3+
export * from "./topic.types";
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Badge } from "../badge";
2+
import { Level } from "../level";
3+
import { TopicElement } from "./topic.types";
4+
import { withAs } from "@/utils/hoc";
5+
6+
export const SubTopic = withAs(
7+
(Component, { level, state, title, ...rest }: TopicElement) => {
8+
return (
9+
<Component {...rest} tabIndex={0} className="rustlanges-subtopic">
10+
<Level variant={level} />
11+
<span className="rustlanges-subtopic__title">{title}</span>
12+
<Badge type="default" variant={state} />
13+
</Component>
14+
);
15+
}
16+
);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { PropsWithChildren } from "react";
2+
import { ArrowDown } from "@/icons";
3+
import { Badge } from "../badge";
4+
import { Level } from "../level";
5+
import { TopicElement } from "./topic.types";
6+
7+
type TopicProps = PropsWithChildren & TopicElement;
8+
export const Topic = ({ level, title, state, children }: TopicProps) => {
9+
return (
10+
<details className="rustlanges-topic">
11+
<summary className="rustlanges-topic__summary">
12+
<Level as="span" variant={level} />
13+
<span className="text-h6 rustlanges-topic__title">{title}</span>
14+
<Badge type="default" variant={state} />
15+
<ArrowDown />
16+
</summary>
17+
{children}
18+
</details>
19+
);
20+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { BadgeVariants } from "../badge/badge.const";
2+
import { LevelVariants } from "../level/level.const";
3+
4+
export type TopicElement = {
5+
level: LevelVariants;
6+
title: string;
7+
state: BadgeVariants;
8+
};

js/react/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export * from "./components/radio";
1111
export * from "./components/badge";
1212
export * from "./components/dropdown";
1313
export * from "./components/calendar";
14+
export * from "./components/topic";
1415
export * from "./icons";

js/react/showcase/App.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
DropdownState,
1515
Calendar,
1616
CalendarRangeDate,
17+
Topic,
18+
SubTopic,
1719
} from "@rustlanges/react";
1820
import { ShowComponent } from "./ShowComponent";
1921
import { useState } from "react";
@@ -279,6 +281,40 @@ export function App() {
279281
<Calendar type="multiple" onChange={setMultiple} value={multiple} />
280282
<Calendar type="range" onChange={setRange} value={range} />
281283
</ShowComponent>
284+
<ShowComponent
285+
component={Topic}
286+
title="Topic"
287+
propsDef={{
288+
level: {
289+
type: "string",
290+
default: "n1",
291+
options: ["n1", "n2", "n3", "op"],
292+
},
293+
title: { type: "string", default: "Tópico" },
294+
state: {
295+
type: "string",
296+
default: "completed",
297+
options: ["completed", "pending", "reading", "unread"],
298+
},
299+
}}
300+
/>
301+
<ShowComponent
302+
component={SubTopic}
303+
title="Sub Topic"
304+
propsDef={{
305+
level: {
306+
type: "string",
307+
default: "n1",
308+
options: ["n1", "n2", "n3", "op"],
309+
},
310+
title: { type: "string", default: "Tópico" },
311+
state: {
312+
type: "string",
313+
default: "completed",
314+
options: ["completed", "pending", "reading", "unread"],
315+
},
316+
}}
317+
/>
282318
</div>
283319
);
284320
}

styles/components.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
@import "./components/radio.css";
1010
@import "./components/tag.css";
1111
@import "./components/text.css";
12+
@import "./components/topic.css";

styles/components/topic.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@layer component {
2+
.rustlanges-topic {
3+
@apply w-full;
4+
}
5+
.rustlanges-topic[open] svg {
6+
@apply -rotate-180;
7+
}
8+
9+
.rustlanges-topic__summary::-webkit-details-marker {
10+
display: none;
11+
}
12+
13+
.rustlanges-topic__summary {
14+
@apply grid w-full grid-cols-[auto_1fr_auto_auto] items-center gap-2 border-y border-black px-3 py-4;
15+
16+
& > svg {
17+
@apply duration-400 size-6 transition;
18+
}
19+
}
20+
21+
.rustlanges-topic__title {
22+
@apply text-neutral-950 dark:text-neutral-50;
23+
}
24+
25+
.rustlanges-subtopic {
26+
@apply grid w-full grid-cols-[auto_1fr_auto] items-center gap-2 border-b px-6 py-2.5;
27+
@apply border-b-gray dark:border-b-neutral-600;
28+
}
29+
30+
.rustlanges-subtopic__title {
31+
@apply text-neutral-950;
32+
@apply desktop:text-sm text-xs;
33+
@apply dark:text-neutral-50;
34+
}
35+
}

0 commit comments

Comments
 (0)