Skip to content

Commit ed07ac9

Browse files
committed
Move styles for SlidePanel to a CSS module
1 parent 7ec75af commit ed07ac9

File tree

4 files changed

+60
-47
lines changed

4 files changed

+60
-47
lines changed

src/components/viewers/SlidePanel.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import React, { ReactNode, useCallback, useEffect, useState } from 'react'
1+
import React, { CSSProperties, ReactNode, useCallback, useEffect, useMemo, useState } from 'react'
22
import { useConfig } from '../../hooks/useConfig.js'
3+
import { cn } from '../../lib/utils.js'
4+
import styles from '../../styles/viewers/SlidePanel.module.css'
35

46
interface SlidePanelProps {
57
mainContent: ReactNode
@@ -16,7 +18,7 @@ const WIDTH = {
1618
* Slide out panel component with resizing.
1719
*/
1820
export default function SlidePanel({ mainContent, panelContent, isPanelOpen }: SlidePanelProps) {
19-
const { slidePanel } = useConfig()
21+
const { slidePanel, customClass } = useConfig()
2022
const minWidth = slidePanel?.minWidth && slidePanel.minWidth > 0 ? slidePanel.minWidth : WIDTH.MIN
2123
function validWidth(width?: number): number | undefined {
2224
if (width && minWidth <= width) {
@@ -74,24 +76,32 @@ export default function SlidePanel({ mainContent, panelContent, isPanelOpen }: S
7476
}
7577
}, [panelRef, panelWidth])
7678

79+
const panelWidthStyle = useMemo(() => {
80+
return isPanelOpen ? {
81+
'--panel-width': `${panelWidth}px`,
82+
} as CSSProperties :
83+
undefined
84+
}, [panelWidth, isPanelOpen])
85+
7786
return (
78-
<div className="slideContainer">
79-
<div className="slideMain">
87+
<div className={cn(styles.slidePanel, customClass?.slidePanel)}>
88+
<article>
8089
{mainContent}
81-
</div>
90+
</article>
8291
{isPanelOpen &&
8392
<div
84-
className="resizer"
93+
role="separator"
94+
aria-orientation="vertical"
8595
onMouseDown={handleMouseDown}
8696
/>
8797
}
88-
<div
89-
className={resizingClientX === -1 ? 'slidePanel' : 'slidePanel slideDragging'}
98+
<article
9099
ref={panelRef}
91-
style={isPanelOpen ? { width: panelWidth } : undefined}
100+
data-resizing={resizingClientX !== -1}
101+
style={panelWidthStyle}
92102
>
93103
{panelContent}
94-
</div>
104+
</article>
95105
</div>
96106
)
97107
}

src/hooks/useConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface Config {
1717
markdownView?: string
1818
sideBar?: string
1919
slideCloseButton?: string
20+
slidePanel?: string
2021
spinner?: string
2122
textView?: string
2223
welcome?: string

src/styles/app.css

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -262,40 +262,3 @@ input.search:focus {
262262
.folder {
263263
background-image: url("../assets/folder.svg");
264264
}
265-
266-
.slideContainer {
267-
display: flex;
268-
flex: 1;
269-
min-height: 0;
270-
}
271-
272-
.slideMain {
273-
display: flex;
274-
flex: 1;
275-
flex-direction: column;
276-
min-width: 100px;
277-
overflow: auto;
278-
}
279-
280-
.slidePanel {
281-
display: flex;
282-
flex-direction: column;
283-
width: 0;
284-
transition: width 0.2s;
285-
}
286-
287-
.slideDragging {
288-
transition: none;
289-
}
290-
291-
.resizer {
292-
width: 5px;
293-
cursor: col-resize;
294-
background-color: #bfbbbb;
295-
transition: background-color 0.2s;
296-
user-select: none;
297-
}
298-
299-
.resizer:hover {
300-
background-color: #9f9999;
301-
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.slidePanel {
2+
display: flex;
3+
flex: 1;
4+
min-height: 0;
5+
6+
& > article {
7+
display: flex;
8+
flex-direction: column;
9+
}
10+
11+
/* main content */
12+
& > article:nth-of-type(1) {
13+
flex: 1;
14+
min-height: 0;
15+
overflow: auto;
16+
}
17+
/* panel content */
18+
& > article:nth-of-type(2) {
19+
width: var(--panel-width, 0);
20+
transition: width 0.2s;
21+
22+
&[data-resizing="true"] {
23+
transition: none;
24+
}
25+
}
26+
27+
/* resizer separator */
28+
& > [role="separator"] {
29+
width: 5px;
30+
cursor: col-resize;
31+
background-color: #bfbbbb;
32+
transition: background-color 0.2s;
33+
user-select: none;
34+
35+
&:hover {
36+
background-color: #9f9999;
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)