Skip to content

Commit 1cc6eac

Browse files
committed
fix: migrate SidebarItem component styles from SCSS to Tailwind CSS
1 parent 29288b2 commit 1cc6eac

2 files changed

Lines changed: 29 additions & 130 deletions

File tree

src/components/SidebarItem/SidebarItem.jsx

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import PropTypes from "prop-types";
22
import { Component } from "react";
3-
import "./SidebarItem.scss";
43
import { NavLink } from "react-router-dom";
54
import ChevronRightIcon from "../../styles/icons/chevron-right.svg";
65
import BarIcon from "../../styles/icons/vertical-bar.svg";
76
import list2Tree from "../../utilities/list2Tree/index.js";
87

9-
const block = "sidebar-item";
10-
118
export default class SidebarItem extends Component {
129
static propTypes = {
1310
title: PropTypes.string,
@@ -34,19 +31,26 @@ export default class SidebarItem extends Component {
3431
}
3532
}
3633

37-
renderAnchors(anchors) {
34+
renderAnchors(anchors, isOpen) {
3835
return (
39-
<ul className={`${block}__anchors`}>
36+
<ul
37+
className={`relative my-[0.35em] basis-full list-none flex-wrap overflow-hidden pl-6 leading-[19px] before:absolute before:left-6 before:top-0 before:h-[calc(100%-0.6em)] before:border-l before:border-dashed before:border-[#999999] before:content-[''] ${
38+
isOpen ? "flex" : "hidden"
39+
}`}
40+
>
4041
{anchors.map((anchor) => (
4142
<li
4243
key={this._generateAnchorURL(anchor)}
43-
className={`${block}__anchor`}
44+
className="relative my-[0.25em] basis-full truncate pl-4 first:mt-0 last:mb-0 before:absolute before:left-0 before:top-[10px] before:w-[0.5em] before:border-b before:border-dashed before:border-[#999999] before:content-['']"
4445
title={anchor.title}
4546
>
46-
<NavLink to={this._generateAnchorURL(anchor)}>
47+
<NavLink
48+
to={this._generateAnchorURL(anchor)}
49+
className="text-slate-700 hover:text-[#175d96]"
50+
>
4751
{anchor.title2}
4852
</NavLink>
49-
{anchor.children && this.renderAnchors(anchor.children)}
53+
{anchor.children && this.renderAnchors(anchor.children, isOpen)}
5054
</li>
5155
))}
5256
</ul>
@@ -55,48 +59,54 @@ export default class SidebarItem extends Component {
5559

5660
render() {
5761
const { title, anchors = [] } = this.props;
58-
const openMod = this.state.open ? `${block}--open` : "";
59-
const disabledMod = anchors.length === 0 ? `${block}--disabled` : "";
62+
const isOpen = this.state.open;
63+
const hasAnchors = anchors.length > 0;
6064

6165
const filteredAnchors = anchors.filter((anchor) => anchor.level > 1);
6266
const tree = list2Tree(title, filteredAnchors);
6367

6468
return (
65-
<div className={`${block} ${openMod} ${disabledMod}`}>
66-
{anchors.length > 0 ? (
69+
<div className="relative my-[0.6em] flex flex-wrap text-[15px]">
70+
{hasAnchors ? (
6771
<button
68-
className={`${block}__toggle-button`}
72+
className="flex items-center border-0 bg-transparent p-0"
6973
onClick={this._toggle.bind(this)}
7074
aria-label={`Toggle ${title} section`}
71-
aria-expanded={this.state.open}
75+
aria-expanded={isOpen}
7276
>
7377
<ChevronRightIcon
7478
width={15}
7579
height={17}
7680
fill="#175d96"
77-
className={`${block}__toggle`}
81+
className={`mr-2 mt-[0.125em] basis-auto shrink-0 cursor-pointer text-[#175d96] transition-all duration-[250ms] hover:text-[#333333] ${
82+
isOpen ? "origin-center rotate-90" : ""
83+
}`}
7884
/>
7985
</button>
8086
) : (
8187
<BarIcon
82-
className={`${block}__toggle`}
88+
className="mr-2 mt-[0.125em] basis-auto shrink-0 cursor-pointer text-[#aaaaaa]"
8389
width={15}
8490
height={17}
85-
fill="#175d96"
91+
fill="#aaaaaa"
8692
/>
8793
)}
8894

8995
<NavLink
9096
end
9197
key={this.props.url}
92-
className={`${block}__title`}
98+
className={({ isActive }) =>
99+
`max-w-[85%] basis-auto grow truncate text-slate-700 ${
100+
isActive ? "font-semibold text-[#333333]" : ""
101+
}`
102+
}
93103
to={this.props.url}
94104
onClick={this.scrollTop}
95105
>
96106
{title}
97107
</NavLink>
98108

99-
{anchors.length > 0 ? this.renderAnchors(tree) : null}
109+
{hasAnchors ? this.renderAnchors(tree, isOpen) : null}
100110
</div>
101111
);
102112
}

src/components/SidebarItem/SidebarItem.scss

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

0 commit comments

Comments
 (0)