Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
refactor content card stories to use controls instead of knobs
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhmarsh committed Jan 7, 2022
1 parent 6e66d68 commit 7af938b
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 97 deletions.
14 changes: 13 additions & 1 deletion .storybook/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,17 @@ import idHelper from "./idHelper";
import parentWrapper from "./parentWrapper";
import repeat from "./repeat";
import scalingRuleWrapper from "./scalingRuleWrapper";
import srcSet from "./srcSet";

export {
backgroundOverride,
exampleComponent,
idHelper,
html,
parentWrapper,
repeat,
scalingRuleWrapper,
srcSet
};


export { backgroundOverride, exampleComponent, idHelper, html, parentWrapper, repeat, scalingRuleWrapper };
8 changes: 8 additions & 0 deletions .storybook/helpers/srcSet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default (srcSet) => {
const widths = Object.keys(srcSet.sizes);
return widths
.map((width) => {
return `${srcSet.sizes[width]} ${width},`;
})
.join("\n");
};
119 changes: 45 additions & 74 deletions src/components/card/content-card/content-card.stories.js
Original file line number Diff line number Diff line change
@@ -1,105 +1,76 @@
import { html } from ".storybook/helpers";
import { withKnobs, text, boolean, number } from "@storybook/addon-knobs";

import { html, srcSet} from ".storybook/helpers";
import scssExports from "../../../global/exports.scss";

import image768 from ".storybook/assets/images/full-width-image/seurat_circus_sideshow.jpg";
import image960 from ".storybook/assets/images/full-width-image/seurat_circus_sideshow-960.jpg";
import image1440 from ".storybook/assets/images/full-width-image/seurat_circus_sideshow-1440.jpg";
import image2160 from ".storybook/assets/images/full-width-image/seurat_circus_sideshow-2160.jpg";

const imageWidth = 3920;
const imageHeight = 2621;
import image from ".storybook/assets/images/full-width-image";

export default {
decorators: [withKnobs],
title: "Cards/Content Card",
args: {
cardMode: "",
index: 0,
heading: {
withHeading: true,
headingLink: true,
headingText: "Heading Text That Can Extend to Three Lines Maximum, Character Count 100",
},
tagText: "",
description: "This illustrated volume presents a comprehensive overview of the Sahel's diverse cultural traditions.Order yours today."
}
};

const Heading = (index) => {
return html` ${text(
"Heading",
"Heading Text That Can Extend to Three Lines Maximum, Character Count 100",
`Card ${index}`
)}`;
};

const HeadingWithLink = (index) => {
return html` <a class="content-card__heading-link" href="#some-link"
>${Heading(index)}</a
>`;
};

const srcSet = `${image768} 768w,
${image960} 960w,
${image1440} 1440w,
${image2160} 2160w`;

