merge conflicts
[arvados-workbench2.git] / src / components / details-attribute / details-attribute.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 Typography from '@material-ui/core/Typography';
7 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
8 import { ArvadosTheme } from '../../common/custom-theme';
9
10 type CssRules = 'attribute' | 'label' | 'value' | 'link';
11
12 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
13     attribute: {
14         display: 'flex',
15         alignItems: 'flex-start',
16         marginBottom: theme.spacing.unit
17     },
18     label: {
19         color: theme.palette.grey["500"],
20         width: '40%'
21     },
22     value: {
23         width: '60%',
24         display: 'flex',
25         alignItems: 'flex-start',
26         textTransform: 'capitalize'
27     },
28     link: {
29         width: '60%',
30         color: theme.palette.primary.main,
31         textDecoration: 'none',
32         overflowWrap: 'break-word'
33     }
34 });
35
36 interface DetailsAttributeDataProps {
37     label: string;
38     value?: string | number;
39     link?: string;
40     children?: React.ReactNode;
41 }
42
43 type DetailsAttributeProps = DetailsAttributeDataProps & WithStyles<CssRules>;
44
45 export const DetailsAttribute = withStyles(styles)(({ label, link, value, children, classes }: DetailsAttributeProps) =>
46     <Typography component="div" className={classes.attribute}>
47         <Typography component="span" className={classes.label}>{label}</Typography>
48         { link
49             ? <a href={link} className={classes.link} target='_blank'>{value}</a>
50             : <Typography component="span" className={classes.value}>
51                 {value}
52                 {children}
53             </Typography> }
54     </Typography>
55 );