feat: add SettingsObjectFieldPreview and SettingsObjectFieldPreviewCard (#2376)

* feat: add SettingsObjectFieldPreview

Closes #2343

* feat: add SettingsObjectFieldPreviewCard

Closes #2349

* Fix ci

* Fix tests

* Fix tests

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Thaïs
2023-11-06 23:14:47 +01:00
committed by GitHub
parent b3d460eb75
commit 377f95c9db
5 changed files with 225 additions and 7 deletions

View File

@ -2,20 +2,21 @@ import { useEffect, useState } from 'react';
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
import { useLazyLoadIcons } from './useLazyLoadIcons';
export const useLazyLoadIcon = (iconKey: string) => {
const { isLoadingIcons, icons } = useLazyLoadIcons();
const [Icon, setIcon] = useState<IconComponent | undefined>();
const [isLoadingIcon, setIsLoadingIcon] = useState(true);
useEffect(() => {
if (!iconKey) return;
import(`@tabler/icons-react/dist/esm/icons/${iconKey}.js`).then(
(lazyLoadedIcon) => {
setIcon(lazyLoadedIcon.default);
setIsLoadingIcon(false);
},
);
}, [iconKey]);
if (!isLoadingIcons) {
setIcon(icons[iconKey]);
setIsLoadingIcon(false);
}
}, [iconKey, icons, isLoadingIcons]);
return { Icon, isLoadingIcon };
};