const ContentCardTemplate = (cardMode = "", index = "", withHeading = true) => {
return html`
<div class="content-card ${cardMode}">
const ContentCardTemplate = (args) => html`
<div class="content-card ${args.cardMode}">
<div class="card-image__wrapper card-image__wrapper--has-invisible-link">
<a href="anywhere" class="invisible-redundant-link" aria-hidden="true" tabindex="-1"></a>
<img class="card-image" alt="An image alt, for accessibility" width="${imageWidth}" height="${imageHeight}"
src="${image768}" srcset="${srcSet}" sizes="(min-width: ${scssExports.bp900}) 720px, 90vw" />
<img class="card-image" alt="An image alt, for accessibility" width="${image.width}" height="${image.height}"
src="${image.srcSet.fallback}" srcset="${srcSet(image.srcSet)}" sizes="(min-width: ${scssExports.bp900}) 720px, 90vw" />
</div>
<div class="content-card__body">
<div class="content-card__eyebrow">
${text("Tag Text", "tag text", `Card ${index}`)}
${args.tagText ? args.tagText : `Card ${args.index}`}
</div>
${withHeading ? html`
${args.heading.withHeading ? html`
<h3 class="content-card__heading">
${boolean("Heading Is A Link?", true, `Card ${index}`)
? HeadingWithLink(index)
: Heading(index)}
${args.heading.headingLink ? html`<a class="content-card__heading-link" href="#some-link">${args.heading.headingText}</a>` : args.heading.headingText}
</h3>
` : ""}
<p>
${text("Description", `This illustrated volume presents a comprehensive overview of the Sahel's diverse cultural
traditions. Order yours today.`, `Card ${index}`)}
${args.description ? args.description : `Card ${args.index} description.`}
</p>
</div>
</div>`;
};

const ContentCard = () => {
return ContentCardTemplate();
};

const ContentCards = () => {
const cardCount = number("Card Count", 2, { range: true, min: 2, max: 4 });
const cards = Array.apply(null, Array(cardCount)).map((card, index) =>
ContentCardTemplate("has-border", index + 1)
);
return html` <section class="card-container card-container--auto-fit">
${cards.reduce((total, card) => total + card, "")}
export const ContentCard = (args) => ContentCardTemplate(args);

export const ContentCards = (args) => html`
<section class="card-container card-container--auto-fit">
${ [...Array(args.cardCount).keys()]
.map((index) => ContentCardTemplate({ ...args, index: (index + 1) }))
.join("\n")
}
</section>`;
};

const TwoUpContentCard = () => {
return ContentCardTemplate("two-up");
ContentCards.args = {
cardCount: 2,
cardMode: "has-border"
};

const TwoUpContentCardMixedHeadings = () => html`
export const TwoUpContentCard = (args) => ContentCardTemplate(args);
TwoUpContentCard.args = {cardMode: "two-up"};

export const TwoUpContentCardMixedHeadings = (args) => html`
<section class="card-container card-container--auto-fit">
${ContentCardTemplate("two-up", 1, false)}
${ContentCardTemplate("two-up", 2, true)}
${ContentCardTemplate({...args, index: 1, heading: {withHeading: false}})}
${ContentCardTemplate({...args, index: 2})}
</section>
`;

const ThreeUpContentCard = () => {
return ContentCardTemplate("three-up");
};

const ProductiveContentCard = () => {
return ContentCardTemplate("content-card--productive");
export const ThreeUpContentCard = (args) => ContentCardTemplate(args);
ThreeUpContentCard.args = {
cardMode: "three-up"
};

export {
ContentCard,
ContentCards,
ThreeUpContentCard,
TwoUpContentCard,
TwoUpContentCardMixedHeadings,
ProductiveContentCard,
};
export const ProductiveContentCard = (args) => ContentCardTemplate(args);
ProductiveContentCard.args = {
cardMode: "content-card--productive"
};
21 changes: 6 additions & 15 deletions src/components/image-container/image-container.stories.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { html } from ".storybook/helpers";
import { html, srcSet } from ".storybook/helpers";
import defaultImage from ".storybook/assets/images/full-width-image";

export default {
title: "Image Containers",
includeStories: ["fullWidth", "halfWidth", "lazyLoaded"],
excludeStories: "sizesTemplate"
includeStories: ["fullWidth", "halfWidth", "lazyLoaded"]
};

const sizesTemplate = (srcSet) => {
const widths = Object.keys(srcSet.sizes);
return widths
.map((width) => {
return `${srcSet.sizes[width]} ${width},`;
})
.join("\n");
};

const fullWidth = () => {
// Don't forget alt attribute.
Expand All @@ -29,7 +20,7 @@ const fullWidth = () => {
width="${image.width}"
height="${image.height}"
src="${image.srcSet.fallback}"
srcset="${sizesTemplate(image.srcSet)}"
srcset="${srcSet(image.srcSet)}"
sizes="100vw"
/>
</div>
Expand All @@ -47,7 +38,7 @@ const halfWidth = () => {
width="${image.width}"
height="${image.height}"
src="${image.srcSet.fallback}"
srcset="${sizesTemplate(image.srcSet)}"
srcset="${srcSet(image.srcSet)}"
sizes="50vw"
/>
</div>
Expand Down Expand Up @@ -75,11 +66,11 @@ const lazyLoaded = () => {
width="${image.width}"
height="${image.height}"
data-src="${image.srcSet.fallback}"
data-srcset="${sizesTemplate(image.srcSet)}"
data-srcset="${srcSet(image.srcSet)}"
data-sizes="100vw"
/>
</div>
`;
};

export { fullWidth, halfWidth, lazyLoaded, sizesTemplate };
export { fullWidth, halfWidth, lazyLoaded };
7 changes: 3 additions & 4 deletions src/components/tile/tile.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { html, repeat } from ".storybook/helpers";
import { sizesTemplate } from "../image-container/image-container.stories";
import { html, repeat, srcSet } from ".storybook/helpers";
import greekHall from ".storybook/assets/images/greek-hall";

const { image16x9 } = greekHall;
Expand All @@ -20,7 +19,7 @@ const Tile = (args) => html`
<div class="tile__image image-container">
${args.link ? html`<a class="invisible-redundant-link" aria-hidden="true" tabindex="-1" href="${args.link}"></a>` : ""}
<img class="image-container__image" alt="${args.image16x9.alt}" width="${args.image16x9.width}" height="${args.image16x9.height}"
src="${image16x9.srcSet.fallback}" srcset="${sizesTemplate(image16x9.srcSet)}" sizes="(orientation: landscape) 21vw, 50vw" />
src="${image16x9.srcSet.fallback}" srcset="${srcSet(image16x9.srcSet)}" sizes="(orientation: landscape) 21vw, 50vw" />
</div>
<div>
<h4 class="tile__heading">${args.link ? html`<a href="${args.link}">${args.heading}</a>` : args.heading}</h4>
Expand All @@ -34,7 +33,7 @@ const HeroTile = (args) => html`
<div class="tile__image image-container">
${args.link ? html`<a class="invisible-redundant-link" aria-hidden="true" tabindex="-1" href="${args.link}"></a>` : ""}
<img class="image-container__image" alt="${image16x9.alt}" width="${image16x9.width}" height="${image16x9.height}"
src="${image16x9.srcSet.fallback}" srcset="${sizesTemplate(image16x9.srcSet)}" sizes="(orientation: landscape) 42.5vw, 85vw" />
src="${image16x9.srcSet.fallback}" srcset="${srcSet(image16x9.srcSet)}" sizes="(orientation: landscape) 42.5vw, 85vw" />
</div>
<div>
<h3 class="tile__heading">${args.link ? html`<a href="${args.link}">${args.heading}</a>` : args.heading}</h3>
Expand Down
5 changes: 2 additions & 3 deletions src/global/lazyload/lazyload.stories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { html } from ".storybook/helpers";
import { html, srcSet } from ".storybook/helpers";
import defaultImage from ".storybook/assets/images/full-width-image";
import { sizesTemplate } from "../../components/image-container/image-container.stories";

export default {
title: "Elements/Images/Lazyloaded"
Expand All @@ -16,7 +15,7 @@ const loadedImage = () => {
alt="${image.alt}"
width="${image.width}"
height="${image.height}"
srcset="${sizesTemplate(image.srcSet)}"
srcset="${srcSet(image.srcSet)}"
sizes="100vw"
/>
</div>
Expand Down

0 comments on commit 7af938b

Please sign in to comment.