~bigbes/lethe

ref: f1673181bc8cd0298403408f20740423a43b84a0 lethe/web/src/features/settings/SectionRail.tsx -rw-r--r-- 1.3 KiB
f1673181 — Eugene Blikh collector: fix daemon drain and backfill start 24 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React from 'react'

interface Section<K extends string> {
  key: K
  label: string
  disabled?: boolean
  tag?: string
}

interface SectionRailProps<K extends string> {
  sections: Section<K>[]
  active: K
  onSelect: (k: K) => void
}

export function SectionRail<K extends string>({
  sections,
  active,
  onSelect,
}: SectionRailProps<K>): React.JSX.Element {
  return (
    <div className="section-rail">
      {sections.map((s) => {
        const isActive = s.key === active
        const cls = [
          'section-row',
          isActive ? 'active' : '',
          s.disabled ? 'disabled' : '',
        ]
          .filter(Boolean)
          .join(' ')

        return (
          <div
            key={s.key}
            className={cls}
            onClick={s.disabled ? undefined : () => onSelect(s.key)}
            role={s.disabled ? undefined : 'button'}
            tabIndex={s.disabled ? undefined : 0}
            onKeyDown={
              s.disabled
                ? undefined
                : (e) => {
                    if (e.key === 'Enter' || e.key === ' ') onSelect(s.key)
                  }
            }
          >
            {s.label}
            {s.tag != null && (
              <span className="section-row-tag">{s.tag}</span>
            )}
          </div>
        )
      })}
    </div>
  )
}