Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ResourceListDetails doc block #3129

Merged
merged 18 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .storybook/assets/images/adobe_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions .storybook/assets/images/github_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions .storybook/assets/images/npm_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
187 changes: 165 additions & 22 deletions .storybook/blocks/ComponentDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { useOf } from '@storybook/blocks';
import { ResetWrapper } from "@storybook/components";
import { styled } from "@storybook/theming";
import React, { useEffect, useState } from "react";
import { Code } from "./Typography.jsx";
import AdobeSVG from "../assets/images/adobe_logo.svg?raw";
import GitHubSVG from "../assets/images/github_logo.svg?raw";
import NpmSVG from "../assets/images/npm_logo.svg?raw";
import { Body, Code, Heading } from "./Typography.jsx";
import { fetchToken } from "./utilities.js";

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

export const ResourceSection = styled.section`
display: flex;
flex-flow: row wrap;
align-items: center;
`;

export const ResourceLink = styled.a`
position: relative;
marissahuysentruyt marked this conversation as resolved.
Show resolved Hide resolved
display: inline-flex;
flex-direction: row;
align-items: center;
margin-block-end: 16px;
margin-inline-end: 16px;
box-sizing: border-box;
text-decoration: none;
min-inline-size: 100px;
border: 1px solid transparent;
border-radius: 5px;
border-color: rgb(230, 230, 230);
overflow: hidden;
marissahuysentruyt marked this conversation as resolved.
Show resolved Hide resolved
color: rgb(0, 0, 0);

&:hover {
border-color: rgb(213, 213, 213);
}
`;

export const ResourceIconWrapper = styled.div`
background-color: rgba(248, 248, 248);
padding: 12px;
display: flex;
inline-size: 40px;
block-size: 40px;
`;

export const ResourceTextWrapper = styled.div`
margin-inline: 16px;
`;

const VersionDetails = ({ tag, data = {}, isDeprecated = false, skipDate = false, skipLink = false }) => {
let statusType = "notice";
let statusMessage = "Not yet available on the npm registry.";
Expand Down Expand Up @@ -264,13 +306,104 @@ function fetchNpmData(packageName, setnpmData, setIsLoading) {
}, [cache, setCache, packageName, setnpmData, setIsLoading]);
}

const fetchLogo = (brand) => {
switch(brand) {
case "npm":
return NpmSVG;
case "GitHub":
return GitHubSVG;
case "Adobe":
return AdobeSVG;
}

return;
}

/**
* Displays a resource card containing text and an image that links to a particular resource.
*
* @param {string} heading - heading of the resource card
* @param {string} alt - additional description of the resource card
* @param {string} image - the SVG image
* @param {string} href - optional link to the resource, found in packageJson?.spectrum?.guidelines
* @returns {string}
*/
export const ResourceLinkContent = ({ heading, alt, logo, href }) => {
if (!href) return;

return (
<ResourceLink href={href} className="sb-unstyled" title={alt}>
<ResourceIconWrapper dangerouslySetInnerHTML={{ __html: fetchLogo(logo) }} />
<ResourceTextWrapper>
{heading ? <Heading size="xs">{heading}</Heading> : ""}
{alt ? <Body size="s">{alt}</Body> : ""}
</ResourceTextWrapper>
</ResourceLink>
);
};

