Skip to content

Commit 49fed0d

Browse files
committed
use CSS module for Folder styles
1 parent 2c9d13d commit 49fed0d

File tree

4 files changed

+74
-64
lines changed

4 files changed

+74
-64
lines changed

src/components/Folder.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useRef, useState } from 'react'
22
import { useConfig } from '../hooks/useConfig.js'
33
import type { DirSource, FileMetadata } from '../lib/sources/types.js'
44
import { cn, formatFileSize, getFileDate, getFileDateShort } from '../lib/utils.js'
5+
import styles from '../styles/Folder.module.css'
56
import Breadcrumb from './Breadcrumb.js'
67
import Center from './Center.js'
78
import Layout from './Layout.js'
@@ -21,8 +22,7 @@ export default function Folder({ source }: FolderProps) {
2122
const [searchQuery, setSearchQuery] = useState('')
2223
const searchRef = useRef<HTMLInputElement>(null)
2324
const listRef = useRef<HTMLUListElement>(null)
24-
25-
const { routes } = useConfig()
25+
const { routes, customClass } = useConfig()
2626

2727
// Fetch files on component mount
2828
useEffect(() => {
@@ -98,18 +98,18 @@ export default function Folder({ source }: FolderProps) {
9898
<Center><Spinner /></Center> :
9999
filtered.length === 0 ?
100100
<Center>No files</Center> :
101-
<ul className='file-list' ref={listRef}>
101+
<ul className={cn(styles.fileList, customClass?.fileList)} ref={listRef}>
102102
{filtered.map((file, index) =>
103103
<li key={index}>
104104
<a href={routes?.getSourceRouteUrl?.({ sourceId: file.sourceId }) ?? location.href}>
105-
<span className={cn('file-name', 'file', file.kind === 'directory' && 'folder')}>
105+
<span data-file-kind={file.kind}>
106106
{file.name}
107107
</span>
108108
{file.kind === 'file' && <>
109-
{file.size !== undefined && <span className='file-size' title={file.size.toLocaleString() + ' bytes'}>
109+
{file.size !== undefined && <span data-file-size title={file.size.toLocaleString() + ' bytes'}>
110110
{formatFileSize(file.size)}
111111
</span>}
112-
<span className='file-date' title={getFileDate(file)}>
112+
<span data-file-date title={getFileDate(file)}>
113113
{getFileDateShort(file)}
114114
</span>
115115
</>}

src/hooks/useConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface Config {
1414
center?: string
1515
contentWrapper?: string
1616
errorBar?: string
17+
fileList?: string
1718
highTable?: string
1819
imageView?: string
1920
layout?: string

src/styles/Folder.module.css

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
.fileList {
2+
/* file list */
3+
flex: 1;
4+
list-style: none;
5+
overflow-y: auto;
6+
padding-left: 0;
7+
/* browsers like to cover the bottom row */
8+
padding-bottom: 24px;
9+
10+
& > li {
11+
margin: 0;
12+
13+
&:first-child > a {
14+
border-top: none;
15+
}
16+
17+
& > a {
18+
border-top: 1px solid #ddd;
19+
color: #444;
20+
display: flex;
21+
padding: 8px 16px 8px 20px;
22+
text-decoration: none;
23+
24+
&:hover {
25+
background-color: #e2e2ee;
26+
}
27+
28+
& > span {
29+
overflow: hidden;
30+
text-overflow: ellipsis;
31+
white-space: nowrap;
32+
33+
&[data-file-kind] {
34+
/* file name + icon */
35+
flex: 1;
36+
min-width: 80px;
37+
38+
background-position: left center;
39+
background-repeat: no-repeat;
40+
background-size: 12px;
41+
padding-left: 22px;
42+
43+
&[data-file-kind="directory"] {
44+
background-image: url("../assets/folder.svg");
45+
}
46+
47+
&[data-file-kind="file"] {
48+
background-image: url("../assets/file.svg");
49+
}
50+
}
51+
52+
&[data-file-size] {
53+
/* file size */
54+
color: #666;
55+
margin: 0 16px;
56+
text-align: right;
57+
}
58+
59+
&[data-file-date] {
60+
/* file date */
61+
min-width: 90px;
62+
text-align: right;
63+
}
64+
}
65+
}
66+
}
67+
}

src/styles/app.css

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -91,61 +91,3 @@ input.search:focus {
9191
padding-left: 8px;
9292
width: 180px;
9393
}
94-
95-
/* file list */
96-
.file-list {
97-
flex: 1;
98-
list-style: none;
99-
overflow-y: auto;
100-
padding-left: 0;
101-
/* browsers like to cover the bottom row */
102-
padding-bottom: 24px;
103-
}
104-
.file-list li {
105-
margin: 0;
106-
}
107-
.file-list li:first-child a {
108-
border-top: none;
109-
}
110-
.file-list a {
111-
border-top: 1px solid #ddd;
112-
color: #444;
113-
display: flex;
114-
padding: 8px 16px 8px 20px;
115-
text-decoration: none;
116-
}
117-
.file-list a:hover {
118-
background-color: #e2e2ee;
119-
}
120-
121-
.file-list a > span {
122-
overflow: hidden;
123-
text-overflow: ellipsis;
124-
white-space: nowrap;
125-
}
126-
127-
.file-name {
128-
flex: 1;
129-
min-width: 80px;
130-
}
131-
.file-size {
132-
color: #666;
133-
margin: 0 16px;
134-
text-align: right;
135-
}
136-
.file-date {
137-
min-width: 90px;
138-
text-align: right;
139-
}
140-
141-
/* file icons */
142-
.file {
143-
background-image: url("../assets/file.svg");
144-
background-position: left center;
145-
background-repeat: no-repeat;
146-
background-size: 12px;
147-
padding-left: 22px;
148-
}
149-
.folder {
150-
background-image: url("../assets/folder.svg");
151-
}

0 commit comments

Comments
 (0)