17782: Fixes absolute import paths from '~/somedir/...' to 'somedir/...'
[arvados.git] / src / components / code-snippet / code-snippet.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { StyleRulesCallback, WithStyles, Typography, withStyles } from '@material-ui/core';
7 import { ArvadosTheme } from 'common/custom-theme';
8 import classNames from 'classnames';
9
10 type CssRules = 'root' | 'space';
11
12 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
13     root: {
14         boxSizing: 'border-box',
15         overflow: 'auto',
16         padding: theme.spacing.unit
17     },
18     space: {
19         marginLeft: '15px'
20     }
21 });
22
23 export interface CodeSnippetDataProps {
24     lines: string[];
25     className?: string;
26     apiResponse?: boolean;
27 }
28
29 type CodeSnippetProps = CodeSnippetDataProps & WithStyles<CssRules>;
30
31 export const CodeSnippet = withStyles(styles)(
32     ({ classes, lines, className, apiResponse }: CodeSnippetProps) =>
33         <Typography
34         component="div"
35         className={classNames(classes.root, className)}>
36             {
37                 lines.map((line: string, index: number) => {
38                     return <Typography key={index} className={apiResponse ? classes.space : className} component="pre">{line}</Typography>;
39                 })
40             }
41         </Typography>
42     );