-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathScreenshotTabs.tsx
More file actions
41 lines (32 loc) · 1 KB
/
ScreenshotTabs.tsx
File metadata and controls
41 lines (32 loc) · 1 KB
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
import React from 'react';
//@ts-ignore
import TabItem from '@theme/TabItem';
//@ts-ignore
import Tabs from '@theme/Tabs';
import type { DataObject } from '../utils/themeColors';
type ScreenshotTabsProps = {
screenshotData: DataObject | string;
baseUrl: string;
};
const getClassName = (value: string) =>
value.endsWith('.gif')
? 'gifScreenshot'
: `tabScreenshot${value.includes('full-width') ? 'full-width' : ''}`;
const ScreenshotTabs: React.FC<ScreenshotTabsProps> = ({
screenshotData,
baseUrl,
}) => {
const renderScreenhot = (src: string): React.JSX.Element => (
<img src={`${baseUrl}${src}`} className={getClassName(src)} />
);
if (typeof screenshotData === 'string') {
return renderScreenhot(screenshotData);
}
const screenshots = Object.entries(screenshotData).map(([key, value]) => (
<TabItem key={key} value={key} label={key} default>
{renderScreenhot(value as string)}
</TabItem>
));
return <Tabs>{screenshots}</Tabs>;
};
export default ScreenshotTabs;