diff options
author | Tim Becker <tim.becker@mni.thm.de> | 2021-03-24 23:26:14 +0100 |
---|---|---|
committer | Sascha <GlancingMind@outlook.com> | 2021-04-08 14:56:59 +0200 |
commit | d39e6c4c4391c1a3cd96f791b47d66b043da7f51 (patch) | |
tree | c4a45588aa95d4ac76350c5b718ee2dca85ce5e8 /webui/src/components/Label.tsx | |
parent | abbed0ff129755386ccbf89409ff8c3877f86d20 (diff) | |
download | git-bug-d39e6c4c4391c1a3cd96f791b47d66b043da7f51.tar.gz |
Add label menu to bug detail page
Also support label color in label filter menu on bug list page
Diffstat (limited to 'webui/src/components/Label.tsx')
-rw-r--r-- | webui/src/components/Label.tsx | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/webui/src/components/Label.tsx b/webui/src/components/Label.tsx index 111f6d7f..13c913c9 100644 --- a/webui/src/components/Label.tsx +++ b/webui/src/components/Label.tsx @@ -1,56 +1,43 @@ import React from 'react'; +import { Chip } from '@material-ui/core'; import { common } from '@material-ui/core/colors'; -import { makeStyles } from '@material-ui/core/styles'; import { - getContrastRatio, darken, + getContrastRatio, } from '@material-ui/core/styles/colorManipulator'; -import { LabelFragment } from '../graphql/fragments.generated'; -import { Color } from 'src/gqlTypes'; +import { Color } from '../gqlTypes'; + +import { LabelFragment } from './fragments.generated'; + +const _rgb = (color: Color) => + 'rgb(' + color.R + ',' + color.G + ',' + color.B + ')'; // Minimum contrast between the background and the text color const contrastThreshold = 2.5; - // Guess the text color based on the background color const getTextColor = (background: string) => getContrastRatio(background, common.white) >= contrastThreshold ? common.white // White on dark backgrounds : common.black; // And black on light ones -const _rgb = (color: Color) => - 'rgb(' + color.R + ',' + color.G + ',' + color.B + ')'; - // Create a style object from the label RGB colors const createStyle = (color: Color) => ({ backgroundColor: _rgb(color), color: getTextColor(_rgb(color)), borderBottomColor: darken(_rgb(color), 0.2), + margin: '3px', }); -const useStyles = makeStyles((theme) => ({ - label: { - ...theme.typography.body1, - padding: '1px 6px 0.5px', - fontSize: '0.9em', - fontWeight: 500, - margin: '0.05em 1px calc(-1.5px + 0.05em)', - borderRadius: '3px', - display: 'inline-block', - borderBottom: 'solid 1.5px', - verticalAlign: 'bottom', - }, -})); - type Props = { label: LabelFragment }; function Label({ label }: Props) { - const classes = useStyles(); return ( - <span className={classes.label} style={createStyle(label.color)}> - {label.name} - </span> + <Chip + size={'small'} + label={label.name} + style={createStyle(label.color)} + ></Chip> ); } - export default Label; |