mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-15 14:08:49 +00:00
fix: Revert moving createIcons to separate file
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
import replaceElement from './replaceElement';
|
||||
|
||||
/**
|
||||
* Replaces all elements with matching nameAttr with the defined icons
|
||||
* @param {{ icons?: object, nameAttr?: string, attrs?: object }} options
|
||||
*/
|
||||
const createIcons = ({ icons = {}, nameAttr = 'data-lucide', attrs = {} } = {}) => {
|
||||
if (!Object.values(icons).length) {
|
||||
throw new Error(
|
||||
"Please provide an icons object.\nIf you want to use all the icons you can import it like:\n `import { createIcons, icons } from 'lucide';\nlucide.createIcons({icons});`",
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof document === 'undefined') {
|
||||
throw new Error('`createIcons()` only works in a browser environment.');
|
||||
}
|
||||
|
||||
const elementsToReplace = document.querySelectorAll(`[${nameAttr}]`);
|
||||
Array.from(elementsToReplace).forEach((element) =>
|
||||
replaceElement(element, { nameAttr, icons, attrs }),
|
||||
);
|
||||
|
||||
/** @todo: remove this block in v1.0 */
|
||||
if (nameAttr === 'data-lucide') {
|
||||
const deprecatedElements = document.querySelectorAll('[icon-name]');
|
||||
if (deprecatedElements.length > 0) {
|
||||
console.warn(
|
||||
'[Lucide] Some icons were found with the now deprecated icon-name attribute. These will still be replaced for backwards compatibility, but will no longer be supported in v1.0 and you should switch to data-lucide',
|
||||
);
|
||||
Array.from(deprecatedElements).forEach((element) =>
|
||||
replaceElement(element, { nameAttr: 'icon-name', icons, attrs }),
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default createIcons;
|
||||
@@ -1,9 +1,41 @@
|
||||
import replaceElement from './replaceElement';
|
||||
import * as iconAndAliases from './iconsAndAliases';
|
||||
|
||||
/*
|
||||
Create Icons function export.
|
||||
*/
|
||||
export { default as createIcons } from './createIcons';
|
||||
/**
|
||||
* Replaces all elements with matching nameAttr with the defined icons
|
||||
* @param {{ icons?: object, nameAttr?: string, attrs?: object }} options
|
||||
*/
|
||||
const createIcons = ({ icons = {}, nameAttr = 'data-lucide', attrs = {} } = {}) => {
|
||||
if (!Object.values(icons).length) {
|
||||
throw new Error(
|
||||
"Please provide an icons object.\nIf you want to use all the icons you can import it like:\n `import { createIcons, icons } from 'lucide';\nlucide.createIcons({icons});`",
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof document === 'undefined') {
|
||||
throw new Error('`createIcons()` only works in a browser environment.');
|
||||
}
|
||||
|
||||
const elementsToReplace = document.querySelectorAll(`[${nameAttr}]`);
|
||||
Array.from(elementsToReplace).forEach((element) =>
|
||||
replaceElement(element, { nameAttr, icons, attrs }),
|
||||
);
|
||||
|
||||
/** @todo: remove this block in v1.0 */
|
||||
if (nameAttr === 'data-lucide') {
|
||||
const deprecatedElements = document.querySelectorAll('[icon-name]');
|
||||
if (deprecatedElements.length > 0) {
|
||||
console.warn(
|
||||
'[Lucide] Some icons were found with the now deprecated icon-name attribute. These will still be replaced for backwards compatibility, but will no longer be supported in v1.0 and you should switch to data-lucide',
|
||||
);
|
||||
Array.from(deprecatedElements).forEach((element) =>
|
||||
replaceElement(element, { nameAttr: 'icon-name', icons, attrs }),
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export { createIcons };
|
||||
|
||||
/*
|
||||
Create Element function export.
|
||||
|
||||
Reference in New Issue
Block a user