Skip to content

Commit

Permalink
chore(storybook): align typography elements for VRTs
Browse files Browse the repository at this point in the history
  • Loading branch information
castastrophe committed Oct 30, 2024
1 parent 469f731 commit d7d05af
Show file tree
Hide file tree
Showing 29 changed files with 417 additions and 391 deletions.
90 changes: 69 additions & 21 deletions .storybook/decorators/utilities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Template as Typography } from "@spectrum-css/typography/stories/template.js";
import { html, nothing } from "lit";
import { styleMap } from "lit/directives/style-map.js";
import { when } from "lit/directives/when.js";
Expand All @@ -11,26 +10,58 @@ import { capitalize } from "lodash-es";
* @param {string} props.content - The content to render in the heading or code block.
* @param {string} props.size - The size of the heading to render.
* @param {string} props.weight - The weight of the heading to render.
* @param {string[]} props.customClasses - Additional classes to apply to the heading or code block.
*/
const Heading = ({
semantics = "heading",
content,
size = "l",
weight,
customClasses = [],
} = {}) => {
return Typography({
semantics,
size,
weight,
content,
skipLineBreak: true,
customClasses: ["chromatic-ignore", ...customClasses],
customStyles: {
"color": semantics === "detail" ? "var(--spectrum-heading-color)" : undefined,
} = {}, context = {}) => {
if (!content) return nothing;

const headingStyles = {
"display": "block",
"color": "black",
"font-family": 'adobe-clean, "adobe clean", "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Trebuchet MS", "Lucida Grande", sans-serif',
"font-size": "11px",
"line-height": "1.3",
"font-weight": "700",
};

if ((size === "xxs" && semantics === "heading") || size === "l") {
headingStyles["font-size"] = "14px";
}

if (semantics === "detail") {
headingStyles["letter-spacing"] = ".06em";
headingStyles["text-transform"] = "uppercase";
}

if (weight === "light") {
if (semantics === "heading") {
headingStyles["font-weight"] = "300";
}
else {
headingStyles["font-weight"] = "400";
}
});
}

if (context.globals?.color.startsWith("dark")) {
headingStyles["color"] = context?.args?.staticColor ?? "white";
}
else if (typeof context?.args?.staticColor !== "undefined") {
headingStyles["color"] = context?.args?.staticColor;
}


return html`
<span
class="chromatic-ignore"
style=${styleMap(headingStyles)}
>
${content}
</span>
`;
};

