import React, { ReactElement, useEffect } from 'react' import { withStyles, Theme, createStyles } from '@material-ui/core/styles' import { Tabs, Tab, Box, Typography } from '@material-ui/core' import CodeBlock from './CodeBlock' interface TabPanelProps { children?: React.ReactNode index: number value: number } interface Props { linux: string mac: string showLineNumbers?: boolean } function a11yProps(index: number) { return { id: `simple-tab-${index}`, 'aria-controls': `simple-tabpanel-${index}`, } } function getOS() { const userAgent = window.navigator.userAgent const platform = window.navigator.platform const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'] const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'] const iosPlatforms = ['iPhone', 'iPad', 'iPod'] if (macosPlatforms.includes(platform)) return 'macOS' if (iosPlatforms.includes(platform)) return 'iOS' if (windowsPlatforms.includes(platform)) return 'windows' if (/Android/.test(userAgent)) return 'android' if (/Linux/.test(platform)) return 'linux' return null } export default function CodeBlockTabs(props: Props): ReactElement { const [value, setValue] = React.useState(0) const handleChange = (event: React.ChangeEvent, newValue: number) => { setValue(newValue) } useEffect(() => { const os = getOS() if (os === 'windows') { setValue(0) } else if (os === 'linux') { setValue(0) } else if (os === 'macOS') { setValue(1) } }, []) function TabPanel(props: TabPanelProps) { const { children, value, index, ...other } = props return ( ) } const AntTabs = withStyles({ root: { borderBottom: '1px solid #e8e8e8', }, indicator: { backgroundColor: '#3f51b5', }, })(Tabs) interface StyledTabProps { label: string } const AntTab = withStyles((theme: Theme) => createStyles({ root: { textTransform: 'none', minWidth: 72, backgroundColor: 'transparent', fontWeight: theme.typography.fontWeightRegular, marginRight: theme.spacing(4), fontFamily: [ '-apple-system', 'BlinkMacSystemFont', '"Segoe UI"', 'Roboto', '"Helvetica Neue"', 'Arial', 'sans-serif', '"Apple Color Emoji"', '"Segoe UI Emoji"', '"Segoe UI Symbol"', ].join(','), '&:hover': { color: '#3f51b5', opacity: 1, }, '&$selected': { color: '#3f51b5', fontWeight: theme.typography.fontWeightMedium, }, '&:focus': { color: '#3f51b5', }, }, selected: {}, }), )((props: StyledTabProps) => ) return (
) }