-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
EditorTabs.tsx
55 lines (50 loc) · 1.47 KB
/
EditorTabs.tsx
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
import EditIcon from '@site/src/icons/edit.svg';
import clsx from 'clsx';
import React from 'react';
import styles from './EditorTabs.module.css';
export interface EditorTabsProps<T extends string | boolean> {
readonly tabs: ({ value: T; label: string } | T)[];
readonly active: T;
readonly showVisualEditor?: boolean;
readonly change: (name: T) => void;
readonly showModal?: (name: T) => void;
}
function EditorTabs<T extends string | boolean>({
tabs,
active,
showVisualEditor,
change,
showModal,
}: EditorTabsProps<T>): JSX.Element {
const tabsWithLabels = tabs.map(tab =>
typeof tab !== 'object' ? { value: tab, label: String(tab) } : tab,
);
return (
<div className={clsx(styles.tabContainer, 'padding--xs')}>
<div role="tablist" className="button-group">
{tabsWithLabels.map(item => (
<button
role="tab"
className={clsx(styles.tabStyle, 'button')}
key={item.label}
aria-selected={active === item.value}
disabled={active === item.value}
onClick={(): void => change(item.value)}
>
{item.label}
</button>
))}
</div>
{showVisualEditor && (
<button
className={clsx(styles.tabStyle, 'button')}
onClick={(): void => showModal?.(active)}
>
Visual Editor
<EditIcon width={12} height={12} />
</button>
)}
</div>
);
}
export default EditorTabs;