feat: 扩展mountIconSpriteToDom方法 (#8476)

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>
This commit is contained in:
qkiroc 2023-10-24 15:40:36 +08:00 committed by GitHub
parent 2b5efd478e
commit cf3eb0f09c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,14 +15,14 @@ export interface SvgIconGroup {
export let svgIcons: SvgIconGroup[] = [];
function getSvgMountNode() {
const node = document.getElementById('amis-icon-manage-mount-node');
function getSvgMountNode(nodeId: string = 'amis-icon-manage-mount-node') {
const node = document.getElementById(nodeId);
if (node) {
return node;
} else {
const newNode = document.createElement('div');
newNode.setAttribute('id', 'amis-icon-manage-mount-node');
newNode.setAttribute('id', nodeId);
newNode.setAttribute('style', 'width:0;height:0;visibility:hidden;');
if (document.body.firstElementChild) {
@ -35,9 +35,9 @@ function getSvgMountNode() {
}
}
export function mountIconSpiriteToDom(spirite: string) {
const node = getSvgMountNode();
node && (node.innerHTML = spirite);
export function mountIconSpriteToDom(sprite: string, nodeId?: string) {
const node = getSvgMountNode(nodeId);
node && (node.innerHTML = sprite);
}
type refreshIconListFunc = null | (() => any);
@ -47,17 +47,17 @@ export let refreshIconList: refreshIconListFunc = null;
export function setRefreshSvgListAction(
func: ({
setSvgIconList,
mountIconSpiriteToDom
mountIconSpriteToDom
}: {
setSvgIconList: (arr: SvgIconGroup[]) => void;
mountIconSpiriteToDom: (str: string) => void;
mountIconSpriteToDom: (str: string) => void;
}) => any
) {
if (func && typeof func === 'function') {
refreshIconList = () =>
func({
setSvgIconList,
mountIconSpiriteToDom
mountIconSpriteToDom
});
} else {
refreshIconList = null;