Skip to content

Commit

Permalink
feat(storybook): update chromatic add-on to latest version
Browse files Browse the repository at this point in the history
BREAKING CHANGE: New chromatic configuration required for updated
version support.
  • Loading branch information
castastrophe committed Jan 2, 2025
1 parent b679cb3 commit 7a869a3
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 890 deletions.
12 changes: 12 additions & 0 deletions .changeset/tasty-pigs-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@spectrum-css/preview": major
---

Update the Chromatic add-on to the currently maintained package:

- from "@chromaui/addon-visual-tests": "^1.0.0"
- to "@chromatic-com/storybook": "^3.2.3"

This requires an update to the chromatic.config.json settings, removal of the generic argTypesRegex from the preview config, and a stricter import in the doc blocks.

To support a successful build, our test command must maintain the autodocs and mdx syntax.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ CHROMATIC_PROJECT_ID="Project:64762974a45b8bc5ca1705a2"
# Note: the build script here should be defined in .storybook/package.json
# this is used by the chromatic storybook addon to build the storybook on the fly
CHROMATIC_BUILD_SCRIPT_NAME="build"
CHROMATIC_ONLY_CHANGED=true
CHROMATIC_STORYBOOK_BASE_DIR=".storybook"
CHROMATIC_ZIP=true

# NX settings
NX_PREFER_TS_NODE=true
Expand Down
85 changes: 10 additions & 75 deletions .storybook/blocks/ColorPalette.jsx
Original file line number Diff line number Diff line change
@@ -1,83 +1,18 @@
import { ResetWrapper } from "@storybook/components";
import { styled } from "@storybook/theming";
import { capitalize } from "lodash-es";
import React from "react";
import { ThemeContainer } from "./ThemeContainer";
import { Body, Heading } from "./Typography";
import { List } from "./Layouts.jsx";
import {
Swatch,
SwatchColors,
SwatchGroup,
SwatchGroupLabel,
SwatchSet,
} from "./Swatches.jsx";
import { ThemeContainer } from "./ThemeContainer.jsx";
import { Body, Heading } from "./Typography.jsx";
import { fetchToken } from "./utilities.js";

export const SwatchGroupLabel = styled.div`
display: flex;
flex-direction: column;
margin-top: 16px;
align-self: flex-start;
justify-content: center;
text-wrap: nowrap;
inline-size: max-content;
block-size: ${props => props.size ?? 32}px;
color: ${props => `var(--spectrum-neutral-subdued-content-color-default, ${props.theme.defaultText})`};
`;

export const SwatchSet = styled.div`
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 2px;
color: ${props => `var(--spectrum-neutral-subdued-content-color-default, ${props.theme.defaultText})`};
`;

export const Swatch = styled.div`
position: relative;
inline-size: var(--swatch-size, ${props => props.size ?? 32}px);
block-size: var(--swatch-size, ${props => props.size ?? 32}px);
outline: none;
user-select: none;
&::before {
position: absolute;
inset: 0;
inline-size: 100%;
block-size: 100%;
content: "";
opacity: 1;
border: 1px solid rgba(0, 0, 0, 51%);
border-radius: ${props => `${props.theme.appBorderRadius}px` ?? `var(--spectrum-corner-radius-100, 4px)`};
${props => props.background && `background: ${props.background};`}
}
.spectrum--dark &::before,
.spectrum--darkest &::before {
border-color: rgba(255, 255, 255, 51%);
}
`;

export const SwatchColors = styled.div`
display: inline-flex;
flex-direction: row;
flex-wrap: wrap;
gap: ${props => props.size > 0 ? (props.size * 0.2) : 8}px;
align-items: flex-start;
justify-content: flex-start;
`;

export const SwatchGroup = styled.div`
position: relative;
display: flex;
flex-direction: column;
flex: 1;
`;

const List = styled.div`
display: grid;
gap: 24px;
grid-template-columns: 1fr auto;
grid-template-rows: auto;
align-items: center;
justify-content: center;
`;

