@luscii-healthtech/web-ui 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,17 +5,36 @@ import { RestPropped } from "../../types/general.types";
5
5
 
6
6
  import "./Text.scss";
7
7
 
8
- export type TextStyle = "sm" | "sm-strong" | "base" | "strong" | "lg" | "lg-strong" | "xl" | "xl-strong" | string;
8
+ export type TextStyle =
9
+ | "sm"
10
+ | "sm-strong"
11
+ | "base"
12
+ | "strong"
13
+ | "lg"
14
+ | "lg-strong"
15
+ | "xl"
16
+ | "xl-strong";
9
17
 
10
18
  //Extend with other colors that we want to enable for text
11
- export type TextColor = "base" | "gray-500" | "gray-200" | "white" | "blue" | "red" | "green" | "amber" | "inherit";
19
+ export type TextColor =
20
+ | "base"
21
+ | "slate-500"
22
+ | "slate-200"
23
+ | "white"
24
+ | "blue-800"
25
+ | "red"
26
+ | "green"
27
+ | "amber";
28
+
29
+ export type TextHoverColor = "blue-900" | "white";
12
30
 
13
31
  export interface TextProps extends RestPropped {
14
32
  text: string;
15
33
  type?: TextStyle; //defaults to "base"
16
34
  inline?: boolean; //defaults to false
17
35
  color?: TextColor; //defaults to "base"
18
- hoverColor?: TextColor; //defaults to "base"
36
+ hoverColor?: TextHoverColor; //defaults to "base"
37
+ hoverInGroup?: boolean;
19
38
  className?: string;
20
39
  containsDangerousHtml?: boolean; //defaults to false
21
40
  truncate?: boolean; //defaults to false
@@ -23,43 +42,74 @@ export interface TextProps extends RestPropped {
23
42
  }
24
43
 
25
44
  export const Text = (props: TextProps): JSX.Element => {
45
+ /**
46
+ * One might argue that we're duplicating strings in this file.
47
+ * That's how tailwind expects to detect used classes, so please do not make
48
+ * anything dynamic or try to string concat class names.
49
+ * https://v1.tailwindcss.com/docs/controlling-file-size
50
+ */
51
+
52
+ const allowedColors: Record<TextColor, string> = {
53
+ base: "text-slate-700",
54
+ "slate-500": "text-slate-500",
55
+ "slate-200": "text-slate-200",
56
+ red: "text-red-700",
57
+ green: "text-green-700",
58
+ amber: "text-yellow-700",
59
+ white: "text-white",
60
+ "blue-800": "text-blue-800",
61
+ };
62
+
63
+ const allowedHoverColors: Record<TextHoverColor, string> = {
64
+ "blue-900": "hover:text-blue-900",
65
+ white: "hover:text-white",
66
+ };
67
+
68
+ // What is a group hover? https://v1.tailwindcss.com/docs/pseudo-class-variants#group-hover
69
+ const allowedGroupHoverColors: Record<TextHoverColor, string> = {
70
+ "blue-900": "group-hover:text-blue-900",
71
+ white: "group-hover:text-white",
72
+ };
73
+
74
+ const selectedHoverColor =
75
+ props.hoverColor &&
76
+ !props.hoverInGroup &&
77
+ allowedHoverColors[props.hoverColor];
78
+
79
+ const selectedGroupHoverColor =
80
+ props.hoverColor &&
81
+ props.hoverInGroup &&
82
+ allowedGroupHoverColors[props.hoverColor];
83
+
26
84
  const containerProps = {
27
85
  "data-test-id": props["data-test-id"],
28
86
  className: classNames(
29
- // apply different style classes
30
- // for now we stick with font-size 16px on the body
31
- // so I am adjusting our styles accordingly (one step down)
32
- {
33
- "text-xs font-medium": props.type === "sm",
34
- "text-xs font-semibold": props.type === "sm-strong",
35
- "text-sm": props.type === "base",
36
- "text-sm font-semibold": props.type === "strong",
37
- "": props.type === "lg",
38
- "font-semibold": props.type === "lg-strong",
39
- "text-lg": props.type === "xl",
40
- "font-semibold text-lg": props.type === "xl-strong",
41
- },
42
- {
43
- inline: props.inline,
44
- // FIXME: this class doesn't do anything without a max-width
45
- truncate: props.truncate,
46
- },
47
- {
48
- "text-slate-700": props.color === "base",
49
- "text-slate-500": props.color === "gray-500",
50
- "text-slate-200": props.color === "gray-200",
51
- "text-red-700": props.color === "red",
52
- "text-green-700": props.color === "green",
53
- "text-yellow-700": props.color === "amber",
54
- "text-blue-700": props.color === "blue",
55
- "text-white": props.color === "white",
56
- "text-primary-dark": props.color === "blue",
57
- },
58
- {
59
- "in-html-link": props.containsDangerousHtml,
60
- },
61
- //can be used to overwrite other classes like the color
62
- props.className
87
+ // apply different style classes
88
+ // for now we stick with font-size 16px on the body
89
+ // so I am adjusting our styles accordingly (one step down)
90
+ {
91
+ "text-xs font-medium": props.type === "sm",
92
+ "text-xs font-semibold": props.type === "sm-strong",
93
+ "text-sm": props.type === "base",
94
+ "text-sm font-semibold": props.type === "strong",
95
+ "": props.type === "lg",
96
+ "font-semibold": props.type === "lg-strong",
97
+ "text-lg": props.type === "xl",
98
+ "font-semibold text-lg": props.type === "xl-strong",
99
+ },
100
+ {
101
+ inline: props.inline,
102
+ // FIXME: this class doesn't do anything without a max-width
103
+ truncate: props.truncate,
104
+ },
105
+ allowedColors[props.color || "base"],
106
+ selectedHoverColor,
107
+ selectedGroupHoverColor,
108
+ {
109
+ "in-html-link": props.containsDangerousHtml,
110
+ },
111
+ //can be used to overwrite other classes like the color
112
+ props.className
63
113
  ),
64
114
  };
65
115
 
@@ -6,7 +6,8 @@ import Button from "../Button/Button";
6
6
  import { RestPropped } from "../../types/general.types";
7
7
  import { ButtonProps } from "../Button/Button.types";
8
8
 
9
- export interface ViewItemProps<AccessoryType extends JSX.Element> extends RestPropped {
9
+ export interface ViewItemProps<AccessoryType extends JSX.Element>
10
+ extends RestPropped {
10
11
  titleProps?: TextProps;
11
12
  // deprecated: use titleProps instead
12
13
  title?: string;
@@ -22,7 +23,7 @@ export interface ViewItemProps<AccessoryType extends JSX.Element> extends RestPr
22
23
  buttons?: ButtonProps[];
23
24
  }
24
25
 
25
- export function ViewItem<AccessoryType extends JSX.Element> ({
26
+ export function ViewItem<AccessoryType extends JSX.Element>({
26
27
  titleProps,
27
28
  title,
28
29
  titleAccessory,
@@ -36,29 +37,40 @@ export function ViewItem<AccessoryType extends JSX.Element> ({
36
37
  const titlePropsMerged = titleProps ?? { text: title ?? defaultContent };
37
38
  const contentPropsMerged =
38
39
  contentProps ??
39
- content?.map((line) => {
40
+ content?.map(line => {
40
41
  return { text: line, className: "cweb-view-content-text" } as TextProps;
41
42
  });
42
43
 
43
44
  return (
44
45
  <div className={classNames("vitals-view-item", className)} {...restProps}>
45
- <div className={"vitals-view-item-title-line flex justify-start flex-row items-start"}>
46
+ <div
47
+ className={
48
+ "vitals-view-item-title-line flex justify-start flex-row items-start"
49
+ }
50
+ >
46
51
  {titlePropsMerged && (
47
52
  <Text
48
- className={classNames(titlePropsMerged.className, "vitals-view-item-title mb-1 mr-2")}
49
- color="gray-500"
53
+ className={classNames(
54
+ titlePropsMerged.className,
55
+ "vitals-view-item-title mb-1 mr-2"
56
+ )}
57
+ color="slate-500"
50
58
  {...titlePropsMerged}
51
59
  />
52
60
  )}
53
61
  {titleAccessory}
54
62
  </div>
55
63
  {contentPropsMerged &&
56
- contentPropsMerged?.map((textProps) => <Text {...textProps} key={textProps.key || textProps.text} />)}
57
- {(!contentPropsMerged || contentPropsMerged?.length === 0) && <Text text={defaultContent} key="empty-text" />}
64
+ contentPropsMerged?.map(textProps => (
65
+ <Text {...textProps} key={textProps.key || textProps.text} />
66
+ ))}
67
+ {(!contentPropsMerged || contentPropsMerged?.length === 0) && (
68
+ <Text text={defaultContent} key="empty-text" />
69
+ )}
58
70
 
59
71
  <div className="flex flex-row cweb-view-buttons" key="cweb-view-buttons">
60
72
  {buttons &&
61
- buttons.map((button) => (
73
+ buttons.map(button => (
62
74
  <Button
63
75
  {...button}
64
76
  className={classNames("cweb-view-button ml-3", button.className)}