/**
Expand All @@ -54,7 +85,8 @@ export const Container = ({
withBorder = true,
containerStyles = {},
wrapperStyles = {},
} = {}) => {
} = {}, context = {}) => {
const isDocs = context?.viewMode === "docs";
const headingConfig = { size: "l", semantics: type };
let gap = 40;

Expand Down Expand Up @@ -100,6 +132,13 @@ export const Container = ({
${when(heading, () => Heading({
...headingConfig,
content: heading
}, {
...context,
globals: {
...context.globals ?? {},
// If the level is 1 and we are not in docs view, use the light color theme for the heading
color: level === 1 && !isDocs ? "light" : context.globals?.color,
}
}))}
<div
data-inner-container
Expand All @@ -117,7 +156,7 @@ export const Container = ({
...wrapperStyles,
})}
>
${renderContent(content)}
${renderContent(content, { context })}
</div>
</div>
`;
Expand Down Expand Up @@ -173,6 +212,15 @@ export const States = ({
return nothing
}

context = {
...context,
args: {
...context.args,
...args,
...item,
}
};

return Container({
heading: stateData.some(({ testHeading }) => testHeading) ? testHeading : "",
level: 3,
Expand All @@ -182,9 +230,9 @@ export const States = ({
...stateWrapperStyles,
},
content: Template({ ...args, ...item }, context),
});
}, context);
})
});
}, context);
};

/**
Expand Down Expand Up @@ -264,8 +312,8 @@ export const ArgGrid = ({
...(typeof args?.name !== "undefined" ? {name: `${args.name}-${argKey}-${index}`} : {}),
...(typeof args?.id !== "undefined" ? {id: `${args.id}-${argKey}-${index}`} : {}),
}, context)
})),
});
}, context)),
}, context);
};

/**
Expand Down Expand Up @@ -450,7 +498,7 @@ export const Variants = ({
() => AltTemplate(data, context)
)}
`,
});
}, context);
}
)}
Expand Down
8 changes: 4 additions & 4 deletions components/actionbutton/stories/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const ActionButtonsWithIconOptions = (args, context) => Container({
hasPopup: "true",
}, context)}
`
});
}, context);

export const IconOnlyOption = (args, context) => Container({
withBorder: false,
Expand All @@ -179,7 +179,7 @@ export const IconOnlyOption = (args, context) => Container({
hasPopup: "true",
}, context)}
`
});
}, context);

export const TreatmentTemplate = (args, context) => Container({
withBorder: false,
Expand All @@ -200,5 +200,5 @@ export const TreatmentTemplate = (args, context) => Container({
isSelected,
isDisabled,
})
}, context ))}`,
});
}, context))}`,
}, context);
27 changes: 13 additions & 14 deletions components/actiongroup/stories/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const OverflowOption = (context) => Container({
},
]
}, context)
})}
}, context)}
${Container({
withBorder: false,
heading: "Collapse",
Expand Down Expand Up @@ -126,9 +126,9 @@ export const OverflowOption = (context) => Container({
},
]
}, context)
})}
}, context)}
`
});
}, context);

export const TreatmentTemplate = (args, context) => Container({
withBorder: false,
Expand All @@ -140,14 +140,13 @@ export const TreatmentTemplate = (args, context) => Container({
{ heading: "Default", },
{ iconOnly: true, heading: "Icon-only", },
{ iconOnly: true, areQuiet: true, heading: "Quiet, icon-only", },
].map(({ heading, areQuiet, iconOnly }) => Container({
withBorder: false,
heading: heading,
content: Template({
...args,
areQuiet,
iconOnly,
}, context)}
))}`
});

].map(({ heading, areQuiet, iconOnly }) => Container({
withBorder: false,
heading: heading,
content: Template({
...args,
areQuiet,
iconOnly,
}, context)
}, context))}`
}, context);
10 changes: 5 additions & 5 deletions components/alertbanner/stories/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const ActionableOptionsTemplate = (args, context) => Container({
text: "Your trial has expired",
actionButtonText: "Buy now",
}, context),
})}
}, context)}
${Container({
withBorder: false,
direction: "column",
Expand All @@ -144,7 +144,7 @@ export const ActionableOptionsTemplate = (args, context) => Container({
actionButtonText: "Buy now",
showCloseButton: false,
}, context),
})}
}, context)}
${Container({
withBorder: false,
direction: "column",
Expand All @@ -157,7 +157,7 @@ export const ActionableOptionsTemplate = (args, context) => Container({
text: "Your trial has expired",
actionButtonText: "",
}),
})}
}, context)}
${Container({
withBorder: false,
direction: "column",
Expand All @@ -171,6 +171,6 @@ export const ActionableOptionsTemplate = (args, context) => Container({
actionButtonText: "",
showCloseButton: false,
}, context),
})}
}, context)}
`,
});
}, context);
40 changes: 20 additions & 20 deletions components/button/stories/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const Template = ({
${when(iconName && !iconAfterLabel, () =>
Icon({ iconName, setName: iconSet, size }, context)
)}
${when(label && !hideLabel, () =>
${when(label && !hideLabel, () =>
html`<span class=${`${rootClass}-label`}>${label}</span>`
)}
${when(iconName && iconAfterLabel, () =>
Expand Down Expand Up @@ -131,7 +131,7 @@ export const ButtonsWithIconOptions = ({
iconName: iconName ?? "Edit",
}, context)}
`,
});
}, context);

/**
* Display the buttons with icon options for each treatment option.
Expand All @@ -155,23 +155,23 @@ export const TextOverflowTemplate = (args, context = {}) => Container({
rowGap: "12px",
},
content: html`
${Template({
...args,
customStyles: {
"max-inline-size": "480px",
},
label: "An example of text overflow behavior when there is no icon. When the button text is too long for the horizontal space available, it wraps to form another line.",
}, context)}
${Template({
...args,
customStyles: {
"max-inline-size": "480px",
},
iconName: "Edit",
iconSet: "workflow",
label: "An example of text overflow behavior when the button has an icon. When the button text is too long for the horizontal space available, it wraps to form another line.",
}, context)}
`,
${Template({
...args,
customStyles: {
"max-inline-size": "480px",
},
label: "An example of text overflow behavior when there is no icon. When the button text is too long for the horizontal space available, it wraps to form another line.",
}, context)}
${Template({
...args,
customStyles: {
"max-inline-size": "480px",
},
iconName: "Edit",
iconSet: "workflow",
label: "An example of text overflow behavior when the button has an icon. When the button text is too long for the horizontal space available, it wraps to form another line.",
}, context)}
`,
}, context);

export const TextWrapTemplate = (args, context = {}) => Container({
Expand Down Expand Up @@ -206,4 +206,4 @@ export const TextWrapTemplate = (args, context = {}) => Container({
noWrap: true,
}, context)}
`,
}, context);
}, context);
15 changes: 7 additions & 8 deletions components/checkbox/stories/template.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Template as Icon } from "@spectrum-css/icon/stories/template.js";
import { getRandomId, Container } from "@spectrum-css/preview/decorators";
import { Container, getRandomId } from "@spectrum-css/preview/decorators";
import { html } from "lit";
import { classMap } from "lit/directives/class-map.js";
import { ifDefined } from "lit/directives/if-defined.js";
Expand Down Expand Up @@ -126,7 +126,7 @@ export const DocsCheckboxGroup = (args, context) => Container({
customStyles: { "max-inline-size": "200px" },
})}
`
});
}, context);

/* This template group showcases multiple CheckboxGroups in various states of disabled, read-only, invalid, etc. */
export const AllVariantsCheckboxGroup = (args, context) => Container({
Expand All @@ -137,25 +137,24 @@ export const AllVariantsCheckboxGroup = (args, context) => Container({
direction: "column",
heading: "Default",
content: DocsCheckboxGroup(args, context)
})}
}, context)}
${Container({
withBorder: false,
direction: "column",
heading: "Invalid",
content: DocsCheckboxGroup({...args, isInvalid: true }, context)
})}
}, context)}
${Container({
withBorder: false,
direction: "column",
heading: "Disabled",
content: DocsCheckboxGroup({...args, isDisabled: true }, context)
})}
}, context)}
${Container({
withBorder: false,
direction: "column",
heading: "Read-only",
content: DocsCheckboxGroup({...args, isReadOnly: true }, context)
})}
}, context)}
`
});
}, context);
Loading

0 comments on commit d7d05af

Please sign in to comment.