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:
Eric Fennis
2024-06-25 09:56:55 +02:00
committed by GitHub
parent f980863f6c
commit e11fa135a0
31 changed files with 835 additions and 64 deletions

View File

@@ -28,6 +28,10 @@ export default defineConfig({
new URL('./theme/components/overrides/VPFooter.vue', import.meta.url),
),
},
{
find: '~/.vitepress',
replacement: fileURLToPath(new URL('./', import.meta.url)),
},
],
},
},

View File

@@ -0,0 +1,186 @@
[
{
"name": "accessibility",
"title": "Accessibility"
},
{
"name": "account",
"title": "Accounts & access"
},
{
"name": "animals",
"title": "Animals"
},
{
"name": "arrows",
"title": "Arrows"
},
{
"name": "brands",
"title": "Brands"
},
{
"name": "buildings",
"title": "Buildings"
},
{
"name": "charts",
"title": "Charts"
},
{
"name": "communication",
"title": "Communication"
},
{
"name": "connectivity",
"title": "Connectivity"
},
{
"name": "currency",
"title": "Currency"
},
{
"name": "cursors",
"title": "Cursors"
},
{
"name": "design",
"title": "Design"
},
{
"name": "development",
"title": "Coding & development"
},
{
"name": "devices",
"title": "Devices"
},
{
"name": "emoji",
"title": "Emoji"
},
{
"name": "files",
"title": "File icons"
},
{
"name": "food-beverage",
"title": "Food & beverage"
},
{
"name": "furniture",
"title": "Furniture"
},
{
"name": "gaming",
"title": "Gaming"
},
{
"name": "home",
"title": "Home"
},
{
"name": "layout",
"title": "Layout"
},
{
"name": "mail",
"title": "Mail"
},
{
"name": "maps",
"title": "Maps"
},
{
"name": "maths",
"title": "Maths"
},
{
"name": "medical",
"title": "Medical"
},
{
"name": "money",
"title": "Money"
},
{
"name": "multimedia",
"title": "Multimedia"
},
{
"name": "nature",
"title": "Nature"
},
{
"name": "navigation",
"title": "Navigation"
},
{
"name": "notifications",
"title": "Notifications"
},
{
"name": "people",
"title": "People"
},
{
"name": "photography",
"title": "Photography"
},
{
"name": "science",
"title": "Science"
},
{
"name": "seasons",
"title": "Seasons"
},
{
"name": "security",
"title": "Security"
},
{
"name": "shapes",
"title": "Shapes"
},
{
"name": "shopping",
"title": "Shopping"
},
{
"name": "social",
"title": "Social"
},
{
"name": "sports",
"title": "Sports"
},
{
"name": "sustainability",
"title": "Sustainability"
},
{
"name": "text",
"title": "Text formatting"
},
{
"name": "time",
"title": "Time & calendar"
},
{
"name": "tools",
"title": "Tools"
},
{
"name": "transportation",
"title": "Transportation"
},
{
"name": "travel",
"title": "Travel"
},
{
"name": "weather",
"title": "Weather"
}
]

View File