/**
* A single color row your styleguide showing title, subtitle and one or more colors, used
* as a child of `ColorPalette`.
Expand Down
71 changes: 1 addition & 70 deletions .storybook/blocks/ComponentDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,10 @@ 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 WCSVG from "../assets/images/wc_logo.svg?raw";
import { DDefinition, DList, DTerm } from "./Layouts.jsx";
import { Body, Code, Heading } from "./Typography.jsx";
import { fetchToken } from "./utilities.js";

export const DList = styled.dl`
display: grid;
grid-template-columns: max-content 1fr;
column-gap: 20px;
row-gap: 14px;
padding-block: 0.75rem;
margin-block: 0.5rem 2.5rem;
border-block: ${props => !props.skipBorder ? "1px solid hsla(203deg, 50%, 30%, 15%)" : "0"};
& & {
border-block: 0px;
margin-block: 0;
padding-inline-start: 0.75rem;
padding-block-start: 0.25rem;
}
details > & {
margin-inline-start: 12px;
}
`;

export const DTerm = styled.dt`
font-weight: ${props => props.theme.typography.weight.bold ?? "bold"};
padding: 0;
margin: 0;
font-size: ${props => props.theme.typography.size.s};
`;

export const Details = styled.details`
cursor: pointer;
grid-column: 1 / 3;
padding: 0;
&[open] > summary::before {
transform: rotate(90deg);
}
`;

export const Summary = styled.summary`
display: inline-flex;
align-items: center;
font-weight: ${props => props.theme.typography.weight.bold ?? "bold"};
padding: 0;
padding-block-end: 0.75rem;
margin: 0;
font-size: ${props => props.theme.typography.size.s};
list-style: none;
&::-webkit-details-marker {
display: none;
}
&::before {
content: '';
width: 10px;
height: 10px;
background-image: url('data:image/svg+xml,<svg focusable="false" aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><path d="M3 9.95a.875.875 0 0 1-.615-1.498L5.88 5 2.385 1.547A.875.875 0 0 1 3.615.302L7.74 4.377a.876.876 0 0 1 0 1.246L3.615 9.698A.87.87 0 0 1 3 9.95"></path></svg>');
background-size: cover;
margin-inline-end: .75em;
transition: 0.2s;
}
`;

export const DDefinition = styled.dd`
font-style: normal;
padding: 0;
margin: 0;
font-size: ${props => props.theme.typography.size.s};
`;

export const DSet = ({ term, children }) => {
return (
<>
Expand Down
97 changes: 97 additions & 0 deletions .storybook/blocks/Layouts.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { styled } from "@storybook/theming";

export const Container = styled.section`
color: var(--spectrum-neutral-content-color-default);
background-color: var(--spectrum-background-layer-1-color);
display: ${props => props.display ?? "flex" };
padding-inline: 48px 24px;
padding-block: 60px;
flex-direction: column;
align-items: flex-start;
gap: 60px;
border-radius: 16px;
`;

export const List = styled.div`
display: grid;
gap: 24px;
grid-template-columns: 1fr auto;
grid-template-rows: auto;
align-items: center;
justify-content: center;
`;

export const DList = styled.dl`
display: grid;
grid-template-columns: max-content 1fr;
column-gap: 20px;
row-gap: 14px;
padding-block: 0.75rem;
margin-block: 0.5rem 2.5rem;
border-block: ${props => !props.skipBorder ? "1px solid hsla(203deg, 50%, 30%, 15%)" : "0"};
& & {
border-block: 0px;
margin-block: 0;
padding-inline-start: 0.75rem;
padding-block-start: 0.25rem;
}
details > & {
margin-inline-start: 12px;
}
`;

export const DTerm = styled.dt`
font-weight: ${props => props.theme.typography.weight.bold ?? "bold"};
padding: 0;
margin: 0;
font-size: ${props => props.theme.typography.size.s};
`;

export const DDefinition = styled.dd`
font-style: normal;
padding: 0;
margin: 0;
font-size: ${props => props.theme.typography.size.s};
`;

export const Details = styled.details`
cursor: pointer;
grid-column: 1 / 3;
padding: 0;
&[open] > summary::before {
transform: rotate(90deg);
}
`;

export const Summary = styled.summary`
display: inline-flex;
align-items: center;
font-weight: ${props => props.theme.typography.weight.bold ?? "bold"};
padding: 0;
padding-block-end: 0.75rem;
margin: 0;
font-size: ${props => props.theme.typography.size.s};
list-style: none;
&::-webkit-details-marker {
display: none;
}
&::before {
content: '';
width: 10px;
height: 10px;
background-image: url('data:image/svg+xml,<svg focusable="false" aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><path d="M3 9.95a.875.875 0 0 1-.615-1.498L5.88 5 2.385 1.547A.875.875 0 0 1 3.615.302L7.74 4.377a.876.876 0 0 1 0 1.246L3.615 9.698A.87.87 0 0 1 3 9.95"></path></svg>');
background-size: cover;
margin-inline-end: .75em;
transition: 0.2s;
}
`;

export const Table = styled.table`
--mod-table-cursor-row-default: auto;
padding-block: 10px;
`;
7 changes: 1 addition & 6 deletions .storybook/blocks/PropertiesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ import "@spectrum-css/table/dist/index.css";

import { DocsContext, useOf } from "@storybook/blocks";
import { NAVIGATE_URL } from "@storybook/core-events";
import { styled } from "@storybook/theming";
import React, { useContext } from 'react';
import { Table } from "./Layouts.jsx";
import { ThemeContainer } from "./ThemeContainer.jsx";
import { Body, Code, LinkableHeading } from "./Typography.jsx";

export const Table = styled.table`
--mod-table-cursor-row-default: auto;
padding-block: 10px;
`;

/**
* Displays the modifiable custom properties for a component based on the metadata provided in the story.
* The story metadata object is imported from the "metadata.json" file in the component's directory.
Expand Down
64 changes: 64 additions & 0 deletions .storybook/blocks/Swatches.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { styled } from "@storybook/theming";

export const SwatchGroupLabel = styled.div`
display: flex;
flex-direction: column;
margin-top: 16px;
align-self: flex-start;
justify-content: center;
text-wrap: nowrap;
inline-size: max-content;
block-size: ${props => props.size ?? 32}px;
color: ${props => `var(--spectrum-neutral-subdued-content-color-default, ${props.theme.defaultText})`};
`;

export const SwatchSet = styled.div`
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 2px;
color: ${props => `var(--spectrum-neutral-subdued-content-color-default, ${props.theme.defaultText})`};
`;

export const Swatch = styled.div`
position: relative;
inline-size: var(--swatch-size, ${props => props.size ?? 32}px);
block-size: var(--swatch-size, ${props => props.size ?? 32}px);
outline: none;
user-select: none;
&::before {
position: absolute;
inset: 0;
inline-size: 100%;
block-size: 100%;
content: "";
opacity: 1;
border: 1px solid rgba(0, 0, 0, 51%);
border-radius: ${props => `${props.theme.appBorderRadius}px` ?? `var(--spectrum-corner-radius-100, 4px)`};
${props => props.background && `background: ${props.background};`}
}
.spectrum--dark &::before,
.spectrum--darkest &::before {
border-color: rgba(255, 255, 255, 51%);
}
`;

export const SwatchColors = styled.div`
display: inline-flex;
flex-direction: row;
flex-wrap: wrap;
gap: ${props => props.size > 0 ? (props.size * 0.2) : 8}px;
align-items: flex-start;
justify-content: flex-start;
`;

export const SwatchGroup = styled.div`
position: relative;
display: flex;
flex-direction: column;
flex: 1;
`;
Loading

0 comments on commit 7a869a3

Please sign in to comment.