Skip to content

Commit b9930eb

Browse files
authored
Merge pull request #109 from agility/dlo/revert-tablericon
Reverting the change in tabler icon
2 parents ec2a277 + 2d7a1f6 commit b9930eb

3 files changed

Lines changed: 33 additions & 67 deletions

File tree

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"name": "@agility/plenum-ui",
3-
"version": "2.2.7",
3+
"version": "2.2.8",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"module": "dist/index.js",
77
"types": "dist/index.d.ts",
8-
"sideEffects": ["**/*.css"],
8+
"sideEffects": [
9+
"**/*.css"
10+
],
911
"engines": {
1012
"node": ">= 18.0.0"
1113
},

stories/atoms/icons/TablerIcon.tsx

Lines changed: 27 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,21 @@
1-
import React from "react";
1+
import React, { useState, useEffect, type ComponentType } from "react";
22
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";
323
import { ClassNameWithAutocomplete } from "@/utils/types";
334

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();
6319

6420
export interface ITablerIconProps extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> {
6521
icon: TablerIconName;
@@ -69,9 +25,18 @@ export interface ITablerIconProps extends React.DetailedHTMLProps<React.HTMLAttr
6925
const TablerIcon: React.FC<ITablerIconProps> = ({
7026
icon,
7127
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;
7540
return (
7641
<i>
7742
<Icon className={className} />

stories/organisms/DropdownWithMultiSelect/tests/DropdownWithMultiSelect.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ describe("DropdownWithMultiSelect", () => {
3939
vi.stubGlobal("ResizeObserver", ResizeObserver);
4040
});
4141

42-
it("renders a button", () => {
42+
it("renders a button", async () => {
4343
const { container } = render(<DropdownWithMultiSelect {...defaultProps} />);
4444
const button = screen.getByRole("button", { name: /Filters/i });
4545
expect(button).toBeInTheDocument();
46-
const icon = container.querySelector("svg");
47-
expect(icon).toBeInTheDocument();
46+
await waitFor(() => expect(container.querySelector("svg")).toBeInTheDocument());
4847
});
4948

5049
it("opens the popover and shows options", async () => {

0 commit comments

Comments
 (0)