@ncds/ui-admin-icon 0.0.11 → 0.0.13

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,23 +1,25 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- const covertToPascalCase = (str) => {
3
- return str.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase()).replace(/^[a-z]/, (char) => char.toUpperCase());
4
- };
1
+ import React, { useEffect, useState, useRef } from 'react';
2
+ import { getIcon } from './map';
5
3
  const Icon = ({ name, ...props }) => {
6
4
  const iconRef = useRef(null);
7
- const [isLoaded, setIsLoaded] = useState(false);
5
+ const [isLoading, setIsLoading] = useState(true);
8
6
  useEffect(() => {
9
- const importIcon = async () => {
10
- setIsLoaded(false);
11
- const { default: IconComponent } = await import(`./components/${covertToPascalCase(name)}`);
12
- iconRef.current = IconComponent;
13
- setIsLoaded(true);
14
- };
15
- importIcon();
7
+ setIsLoading(true);
8
+ getIcon(name)
9
+ ?.then((module) => {
10
+ iconRef.current = module.default;
11
+ setIsLoading(false);
12
+ })
13
+ .catch((error) => {
14
+ console.error(error);
15
+ setIsLoading(false);
16
+ });
16
17
  }, [name]);
17
18
  const IconComponent = iconRef.current;
18
- if (!isLoaded || !IconComponent)
19
+ if (isLoading || !IconComponent)
19
20
  return null;
20
21
  return React.createElement(IconComponent, { ...props });
21
22
  };
22
23
  export default Icon;
23
- export * from './components';
24
+ // 모든 컴포넌트를 정적으로 내보내지 않음
25
+ // export * from './components';