@@ -10,18 +10,24 @@ type CodeExampleType = {
const getIconCodes = (): CodeExampleType => {
return [
{
language: 'html',
title: 'HTML',
code: `<i data-lucide="Name"></i>`,
language: 'js',
title: 'Vanilla',
code: `\
import { createIcons, icons } from 'lucide';
createIcons({ icons });
document.body.append('<i data-lucide="$Name"></i>');\
`,
},
{
language: 'tsx',
title: 'React',
code: `import { PascalCase } from 'lucide-react';
code: `import { $PascalCase } from 'lucide-react';
const App = () => {
return (
<PascalCase />
<$PascalCase />
);
};
@@ -32,11 +38,11 @@ export default App;
language: 'vue',
title: 'Vue',
code: `<script setup>
import { PascalCase } from 'lucide-vue-next';
import { $PascalCase } from 'lucide-vue-next';
</script>
<template>
<PascalCase />
<$PascalCase />
</template>
`,
},
@@ -44,20 +50,20 @@ export default App;
language: 'svelte',
title: 'Svelte',
code: `<script>
import { PascalCase } from 'lucide-svelte';
import { $PascalCase } from 'lucide-svelte';
</script>
<PascalCase />
<$PascalCase />
`,
},
{
language: 'tsx',
title: 'Preact',
code: `import { PascalCase } from 'lucide-preact';
code: `import { $PascalCase } from 'lucide-preact';
const App = () => {
return (
<PascalCase />
<$PascalCase />
);
};
@@ -67,11 +73,11 @@ export default App;
{
language: 'tsx',
title: 'Solid',
code: `import { PascalCase } from 'lucide-solid';
code: `import { $PascalCase } from 'lucide-solid';
const App = () => {
return (
<PascalCase />
<$PascalCase />
);
};
@@ -82,16 +88,16 @@ export default App;
language: 'tsx',
title: 'Angular',
code: `// app.module.ts
import { LucideAngularModule, PascalCase } from 'lucide-angular';
import { LucideAngularModule, $PascalCase } from 'lucide-angular';
@NgModule({
imports: [
LucideAngularModule.pick({ PascalCase })
LucideAngularModule.pick({ $PascalCase })
],
})
// app.component.html
<lucide-icon name="Name"></lucide-icon>
<lucide-icon name="$Name"></lucide-icon>
`,
},
{
@@ -101,7 +107,7 @@ import { LucideAngularModule, PascalCase } from 'lucide-angular';
@import ('~lucide-static/font/Lucide.css');
</style>
<div class="icon-Name"></div>
<div class="icon-$Name"></div>
`,
},
];

View File

@@ -0,0 +1,161 @@
import { bundledLanguages, type ThemeRegistration } from 'shikiji';
import { getHighlighter } from 'shikiji';
type CodeExampleType = {
title: string;
language: string;
code: string;
}[];
const getIconCodes = (): CodeExampleType => {
return [
{
language: 'js',
title: 'Vanilla',
code: `\
import { createIcons, icons } from 'lucide';
import { $Name } from '@lucide/lab';
createIcons({
icons: {
$Name
}
});
document.body.append('<i data-lucide="$Name"></i>');\
`,
},
{
language: 'tsx',
title: 'React',
code: `import { Icon } from 'lucide-react';
import { $Name } from '@lucide/lab';
const App = () => {
return (
<Icon iconNode={$Name} />
);
};
export default App;
`,
},
{
language: 'vue',
title: 'Vue',
code: `<script setup>
import { Icon } from 'lucide-vue-next';
import { $Name } from '@lucide/lab';
</script>
<template>
<Icon :iconNode="burger" />
</template>
`,
},
{
language: 'svelte',
title: 'Svelte',
code: `<script>
import { Icon } from 'lucide-svelte';
import { $Name } from '@lucide/lab';
</script>
<Icon iconNode={burger} />
`,
},
{
language: 'tsx',
title: 'Preact',
code: `import { Icon } from 'lucide-preact';
import { $Name } from '@lucide/lab';
const App = () => {
return (
<Icon iconNode={$Name} />
);
};
export default App;
`,
},
{
language: 'tsx',
title: 'Solid',
code: `import { Icon } from 'lucide-solid';
import { $Name } from '@lucide/lab';
const App = () => {
return (
<Icon iconNode={$Name} />
);
};
export default App;
`,
},
{
language: 'tsx',
title: 'Angular',
code: `// app.module.ts
import { LucideAngularModule, $PascalCase } from 'lucide-angular';
import { $Name } from '@lucide/lab';
@NgModule({
imports: [
LucideAngularModule.pick({ $Name })
],
})
// app.component.html
<lucide-icon name="$Name"></lucide-icon>
`,
},
];
};
export type ThemeOptions =
| ThemeRegistration
| { light: ThemeRegistration; dark: ThemeRegistration };
const highLightCode = async (code: string, lang: string, active?: boolean) => {
const highlighter = await getHighlighter({
themes: ['github-light', 'github-dark'],
langs: Object.keys(bundledLanguages),
});
const highlightedCode = highlighter
.codeToHtml(code, {
lang,
themes: {
light: 'github-light',
dark: 'github-dark',
},
defaultColor: false,
})
.replace('shiki-themes', 'shiki-themes vp-code');
return `<div class="language-${lang} ${active ? 'active' : ''}">
<button title="Copy Code" class="copy"></button>
<span class="lang">${lang}</span>
${highlightedCode}
</div>`;
};
export default async function createCodeExamples() {
const codes = getIconCodes();
const codeExamplePromises = codes.map(async ({ title, language, code }, index) => {
const isFirst = index === 0;
const codeString = await highLightCode(code, language, isFirst);
return {
title,
language: language,
code: codeString,
};
});
return Promise.all(codeExamplePromises);
}

View File

@@ -0,0 +1,32 @@
import { bundledLanguages, type ThemeRegistration } from 'shikiji';
import { getHighlighter } from 'shikiji';
export type ThemeOptions =
| ThemeRegistration
| { light: ThemeRegistration; dark: ThemeRegistration };
const highLightCode = async (code: string, lang: string, active?: boolean) => {
const highlighter = await getHighlighter({
themes: ['github-light', 'github-dark'],
langs: Object.keys(bundledLanguages),
});
const highlightedCode = highlighter
.codeToHtml(code, {
lang,
themes: {
light: 'github-light',
dark: 'github-dark',
},
defaultColor: false,
})
.replace('shiki-themes', 'shiki-themes vp-code');
return `<div class="language-${lang} ${active ? 'active' : ''}">
<button title="Copy Code" class="copy"></button>
<span class="lang">${lang}</span>
${highlightedCode}
</div>`;
};
export default highLightCode;

View File

@@ -0,0 +1,5 @@
export type CodeExampleType = {
title: string;
language: string;
code: string;
}[];

View File

@@ -0,0 +1,90 @@
<script setup lang="ts">
import { computed } from 'vue';
const props = defineProps<{
label: string
id: string
value: string
modelValue: string | string[]
}>()
const emit = defineEmits(['change', 'input', 'update:modelValue'])
const model = computed({
get: () => {
if (Array.isArray(props.modelValue)) {
return props.modelValue.includes(props.value)
}
return props.modelValue === props.value
},
set: (value: string) => {
if (Array.isArray(props.modelValue)) {
const newValue = [...props.modelValue]
const index = newValue.indexOf(props.value)
if (value) {
if (index === -1) {
newValue.push(props.value)
}
} else {
if (index !== -1) {
newValue.splice(index, 1)
}
}
emit('update:modelValue', newValue)
} else {
emit('update:modelValue', value)
}
}
})
</script>
<template>
<div class="checkbox-wrapper">
<input
type="checkbox"
class="checkbox"
ref="input"
:id="id"
v-model="model"
v-bind="$attrs"
/>
<label :for="id" class="checkbox-label">
{{ label }}
</label>
</div>
</template>
<style scoped>
.checkbox-wrapper {
display: flex;
align-items: center;
gap: 8px;
}
.checkbox-label {
line-height: 20px;
font-size: 13px;
color: var(--vt-c-text-1);
transition: color .5s;
display: block;
}
.checkbox {
-webkit-appearance: none;
appearance: none;
width: 16px;
height: 16px;
cursor: pointer;
border: 1px solid var(--vp-input-border-color);
background-color: var(--vp-input-switch-bg-color);
border-radius: 4px;
}
.checkbox:checked {
border-color: transparent;
background: url("data:image/svg+xml,%3Csvg width='12px' height='12px' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E")
center no-repeat var(--vp-c-brand);;
}
</style>

View File

@@ -3,7 +3,7 @@ export interface TeamMember {
name: string
title: string
image: string
sponsor: string
sponsor?: string
socialLinks: DefaultTheme.SocialLink[]
}
</script>

View File

@@ -6,6 +6,7 @@ import { isActive } from 'vitepress/dist/client/shared'
import { useActiveAnchor } from '../../composables/useActiveAnchor'
import { data } from './CategoryList.data'
import CategoryListItem from './CategoryListItem.vue'
import SidebarTitle from './SidebarTitle.vue'
import { useCategoryView } from '../../composables/useCategoryView'
const { page } = useData()
@@ -46,10 +47,13 @@ watch(headers, () => {
<template>
<div class="category-list" ref="container">
<VPLink class="sidebar-title" href="/icons/" :class="{ 'active': overviewIsActive } ">
<SidebarTitle>
View
</SidebarTitle>
<VPLink class="sidebar-link sidebar-text" href="/icons/" :class="{ 'active': overviewIsActive } ">
All
</VPLink>
<VPLink class="sidebar-title" href="/icons/categories" :class="{ 'active': categoriesIsActive } ">
<VPLink class="sidebar-link sidebar-text" href="/icons/categories" :class="{ 'active': categoriesIsActive } ">
Categories
</VPLink>
<div class="content">
@@ -62,17 +66,20 @@ watch(headers, () => {
</template>
<style scoped>
.sidebar-title {
font-weight: 500;
color: var(--vp-c-text-2);
margin-bottom: 6px;
.sidebar-text {
line-height: 24px;
font-size: 14px;
display: block;
transition: color 0.25s;
padding: 4px 0;
}
.sidebar-title:hover, .sidebar-title.active {
.sidebar-link {
font-weight: 500;
color: var(--vp-c-text-2);
}
.sidebar-link:hover, .sidebar-link.active {
color: var(--vp-c-brand);
}
.content {

View File

@@ -11,21 +11,32 @@ import IconInfo from './IconInfo.vue';
import Badge from '../base/Badge.vue';
import { computedAsync } from '@vueuse/core';
import { satisfies } from 'semver';
import { useExternalLibs } from '../../composables/useExternalLibs';
const props = defineProps<{
iconName: string | null
}>()
const { externalIconNodes } = useExternalLibs()
const { go } = useRouter()
const icon = computedAsync<IconEntity | null>(async () => {
if (props.iconName) {
try {
if (props.iconName.includes(':')) {
const [library, name] = props.iconName.split(':')
return externalIconNodes.value[library].find((icon) => icon.name === name)
} else {
return (await import(`../../../data/iconDetails/${props.iconName}.ts`)).default as IconEntity
}
} catch (err) {
if (!props.iconName.includes(':')) {
go(`/icons/${props.iconName}`)
}
}
}
return null
}, null)
@@ -56,7 +67,7 @@ const Expand = createLucideIcon('Expand', expand)
class="version"
:href="releaseTagLink(icon.createdRelease.version)"
>v{{ icon.createdRelease.version }}</Badge>
<IconButton @click="go(`/icons/${icon.name}`)">
<IconButton @click="go(icon.externalLibrary ? `/icons/${icon.externalLibrary}/${icon.name}` : `/icons/${icon.name}`)">
<component :is="Expand" />
</IconButton>
<IconButton @click="onClose">

View File

@@ -25,8 +25,10 @@ function setActiveIcon(name: string) {
:key="icon.name"
>
<IconItem
v-bind="icon"
@setActiveIcon="setActiveIcon(icon.name)"
:iconNode="icon.iconNode"
:name="icon.name"
:externalLibrary="icon.externalLibrary"
@setActiveIcon="setActiveIcon"
:active="activeIcon === icon.name"
customizable
:overlayMode="overlayMode"

View File

@@ -7,6 +7,8 @@ import CopyCodeButton from './CopyCodeButton.vue';
import VPButton from 'vitepress/dist/client/theme-default/components/VPButton.vue';
import {useData, useRouter} from 'vitepress';
import { computed } from 'vue';
import createLucideIcon from 'lucide-vue-next/src/createLucideIcon';
import { diamond } from '../../../data/iconNodes'
const props = defineProps<{
icon: IconEntity
@@ -20,13 +22,21 @@ const tags = computed(() => {
if (!props.icon || !props?.icon?.tags) return []
return props.icon.tags.join(' • ')
})
const DiamondIcon = createLucideIcon('Diamond', diamond)
</script>
<template>
<div class="icon-info">
<div class="icon-name-wrapper">
<IconDetailName class="icon-name">
{{ icon.name }}
</IconDetailName>
<div v-if="icon.externalLibrary" class="icon-external-lib">
<DiamondIcon fill="currentColor" :size="12"/>
{{ icon.externalLibrary }}
</div>
</div>
<div class="tags-scroller" v-if="tags.length">
<p class="icon-tags horizontal-scroller">
{{ tags }}
@@ -44,10 +54,10 @@ const tags = computed(() => {
<div class="group buttons">
<VPButton
v-if="!page?.relativePath?.startsWith?.(`icons/${icon.name}`)"
:href="`/icons/${icon.name}`"
v-if="!page?.relativePath?.startsWith?.(icon.externalLibrary ? `icons/${icon.externalLibrary}/${icon.name}`: `icons/${icon.name}`)"
:href="icon.externalLibrary ? `/icons/${icon.externalLibrary}/${icon.name}`: `/icons/${icon.name}`"
text="See in action"
@click="go(`/icons/${icon.name}`)"
@click="go(icon.externalLibrary ? `/icons/${icon.externalLibrary}/${icon.name}`: `/icons/${icon.name}`)"
/>
<CopySVGButton :name="icon.name" :popoverPosition="popoverPosition"/>
<CopyCodeButton :name="icon.name" :popoverPosition="popoverPosition"/>
@@ -67,9 +77,27 @@ const tags = computed(() => {
text-transform: capitalize;
}
.icon-name {
margin-right: -36px;
}
.icon-name-wrapper {
display: flex;
align-items: center;
gap: 2px;
margin-bottom: 4px;
}
.icon-external-lib {
color: var(--vp-c-brand-dark);
padding: 4px 12px;
font-size: 16px;
font-weight: 600;
line-height: 28px;
display: flex;
gap: 8px;
align-items: center;
}
.icon-tags {
font-size: 16px;
color: var(--vp-c-text-2);

View File

@@ -6,6 +6,7 @@ import { useRouter } from 'vitepress';
import getSVGIcon from '../../utils/getSVGIcon';
import useConfetti from '../../composables/useConfetti';
import Tooltip from '../base/Tooltip.vue';
import { diamond } from '../../../data/iconNodes'
const downloadText = 'Download!'
const copiedText = 'Copied!'
@@ -16,6 +17,7 @@ const props = defineProps<{
name: string;
iconNode: IconNode;
active: boolean;
externalLibrary?: string;
customizable?: boolean;
overlayMode?: boolean
hideIcon?: boolean
@@ -33,8 +35,9 @@ const icon = computed(() => {
return createLucideIcon(props.name, props.iconNode)
})
async function navigateToIcon(event) {
const href = computed(() => props.externalLibrary ? `/icons/${props.externalLibrary}/${props.name}` : `/icons/${props.name}`)
async function navigateToIcon(event) {
if (event.shiftKey) {
event.preventDefault()
const svgString = getSVGIcon(event.target.firstChild, {
@@ -50,13 +53,16 @@ async function navigateToIcon(event) {
if(props.overlayMode && showOverlay.value) {
event.preventDefault()
window.history.pushState({}, '', `/icons/${props.name}`)
emit('setActiveIcon', props.name)
window.history.pushState({}, '', props.externalLibrary ? `/icons/${props.externalLibrary}/${props.name}` : `/icons/${props.name}`)
emit('setActiveIcon', props.externalLibrary ? `${props.externalLibrary}:${props.name}`: props.name)
} else {
event.preventDefault()
go(`/icons/${props.name}`)
go(props.externalLibrary ? `/icons/${props.externalLibrary}/${props.name}` : `/icons/${props.name}`)
}
}
const DiamondIcon = createLucideIcon('Diamond', diamond)
</script>
<template>
@@ -66,7 +72,7 @@ async function navigateToIcon(event) {
@click="navigateToIcon"
:class="{ active, animate }"
:aria-label="name"
:href="`/icons/${props.name}`"
:data-confetti-text="confettiText"
ref="ref"
>
@@ -80,6 +86,13 @@ async function navigateToIcon(event) {
}"
/>
</KeepAlive>
<div
v-if="externalLibrary"
class="floating-diamond"
aria-hidden="true"
>
<DiamondIcon fill="currentColor" :size="8"/>
</div>
</a>
</Tooltip>
</template>
@@ -88,6 +101,7 @@ async function navigateToIcon(event) {
<style scoped>
.icon-button {
position: relative;
display: inline-block;
border: 1px solid transparent;
text-align: center;
@@ -104,6 +118,13 @@ async function navigateToIcon(event) {
color: var(--vp-c-text-1);
}
.floating-diamond {
position: absolute;
top: 4px;
right: 4px;
color: var(--vp-c-brand);
}
.confetti-button:before,
.confetti-button:after {
z-index: 100;

View File

@@ -19,7 +19,7 @@ export type CategoryRow = CategoryNameRow | CategoryIconsRow;
import IconGrid from './IconGrid.vue'
defineProps<{
activeIconName: string
activeIconName: string | null
categoryRow: CategoryRow
}>()

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, computed, defineAsyncComponent, onMounted } from 'vue';
import { ref, computed, defineAsyncComponent, onMounted, watch, watchEffect } from 'vue';
import type { IconEntity, Category } from '../../types';
import useSearch from '../../composables/useSearch';
import InputSearch from '../base/InputSearch.vue';
@@ -69,7 +69,7 @@ const categories = computed(() => {
return props.categories
.map(({ name, title }) => {
const categoryIcons = props.icons.filter((icon) => {
const iconCategories = props.iconCategories[icon.name];
const iconCategories = icon?.externalLibrary ? icon.categories : props.iconCategories[icon.name]
return iconCategories?.includes(name);
});
@@ -140,6 +140,12 @@ function handleCloseDrawer() {
window.history.pushState({}, '', '/icons/categories');
}
watchEffect(() => {
console.log(props.icons.find((icon) => icon.name === 'burger'));
});
</script>
<template>

View File

@@ -0,0 +1,47 @@
<script setup lang="ts">
import Checkbox from '../base/Checkbox.vue'
import SidebarTitle from './SidebarTitle.vue'
import { useExternalLibs } from '../../composables/useExternalLibs';
import { ExternalLibs } from '../../types';
interface ExternalLibrary {
name: string;
value: ExternalLibs;
}
const externalLibraries: ExternalLibrary[] = [
{
name: 'Lab',
value: 'lab'
},
];
const { selectedLibs } = useExternalLibs();
</script>
<template>
<div class="external-library-select">
<SidebarTitle>
Include external libs
</SidebarTitle>
<ul>
<li
v-for="library in externalLibraries"
:key="library.name"
>
<Checkbox
:label="library.name"
:id="library.name"
v-model="selectedLibs"
:value="library.value"
/>
</li>
</ul>
</div>
</template>
<style scoped>
.external-library-select {
margin-bottom: 24px;
}
</style>

View File

@@ -0,0 +1,19 @@
<template>
<h2 class="sidebar-title sidebar-text">
<slot />
</h2>
</template>
<style scoped>
.sidebar-title {
font-weight: 700;
color: var(--vp-c-text-1);
}
.sidebar-text {
line-height: 24px;
font-size: 14px;
display: block;
transition: color 0.25s;
padding: 4px 0;
}
</style>

View 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;
}

View File

@@ -0,0 +1,29 @@
import { computed } from 'vue';
import { useExternalLibs } from '~/.vitepress/theme/composables/useExternalLibs';
import { IconEntity } from '../types';
const useIconsWithExternalLibs = (initialIcons?: IconEntity[]) => {
const { externalIconNodes } = useExternalLibs();
return computed(() => {
let icons = [];
if (initialIcons) {
icons = icons.concat(initialIcons);
}
const externalIconNodesArray = Object.values(externalIconNodes.value);
if (externalIconNodesArray?.length) {
externalIconNodesArray.forEach((iconNodes) => {
if (iconNodes?.length) {
icons = icons.concat(iconNodes);
}
});
}
return icons;
});
};
export default useIconsWithExternalLibs;

View File

@@ -7,6 +7,7 @@ import HomeHeroIconsCard from './components/home/HomeHeroIconsCard.vue';
import HomeHeroBefore from './components/home/HomeHeroBefore.vue';
import { ICON_STYLE_CONTEXT, iconStyleContext } from './composables/useIconStyle';
import { CATEGORY_VIEW_CONTEXT, categoryViewContext } from './composables/useCategoryView';
import { EXTERNAL_LIBS_CONTEXT, externalLibContext } from './composables/useExternalLibs';
const theme: Partial<Theme> = {
extends: DefaultTheme,
@@ -20,6 +21,7 @@ const theme: Partial<Theme> = {
enhanceApp({ app }) {
app.provide(ICON_STYLE_CONTEXT, iconStyleContext);
app.provide(CATEGORY_VIEW_CONTEXT, categoryViewContext);
app.provide(EXTERNAL_LIBS_CONTEXT, externalLibContext);
},
};

View File

@@ -3,6 +3,7 @@ import { useData } from 'vitepress'
import CategoryList from '../components/icons/CategoryList.vue'
import SidebarIconCustomizer from '../components/icons/SidebarIconCustomizer.vue'
import ExternalLibrarySelect from '../components/icons/SidebarExternalLibrarySelect.vue'
const { page } = useData()
@@ -11,6 +12,7 @@ const { page } = useData()
<template>
<div>
<SidebarIconCustomizer v-if="page?.relativePath?.startsWith?.('icons')"/>
<ExternalLibrarySelect v-if="page?.relativePath?.startsWith?.('icons')"/>
<CategoryList v-if="page?.relativePath?.startsWith?.('icons')"/>
</div>
</template>

View File

@@ -1,13 +1,18 @@
export type IconNode = [elementName: string, attrs: Record<string, string>][];
export type IconNodeWithKeys = [elementName: string, attrs: Record<string, string>, key: string][];
export interface IconEntity {
name: string;
export interface IconMetaData {
tags: string[];
categories: string[];
contributors: string[];
aliases?: string[];
}
export type ExternalLibs = 'lab';
export interface IconEntity extends IconMetaData {
name: string;
iconNode: IconNode;
externalLibrary?: ExternalLibs;
createdRelease?: Release;
changedRelease?: Release;
}

View File

@@ -87,7 +87,7 @@ import { burger } from '@lucide/lab';
</script>
<template>
<Icon :iconNode={burger} />
<Icon :iconNode="burger" />
</template>
```

View File

@@ -10,14 +10,14 @@ sidebar: true
<script setup>
import { computed } from 'vue'
import { useData } from 'vitepress'
import IconPreview from '../.vitepress/theme/components/icons/IconPreview.vue'
import IconPreviewSmall from '../.vitepress/theme/components/icons/IconPreviewSmall.vue'
import IconInfo from '../.vitepress/theme/components/icons/IconInfo.vue'
import IconContributors from '../.vitepress/theme/components/icons/IconContributors.vue'
import RelatedIcons from '../.vitepress/theme/components/icons/RelatedIcons.vue'
import CodeGroup from '../.vitepress/theme/components/base/CodeGroup.vue'
import Badge from '../.vitepress/theme/components/base/Badge.vue'
import Label from '../.vitepress/theme/components/base/Label.vue'
import IconPreview from '~/.vitepress/theme/components/icons/IconPreview.vue'
import IconPreviewSmall from '~/.vitepress/theme/components/icons/IconPreviewSmall.vue'
import IconInfo from '~/.vitepress/theme/components/icons/IconInfo.vue'
import IconContributors from '~/.vitepress/theme/components/icons/IconContributors.vue'
import RelatedIcons from '~/.vitepress/theme/components/icons/RelatedIcons.vue'
import CodeGroup from '~/.vitepress/theme/components/base/CodeGroup.vue'
import Badge from '~/.vitepress/theme/components/base/Badge.vue'
import Label from '~/.vitepress/theme/components/base/Label.vue'
import VPButton from 'vitepress/dist/client/theme-default/components/VPButton.vue';
import { data } from './codeExamples.data'
import { camelCase, startCase } from 'lodash-es'
@@ -32,7 +32,7 @@ const tabs = computed(() => data.codeExamples?.map(
const codeExample = computed(() => data.codeExamples?.map(
(codeExample) => {
const pascalCase = startCase(camelCase( params.value.name)).replace(/\s/g, '')
return codeExample.code.replace(/PascalCase/g, pascalCase).replace(/Name/g, params.value.name)
return codeExample.code.replace(/\$PascalCase/g, pascalCase).replace(/\$Name/g, params.value.name)
}
).join('') ?? []
)
@@ -100,7 +100,10 @@ function releaseTagLink(version) {
</div>
</div>
<RelatedIcons :icons="params.relatedIcons" />
<RelatedIcons
v-if="params.relatedIcons"
:icons="params.relatedIcons"
/>
<style module>
.preview {

View File

@@ -10,13 +10,16 @@ import { data } from './icons.data.ts'
import { data as categoriesData } from './categories.data.ts'
import PageContainer from '../.vitepress/theme/components/PageContainer.vue'
import IconsCategoryOverview from '../.vitepress/theme/components/icons/IconsCategoryOverview.vue'
import useIconsWithExternalLibs from '~/.vitepress/theme/composables/useIconsWithExternalLibs'
const icons = useIconsWithExternalLibs(data.icons)
</script>
<div class="VPDoc content">
<PageContainer>
<IconsCategoryOverview
:categories="categoriesData.categories"
:icons="data.icons"
:icons="icons"
:iconCategories="categoriesData.iconCategories"
/>
</PageContainer>

View File

@@ -1,11 +1,9 @@
import createCodeExamples from '../.vitepress/lib/createCodeExamples';
import createCodeExamples from '../.vitepress/lib/codeExamples/createCodeExamples';
export default {
async load() {
const codeExamples = await createCodeExamples();
// const randomIcons = Array.from({ length: 200 }, () => getRandomItem(icons))
return {
codeExamples,
};

View File

@@ -10,13 +10,17 @@ head:
---
<script setup>
import { computed } from 'vue'
import { data } from './icons.data.ts'
import IconsOverview from '../.vitepress/theme/components/icons/IconsOverview.vue'
import PageContainer from '../.vitepress/theme/components/PageContainer.vue'
import IconsOverview from '~/.vitepress/theme/components/icons/IconsOverview.vue'
import PageContainer from '~/.vitepress/theme/components/PageContainer.vue'
import useIconsWithExternalLibs from '~/.vitepress/theme/composables/useIconsWithExternalLibs'
const icons = useIconsWithExternalLibs(data.icons)
</script>
<div class="VPDoc content">
<PageContainer>
<IconsOverview :icons="data.icons" />
<IconsOverview :icons="icons" />
</PageContainer>
</div>

10
docs/icons/lab/[name].md Normal file
View File

@@ -0,0 +1,10 @@
---
layout: doc
footer: false
aside: false
editLink: false
next: false
prev: false
sidebar: true
---
<!--@include: ../[name].md -->

View File

@@ -0,0 +1,19 @@
import { IconEntity } from '../../.vitepress/theme/types';
export default {
paths: async () => {
const iconDetailsResponse = await fetch('https://lab.lucide.dev/api/icon-details');
const iconDetails = (await iconDetailsResponse.json()) as Record<string, IconEntity>;
return Object.values(iconDetails).map((iconEntity) => {
const params = {
externalLibrary: 'lab',
...iconEntity,
};
return {
params,
};
});
},
};

View File

@@ -0,0 +1,11 @@
import createCodeExamples from '../../.vitepress/lib/codeExamples/createLabCodeExamples';
export default {
async load() {
const codeExamples = await createCodeExamples();
return {
codeExamples,
};
},
};

View File

@@ -5,5 +5,8 @@
"allowImportingTsExtensions": true,
"allowSyntheticDefaultImports": true,
"noEmit": true,
"paths": {
"~/.vitepress/*": ["./.vitepress/*"],
},
},
}