/**
* Displays the list of relevant component links (to NPM, repo, guidelines, etc).
*
* The rootClassName is read from the story's default args, found in the story's metadata.
*
* The for loop is particularly helpful to match guidelines links for any nested components
* (i.e. meter, form). We need to check that the rootClassName matches the rootClass found
* in the packageJson.spectrum, to link to the correct guidelines page.
*
* Deprecated components should not show a GitHub resource card.
*
* @param {string} packageName - packageName sourced from packageJson?.name
* @param {string[]} spectrumData - an array of objects sourced from packageJson?.spectrum
* @param {string} rootClassName - a component's default rootClass arg
* @returns {string}
*/
export const ResourceListDetails = ({ packageName, spectrumData = [], rootClassName, isDeprecated }) => {
if (!packageName) return;
rise-erpelding marked this conversation as resolved.
Show resolved Hide resolved

let href;

for(let i = 0; i < spectrumData?.length; i++) {
if (spectrumData[i]?.guidelines && spectrumData[i]?.rootClass === rootClassName) {
href = spectrumData[i]?.guidelines;
}
}

return (
<ResourceSection className="sb-unstyled">
{href ?
<ResourceLinkContent
className="doc-block-resource-cards"
heading="View guidelines"
alt="Spectrum website"
logo="Adobe"
href={href}/> : ""}
<ResourceLinkContent
className="doc-block-resource-cards"
heading="View package"
alt="npm"
logo="npm"
href={`https://npmjs.com/${packageName}`}/>
{!isDeprecated ?
<ResourceLinkContent
className="doc-block-resource-cards"
heading="View repository"
alt="GitHub"
logo="GitHub"
href={`https://github.com/adobe/spectrum-css/tree/main/components/${packageName.split('/').pop()}`}/> : ""}
</ResourceSection>
)
};

