Compare commits
9 commits
vitepress-
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1a02a04d4 | ||
|
|
d79f705483 | ||
|
|
742ea78395 | ||
|
|
891daab994 | ||
|
|
7ae293b184 | ||
|
|
56972960bb | ||
|
|
044a548aaa | ||
|
|
4818b6e1dd | ||
|
|
390e824cfe |
27 changed files with 421 additions and 59 deletions
|
|
@ -13,6 +13,7 @@ ungroup
|
|||
toc
|
||||
sunlounger
|
||||
monstera
|
||||
floorball
|
||||
|
||||
# Search tags and terms used in icon and category metadata
|
||||
checkmark
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import getSVGIcon from '../../utils/getSVGIcon';
|
|||
import useConfetti from '../../composables/useConfetti';
|
||||
import Tooltip from '../base/Tooltip.vue';
|
||||
import { diamond } from '../../../data/iconNodes';
|
||||
import { setLibraryParams } from '../../composables/useExternalLibs';
|
||||
|
||||
const downloadText = 'Download!';
|
||||
const copiedText = 'Copied!';
|
||||
|
|
@ -76,13 +77,17 @@ async function navigateToIcon(event) {
|
|||
if (props.overlayMode && showOverlay.value) {
|
||||
event.preventDefault();
|
||||
|
||||
window.history.pushState(
|
||||
{},
|
||||
'',
|
||||
props.externalLibrary
|
||||
? `/icons/${props.externalLibrary}/${props.name}`
|
||||
: `/icons/${props.name}`,
|
||||
// Keep ?library= so the selection survives opening and closing the drawer.
|
||||
const url = setLibraryParams(
|
||||
new URL(
|
||||
props.externalLibrary
|
||||
? `/icons/${props.externalLibrary}/${props.name}`
|
||||
: `/icons/${props.name}`,
|
||||
window.location.origin,
|
||||
),
|
||||
);
|
||||
|
||||
window.history.pushState({}, '', url);
|
||||
emit(
|
||||
'setActiveIcon',
|
||||
props.externalLibrary ? `${props.externalLibrary}:${props.name}` : props.name,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import useSearchPlaceholder from '../../utils/useSearchPlaceholder.ts';
|
|||
import Icon from '@lucide/vue/src/Icon';
|
||||
import { listSortDescending } from '~/.vitepress/data/iconNodes';
|
||||
import { track, trackDebounced } from '../../utils/openpanel';
|
||||
import { setLibraryParams } from '../../composables/useExternalLibs';
|
||||
|
||||
const ICON_SIZE = 56;
|
||||
const ICON_GRID_GAP = 8;
|
||||
|
|
@ -206,6 +207,8 @@ function handleCloseDrawer() {
|
|||
url.searchParams.set('search', searchQueryDebounced.value);
|
||||
}
|
||||
|
||||
setLibraryParams(url);
|
||||
|
||||
window.history.pushState({}, '', url);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { ref, inject, Ref, watch } from 'vue';
|
||||
import { ref, inject, Ref, watch, onMounted } from 'vue';
|
||||
import { useLocalStorage } from '@vueuse/core';
|
||||
import { ExternalLibs, IconEntity } from '../types';
|
||||
|
||||
export const EXTERNAL_LIBS_CONTEXT = Symbol('externalLibs');
|
||||
|
|
@ -6,11 +7,11 @@ export const EXTERNAL_LIBS_CONTEXT = Symbol('externalLibs');
|
|||
type ExternalIconNodes = Partial<Record<ExternalLibs, IconEntity[]>>;
|
||||
|
||||
interface ExternalLibContext {
|
||||
selectedLibs: Ref<[ExternalLibs]>;
|
||||
selectedLibs: Ref<ExternalLibs[]>;
|
||||
externalIconNodes: Ref<ExternalIconNodes>;
|
||||
}
|
||||
|
||||
export const externalLibContext = {
|
||||
export const externalLibContext: ExternalLibContext = {
|
||||
selectedLibs: ref([]),
|
||||
externalIconNodes: ref({}),
|
||||
};
|
||||
|
|
@ -19,41 +20,104 @@ const externalLibIconNodesAPI = {
|
|||
lab: `${import.meta.env.DEV ? 'http://localhost:3000' : ''}/api/lab/icon-details`,
|
||||
};
|
||||
|
||||
export function useExternalLibs(): ExternalLibContext {
|
||||
const context = inject<ExternalLibContext>(EXTERNAL_LIBS_CONTEXT);
|
||||
// URL query parameter for preselecting external libraries, e.g. /icons/?library=lab
|
||||
// Repeat it for several libraries: ?library=lab&library=other
|
||||
const URL_PARAM = 'library';
|
||||
|
||||
watch(context?.selectedLibs, async (selectedLibs) => {
|
||||
const savedIconNodes = { ...context?.externalIconNodes.value };
|
||||
const newExternalIconNodes: ExternalIconNodes = {};
|
||||
const storedLibs = useLocalStorage<ExternalLibs[]>('external-libs', [], { initOnMounted: false });
|
||||
|
||||
try {
|
||||
for (const lib of selectedLibs) {
|
||||
if (savedIconNodes[lib]) {
|
||||
newExternalIconNodes[lib] = savedIconNodes[lib];
|
||||
} else {
|
||||
const response = await fetch(externalLibIconNodesAPI[lib]);
|
||||
const iconDetails = await response.json();
|
||||
const isExternalLib = (value: string): value is ExternalLibs =>
|
||||
Object.keys(externalLibIconNodesAPI).includes(value);
|
||||
|
||||
if (iconDetails) {
|
||||
newExternalIconNodes[lib] = Object.values(iconDetails).map((iconEntity: IconEntity) => {
|
||||
return {
|
||||
...iconEntity,
|
||||
externalLibrary: lib,
|
||||
};
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Writes the current library selection into `url` as `?library=` params, replacing any
|
||||
* existing ones. Use it when building URLs for history.pushState so the param survives.
|
||||
*/
|
||||
export const setLibraryParams = (url: URL, libs = externalLibContext.selectedLibs.value) => {
|
||||
url.searchParams.delete(URL_PARAM);
|
||||
|
||||
for (const lib of libs) {
|
||||
url.searchParams.append(URL_PARAM, lib);
|
||||
}
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
// Keep the URL shareable and remember the selection for the next visit.
|
||||
const persistSelection = (libs: ExternalLibs[]) => {
|
||||
storedLibs.value = libs;
|
||||
|
||||
const url = setLibraryParams(new URL(window.location.href), libs);
|
||||
window.history.replaceState(window.history.state, '', url);
|
||||
};
|
||||
|
||||
// `?library=` wins (shared links, Back/Forward); otherwise use the last selection.
|
||||
const syncSelection = () => {
|
||||
const { selectedLibs } = externalLibContext;
|
||||
const libsFromUrl = new URLSearchParams(window.location.search)
|
||||
.getAll(URL_PARAM)
|
||||
.filter(isExternalLib);
|
||||
const libs = libsFromUrl.length
|
||||
? [...new Set(libsFromUrl)]
|
||||
: storedLibs.value.filter(isExternalLib);
|
||||
|
||||
if (String(libs) !== String(selectedLibs.value)) {
|
||||
selectedLibs.value = libs;
|
||||
}
|
||||
|
||||
// Also when nothing changed, to restore the param on URLs that dropped it.
|
||||
persistSelection(libs);
|
||||
};
|
||||
|
||||
const fetchExternalIconNodes = async (selectedLibs: ExternalLibs[]) => {
|
||||
const { externalIconNodes } = externalLibContext;
|
||||
const savedIconNodes = { ...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 iconDetails = await response.json();
|
||||
|
||||
if (iconDetails) {
|
||||
newExternalIconNodes[lib] = Object.values(iconDetails).map((iconEntity: IconEntity) => {
|
||||
return {
|
||||
...iconEntity,
|
||||
externalLibrary: lib,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
context.externalIconNodes.value = newExternalIconNodes;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
|
||||
externalIconNodes.value = newExternalIconNodes;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Registered once at module level so they outlive any single component. The selection only
|
||||
// changes in the browser, so the watchers never run during SSR.
|
||||
watch(externalLibContext.selectedLibs, persistSelection);
|
||||
watch(externalLibContext.selectedLibs, fetchExternalIconNodes);
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('popstate', syncSelection);
|
||||
}
|
||||
|
||||
export function useExternalLibs(): ExternalLibContext {
|
||||
const context = inject<ExternalLibContext>(EXTERNAL_LIBS_CONTEXT);
|
||||
|
||||
if (!context) {
|
||||
throw new Error('useExternalLibs must be used with externalLibs context');
|
||||
}
|
||||
|
||||
// Apply the URL/stored selection after hydration to avoid an SSR mismatch on the checkbox.
|
||||
// Runs on every mount so client-side navigation to a URL carrying the param reapplies it.
|
||||
onMounted(syncSelection);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
|
|
|||
34
icons/folder-network.json
Normal file
34
icons/folder-network.json
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"$schema": "../icon.schema.json",
|
||||
"contributors": [
|
||||
"$extends:folder"
|
||||
],
|
||||
"use-cases": [
|
||||
"Representing FTP or SFTP directories",
|
||||
"Identifying shared folders and network drives",
|
||||
"Browsing files on remote servers",
|
||||
"Representing network-attached storage"
|
||||
],
|
||||
"tags": [
|
||||
"$extends:folder",
|
||||
"network",
|
||||
"ftp",
|
||||
"sftp",
|
||||
"file transfer",
|
||||
"file transfer protocol",
|
||||
"shared folder",
|
||||
"file sharing",
|
||||
"network drive",
|
||||
"network storage",
|
||||
"remote",
|
||||
"server",
|
||||
"nas",
|
||||
"smb",
|
||||
"nfs"
|
||||
],
|
||||
"categories": [
|
||||
"$extends:folder",
|
||||
"connectivity",
|
||||
"development"
|
||||
]
|
||||
}
|
||||
17
icons/folder-network.svg
Normal file
17
icons/folder-network.svg
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M12 14v4" />
|
||||
<path d="M17 4a2 2 0 012 2v6a2 2 0 01-2 2H7a2 2 0 01-2-2V4a2 2 0 012-2h2.5a1.5 1.5 0 011.2.6l.6.8a1.5 1.5 0 001.2.6z" />
|
||||
<path d="M21 20h-7" />
|
||||
<path d="M3 20h7" />
|
||||
<circle cx="12" cy="20" r="2" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 438 B |
20
icons/folder-plus-corner.json
Normal file
20
icons/folder-plus-corner.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "../icon.schema.json",
|
||||
"contributors": [
|
||||
"$extends:folder",
|
||||
"nicolasakf",
|
||||
"jguddas"
|
||||
],
|
||||
"use-cases": [
|
||||
"Creating a new folder in file managers and cloud storage apps",
|
||||
"Adding files or items to an existing folder or collection",
|
||||
"Starting a new project or workspace in productivity tools"
|
||||
],
|
||||
"tags": [
|
||||
"$extends:folder",
|
||||
"$group:plus"
|
||||
],
|
||||
"categories": [
|
||||
"$extends:folder"
|
||||
]
|
||||
}
|
||||
15
icons/folder-plus-corner.svg
Normal file
15
icons/folder-plus-corner.svg
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M16 17h6" />
|
||||
<path d="M19 14v6" />
|
||||
<path d="M22 11.354V8a2 2 0 00-2-2h-7.9a2 2 0 01-1.69-.9L9.6 3.9A2 2 0 007.93 3H4a2 2 0 00-2 2v13a2 2 0 002 2h9.354" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 378 B |
20
icons/rectangle-landscape-play.json
Normal file
20
icons/rectangle-landscape-play.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "../icon.schema.json",
|
||||
"contributors": [
|
||||
"scottgriffinm"
|
||||
],
|
||||
"use-cases": [
|
||||
"Indicating embedded video content in documentation, help centers, or knowledge bases.",
|
||||
"Video file type indicator in file managers, email attachments, or chat apps."
|
||||
],
|
||||
"tags": [
|
||||
"music",
|
||||
"video",
|
||||
"start",
|
||||
"movie"
|
||||
],
|
||||
"categories": [
|
||||
"arrows",
|
||||
"multimedia"
|
||||
]
|
||||
}
|
||||
14
icons/rectangle-landscape-play.svg
Normal file
14
icons/rectangle-landscape-play.svg
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M15.033 11.44a.65.65 0 010 1.12l-4.065 2.352a.65.65 0 01-.968-.56V9.648a.65.65 0 01.967-.56z" />
|
||||
<rect x="2" y="5" width="20" height="14" rx="2" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 369 B |
28
lab/floorball.json
Normal file
28
lab/floorball.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"$schema": "../icon.schema.json",
|
||||
"contributors": [
|
||||
"Bulgymizi"
|
||||
],
|
||||
"use-cases": [
|
||||
"Labeling floorball sessions in workout logs",
|
||||
"Identifying floorball equipment in sporting goods catalogs",
|
||||
"Labeling floorball practices and matches in club calendars"
|
||||
],
|
||||
"tags": [
|
||||
"ball",
|
||||
"innebandy",
|
||||
"unihockey",
|
||||
"salibandy",
|
||||
"equipment",
|
||||
"perforated",
|
||||
"plastic",
|
||||
"hollow",
|
||||
"indoor",
|
||||
"team",
|
||||
"match",
|
||||
"training"
|
||||
],
|
||||
"categories": [
|
||||
"sports"
|
||||
]
|
||||
}
|
||||
18
lab/floorball.svg
Normal file
18
lab/floorball.svg
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M14.5 21.682a1 1 0 00-5 0" />
|
||||
<path d="M2.318 14.5a1 1 0 000-5" />
|
||||
<path d="M21.682 9.5a1 1 0 000 5" />
|
||||
<path d="M9.5 2.318a1 1 0 005 0" />
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<circle cx="12" cy="12" r="2.5" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 438 B |
33
lab/golf-ball.json
Normal file
33
lab/golf-ball.json
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"$schema": "../icon.schema.json",
|
||||
"contributors": [
|
||||
"alexrefshauge",
|
||||
"karsa-mistmere"
|
||||
],
|
||||
"use-cases": [],
|
||||
"tags": [
|
||||
"sport",
|
||||
"ball",
|
||||
"play",
|
||||
"score",
|
||||
"golf",
|
||||
"club",
|
||||
"course",
|
||||
"tee",
|
||||
"fairway",
|
||||
"green",
|
||||
"putting",
|
||||
"putt",
|
||||
"golfer",
|
||||
"hole",
|
||||
"tournament",
|
||||
"recreation",
|
||||
"leisure",
|
||||
"outdoor",
|
||||
"game",
|
||||
"bounce"
|
||||
],
|
||||
"categories": [
|
||||
"sports"
|
||||
]
|
||||
}
|
||||
18
lab/golf-ball.svg
Normal file
18
lab/golf-ball.svg
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M10 16h.01" />
|
||||
<path d="M13 13h.01" />
|
||||
<path d="M14 17h.01" />
|
||||
<path d="M16 10h.01" />
|
||||
<path d="M17 14h.01" />
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 374 B |
20
lab/shuttlecock.json
Normal file
20
lab/shuttlecock.json
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "../icon.schema.json",
|
||||
"contributors": [
|
||||
"felipeajzanetti"
|
||||
],
|
||||
"use-cases": [],
|
||||
"tags": [
|
||||
"sport",
|
||||
"badminton",
|
||||
"racket",
|
||||
"shuttlecock",
|
||||
"game",
|
||||
"sports",
|
||||
"equipment"
|
||||
],
|
||||
"categories": [
|
||||
"sports",
|
||||
"gaming"
|
||||
]
|
||||
}
|
||||
16
lab/shuttlecock.svg
Normal file
16
lab/shuttlecock.svg
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="m14 10 1-5" />
|
||||
<path d="M3 5a3 3 0 016 0 3 3 0 016 0 3 3 0 016 0l-5 9H8z" />
|
||||
<path d="M8 18a4 4 0 008 0z" />
|
||||
<path d="m9 5 1 5" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 356 B |
|
|
@ -18,7 +18,7 @@ export interface LucideConfig {
|
|||
* Stroke width
|
||||
* @default 2
|
||||
*/
|
||||
strokeWidth: number;
|
||||
strokeWidth: string | number;
|
||||
/**
|
||||
* Whether to use absolute stroke width.
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ import { createContext, h, type ComponentChildren } from 'preact';
|
|||
import { useContext, useMemo } from 'preact/hooks';
|
||||
|
||||
const LucideContext = createContext<{
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
@ -22,9 +22,9 @@ const LucideContext = createContext<{
|
|||
|
||||
interface LucideProviderProps {
|
||||
children: ComponentChildren;
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { createContext, createElement, type ReactNode, useContext, useMemo } from 'react';
|
||||
|
||||
const LucideContext = createContext<{
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
@ -21,9 +21,9 @@ const LucideContext = createContext<{
|
|||
|
||||
interface LucideProviderProps {
|
||||
children: ReactNode;
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import { createContext, createElement, type ReactNode, useContext, useMemo } fro
|
|||
import { LucideProps } from './types';
|
||||
|
||||
type LucideConfig = {
|
||||
size: number;
|
||||
size: number | string;
|
||||
color: string;
|
||||
strokeWidth: number;
|
||||
strokeWidth: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { createContext, splitProps, type JSXElement } from 'solid-js';
|
||||
|
||||
export const LucideContext = createContext<{
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
@ -21,9 +21,9 @@ export const LucideContext = createContext<{
|
|||
|
||||
interface LucideProviderProps {
|
||||
children: JSXElement;
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ This package include the following Lucide implementations:
|
|||
This package is suitable for very specific use cases for example if you want to use icon fonts, svg sprites, normal svgs or Common.js Svg strings in your javascript project.
|
||||
|
||||
> [!WARNING]
|
||||
> It is not recommended to use this package for svg sprites or icon fonts for web pages/applications, for prototyping it is ok. We recommend to bundlers for web applications to make sure you only bundle the used icons from this icon library (Threeshaking). Otherwise it will load all the icons, making you webpage loading slower. Threeshaking is only available in the packages: [lucide](https://github.com/lucide-icons/lucide/tree/main/packages/lucide), [lucide-react](https://github.com/lucide-icons/lucide/tree/main/packages/lucide-react), [lucide-vue](https://github.com/lucide-icons/lucide/tree/main/packages/lucide-vue), [lucide-vue-next](https://github.com/lucide-icons/lucide/tree/main/packages/lucide-vue-next), [lucide-angular](https://github.com/lucide-icons/lucide/tree/main/packages/lucide-angular), [lucide-preact](https://github.com/lucide-icons/lucide/tree/main/packages/lucide-preact)
|
||||
> It is not recommended to use this package for SVG sprites or icon fonts for web pages/applications; for prototyping, it is ok. We recommend that bundlers for web applications make sure you only bundle the used icons from this icon library (tree-shaking). Otherwise, it will load all the icons, making your webpage load more slowly. Tree-shaking is available in our other [packages](https://lucide.dev/packages).
|
||||
|
||||
## Installation
|
||||
|
||||
|
|
|
|||
|
|
@ -30,11 +30,18 @@ function buildLucideIconNode(icon: LucideIconData, params: LucideBuildParams = {
|
|||
? mergeClasses(...classNamesFromClassName)
|
||||
: mergeClasses('lucide', ...iconClassNames, ...classNamesFromClassName);
|
||||
|
||||
const calculatedStrokeWidth = params.absoluteStrokeWidth
|
||||
? (Number(params.strokeWidth ?? defaultAttributes['stroke-width']) *
|
||||
let calculatedStrokeWidth = params.strokeWidth ?? defaultAttributes['stroke-width'];
|
||||
|
||||
if (params.absoluteStrokeWidth) {
|
||||
const scaled =
|
||||
(Number(calculatedStrokeWidth) *
|
||||
Number(icon.size ?? icon.width ?? defaultAttributes['width'])) /
|
||||
Number(params.size ?? params.width ?? defaultAttributes['width'])
|
||||
: (params.strokeWidth ?? defaultAttributes['stroke-width']);
|
||||
Number(params.size ?? params.width ?? defaultAttributes['width']);
|
||||
|
||||
// Only numeric lengths can be scaled; a CSS unit such as `1em`, or a size of `0`, makes the
|
||||
// conversion non-finite, so the unscaled width stands rather than emitting `NaN`.
|
||||
if (Number.isFinite(scaled)) calculatedStrokeWidth = scaled;
|
||||
}
|
||||
|
||||
const attributes = {
|
||||
...Object.entries(defaultAttributes).reduce((attrs, [attrName, value]) => {
|
||||
|
|
|
|||
29
packages/shared/tests/buildLucideIconNode.spec.ts
Normal file
29
packages/shared/tests/buildLucideIconNode.spec.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import buildLucideIconNode from '../src/build/buildLucideIconNode';
|
||||
|
||||
const icon = { name: 'circle', size: 24, node: [] };
|
||||
|
||||
const strokeWidthOf = (params: Parameters<typeof buildLucideIconNode>[1]) =>
|
||||
buildLucideIconNode(icon, params)[1]['stroke-width'];
|
||||
|
||||
describe('buildLucideIconNode absoluteStrokeWidth', () => {
|
||||
it('scales the stroke width for numeric sizes', () => {
|
||||
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: 2, size: 48 })).toBe(1);
|
||||
});
|
||||
|
||||
it('falls back to the unscaled width for a CSS unit size', () => {
|
||||
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: 2, size: '1em' })).toBe(2);
|
||||
});
|
||||
|
||||
it('falls back to the unscaled width for a non-numeric stroke width', () => {
|
||||
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: '1em', size: 48 })).toBe('1em');
|
||||
});
|
||||
|
||||
it('falls back to the unscaled width for a zero size', () => {
|
||||
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: 2, size: 0 })).toBe(2);
|
||||
});
|
||||
|
||||
it('leaves the stroke width alone when not absolute', () => {
|
||||
expect(strokeWidthOf({ strokeWidth: 2, size: 48 })).toBe(2);
|
||||
});
|
||||
});
|
||||
|
|
@ -4,8 +4,8 @@ const LucideContext = Symbol('lucide-context');
|
|||
|
||||
export interface LucideGlobalContext {
|
||||
color?: string;
|
||||
size?: number;
|
||||
strokeWidth?: number;
|
||||
size?: number | string;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { provide, inject } from 'vue';
|
|||
export const LUCIDE_CONTEXT = Symbol('lucide-icons');
|
||||
|
||||
interface LucideIconsContext {
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import type {
|
|||
} from '@lucide/shared/types';
|
||||
|
||||
export interface LucideProps extends Partial<SVGAttributes> {
|
||||
size?: 24 | number;
|
||||
size?: 24 | number | string;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
|
|
|
|||
Loading…
Reference in a new issue