fix(front/Icon): better match icon type against Lucide Icons full name instead of starting with fa to avoid collisions
This commit is contained in:
parent
0e0e633e08
commit
1e72ec7172
@ -1,5 +1,7 @@
|
||||
import {createIcons, icons} from "lucide";
|
||||
|
||||
import {toLucideIconsPascalCase} from "../../common/StringUtils.js";
|
||||
|
||||
let hasAlreadyReplacedIcons = false;
|
||||
|
||||
export function replaceIcons(once: boolean): void {
|
||||
@ -9,3 +11,7 @@ export function replaceIcons(once: boolean): void {
|
||||
hasAlreadyReplacedIcons = true;
|
||||
}
|
||||
}
|
||||
|
||||
export function isLucideIcon(iconName: string): boolean {
|
||||
return Object.keys(icons).indexOf(toLucideIconsPascalCase(iconName)) >= 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import {replaceIcons} from "../../ts/icons.js";
|
||||
import {replaceIcons, isLucideIcon} from "../../ts/icons.js";
|
||||
import {afterUpdate, onMount} from "svelte";
|
||||
|
||||
export let name: string;
|
||||
@ -39,9 +39,9 @@
|
||||
</style>
|
||||
|
||||
{#if name}
|
||||
{#if name.startsWith('fa') }
|
||||
<i class="{name} icon" aria-hidden="true" {...$$restProps}></i>
|
||||
{:else}
|
||||
{#if isLucideIcon(name) >= 0 }
|
||||
<i icon-name="{name}" class="icon" aria-hidden="true" {...$$restProps}></i>
|
||||
{:else}
|
||||
<i class="{name} icon" aria-hidden="true" {...$$restProps}></i>
|
||||
{/if}
|
||||
{/if}
|
||||
|
2
src/common/StringUtils.ts
Normal file
2
src/common/StringUtils.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export const toLucideIconsPascalCase = (string: string): string =>
|
||||
string.replace(/(\w)(\w*)(_|-|\s*)/g, (g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase());
|
Loading…
Reference in New Issue
Block a user