@luscii-healthtech/web-ui 7.6.2 → 8.0.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # web-ui
1
+ # WebUI
2
2
 
3
- The web-ui repository contains the UI components for Luscii's front-end projects. It is published to NPM for usage into our projects. It uses Storybook and is published to Chromatic for easy review of visual changes.
3
+ The `web-ui` repository contains the UI components for Luscii's frontend projects. It is published to NPM for usage into our projects. It uses Storybook and is published to Chromatic for easy review and tracking of visual changes.
4
4
 
5
5
  ## Running locally
6
6
 
@@ -31,17 +31,84 @@ Or use the shortcut:
31
31
  yarn test-copy-build
32
32
  ```
33
33
 
34
- When you run cVitals again, it should contain your latest updates in the component library. Use this to make sure your changes are solid before opening a pull request.
34
+ When you run `cVitals-Web` again, it should contain your latest updates in the component library. Use this to make sure your changes are solid before opening a pull request.
35
35
 
36
36
  ## Contributing
37
37
 
38
- Make sure you understand our design system and follow its guidelines. They are documented in Storybook. We highly value consistency, simplicity and usability. Don't mess it up.
38
+ Thank you for your help in keeping our component library organized and easy to use!
39
39
 
40
- If you want to add components, do so in the `/src/components` directory.
40
+ When adding components, please make sure to implement them consistently in our projects and that it is clear where and when they should be used. We want to avoid having many similar components. If you want to add components, do so in the `/src/components` directory. When you create new components, add them to Storybook as well. Stories go in the `/stories` directory.
41
41
 
42
- Please stay vigilant when adding components that we implement them consistently in our projects and that it is clear where and when they have to be used. We want to avoid a lot of components that are similar.
42
+ If you add new components, please make sure they fit in with our existing ones and that it's clear where and when they should be used. We want to avoid having too many similar components.
43
43
 
44
- When you create new components, you must add them to Storybook as well. Stories go in the `/stories` directory.
44
+ ### Documentation
45
+
46
+ Every component should have proper documentation that explains when, where and how to use it. This sounds like a lot of work, but it doesn't have to be. And it's important, also for you, to quickly see how to best use a component.
47
+
48
+ Component documentation should include the following parts:
49
+
50
+ - A short explanation of each prop in a JSDoc comment style.
51
+ - A stories file (`<ComponentName>.stories.tsx`).
52
+ - A docs file (`<ComponentName>.docs.mdx`).
53
+
54
+ Below is an explanation of each.
55
+
56
+ #### Props documented via JSDoc comments
57
+
58
+ A short explanation of each prop in a JSDoc comment style. These will show up in your IDE for on the fly documentation when you need it. It will also show up in Storybook, so this is a double-whammy and provides documentation exactly where you need it.
59
+
60
+ ```ts
61
+ type Props = {
62
+ /**
63
+ * Optional description that will be shown close to the label, used to provide more
64
+ * detail about the field next to the concise text of the label.
65
+ */
66
+ helperText?: string;
67
+ };
68
+ ```
69
+
70
+ #### Stories file
71
+
72
+ Stories files (`*stories.tsx`) will show up in Storybook as separate entries/pages for each component. Each component can have multiple stories defined for it, showing different use cases, variants and states of that component.
73
+ It is important to include stories for a lot of these different variants and states, because visual snapshots will be created of these stories by a tool called Chromatic. This allows us to visually track changes to the component over time, and ensure that it looks and behaves correctly across different use cases. By writing stories that showcase all the different ways your component can be used, you can catch issues early and ensure that your component is robust and reliable.
74
+
75
+ You can find the Chromatic project for WebUI [here](https://www.chromatic.com/library?appId=62b0c4d5afd432f7ee70a740).
76
+
77
+ #### Docs file
78
+
79
+ The component docs file brings everything together and should be considered the source of truth about the component. What should be documented:
80
+
81
+ - Why we have the component and where it should be used.
82
+ - An overview of the different variants and states.
83
+ - Usage guidelines of when and where to use the component.
84
+ - Best practices to show what to do and what not do when working with the component.
85
+
86
+ > 🔎 If you need to e.g. create a story to show how NOT to use a component, you might not want
87
+ > to create a snapshot for that component or show it in the sidebar of Storybook. To omit a story
88
+ > from snapshots, add the following to its parameters:
89
+ >
90
+ > ```ts
91
+ > chromatic: { disableSnapshot: true },
92
+ > ```
93
+ >
94
+ > To hide a story from the sidebar, prefix the story (variable) name
95
+ > with `HIDE_`.
96
+
97
+ Please see examples of other components' docs files for inspiration and try to stay consistent with how they are documented.
98
+
99
+ ### Accessibility
100
+
101
+ WebUI is not currently designed to support screen reader usage. This is because our application is designed specifically for healthcare providers and is not publicly accessible. Our primary users are caregivers who work in healthcare and do not rely on screen readers to be able to use our application.
102
+ However, it is important for developers to write accessible frontend code. Even if our current application is not designed to support screen reader usage. This means following best practices for web accessibility, such as using semantic HTML, providing alternative text for images, and ensuring keyboard navigation is possible. While our primary users may not rely on screen readers, it is important to make our application as inclusive as possible to all users.
103
+
104
+ ### Testing
105
+
106
+ WebUI relies on two types of testing: Visual snapshot testing via Chromatic and interaction testing via Storybook.
107
+
108
+ Visual snapshot testing is handled for you. Any story you write will be picked up by Chromatic and it will create a snapshot for it.
109
+
110
+ Interaction testing via Storybook allows to programmatically interact with the component. This is very helpful in testing any logic that the component may use internally and any states of the component that might be hard/impossible to trigger from the outside.
111
+ More information on how to approach writing interaction tests can be found in [this page of the Storybook documentation](https://storybook.js.org/docs/react/writing-tests/interaction-testing#write-an-interaction-test).
45
112
 
46
113
  ### Adding icons
47
114
 
@@ -79,27 +146,9 @@ We have configured at lot of magic for your convenience.
79
146
 
80
147
  ### On merge to main
81
148
 
82
- 1. Draft a GitHub release.
83
- 2. Version bump of the package.
84
- 3. Publish new package to NPM.
85
-
86
- ---
87
-
88
- ## IE11
89
-
90
- This package includes [dnd-kit](https://dndkit.com) as a peer dependency. The bundle of dnd-kit contains syntax which isn't compatible with IE11, therefore any application needing to support IE11 has to transpile dnd-kit.
91
-
92
- It should also at least include the following polyfills to make it work:
93
-
94
- - [core-js](https://www.npmjs.com/package/core-js)
95
- - [regenerator-runtime](https://www.npmjs.com/package/regenerator-runtime)
96
- - [smoothscroll-polyfill](https://www.npmjs.com/package/smoothscroll-polyfill)
97
-
98
- Optional:
99
-
100
- - [web-animations-js](https://www.npmjs.com/package/web-animations-js)
101
-
102
- This isn't necessary if the [drop animation is disabled](https://github.com/clauderic/dnd-kit/issues/705#issuecomment-1103056336). Check out [this ticket](https://github.com/clauderic/dnd-kit/issues/271) for more information on IE11.
149
+ 1. Drafts a GitHub release.
150
+ 2. Bumps the version of the package.
151
+ 3. Publishes the new package version to NPM.
103
152
 
104
153
  ## Stories
105
154
 
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  import { RestPropped } from "../../types/general.types";
3
3
  import "./Text.css";
4
4
  /**
@@ -8,14 +8,14 @@ import "./Text.css";
8
8
  * https://v1.tailwindcss.com/docs/controlling-file-size
9
9
  */
10
10
  declare const allowedTextStyles: {
11
- sm: string;
12
- "sm-strong": string;
13
- base: string;
14
- strong: string;
15
- lg: string;
16
- "lg-strong": string;
17
- xl: string;
18
- "xl-strong": string;
11
+ readonly sm: "ui-text-xs ui-font-medium";
12
+ readonly "sm-strong": "ui-text-xs ui-font-semibold";
13
+ readonly base: "ui-text-sm";
14
+ readonly strong: "ui-text-sm ui-font-semibold";
15
+ readonly lg: "";
16
+ readonly "lg-strong": "ui-font-semibold";
17
+ readonly xl: "ui-text-lg";
18
+ readonly "xl-strong": "ui-font-semibold ui-text-lg";
19
19
  };
20
20
  export declare const allowedColors: {
21
21
  readonly base: "ui-text-slate-800";
@@ -35,20 +35,72 @@ declare const allowedHoverColors: {
35
35
  export type TextColor = keyof typeof allowedColors;
36
36
  export type TextHoverColor = keyof typeof allowedHoverColors;
37
37
  export type TextStyle = keyof typeof allowedTextStyles;
38
- export interface TextProps extends RestPropped {
39
- text: string;
38
+ export interface TextProps extends RestPropped, React.ComponentPropsWithoutRef<"p"> {
39
+ /**
40
+ * @deprecated
41
+ * Use `children` instead, as you would with a regular `<p>` tag.
42
+ */
43
+ text?: string;
44
+ /**
45
+ * @deprecated
46
+ * Use `variant` instead. "type" is a word that is too ambiguous and
47
+ * is also often used as an attribute name in HTML.
48
+ *
49
+ * @default "base"
50
+ */
40
51
  type?: TextStyle;
52
+ /**
53
+ * The styling variant of the text.
54
+ *
55
+ * @default "base"
56
+ */
57
+ variant?: TextStyle;
58
+ /**
59
+ * Changes the component to be rendered inline. This is useful for
60
+ * using this component inside of itself, for example, when you want
61
+ * to render bold text inside of a paragraph rendered by this same component.
62
+ *
63
+ * @default false
64
+ */
41
65
  inline?: boolean;
66
+ /**
67
+ * @default "base"
68
+ */
42
69
  color?: TextColor;
70
+ /**
71
+ * @default "base"
72
+ */
43
73
  hoverColor?: TextHoverColor;
74
+ /**
75
+ * Tailwind class modifier that allows you to apply hover styles on this component
76
+ * based on the styles of its parent.
77
+ * https://tailwindcss.com/docs/hover-focus-and-other-states#styling-based-on-parent-state
78
+ *
79
+ * @deprecated
80
+ * Since this is a Tailwind specific feature we should not expose this to the consumer. We
81
+ * should only use group-hover styles in the components in WebUI instead.
82
+ */
44
83
  hoverInGroup?: boolean;
45
84
  className?: string;
85
+ /**
86
+ * Interpret an HTML string as regular markup, instead of rendering it as a string.
87
+ *
88
+ * @default false
89
+ */
46
90
  containsDangerousHtml?: boolean;
91
+ /**
92
+ * With this prop enabled, text won't wrap to the next line but instead
93
+ * will be truncated with an ellipsis.
94
+ *
95
+ * @default false
96
+ */
47
97
  truncate?: boolean;
48
98
  /**
49
- * When `true` will work together with the `truncate` props
99
+ * When `true` will work together with the `truncate` prop
50
100
  * and allow a max of two lines when breaking text before applying
51
- * elipsis. Defaults to "`false`"
101
+ * ellipsis.
102
+ *
103
+ * @default false
52
104
  */
53
105
  clampLines?: boolean;
54
106
  "data-test-id"?: string;
@@ -56,11 +108,8 @@ export interface TextProps extends RestPropped {
56
108
  export declare const Text: {
57
109
  (props: TextProps): JSX.Element;
58
110
  defaultProps: {
59
- type: string;
60
- inline: boolean;
61
- color: string;
62
- containsDangerousHtml: boolean;
63
- truncate: boolean;
111
+ variant: "base";
112
+ color: "base";
64
113
  };
65
114
  };
66
115
  export default Text;
@@ -212,7 +212,10 @@ const allowedGroupHoverColors = {
212
212
  white: "ui-group-hover:ui-text-white"
213
213
  };
214
214
  const Text = (props) => {
215
- var _a, _b;
215
+ var _a, _b, _c;
216
+ const { children } = props, rest = __rest(props, ["children"]);
217
+ const Component = props.inline ? "span" : "p";
218
+ const resolvedVariant = (_a = props.type) !== null && _a !== void 0 ? _a : props.variant;
216
219
  const selectedHoverColor = props.hoverColor && !props.hoverInGroup && allowedHoverColors[props.hoverColor];
217
220
  const selectedGroupHoverColor = props.hoverColor && props.hoverInGroup && allowedGroupHoverColors[props.hoverColor];
218
221
  const containerProps = {
@@ -222,7 +225,7 @@ const Text = (props) => {
222
225
  // apply different style classes
223
226
  // for now we stick with ui-font-size 16px on the body
224
227
  // so I am adjusting our styles accordingly (one step down)
225
- allowedTextStyles[(_a = props.type) !== null && _a !== void 0 ? _a : "base"],
228
+ allowedTextStyles[resolvedVariant !== null && resolvedVariant !== void 0 ? resolvedVariant : "base"],
226
229
  allowedColors[(_b = props.color) !== null && _b !== void 0 ? _b : "base"],
227
230
  selectedHoverColor,
228
231
  selectedGroupHoverColor,
@@ -237,14 +240,11 @@ const Text = (props) => {
237
240
  props.className
238
241
  )
239
242
  };
240
- return props.containsDangerousHtml ? React__namespace.default.createElement("p", Object.assign({}, containerProps, { dangerouslySetInnerHTML: { __html: props.text } })) : React__namespace.default.createElement("p", Object.assign({}, containerProps), props.text);
243
+ return props.containsDangerousHtml ? React__namespace.default.createElement(Component, Object.assign({}, rest, containerProps, { dangerouslySetInnerHTML: { __html: (_c = children !== null && children !== void 0 ? children : props.text) !== null && _c !== void 0 ? _c : "" } })) : React__namespace.default.createElement(Component, Object.assign({}, rest, containerProps), children !== null && children !== void 0 ? children : props.text);
241
244
  };
242
245
  Text.defaultProps = {
243
- type: "base",
244
- inline: false,
245
- color: "base",
246
- containsDangerousHtml: false,
247
- truncate: false
246
+ variant: "base",
247
+ color: "base"
248
248
  };
249
249
 
250
250
  const IconWrapper = (SVGComponent) => (props) => React__namespace.default.createElement(SVGComponent, Object.assign({}, props, { role: props.onClick ? "button" : void 0 }));