Skip to content

Commit a5003b6

Browse files
feat: ResourceListDetails doc block (#3129)
* chore: add componentGuidelinesName to package.json - components that have a valid page on the spectrum guidelines site have a componentGuidelinesName key now. - components that do not have a valid page on the spectrum guidelines site have a componentBetaName key that will point to the spectrum-contributions site. - for components that do not any guidelines, setting the componentGuidelinesName key to an empty string in the package.json will make sure the guidelines resource card doesn't render. * feat: resource list component doc block The ResourceListDetails fetches data from each storybook component's package.json, specifically utilizing the package name and optional componentGuidelinesName. It then creates links to the spectrum guidelines, github, and npm sites. If a component doesn't have a spectrum guidelines page, it uses the optional componentBetaName and the spectrum-contributions site instead. - creates new `styled` components related to the resource section, any element wrappers and links - creates ResourceListDetails doc block - creates ResourceListContent component (which are the individual resource cards) - adds some helper functions to generate SVGs corresponding to the links, switch statements, mapping text, etc. * refactor: add support for nested components this applies to form and meter. Form should no longer render a guidelines link card, and meter should navigate to its own guidelines page instead of progress bar's. * chore: pr fixes - update spacing for if() statement - render ResourceListDetails in ComponentDetails - console.warn instead of throw an error - hard codes styles for cards * refactor: svg usage - extracts SVG code to individual jsx files - imports those SVG jsx files to use a components - replaces/refactors svg functions to render new svg components * chore: update package.json - creates a `spectrum` key in each component's package.json to use in ComponentDetails - `spectrum` array holds metadata for components and/or nested components, like the componentName, the guidelineLink, and rootClass - eventually we may be able to add designLink to add Figma links to this block * refactor: resource list component fixes - reorganizes file so ResourceLinkContent and ResourceListDetails are closer to CopmonentDetails, and all fetching/processing helper functions are together - addresses missing field label guidelines link - removes some hardcoded nestedComponent code in favor for a for loop - indentation fixes * chore: break out resource link config * chore: add componentName back to package.json * docs: revert componentName in favor of docsPage: false - removed componentName from field label and progress bar package.jsons - created docsPage parameter for form in the storyMeta - refactored the nested component for loop to check if the guidelines are defined, and if docsPage is undefined. If both of those check out, render the guidelines link. Form is the only component that needed this, since it's the only nested component that doesn't have a guidelines page while its parent (field label) does. * chore: refactor to check for unique rootClass To better capture nested components, as well as components that may not have a guidelines page, this refactor double checks that the hasDocsPage prop is undefined, as well as that the spectrum.rootClass value includes a transformed component title. Adding the additional check of the rootClass helped ensure the proper guidelines link was rendering for nested components, as well as breaking when the condition was met. * chore: refactor to use meta.args.rootClass - instead of comparing a story's title (because meter didn't have a unique rootClass), compare the spectrum.rootClass to the meta.args.rootClass. This is possible now because we have updated the default args for meter to be spectrum-Meter. - removes usage or reformatTitle and hasDocsPage functions and props - adds more thorough JSDoc comments * chore: fix color loupe's root class in package.json * chore: fixes after rebase * docs: add quickaction guidelines link - white space removal * chore: add condition for deprecated component github links * chore: pr fixes - change status prop name to isDeprecated - remove unnecessary skipBorder prop * chore: do not render github cards for deprecated components --------- Co-authored-by: castastrophe <castastrophe@users.noreply.github.com>
1 parent e0c1c6a commit a5003b6

File tree

87 files changed

+753
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+753
-110
lines changed
+5
Loading
+5
Loading

.storybook/assets/images/npm_logo.svg

+11
Loading

.storybook/blocks/ComponentDetails.jsx

+165-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { useOf } from '@storybook/blocks';
22
import { ResetWrapper } from "@storybook/components";
33
import { styled } from "@storybook/theming";
44
import React, { useEffect, useState } from "react";
5-
import { Code } from "./Typography.jsx";
5+
import AdobeSVG from "../assets/images/adobe_logo.svg?raw";
6+
import GitHubSVG from "../assets/images/github_logo.svg?raw";
7+
import NpmSVG from "../assets/images/npm_logo.svg?raw";
8+
import { Body, Code, Heading } from "./Typography.jsx";
69
import { fetchToken } from "./utilities.js";
710

811
export const DList = styled.dl`
@@ -97,6 +100,45 @@ export const StatusLight = styled.span(({ variant = "positive", ...props }) => `
97100
margin-block-end: 1px;
98101
`);
99102

103+
export const ResourceSection = styled.section`
104+
display: flex;
105+
flex-flow: row wrap;
106+
align-items: center;
107+
`;
108+
109+
export const ResourceLink = styled.a`
110+
position: relative;
111+
display: inline-flex;
112+
flex-direction: row;
113+
align-items: center;
114+
margin-block-end: 16px;
115+
margin-inline-end: 16px;
116+
box-sizing: border-box;
117+
text-decoration: none;
118+
min-inline-size: 100px;
119+
border: 1px solid transparent;
120+
border-radius: 5px;
121+
border-color: rgb(230, 230, 230);
122+
overflow: hidden;
123+
color: rgb(0, 0, 0);
124+
125+
&:hover {
126+
border-color: rgb(213, 213, 213);
127+
}
128+
`;
129+
130+
export const ResourceIconWrapper = styled.div`
131+
background-color: rgba(248, 248, 248);
132+
padding: 12px;
133+
display: flex;
134+
inline-size: 40px;
135+
block-size: 40px;
136+
`;
137+
138+
export const ResourceTextWrapper = styled.div`
139+
margin-inline: 16px;
140+
`;
141+
100142
const VersionDetails = ({ tag, data = {}, isDeprecated = false, skipDate = false, skipLink = false }) => {
101143
let statusType = "notice";
102144
let statusMessage = "Not yet available on the npm registry.";
@@ -264,13 +306,104 @@ function fetchNpmData(packageName, setnpmData, setIsLoading) {
264306
}, [cache, setCache, packageName, setnpmData, setIsLoading]);
265307
}
266308

309+
const fetchLogo = (brand) => {
310+
switch(brand) {
311+
case "npm":
312+
return NpmSVG;
313+
case "GitHub":
314+
return GitHubSVG;
315+
case "Adobe":
316+
return AdobeSVG;
317+
}
318+
319+
return;
320+
}
321+
322+
/**
323+
* Displays a resource card containing text and an image that links to a particular resource.
324+
*
325+
* @param {string} heading - heading of the resource card
326+
* @param {string} alt - additional description of the resource card
327+
* @param {string} image - the SVG image
328+
* @param {string} href - optional link to the resource, found in packageJson?.spectrum?.guidelines
329+
* @returns {string}
330+
*/
331+
export const ResourceLinkContent = ({ heading, alt, logo, href }) => {
332+
if (!href) return;
333+
334+
return (
335+
<ResourceLink href={href} className="sb-unstyled" title={alt}>
336+
<ResourceIconWrapper dangerouslySetInnerHTML={{ __html: fetchLogo(logo) }} />
337+
<ResourceTextWrapper>
338+
{heading ? <Heading size="xs">{heading}</Heading> : ""}
339+
{alt ? <Body size="s">{alt}</Body> : ""}
340+
</ResourceTextWrapper>
341+
</ResourceLink>
342+
);
343+
};
344+
345+
/**
346+
* Displays the list of relevant component links (to NPM, repo, guidelines, etc).
347+
*
348+
* The rootClassName is read from the story's default args, found in the story's metadata.
349+
*
350+
* The for loop is particularly helpful to match guidelines links for any nested components
351+
* (i.e. meter, form). We need to check that the rootClassName matches the rootClass found
352+
* in the packageJson.spectrum, to link to the correct guidelines page.
353+
*
354+
* Deprecated components should not show a GitHub resource card.
355+
*
356+
* @param {string} packageName - packageName sourced from packageJson?.name
357+
* @param {string[]} spectrumData - an array of objects sourced from packageJson?.spectrum
358+
* @param {string} rootClassName - a component's default rootClass arg
359+
* @returns {string}
360+
*/
361+
export const ResourceListDetails = ({ packageName, spectrumData = [], rootClassName, isDeprecated }) => {
362+
if (!packageName) return;
363+
364+
let href;
365+
366+
for(let i = 0; i < spectrumData?.length; i++) {
367+
if (spectrumData[i]?.guidelines && spectrumData[i]?.rootClass === rootClassName) {
368+
href = spectrumData[i]?.guidelines;
369+
}
370+
}
371+
372+
return (
373+
<ResourceSection className="sb-unstyled">
374+
{href ?
375+
<ResourceLinkContent
376+
className="doc-block-resource-cards"
377+
heading="View guidelines"
378+
alt="Spectrum website"
379+
logo="Adobe"
380+
href={href}/> : ""}
381+
<ResourceLinkContent
382+
className="doc-block-resource-cards"
383+
heading="View package"
384+
alt="npm"
385+
logo="npm"
386+
href={`https://npmjs.com/${packageName}`}/>
387+
{!isDeprecated ?
388+
<ResourceLinkContent
389+
className="doc-block-resource-cards"
390+
heading="View repository"
391+
alt="GitHub"
392+
logo="GitHub"
393+
href={`https://github.com/adobe/spectrum-css/tree/main/components/${packageName.split('/').pop()}`}/> : ""}
394+
</ResourceSection>
395+
)
396+
};
397+
267398
/**
268399
* Displays the current version number of the component. The version is read from
269400
* the component's parameters, where it was sourced from the package.json file.
270401
*
271-
* Also displays a component status of "deprecated" if it is set in the story's
402+
* Displays a component status of "deprecated" if it is set in the story's
272403
* parameters.
273404
*
405+
* Displays the list of relevant component links (to NPM, repo, guidelines, etc).
406+
*
274407
* Usage of this doc block within MDX template(s):
275408
* <ComponentDetails />
276409
*/
@@ -279,8 +412,16 @@ export const ComponentDetails = () => {
279412

280413
const isDeprecated = storyMeta?.csfFile?.meta?.parameters?.status?.type == "deprecated";
281414
const packageJson = storyMeta?.csfFile?.meta?.parameters?.packageJson ?? {};
415+
const rootClassName = storyMeta?.csfFile?.meta?.args?.rootClass ?? "";
416+
417+
const packageName = packageJson?.name;
418+
419+
if (!packageName) return;
282420

283-
if (!packageJson?.name) return;
421+
let spectrumData = packageJson?.spectrum;
422+
if (typeof spectrumData === "string") {
423+
spectrumData = [spectrumData];
424+
}
284425

285426
const [isLoading, setIsLoading] = useState(true);
286427
const [npmData, setnpmData] = useState({});
@@ -291,26 +432,28 @@ export const ComponentDetails = () => {
291432

292433
return (
293434
<ResetWrapper>
294-
{ !isLoading ?
295-
<DList className="docblock-metadata sb-unstyled">
296-
{ isDeprecated
297-
? <>
298-
<DTerm key={'status'}>Status:</DTerm>
299-
<DDefinition key={'status-data'}>Deprecated</DDefinition>
300-
</>
301-
: ""
302-
}
303-
{ showLocalVersion
304-
? <>
305-
<DTerm key={'version-label'}>Local version:</DTerm>
306-
<DDefinition key={'version'}><VersionDetails tag={"local"} data={allVersions && allVersions.find(([tag]) => tag === "local")?.[1]} isDeprecated={isDeprecated} /></DDefinition>
435+
{ !isLoading ? <>
436+
<DList className="docblock-metadata sb-unstyled">
437+
{ isDeprecated
438+
? <>
439+
<DTerm key={'status'}>Status:</DTerm>
440+
<DDefinition key={'status-data'}>Deprecated</DDefinition>
441+
</>
442+
: ""
443+
}
444+
{ showLocalVersion
445+
? <>
446+
<DTerm key={'version-label'}>Local version:</DTerm>
447+
<DDefinition key={'version'}><VersionDetails tag={"local"} data={allVersions && allVersions.find(([tag]) => tag === "local")?.[1]} isDeprecated={isDeprecated} /></DDefinition>
448+
</>
449+
: <>
450+
<DTerm key={'version-label'}>Latest version:</DTerm>
451+
<DDefinition key={'version'}><VersionDetails tag={"latest"} data={allVersions && allVersions.find(([tag]) => tag === "latest")?.[1]} isDeprecated={isDeprecated} skipLink={true} /></DDefinition>
307452
</>
308-
: <>
309-
<DTerm key={'version-label'}>Latest version:</DTerm>
310-
<DDefinition key={'version'}><VersionDetails tag={"latest"} data={allVersions && allVersions.find(([tag]) => tag === "latest")?.[1]} isDeprecated={isDeprecated} skipLink={true} /></DDefinition>
311-
</>
312-
}
313-
</DList>
453+
}
454+
</DList>
455+
<ResourceListDetails packageName={packageName} spectrumData={spectrumData} rootClassName={rootClassName} isDeprecated={isDeprecated}/>
456+
</>
314457
: ""}
315458
</ResetWrapper>
316459
);

.storybook/blocks/Typography.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ export const Heading = styled.h3`
55
font-family: ${({ theme }) => theme.typography.fontFamily};
66
font-weight: ${({ theme }) => theme.typography.weight.bold};
77
color: inherit;
8-
font-size: ${({ size }) => fetchToken(`font-size-${size === "s" ? 300 : size === "l" ? 700 : size === "xl" ? 900 : 500}`, 22)};
8+
font-size: ${({ size }) => fetchToken(`font-size-${size === "xs" ? 200 : size === "s" ? 300 : size === "l" ? 700 : size === "xl" ? 900 : 500}`, 22)};
99
-webkit-font-smoothing: antialiased;
10+
margin: 0;
1011
1112
> strong {
1213
font-weight: 900;

.storybook/deprecated/quickaction/quickaction.stories.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ export default {
7272
status: {
7373
type: "deprecated"
7474
},
75-
packageJson,
75+
packageJson: {
76+
...packageJson,
77+
"spectrum": [
78+
{
79+
"guidelines": "https://spectrum.adobe.com/page/quick-actions/",
80+
"rootClass": "spectrum-QuickActions",
81+
}
82+
]
83+
}
7684
},
7785
};
7886

.storybook/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
},
1818
],
1919
rootDir: "../",
20-
staticDirs: ["../assets"],
20+
staticDirs: ["../assets", "./assets/images"],
2121
addons: [
2222
{
2323
name: "@storybook/addon-essentials",

components/accordion/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,11 @@
4848
],
4949
"publishConfig": {
5050
"access": "public"
51-
}
51+
},
52+
"spectrum": [
53+
{
54+
"guidelines": "https://spectrum-contributions.corp.adobe.com/page/accordion-beta",
55+
"rootClass": "spectrum-Accordion"
56+
}
57+
]
5258
}

components/actionbar/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,11 @@
5454
],
5555
"publishConfig": {
5656
"access": "public"
57-
}
57+
},
58+
"spectrum": [
59+
{
60+
"guidelines": "https://spectrum.adobe.com/page/action-bar",
61+
"rootClass": "spectrum-ActionBar"
62+
}
63+
]
5864
}

components/actionbutton/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,11 @@
5454
],
5555
"publishConfig": {
5656
"access": "public"
57-
}
57+
},
58+
"spectrum": [
59+
{
60+
"guidelines": "https://spectrum.adobe.com/page/action-button",
61+
"rootClass": "spectrum-ActionButton"
62+
}
63+
]
5864
}

components/actiongroup/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,11 @@
4949
],
5050
"publishConfig": {
5151
"access": "public"
52-
}
52+
},
53+
"spectrum": [
54+
{
55+
"guidelines": "https://spectrum.adobe.com/page/action-group",
56+
"rootClass": "spectrum-ActionGroup"
57+
}
58+
]
5359
}

components/actionmenu/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232
"stories/*",
3333
"metadata/*"
3434
],
35-
"keywords": [
36-
"spectrum",
37-
"css",
38-
"design system",
39-
"adobe"
40-
],
4135
"peerDependencies": {
4236
"@spectrum-css/actionbutton": ">=6",
4337
"@spectrum-css/icon": ">=7",
@@ -52,6 +46,12 @@
5246
"@spectrum-css/popover": "workspace:^",
5347
"@spectrum-css/tokens": "workspace:^"
5448
},
49+
"keywords": [
50+
"spectrum",
51+
"css",
52+
"design system",
53+
"adobe"
54+
],
5555
"publishConfig": {
5656
"access": "public"
5757
}

components/alertbanner/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,11 @@
5959
],
6060
"publishConfig": {
6161
"access": "public"
62-
}
62+
},
63+
"spectrum": [
64+
{
65+
"guidelines": "https://spectrum.adobe.com/page/alert-banner",
66+
"rootClass": "spectrum-AlertBanner"
67+
}
68+
]
6369
}

components/alertdialog/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,11 @@
6464
],
6565
"publishConfig": {
6666
"access": "public"
67-
}
67+
},
68+
"spectrum": [
69+
{
70+
"guidelines": "https://spectrum.adobe.com/page/alert-dialog",
71+
"rootClass": "spectrum-AlertDialog"
72+
}
73+
]
6874
}

0 commit comments

Comments
 (0)