@agility/plenum-ui 2.2.7 → 2.2.8

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,11 +1,13 @@
1
1
  {
2
2
  "name": "@agility/plenum-ui",
3
- "version": "2.2.7",
3
+ "version": "2.2.8",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
- "sideEffects": ["**/*.css"],
8
+ "sideEffects": [
9
+ "**/*.css"
10
+ ],
9
11
  "engines": {
10
12
  "node": ">= 18.0.0"
11
13
  },
@@ -1,65 +1,21 @@
1
- import React from "react";
1
+ import React, { useState, useEffect, type ComponentType } from "react";
2
2
  import { TablerIconName } from "./tablerIconNames";
3
- import {
4
- IconArrowDown,
5
- IconArrowUp,
6
- IconBan,
7
- IconBell,
8
- IconBrandGithub,
9
- IconCheck,
10
- IconChevronDown,
11
- IconCode,
12
- IconConfetti,
13
- IconCopy,
14
- IconCube,
15
- IconDotsVertical,
16
- IconEye,
17
- IconEyeCheck,
18
- IconEyeOff,
19
- IconFolderPlus,
20
- IconGridDots,
21
- IconPaperclip,
22
- IconPencil,
23
- IconPlus,
24
- IconSearch,
25
- IconSelector,
26
- IconThumbUp,
27
- IconTrash,
28
- IconTrashFilled,
29
- IconUpload,
30
- IconX,
31
- } from "@tabler/icons-react";
32
3
  import { ClassNameWithAutocomplete } from "@/utils/types";
33
4
 
34
- const tablerIconMap = {
35
- IconArrowDown,
36
- IconArrowUp,
37
- IconBan,
38
- IconBell,
39
- IconBrandGithub,
40
- IconCheck,
41
- IconChevronDown,
42
- IconCode,
43
- IconConfetti,
44
- IconCopy,
45
- IconCube,
46
- IconDotsVertical,
47
- IconEye,
48
- IconEyeCheck,
49
- IconEyeOff,
50
- IconFolderPlus,
51
- IconGridDots,
52
- IconPaperclip,
53
- IconPencil,
54
- IconPlus,
55
- IconSearch,
56
- IconSelector,
57
- IconThumbUp,
58
- IconTrash,
59
- IconTrashFilled,
60
- IconUpload,
61
- IconX,
62
- } as const;
5
+ let iconRegistry: Record<string, ComponentType<any>> | null = null;
6
+ let registryPromise: Promise<void> | null = null;
7
+
8
+ function loadIconRegistry(): Promise<void> {
9
+ if (!registryPromise) {
10
+ registryPromise = import("@tabler/icons-react").then((mod) => {
11
+ iconRegistry = mod as unknown as Record<string, ComponentType<any>>;
12
+ });
13
+ }
14
+ return registryPromise;
15
+ }
16
+
17
+ // Kick off load eagerly on module import
18
+ loadIconRegistry();
63
19
 
64
20
  export interface ITablerIconProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> {
65
21
  icon: TablerIconName;
@@ -69,9 +25,18 @@ export interface ITablerIconProps extends React.DetailedHTMLProps<React.HTMLAttr
69
25
  const TablerIcon: React.FC<ITablerIconProps> = ({
70
26
  icon,
71
27
  className = "w-6 h-6 text-gray-600"
72
- }: ITablerIconProps): JSX.Element => {
73
- const Icon = tablerIconMap[icon as keyof typeof tablerIconMap];
74
- if (!Icon) return <></>;
28
+ }: ITablerIconProps): JSX.Element | null => {
29
+ const [Icon, setIcon] = useState<ComponentType<any> | null>(
30
+ iconRegistry && icon ? (iconRegistry[icon] ?? null) : null
31
+ );
32
+
33
+ useEffect(() => {
34
+ if (!icon) { setIcon(null); return; }
35
+ if (iconRegistry) { setIcon(iconRegistry[icon] ?? null); return; }
36
+ loadIconRegistry().then(() => setIcon(iconRegistry![icon] ?? null));
37
+ }, [icon]);
38
+
39
+ if (!Icon) return null;
75
40
  return (
76
41
  <i>
77
42
  <Icon className={className} />
@@ -39,12 +39,11 @@ describe("DropdownWithMultiSelect", () => {
39
39
  vi.stubGlobal("ResizeObserver", ResizeObserver);
40
40
  });
41
41
 
42
- it("renders a button", () => {
42
+ it("renders a button", async () => {
43
43
  const { container } = render(<DropdownWithMultiSelect {...defaultProps} />);
44
44
  const button = screen.getByRole("button", { name: /Filters/i });
45
45
  expect(button).toBeInTheDocument();
46
- const icon = container.querySelector("svg");
47
- expect(icon).toBeInTheDocument();
46
+ await waitFor(() => expect(container.querySelector("svg")).toBeInTheDocument());
48
47
  });
49
48
 
50
49
  it("opens the popover and shows options", async () => {