/**
* Displays the current version number of the component. The version is read from
* the component's parameters, where it was sourced from the package.json file.
*
* Also displays a component status of "deprecated" if it is set in the story's
* Displays a component status of "deprecated" if it is set in the story's
* parameters.
*
* Displays the list of relevant component links (to NPM, repo, guidelines, etc).
*
* Usage of this doc block within MDX template(s):
* <ComponentDetails />
*/
Expand All @@ -279,8 +412,16 @@ export const ComponentDetails = () => {

const isDeprecated = storyMeta?.csfFile?.meta?.parameters?.status?.type == "deprecated";
const packageJson = storyMeta?.csfFile?.meta?.parameters?.packageJson ?? {};
const rootClassName = storyMeta?.csfFile?.meta?.args?.rootClass ?? "";

const packageName = packageJson?.name;

if (!packageName) return;

if (!packageJson?.name) return;
let spectrumData = packageJson?.spectrum;
if (typeof spectrumData === "string") {
spectrumData = [spectrumData];
}

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

return (
<ResetWrapper>
{ !isLoading ?
<DList className="docblock-metadata sb-unstyled">
{ isDeprecated
? <>
<DTerm key={'status'}>Status:</DTerm>
<DDefinition key={'status-data'}>Deprecated</DDefinition>
</>
: ""
}
{ showLocalVersion
? <>
<DTerm key={'version-label'}>Local version:</DTerm>
<DDefinition key={'version'}><VersionDetails tag={"local"} data={allVersions && allVersions.find(([tag]) => tag === "local")?.[1]} isDeprecated={isDeprecated} /></DDefinition>
{ !isLoading ? <>
<DList className="docblock-metadata sb-unstyled">
{ isDeprecated
? <>
<DTerm key={'status'}>Status:</DTerm>
<DDefinition key={'status-data'}>Deprecated</DDefinition>
</>
: ""
}
{ showLocalVersion
? <>
<DTerm key={'version-label'}>Local version:</DTerm>
<DDefinition key={'version'}><VersionDetails tag={"local"} data={allVersions && allVersions.find(([tag]) => tag === "local")?.[1]} isDeprecated={isDeprecated} /></DDefinition>
</>
: <>
<DTerm key={'version-label'}>Latest version:</DTerm>
<DDefinition key={'version'}><VersionDetails tag={"latest"} data={allVersions && allVersions.find(([tag]) => tag === "latest")?.[1]} isDeprecated={isDeprecated} skipLink={true} /></DDefinition>
</>
: <>
<DTerm key={'version-label'}>Latest version:</DTerm>
<DDefinition key={'version'}><VersionDetails tag={"latest"} data={allVersions && allVersions.find(([tag]) => tag === "latest")?.[1]} isDeprecated={isDeprecated} skipLink={true} /></DDefinition>
</>
}
</DList>
}
</DList>
<ResourceListDetails packageName={packageName} spectrumData={spectrumData} rootClassName={rootClassName} isDeprecated={isDeprecated}/>
</>
: ""}
</ResetWrapper>
);
Expand Down
3 changes: 2 additions & 1 deletion .storybook/blocks/Typography.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ export const Heading = styled.h3`
font-family: ${({ theme }) => theme.typography.fontFamily};
font-weight: ${({ theme }) => theme.typography.weight.bold};
color: inherit;
font-size: ${({ size }) => fetchToken(`font-size-${size === "s" ? 300 : size === "l" ? 700 : size === "xl" ? 900 : 500}`, 22)};
font-size: ${({ size }) => fetchToken(`font-size-${size === "xs" ? 200 : size === "s" ? 300 : size === "l" ? 700 : size === "xl" ? 900 : 500}`, 22)};
-webkit-font-smoothing: antialiased;
margin: 0;
marissahuysentruyt marked this conversation as resolved.
Show resolved Hide resolved

> strong {
font-weight: 900;
Expand Down
10 changes: 9 additions & 1 deletion .storybook/deprecated/quickaction/quickaction.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ export default {
status: {
type: "deprecated"
},
packageJson,
packageJson: {
...packageJson,
"spectrum": [
{
"guidelines": "https://spectrum.adobe.com/page/quick-actions/",
"rootClass": "spectrum-QuickActions",
}
]
}
},
};

Expand Down
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
},
],
rootDir: "../",
staticDirs: ["../assets"],
staticDirs: ["../assets", "./assets/images"],
addons: [
{
name: "@storybook/addon-essentials",
Expand Down
8 changes: 7 additions & 1 deletion components/accordion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,11 @@
],
"publishConfig": {
"access": "public"
}
},
"spectrum": [
{
"guidelines": "https://spectrum-contributions.corp.adobe.com/page/accordion-beta",
"rootClass": "spectrum-Accordion"
}
]
}
8 changes: 7 additions & 1 deletion components/actionbar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,11 @@
],
"publishConfig": {
"access": "public"
}
},
"spectrum": [
{
"guidelines": "https://spectrum.adobe.com/page/action-bar",
"rootClass": "spectrum-ActionBar"
}
]
}
8 changes: 7 additions & 1 deletion components/actionbutton/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,11 @@
],
"publishConfig": {
"access": "public"
}
},
"spectrum": [
{
"guidelines": "https://spectrum.adobe.com/page/action-button",
"rootClass": "spectrum-ActionButton"
}
]
}
8 changes: 7 additions & 1 deletion components/actiongroup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@
],
"publishConfig": {
"access": "public"
}
},
"spectrum": [
{
"guidelines": "https://spectrum.adobe.com/page/action-group",
"rootClass": "spectrum-ActionGroup"
}
]
}
12 changes: 6 additions & 6 deletions components/actionmenu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
"stories/*",
"metadata/*"
],
"keywords": [
"spectrum",
"css",
"design system",
"adobe"
],
"peerDependencies": {
"@spectrum-css/actionbutton": ">=6",
"@spectrum-css/icon": ">=7",
Expand All @@ -52,6 +46,12 @@
"@spectrum-css/popover": "workspace:^",
"@spectrum-css/tokens": "workspace:^"
},
"keywords": [
"spectrum",
"css",
"design system",
"adobe"
],
"publishConfig": {
"access": "public"
}
Expand Down
8 changes: 7 additions & 1 deletion components/alertbanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,11 @@
],
"publishConfig": {
"access": "public"
}
},
"spectrum": [
{
"guidelines": "https://spectrum.adobe.com/page/alert-banner",
"rootClass": "spectrum-AlertBanner"
}
]
}
8 changes: 7 additions & 1 deletion components/alertdialog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@
],
"publishConfig": {
"access": "public"
}
},
"spectrum": [
{
"guidelines": "https://spectrum.adobe.com/page/alert-dialog",
"rootClass": "spectrum-AlertDialog"
}
]
}
Loading
Loading