Skip to content

Commit 0a25780

Browse files
hyjklmnantfu
andauthored
feat: add the pnpm npm and yarn install commands (#190)
Co-authored-by: Anthony Fu <github@antfu.me>
1 parent ed9d3c1 commit 0a25780

File tree

6 files changed

+106
-17
lines changed

6 files changed

+106
-17
lines changed

src/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ declare module 'vue' {
2323
IconDetail: typeof import('./components/IconDetail.vue')['default']
2424
Icons: typeof import('./components/Icons.vue')['default']
2525
IconSet: typeof import('./components/IconSet.vue')['default']
26+
InstallIconSet: typeof import('./components/InstallIconSet.vue')['default']
2627
Modal: typeof import('./components/Modal.vue')['default']
2728
ModalDialog: typeof import('./components/ModalDialog.vue')['default']
2829
Navbar: typeof import('./components/Navbar.vue')['default']

src/components/IconDetail.vue

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { activeMode, copyPreviewColor, getTransformedId, inBag, preferredCase, p
55
import { Download } from '../utils/pack'
66
import { dataUrlToBlob } from '../utils/dataUrlToBlob'
77
import { idCases } from '../utils/case'
8+
import InstallIconSet from './InstallIconSet.vue'
89
910
const props = defineProps({
1011
icon: {
@@ -122,20 +123,20 @@ const collection = computed(() => {
122123
</div>
123124
<div class="px-6 py-2 mb-2 md:px-2 md:py-4">
124125
<button
125-
class="text-gray-500 hover:text-primary text-sm dark:text-dark-500 !outline-none"
126+
class="op35 hover:text-primary hover:op100 text-sm !outline-none"
126127
@click="showHelp = !showHelp"
127128
>
128129
How to use the icon?
129130
</button>
130-
<div class="flex text-gray-700 relative font-mono dark:text-dark-900">
131+
<div class="flex op75 relative font-mono">
131132
{{ transformedId }}
132133
<IconButton icon="carbon:copy" class="ml-2" @click="copy('id')" />
133134
<IconButton icon="carbon:chevron-up" class="ml-2" @click="showCaseSelect = !showCaseSelect" />
134135
<div class="flex-auto" />
135136
<div
136137
v-if="showCaseSelect"
137138
ref="caseSelector"
138-
class="absolute left-0 bottom-1.8em text-sm rounded shadow p-2 bg-white dark:bg-dark-100 dark:border dark:border-dark-200"
139+
class="absolute left-0 bottom-1.8em text-sm rounded shadow p-2 bg-base dark:border dark:border-dark-200"
139140
>
140141
<div
141142
v-for="[k, v] of Object.entries(idCases)"
@@ -162,7 +163,7 @@ const collection = computed(() => {
162163
>{{ collection.license.title }}</a>
163164
</div>
164165

165-
<p v-if="showCollection && collection" class="flex mb-1 text-gray-500 text-sm">
166+
<p v-if="showCollection && collection" class="flex mb-1 op50 text-sm">
166167
Collection:
167168
<RouterLink
168169
class="ml-1 text-gray-600 hover:text-gray-700 dark:text-gray-300 dark:hover:text-gray-200"
@@ -178,7 +179,7 @@ const collection = computed(() => {
178179
inline-block leading-1em border border-base my-2 mr-2 font-sans pl-2 pr-3 py-1 rounded-full text-sm cursor-pointer
179180
hover:bg-gray-50 dark:hover:bg-dark-200
180181
"
181-
:class="inBag(icon) ? 'text-primary' : 'text-gray-500'"
182+
:class="inBag(icon) ? 'text-primary' : 'op50'"
182183
@click="toggleBag(icon)"
183184
>
184185
<template v-if="inBag(icon)">
@@ -197,7 +198,7 @@ const collection = computed(() => {
197198
inline-block leading-1em border border-base my-2 mr-2 font-sans pl-2 pr-3 py-1 rounded-full text-sm cursor-pointer
198199
hover:bg-gray-50 dark:hover:bg-dark-200
199200
"
200-
:class="activeMode === 'select' ? 'text-primary' : 'text-gray-500'"
201+
:class="activeMode === 'select' ? 'text-primary' : 'op50'"
201202
@click="toggleSelectingMode"
202203
>
203204
<Icon class="inline-block text-lg align-middle" icon="carbon:list-checked" />
@@ -209,7 +210,7 @@ const collection = computed(() => {
209210
inline-block leading-1em border border-base my-2 mr-2 font-sans pl-2 pr-3 py-1 rounded-full text-sm cursor-pointer
210211
hover:bg-gray-50 dark:hover:bg-dark-200
211212
"
212-
:class="copyPreviewColor ? 'text-primary' : 'text-gray-500'"
213+
:class="copyPreviewColor ? 'text-primary' : 'op50'"
213214
@click="copyPreviewColor = !copyPreviewColor"
214215
>
215216
<Icon v-if="!copyPreviewColor" class="inline-block text-lg align-middle" icon="carbon:checkbox" />
@@ -220,7 +221,7 @@ const collection = computed(() => {
220221

221222
<div class="flex flex-wrap mt-2">
222223
<div class="mr-4">
223-
<div class="my-1 text-gray-500 text-sm">
224+
<div class="my-1 op50 text-sm">
224225
Snippets
225226
</div>
226227
<button class="btn small mr-1 mb-1 opacity-75" @click="copy('svg')">
@@ -240,7 +241,7 @@ const collection = computed(() => {
240241
</button>
241242
</div>
242243
<div class="mr-4">
243-
<div class="my-1 text-gray-500 text-sm">
244+
<div class="my-1 op50 text-sm">
244245
Components
245246
</div>
246247
<button class="btn small mr-1 mb-1 opacity-75" @click="copy('vue')">
@@ -275,7 +276,7 @@ const collection = computed(() => {
275276
</button>
276277
</div>
277278
<div class="mr-4">
278-
<div class="my-1 text-gray-500 text-sm">
279+
<div class="my-1 op50 text-sm">
279280
Links
280281
</div>
281282
<button class="btn small mr-1 mb-1 opacity-75" @click="copy('url')">
@@ -286,7 +287,7 @@ const collection = computed(() => {
286287
</button>
287288
</div>
288289
<div class="mr-4">
289-
<div class="my-1 text-gray-500 text-sm">
290+
<div class="my-1 op50 text-sm">
290291
Download
291292
</div>
292293
<button class="btn small mr-1 mb-1 opacity-75" @click="download('svg')">
@@ -321,7 +322,7 @@ const collection = computed(() => {
321322
</button>
322323
</div>
323324
<div class="mr-4">
324-
<div class="my-1 text-gray-500 text-sm">
325+
<div class="my-1 op50 text-sm">
325326
View on
326327
</div>
327328
<a
@@ -342,8 +343,8 @@ const collection = computed(() => {
342343
</a>
343344
</div>
344345
</div>
346+
347+
<InstallIconSet v-if="collection" :collection="collection" />
345348
</div>
346349
</div>
347350
</template>
348-
../utils/copyPng
349-
../utils/svgToPng

src/components/InstallIconSet.vue

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<script setup lang="ts">
2+
import type { PropType } from 'vue'
3+
import { ref } from 'vue'
4+
import type { CollectionMeta } from '../data'
5+
import { selectedPackageManager } from '../store'
6+
7+
const props = defineProps({
8+
collection: {
9+
type: Object as PropType<CollectionMeta>,
10+
required: true,
11+
},
12+
})
13+
14+
const managers = ['pnpm', 'npm', 'yarn', 'bun'] as const
15+
16+
const icons = {
17+
npm: 'i-logos:npm-icon',
18+
pnpm: 'i-logos:pnpm',
19+
yarn: 'i-logos:yarn',
20+
bun: 'i-logos:bun',
21+
}
22+
23+
function selectManager(packageName: string) {
24+
selectedPackageManager.value = packageName
25+
}
26+
27+
const status = ref(false)
28+
29+
async function copyText() {
30+
const text = `${selectedPackageManager.value} ${selectedPackageManager.value !== 'npm' ? 'add' : 'i'} -D @iconify-json/${props.collection.id}`
31+
status.value = true
32+
setTimeout(() => {
33+
status.value = false
34+
}, 2000)
35+
36+
if (text) {
37+
try {
38+
await navigator.clipboard.writeText(text)
39+
return true
40+
}
41+
catch {}
42+
}
43+
return false
44+
}
45+
</script>
46+
47+
<template>
48+
<div lt-md:hidden>
49+
<a
50+
href="https://iconify.design/docs/icons/json.html" target="_blank"
51+
class="my-1 text-sm mt6 block op50 hover:op100 hover:text-primary"
52+
>
53+
Install Iconify Iconset
54+
</a>
55+
<div class="border-1 border-base rounded w-100 mt1">
56+
<div flex="~ gap-4 items-center" p3 border="b base">
57+
<label
58+
v-for="manager in managers" :key="manager"
59+
flex="~ items-center gap-2"
60+
:class="[manager === selectedPackageManager ? 'op100' : 'op25']"
61+
@change="selectManager(manager)"
62+
>
63+
<input type="radio" name="manager" :value="manager" hidden>
64+
<div :class="icons[manager]" />
65+
<div mt--1>{{ manager }}</div>
66+
</label>
67+
</div>
68+
69+
<div flex="~ gap-2 items-center" p3>
70+
<code flex-auto>
71+
<span style="color:#80A665;">{{ selectedPackageManager }}</span>
72+
<span style="color:#DBD7CAEE;" />
73+
<span style="color:#B8A965;">{{ selectedPackageManager !== 'npm' ? ' add ' : ' i ' }} -D </span>
74+
<span style="color:#DBD7CAEE;" /><span style="color:#DBD7CAEE;" />
75+
<span style="color:#C98A7D;">@iconify-json/{{ props.collection.id }}</span>
76+
</code>
77+
<IconButton icon="carbon:copy" @click="copyText" />
78+
</div>
79+
<Notification :value="status">
80+
<Icon icon="mdi:check" class="inline-block mr-2 font-xl align-middle" />
81+
<span class="align-middle">Copied</span>
82+
</Notification>
83+
</div>
84+
</div>
85+
</template>

src/components/Notification.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ withDefaults(
1212
>
1313
<div
1414
class="
15-
px-4 py-1 rounded bg-white inline-block m-3 transition-all duration-300 text-primary border
16-
dark:bg-dark-100 dark:border-dark-300
15+
px-3 py-1 rounded inline-block m-3 transition-all duration-300 text-primary
16+
bg-base border border-base
17+
flex flex-inline items-center
1718
"
1819
:style="value ? {} : { transform: 'translateY(-150%)' }"
1920
:class="value ? 'shadow' : 'shadow-none'"

src/store/localstorage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const bags = useStorage<string[]>('icones-bags', [])
1919
export const activeMode = useStorage<ActiveMode>('active-mode', 'normal')
2020
export const preferredCase = useStorage<IdCase>('icones-preferfed-case', 'iconify')
2121
export const drawerCollapsed = useStorage<boolean>('icones-drawer-collapsed', false)
22+
export const selectedPackageManager = useStorage<string>('icones-package-manager', 'pnpm')
2223

2324
export const excludedCollectionIds = useStorage<string[]>('icones-excluded-collections', [])
2425
export const excludedCategories = useStorage<string[]>('icones-excluded-categories', [

unocss.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineConfig, presetAttributify, presetIcons, presetUno, transformerDir
22

33
export default defineConfig({
44
shortcuts: {
5-
'border-base': 'border-gray-200 dark:border-dark-100',
5+
'border-base': 'border-hex-888/15',
66
'border-dark-only': 'border-transparent dark:border-dark-100',
77
'bg-base': 'bg-white dark:bg-[#181818]',
88
'color-base': 'text-gray-900 dark:text-gray-300',

0 commit comments

Comments
 (0)