mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-08-29 12:08:25 +02:00
docs(icons): External Lucide icons like from lab on lucide.dev (#2194)
* Add section title * Add external libs list in sidebar * Make external lib work * Adds external lib to detail view * fix lint issues * Update to https
This commit is contained in:
57
docs/.vitepress/theme/composables/useExternalLibs.ts
Normal file
57
docs/.vitepress/theme/composables/useExternalLibs.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { ref, inject, Ref, watch } from 'vue';
|
||||
import { ExternalLibs, IconEntity } from '../types';
|
||||
|
||||
export const EXTERNAL_LIBS_CONTEXT = Symbol('externalLibs');
|
||||
|
||||
type ExternalIconNodes = Partial<Record<ExternalLibs, IconEntity[]>>;
|
||||
|
||||
interface ExternalLibContext {
|
||||
selectedLibs: Ref<[ExternalLibs]>;
|
||||
externalIconNodes: Ref<ExternalIconNodes>;
|
||||
}
|
||||
|
||||
export const externalLibContext = {
|
||||
selectedLibs: ref([]),
|
||||
externalIconNodes: ref({}),
|
||||
};
|
||||
|
||||
const externalLibIconNodesAPI = {
|
||||
lab: 'https://lab.lucide.dev/api/icon-details',
|
||||
};
|
||||
|
||||
export function useExternalLibs(): ExternalLibContext {
|
||||
const context = inject<ExternalLibContext>(EXTERNAL_LIBS_CONTEXT);
|
||||
|
||||
watch(context?.selectedLibs, async (selectedLibs) => {
|
||||
const savedIconNodes = { ...context?.externalIconNodes.value };
|
||||
const newExternalIconNodes: ExternalIconNodes = {};
|
||||
|
||||
try {
|
||||
for (const lib of selectedLibs) {
|
||||
if (savedIconNodes[lib]) {
|
||||
newExternalIconNodes[lib] = savedIconNodes[lib];
|
||||
} else {
|
||||
const response = await fetch(externalLibIconNodesAPI[lib]);
|
||||
const iconNodes = await response.json();
|
||||
|
||||
if (iconNodes) {
|
||||
newExternalIconNodes[lib] = Object.values(iconNodes).map((iconEntity: IconEntity) => ({
|
||||
...iconEntity,
|
||||
externalLibrary: lib,
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.externalIconNodes.value = newExternalIconNodes;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
|
||||
if (!context) {
|
||||
throw new Error('useExternalLibs must be used with externalLibs context');
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user