From 022f510369688084af5bcf314a97fd332d7ee265 Mon Sep 17 00:00:00 2001
From: Quentin Gliech <quentingliech@gmail.com>
Date: Tue, 4 Feb 2020 22:03:21 +0100
Subject: webui: convert more things to typescript

---
 webui/src/Label.tsx | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 webui/src/Label.tsx

(limited to 'webui/src/Label.tsx')

diff --git a/webui/src/Label.tsx b/webui/src/Label.tsx
new file mode 100644
index 00000000..e200f929
--- /dev/null
+++ b/webui/src/Label.tsx
@@ -0,0 +1,54 @@
+import React from 'react';
+import { makeStyles } from '@material-ui/core/styles';
+import {
+  getContrastRatio,
+  darken,
+} from '@material-ui/core/styles/colorManipulator';
+import { common } from '@material-ui/core/colors';
+
+import { Color } from './gqlTypes';
+import { LabelFragment } from './Label.generated';
+
+// 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),
+});
+
+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>
+  );
+}
+
+export default Label;
-- 
cgit 


From e5f52401b2a839881fedef5a446f0ed21d2d34c2 Mon Sep 17 00:00:00 2001
From: Quentin Gliech <quentingliech@gmail.com>
Date: Tue, 11 Feb 2020 20:16:56 +0100
Subject: webui: typecheck remaining bug list components

---
 webui/src/Label.tsx | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'webui/src/Label.tsx')

diff --git a/webui/src/Label.tsx b/webui/src/Label.tsx
index e200f929..68c50b9d 100644
--- a/webui/src/Label.tsx
+++ b/webui/src/Label.tsx
@@ -18,7 +18,8 @@ const getTextColor = (background: string) =>
     ? common.white // White on dark backgrounds
     : common.black; // And black on light ones
 
-const _rgb = (color: Color) => 'rgb(' + color.R + ',' + color.G + ',' + color.B + ')';
+const _rgb = (color: Color) =>
+  'rgb(' + color.R + ',' + color.G + ',' + color.B + ')';
 
 // Create a style object from the label RGB colors
 const createStyle = (color: Color) => ({
-- 
cgit 


From 9ddcb4b09215f942cb7889f9756d426ad3c90253 Mon Sep 17 00:00:00 2001
From: Quentin Gliech <quentingliech@gmail.com>
Date: Tue, 11 Feb 2020 20:54:01 +0100
Subject: webui: force import order

---
 webui/src/Label.tsx | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'webui/src/Label.tsx')

diff --git a/webui/src/Label.tsx b/webui/src/Label.tsx
index 68c50b9d..a33b4c2c 100644
--- a/webui/src/Label.tsx
+++ b/webui/src/Label.tsx
@@ -1,13 +1,13 @@
-import React from 'react';
+import { common } from '@material-ui/core/colors';
 import { makeStyles } from '@material-ui/core/styles';
 import {
   getContrastRatio,
   darken,
 } from '@material-ui/core/styles/colorManipulator';
-import { common } from '@material-ui/core/colors';
+import React from 'react';
 
-import { Color } from './gqlTypes';
 import { LabelFragment } from './Label.generated';
+import { Color } from './gqlTypes';
 
 // Minimum contrast between the background and the text color
 const contrastThreshold = 2.5;
-- 
cgit 

