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

Commit

Permalink
migrate secondary button stories to controls/args
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhmarsh committed Dec 27, 2021
1 parent a60658d commit 11eeed4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 110 deletions.
3 changes: 2 additions & 1 deletion .storybook/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import html from "./html";
import repeat from "./repeat";
import backgroundOverride from "./backgroundOverride";

export { html, repeat };
export { html, repeat, backgroundOverride };
1 change: 1 addition & 0 deletions src/global/buttons/_sb-only.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "../../base/base";

/* stylelint-disable max-nesting-depth */
._sb-breathing-room {
display: inline-block;
Expand Down
9 changes: 3 additions & 6 deletions src/global/buttons/primary/primary.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ const argTypes = {

export default {
title: "Elements/Buttons/Primary",
parameters: {
backgrounds: { disable: true }, // TODO: hopefully Chromatic supports backgrounds soon
},
argTypes
};

Expand All @@ -57,8 +54,8 @@ permutations.elementTags.forEach((elementTag) => {
state,
};

let current = [elementTag, styleMode, sizeMode, state].map((option) => { return option.replaceAll("-", ""); });
let storyName = current.join("");
let current = [elementTag, styleMode, sizeMode, state];
let storyName = current.map((option) => option.replaceAll("-", "")).join("");

StoriesToExport[storyName] = (args) => StoryTemplate(args);
StoriesToExport[storyName].story = {
Expand All @@ -77,7 +74,7 @@ const StoryTemplate = (args) => html`
<a class="button primary-button
primary-button--${args.sizeMode.toLowerCase()}
primary-button--${args.styleMode.toLowerCase()}
${args.state === " Hover" ? "_sb--hover" : ""}
${args.state === "Hover" ? "_sb--hover" : ""}
${args.state === "Focus" ? "_sb--focus" : ""}"
role="button"
tabindex="0"
Expand Down
174 changes: 71 additions & 103 deletions src/global/buttons/secondary/secondary.stories.js
Original file line number Diff line number Diff line change
@@ -1,135 +1,103 @@
import html from "../../../../.storybook/helpers/html";
import { withKnobs, text, radios } from "@storybook/addon-knobs";
import backgroundOverride from "../../../../.storybook/helpers/backgroundOverride";
import { html, backgroundOverride } from "../../../../.storybook/helpers";
import "../_sb-only.scss";

export default {
decorators: [withKnobs],
title: "Elements/Buttons/Secondary",
parameters: {
backgrounds: { disable: true }, // TODO: hopefully Chromatic supports backgrounds soon
},
};

const permutations = {
elementTags: ["Button", "Anchor"],
styles: ["Ghost-Light", "Ghost-Dark"],
states: ["Active", "Inactive", "Focus", "Hover"],
};

const StoriesToExport = {
AnchorDefault: () =>
buttonStoryTemplate({ elementTag: "Anchor", styleMode: null }),
ButtonDefault: () =>
buttonStoryTemplate({ elementTag: "Button", styleMode: null }),
const argTypes = {
elementTag: {
options: permutations.elementTags,
control: "inline-radio"
},
styleMode: {
options: permutations.styles,
control: "radio"
},
state: {
options: permutations.states,
control: "radio"
},
viewMode: {
options: ["Just the button", "Give it some breathing room"],
defaultValue: "Give it some breathing room",
control: "radio"
}
};

export default {
title: "Elements/Buttons/Secondary",
argTypes
};

const StoriesToExport = {};

permutations.elementTags.forEach((elementTag) => {
permutations.styles.forEach((styleMode) => {
permutations.states.forEach((state) => {
let storyName = [elementTag, styleMode.replace("-", ""), state].join("");
const args = {
label: "Secondary Button",
elementTag,
styleMode,
state
};

let current = [elementTag, styleMode, state];
let storyName = current.map((option) => option.replaceAll("-", "")).join("");

StoriesToExport[storyName] = () => {
return buttonStoryTemplate({
elementTag,
styleMode,
state,
});
StoriesToExport[storyName] = (args) => SecondaryButton(args);
StoriesToExport[storyName].story = {
title: "Elements/Buttons/Secondary",
name: current.map((option) => option.replaceAll("-", " ")).join(" ")
};
StoriesToExport[storyName].args = args;
});
});
});

const elementTagSelector = (defaultValue) => {
const label = "Element Tag";
return radios(label, permutations.elementTags, defaultValue);
};

const styleSelector = (defaultValue) => {
const label = "Style Modes";
return radios(label, permutations.styles, defaultValue);
};

const stateSelector = (defaultValue) => {
const label = "State";
return radios(label, permutations.states, defaultValue);
};

const buttonStoryTemplate = (options) => {
// reassign the options based on knobs
const elementTag = elementTagSelector(options.elementTag);
const styleMode = styleSelector(options.styleMode);
const state = stateSelector(options.state);
const viewMode = radios("View As", ["Just the button", "Give it some breathing room"], "Give it some breathing room");

const finalOptions = {
elementTag,
styleMode,
state,
};



return html`
${finalOptions.styleMode === "Ghost-Light" ? backgroundOverride() : ""}
${viewMode == "Give it some breathing room" ? "<div class='_sb-breathing-room'>" : ""}
${finalOptions.elementTag === "Anchor"
? anchorTagTemplate(finalOptions)
: finalOptions.elementTag === "Button"
? buttonTagTemplate(finalOptions)
: "Error: no element tag selected"}
${viewMode == "Give it some breathing room" ? "</div>" : ""}
`;
};

const anchorTagTemplate = (options) => {
let styleModifier = options?.styleMode
? `secondary-button--${options.styleMode.toLowerCase()}`
: "";

return html`
<a
class="button secondary-button ${styleModifier}
${options.state === "Hover" ? "_sb--hover" : ""}
${options.state === "Focus" ? "_sb--focus" : ""}"
role="button"
tabindex="0"
${options.state === "Inactive" ? "disabled" : ""}
>
${text("Label", "Secondary Button")}
</a>
`;
};

const buttonTagTemplate = (options) => {
let styleModifier = options?.styleMode
? `secondary-button--${options.styleMode.toLowerCase()}`
: "";
return html`
<button
class="button secondary-button ${styleModifier}
${options.state === "Hover" ? "_sb--hover" : ""}
${options.state === "Focus" ? "_sb--focus" : ""}"
${options.state === "Inactive" ? "disabled" : ""}
>
${text("Label", "Secondary Button")}
</button>
`;
const SecondaryButton = (args) => {
`${console.log("down ehre args is: ", args)}`;
if (args.elementTag === "Button") {
return html`
${args.styleMode !== "Ghost-Dark" ? backgroundOverride() : ""}
${args.viewMode == "Give it some breathing room" ? html`<div class="_sb-breathing-room">` : ""}
<button class="button secondary-button secondary-button--${args.styleMode.toLowerCase()}
${args.state === "Hover" ? "_sb--hover" : ""} ${args.state === "Focus" ? "_sb--focus" : "" }"
${args.state==="Inactive" ? "disabled" : "" }>
${args.label}
</button>
${args.viewMode == "Give it some breathing room" ? "</div>" : ""}
`;
}

if (args.elementTag === "Anchor") {
return html`
${args.styleMode !== "Ghost-Dark" ? backgroundOverride() : ""}
${args.viewMode == "Give it some breathing room" ? html`<div class="_sb-breathing-room">` : ""}
<a class="button secondary-button secondary-button--${args.styleMode.toLowerCase()}
${args.state === "Hover" ? "_sb--hover" : ""} ${args.state === "Focus" ? "_sb--focus" : "" }"
${args.state === "Inactive" ? "disabled" : "" } role="button" tabindex="0">
${args.label}
</a>
${args.viewMode == "Give it some breathing room" ? "</div>" : ""}
`;
}

return html`Error: no element tag selected ${JSON.stringify(args)}`;
};

/* eslint storybook/story-exports: "off" */
export const {
ButtonDefault,
ButtonGhostLightActive,
ButtonGhostLightFocus,
ButtonGhostLightHover,
ButtonGhostDarkActive,
AnchorDefault,

AnchorGhostLightActive,
AnchorGhostLightFocus,
AnchorGhostLightHover,
AnchorGhostDarkActive,
} = StoriesToExport;
} = StoriesToExport;

0 comments on commit 11eeed4

Please sign in to comment.