Skip to content

Commit c52d259

Browse files
yannbfsacrosancticdanielroe
authored
feat: add storybook playground link (npmx-dev#1624)
Co-authored-by: Scott Wu <sw@scottwu.ca> Co-authored-by: Daniel Roe <daniel@roe.dev>
1 parent 4aab312 commit c52d259

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

app/components/Package/Playgrounds.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const providerIcons: Record<string, string> = {
2020
'solid-playground': 'i-simple-icons:solid',
2121
'svelte-playground': 'i-simple-icons:svelte',
2222
'tailwind-playground': 'i-simple-icons:tailwindcss',
23+
'storybook': 'i-simple-icons:storybook',
2324
}
2425
2526
// Map provider id to color class
@@ -37,6 +38,7 @@ const providerColors: Record<string, string> = {
3738
'solid-playground': 'text-provider-solid',
3839
'svelte-playground': 'text-provider-svelte',
3940
'tailwind-playground': 'text-provider-tailwind',
41+
'storybook': 'text-provider-storybook',
4042
}
4143
4244
function getIcon(provider: string): string {

app/composables/npm/usePackage.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ export function transformPackument(
120120
license = license.type
121121
}
122122

123+
// Extract storybook field from the requested version (custom package.json field)
124+
const requestedPkgVersion = requestedVersion ? pkg.versions[requestedVersion] : null
125+
const rawStorybook = requestedPkgVersion?.storybook
126+
const storybook =
127+
rawStorybook && typeof rawStorybook === 'object' && 'url' in rawStorybook
128+
? ({ url: rawStorybook.url } as { url: string })
129+
: undefined
130+
123131
return {
124132
'_id': pkg._id,
125133
'_rev': pkg._rev,
@@ -134,6 +142,7 @@ export function transformPackument(
134142
'keywords': pkg.keywords,
135143
'repository': pkg.repository,
136144
'bugs': pkg.bugs,
145+
...(storybook && { storybook }),
137146
'requestedVersion': versionData,
138147
'versions': filteredVersions,
139148
'securityVersions': securityVersions,

app/pages/package/[[org]]/[name].vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ const { data: readmeData } = useLazyFetch<ReadmeResponse>(
109109
{ default: () => ({ html: '', mdExists: false, playgroundLinks: [], toc: [] }) },
110110
)
111111
112+
const playgroundLinks = computed(() => [
113+
...readmeData.value.playgroundLinks,
114+
// Libraries with a storybook field in package.json contain a link to their deployed playground
115+
...(pkg.value?.storybook?.url
116+
? [
117+
{
118+
url: pkg.value.storybook.url,
119+
provider: 'storybook',
120+
providerName: 'Storybook',
121+
label: 'Storybook',
122+
},
123+
]
124+
: []),
125+
])
126+
112127
const {
113128
data: readmeMarkdownData,
114129
status: readmeMarkdownStatus,
@@ -1357,10 +1372,7 @@ const showSkeleton = shallowRef(false)
13571372
/>
13581373

13591374
<!-- Playground links -->
1360-
<PackagePlaygrounds
1361-
v-if="readmeData?.playgroundLinks?.length"
1362-
:links="readmeData.playgroundLinks"
1363-
/>
1375+
<PackagePlaygrounds v-if="playgroundLinks.length" :links="playgroundLinks" />
13641376

13651377
<PackageCompatibility :engines="displayVersion?.engines" />
13661378

shared/types/npm-registry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export interface SlimPackument {
8383
'keywords'?: string[]
8484
'repository'?: { type?: string; url?: string; directory?: string }
8585
'bugs'?: { url?: string; email?: string }
86+
'storybook'?: { url: string }
8687
/** current version */
8788
'requestedVersion': SlimPackumentVersion | null
8889
/** Only includes dist-tag versions (with installScripts info added per version) */

uno.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export default defineConfig({
104104
solid: '#2C4F7C',
105105
svelte: '#FF3E00',
106106
tailwind: '#06B6D4',
107+
storybook: '#FF4785',
107108
},
108109
},
109110
animation: {

0 commit comments

Comments
 (0)