Merge branch '14434-display-workflow-name'
[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         boxSizing: 'border-box',
21         color: theme.palette.grey["500"],
22         width: '40%'
23     },
24     value: {
25         boxSizing: 'border-box',
26         width: '60%',
27         display: 'flex',
28         alignItems: 'flex-start',
29         textTransform: 'capitalize'
30     },
31     lowercaseValue: {
32         textTransform: 'lowercase'
33     },
34     link: {
35         width: '60%',
36         color: theme.palette.primary.main,
37         textDecoration: 'none',
38         overflowWrap: 'break-word',
39         cursor: 'pointer'
40     }
41 });
42
43 interface DetailsAttributeDataProps {
44     label: string;
45     classLabel?: string;
46     value?: React.ReactNode;
47     classValue?: string;
48     lowercaseValue?: boolean;
49     link?: string;
50     children?: React.ReactNode;
51     onValueClick?: () => void;
52 }
53
54 type DetailsAttributeProps = DetailsAttributeDataProps & WithStyles<CssRules>;
55
56 export const DetailsAttribute = withStyles(styles)(
57     ({ label, link, value, children, classes, classLabel, classValue, lowercaseValue, onValueClick }: DetailsAttributeProps) =>
58         <Typography component="div" className={classes.attribute}>
59             <Typography component="span" className={classnames([classes.label, classLabel])}>{label}</Typography>
60             { link
61                 ? <a href={link} className={classes.link} target='_blank'>{value}</a>
62                 : <Typography
63                     onClick={onValueClick}
64                     component="span"
65                     className={classnames([classes.value, classValue, { [classes.lowercaseValue]: lowercaseValue }])}
66                 >
67                     {value}
68                     {children}
69                 </Typography> }
70         </Typography>
71 );