import * as React from 'react';
import Typography from '@material-ui/core/Typography';
import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
-import { ArvadosTheme } from 'src/common/custom-theme';
+import { ArvadosTheme } from '../../common/custom-theme';
interface AttributeDataProps {
label: string;
+ value?: string | number;
+ link?: string;
}
type AttributeProps = AttributeDataProps & WithStyles<CssRules>;
class Attribute extends React.Component<AttributeProps> {
+ hasLink() {
+ return !!this.props.link;
+ }
+
render() {
- const { label, children, classes } = this.props;
+ const { label, link, value, children, classes } = this.props;
return <Typography component="div" className={classes.attribute}>
- <span className={classes.label}>{label}</span>
- <span className={classes.value}>{children}</span>
- </Typography>;
+ <Typography component="span" className={classes.label}>{label}</Typography>
+ { this.hasLink() ? (
+ <a href='{link}' className={classes.link} target='_blank'>{value}</a>
+ ) : (
+ <Typography component="span" className={classes.value}>
+ {value}
+ {children}
+ </Typography>
+ )}
+ </Typography>;
}
}
-type CssRules = 'attribute' | 'label' | 'value';
+type CssRules = 'attribute' | 'label' | 'value' | 'link';
const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
attribute: {
display: 'flex',
- alignItems: 'center',
+ alignItems: 'flex-start',
marginBottom: theme.spacing.unit
},
label: {
width: '40%'
},
value: {
+ width: '60%',
display: 'flex',
- alignItems: 'center'
+ alignItems: 'flex-start',
+ textTransform: 'capitalize'
+ },
+ link: {
+ width: '60%',
+ color: theme.palette.primary.main,
+ textDecoration: 'none',
+ overflowWrap: 'break-word'
}
});