Merge branch 'master' into 14099-process-service
[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 import * as classnames from "classnames";
10
11 type CssRules = 'attribute' | 'label' | 'value' | 'lowercaseValue' | 'link';
12
13 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
14     attribute: {
15         display: 'flex',
16         alignItems: 'flex-start',
17         marginBottom: theme.spacing.unit
18     },
19     label: {
20         color: theme.palette.grey["500"],
21         width: '40%'
22     },
23     value: {
24         width: '60%',
25         display: 'flex',
26         alignItems: 'flex-start',
27         textTransform: 'capitalize'
28     },
29     lowercaseValue: {
30         textTransform: 'lowercase'
31     },
32     link: {
33         width: '60%',
34         color: theme.palette.primary.main,
35         textDecoration: 'none',
36         overflowWrap: 'break-word',
37         cursor: 'pointer'
38     }
39 });
40
41 interface DetailsAttributeDataProps {
42     label: string;
43     classLabel?: string;
44     value?: React.ReactNode;
45     classValue?: string;
46     lowercaseValue?: boolean;
47     link?: string;
48     children?: React.ReactNode;
49 }
50
51 type DetailsAttributeProps = DetailsAttributeDataProps & WithStyles<CssRules>;
52
53 export const DetailsAttribute = withStyles(styles)(
54     ({ label, link, value, children, classes, classLabel, classValue, lowercaseValue }: DetailsAttributeProps) =>
55         <Typography component="div" className={classes.attribute}>
56             <Typography component="span" className={classnames([classes.label, classLabel])}>{label}</Typography>
57             { link
58                 ? <a href={link} className={classes.link} target='_blank'>{value}</a>
59                 : <Typography component="span" className={classnames([classes.value, classValue, { [classes.lowercaseValue]: lowercaseValue }])}>
60                     {value}
61                     {children}
62                 </Typography> }
63         </Typography>
64 );