@luscii-healthtech/web-ui 0.6.2 → 0.7.2

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.2",
2
+ "version": "0.7.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -17,6 +17,11 @@ export const ButtonV2 = ({
17
17
  className,
18
18
  ...otherAttributes
19
19
  }: ButtonProps): JSX.Element => {
20
+ function handleClick(event: React.MouseEvent<HTMLButtonElement>) {
21
+ event.stopPropagation();
22
+ onClick?.(event);
23
+ }
24
+
20
25
  if (!text && !icon) {
21
26
  console.error(
22
27
  "A text or an icon is required to use this component, please make sure to pass at least one of them as a prop."
@@ -54,7 +59,7 @@ export const ButtonV2 = ({
54
59
  {...otherAttributes}
55
60
  className={buttonClassName}
56
61
  type={"button"}
57
- onClick={onClick}
62
+ onClick={handleClick}
58
63
  disabled={isDisabled}
59
64
  aria-disabled={isDisabled}
60
65
  >
@@ -1,17 +1,24 @@
1
1
  import React from "react";
2
2
  import classNames from "classnames";
3
3
 
4
- import { ListItem, ListItemProps } from "./ListItem";
4
+ import { ListItem } from "./ListItem";
5
+ import {
6
+ ListProps,
7
+ ListItemProps,
8
+ OnAssetLoadErrorPayload,
9
+ } from "./List.types";
5
10
 
6
- export interface ListProps {
7
- items: ListItemProps[];
8
- }
11
+ export { ListProps, ListItemProps, OnAssetLoadErrorPayload };
9
12
 
10
- export const List = ({ items }: ListProps): JSX.Element => {
13
+ export const List = ({ items, onAssetLoadError }: ListProps): JSX.Element => {
11
14
  return (
12
- <ul className={classNames("list-none")}>
15
+ <ul className={classNames("list-none bg-white")}>
13
16
  {items.map(item => (
14
- <ListItem {...item} key={item.itemId} />
17
+ <ListItem
18
+ {...item}
19
+ key={item.itemId}
20
+ onAssetLoadError={onAssetLoadError}
21
+ />
15
22
  ))}
16
23
  </ul>
17
24
  );
@@ -0,0 +1,22 @@
1
+ import { IconProps } from "../Icons/types/IconProps.type";
2
+
3
+ export interface ListItemProps {
4
+ itemId: string | number;
5
+ title: string;
6
+ subtitle?: string;
7
+ icon?: React.FunctionComponent<IconProps> | null | string;
8
+ accessories?: JSX.Element[];
9
+ handleItemClick?: () => void;
10
+ onAssetLoadError?: (payload: OnAssetLoadErrorPayload) => void;
11
+ tooltipId?: string;
12
+ }
13
+
14
+ export type OnAssetLoadErrorPayload = Pick<
15
+ ListItemProps,
16
+ "itemId" | "subtitle" | "title" | "icon"
17
+ >;
18
+
19
+ export interface ListProps {
20
+ items: ListItemProps[];
21
+ onAssetLoadError?: (payload: OnAssetLoadErrorPayload) => void;
22
+ }
@@ -1,45 +1,71 @@
1
1
  import React from "react";
2
2
  import classNames from "classnames";
3
3
 
4
- import { IconProps } from "../Icons/types/IconProps.type";
5
4
  import Text from "../Text/Text";
6
5
 
7
- export interface ListItemProps {
8
- itemId: string | number;
9
- title: string;
10
- subTitle?: string;
11
- icon?: React.FunctionComponent<IconProps> | null;
12
- accessories?: JSX.Element[];
13
- handleItemClick?: () => void;
14
- tooltipId?: string;
15
- }
6
+ import { ListItemProps } from "./List.types";
16
7
 
17
8
  export const ListItem = ({
18
9
  icon,
19
- subTitle,
10
+ subtitle,
20
11
  title,
21
12
  accessories,
22
13
  tooltipId,
14
+ onAssetLoadError,
23
15
  ...restProps
24
- }: ListItemProps): JSX.Element => (
25
- <li
26
- className={classNames(
27
- "flex flex-row items-center space-x-4",
28
- "p-4 border-b last:border-b-0 border-slate-200",
29
- { "cursor-pointer": restProps.handleItemClick }
30
- )}
31
- onClick={restProps.handleItemClick}
32
- data-tip={restProps.itemId}
33
- data-for={tooltipId}
34
- >
35
- {icon && React.createElement(icon, { className: "w-6 h-6" })}
36
- <div className={classNames({ "pl-10": icon === null })}>
37
- <Text text={title} />
38
- {subTitle && <Text text={subTitle} type={"sm"} />}
39
- </div>
40
- <div className={"flex-grow"} />
41
- {accessories}
42
- </li>
43
- );
16
+ }: ListItemProps): JSX.Element => {
17
+ function onListItemIconLoadError() {
18
+ console.error({
19
+ message:
20
+ "Url from icon failed to load, please check the props passed to `ListItem`.",
21
+ icon,
22
+ title,
23
+ subtitle,
24
+ });
25
+
26
+ onAssetLoadError?.({
27
+ title,
28
+ subtitle: subtitle,
29
+ itemId: restProps.itemId,
30
+ icon,
31
+ });
32
+ }
33
+ return (
34
+ <li
35
+ className={classNames(
36
+ "flex flex-row items-center space-x-4 bg-white",
37
+ "p-4 border-b last:border-b-0 border-slate-200",
38
+ {
39
+ "cursor-pointer": restProps.handleItemClick,
40
+ "hover:bg-blue-50 transition-colors ease-in-out duration-300":
41
+ restProps.handleItemClick,
42
+ }
43
+ )}
44
+ onClick={restProps.handleItemClick}
45
+ data-tip={restProps.itemId}
46
+ data-for={tooltipId}
47
+ >
48
+ {/* If the icon is a react component, render it as so */}
49
+ {icon &&
50
+ typeof icon === "function" &&
51
+ React.createElement(icon, { className: "w-6 h-6" })}
52
+ {/* If the icon is a string url, load it in a vanilla img element */}
53
+ {icon && typeof icon === "string" && (
54
+ <img
55
+ src={icon}
56
+ alt="list-item-icon"
57
+ className="w-6 h-6 text-sm"
58
+ onError={onListItemIconLoadError}
59
+ />
60
+ )}
61
+ <div className={classNames({ "pl-10": icon === null })}>
62
+ <Text text={title} />
63
+ {subtitle && <Text text={subtitle} type={"sm"} />}
64
+ </div>
65
+ <div className={"flex-grow"} />
66
+ {accessories}
67
+ </li>
68
+ );
69
+ };
44
70
 
45
71
  export default ListItem;
@@ -14,6 +14,7 @@ export type TableFieldContent<Item> =
14
14
 
15
15
  export interface TableFieldText {
16
16
  text: string;
17
+ breakAllWord?: boolean;
17
18
  tag?: {
18
19
  text: string;
19
20
  color: TagColorTheme;
@@ -34,7 +34,10 @@ export function TableBodyRowDataCell<Item>(
34
34
  </div>
35
35
  )}
36
36
  <Text
37
- className="py-4 text-left leading-5 break-all"
37
+ className={classNames("py-4 text-left leading-5", {
38
+ "break-all": content.breakAllWord,
39
+ "break-words": !content.breakAllWord,
40
+ })}
38
41
  text={content.text === "" ? emptyFieldContentText : content.text}
39
42
  type="base"
40
43
  />
@@ -60,8 +63,7 @@ export function TableBodyRowDataCell<Item>(
60
63
  className="ml-2 first:ml-0"
61
64
  key={action.key}
62
65
  icon={action.icon}
63
- onClick={event => {
64
- event.stopPropagation();
66
+ onClick={() => {
65
67
  action.handleClick(props.item);
66
68
  }}
67
69
  />
package/src/index.tsx CHANGED
@@ -35,7 +35,12 @@ export {
35
35
  LoadingIndicatorProps,
36
36
  } from "./components/LoadingIndicator/LoadingIndicator";
37
37
  export { default as Menu } from "./components/Menu/Menu";
38
- export { List } from "./components/List/List";
38
+ export {
39
+ List,
40
+ ListProps,
41
+ ListItemProps,
42
+ OnAssetLoadErrorPayload,
43
+ } from "./components/List/List";
39
44
  export { MultiSelect } from "./components/MultiSelect/MultiSelect";
40
45
  export { NavLayout, NavMenuLayoutProps } from "./components/NavMenu/NavLayout";
41
46
  export { NavMenu, NavMenuElement } from "./components/NavMenu/NavMenu";