@ncds/ui-admin-icon 0.0.12 → 0.0.14

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.
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.covertToPascalCase = void 0;
4
+ const covertToPascalCase = (str) => {
5
+ return str.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase()).replace(/^[a-z]/, (char) => char.toUpperCase());
6
+ };
7
+ exports.covertToPascalCase = covertToPascalCase;
package/dist/esm/index.js CHANGED
@@ -1,46 +1,16 @@
1
1
  import React, { useEffect, useState, useRef } from 'react';
2
- const covertToPascalCase = (str) => {
3
- return str.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase()).replace(/^[a-z]/, (char) => char.toUpperCase());
4
- };
5
- const viteLoader = (name) => {
6
- const iconName = covertToPascalCase(name);
7
- try {
8
- return import(/* @vite-ignore */ `./components/${iconName}`).then((module) => module.default);
9
- }
10
- catch {
11
- return Promise.reject(new Error(`Icon ${name} not found`));
12
- }
13
- };
14
- const webpackLoader = (name) => {
15
- // @ts-ignore
16
- const requireContext = require.context('./components', true, /\.(js|tsx)$/);
17
- const iconName = covertToPascalCase(name);
18
- try {
19
- return Promise.resolve(requireContext(`./${iconName}`).default);
20
- }
21
- catch {
22
- return Promise.reject(new Error(`Icon ${name} not found`));
23
- }
24
- };
25
- const getIconLoader = () => {
26
- // @ts-ignore
27
- if (typeof require !== 'undefined' && typeof require.context === 'function') {
28
- return webpackLoader;
29
- }
30
- return viteLoader;
31
- };
32
- const loadIcon = getIconLoader();
2
+ import { getIcon } from './map';
33
3
  const Icon = ({ name, ...props }) => {
34
4
  const iconRef = useRef(null);
35
5
  const [isLoading, setIsLoading] = useState(true);
36
6
  useEffect(() => {
37
7
  setIsLoading(true);
38
- loadIcon(name)
39
- .then((component) => {
40
- iconRef.current = component;
8
+ getIcon(name)
9
+ ?.then((module) => {
10
+ iconRef.current = module.default;
41
11
  setIsLoading(false);
42
12
  })
43
- .catch(() => {
13
+ .catch((error) => {
44
14
  setIsLoading(false);
45
15
  });
46
16
  }, [name]);