@luscii-healthtech/web-ui 7.6.3 → 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
@@ -83,6 +83,17 @@ The component docs file brings everything together and should be considered the
83
83
  - Usage guidelines of when and where to use the component.
84
84
  - Best practices to show what to do and what not do when working with the component.
85
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
+
86
97
  Please see examples of other components' docs files for inspiration and try to stay consistent with how they are documented.
87
98
 
88
99
  ### Accessibility
@@ -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 }));