Skip to content

Commit

Permalink
Issue-97: Include additional stories for variants
Browse files Browse the repository at this point in the history
  • Loading branch information
DevLab2425 committed Oct 14, 2024
1 parent dd1c68a commit 933fd6a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/components/edit-on-github/edit-on-github.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ function convertRouteToSubLink(route) {

export default class EditOnGitHub extends HTMLElement {
connectedCallback() {
const label = this.getAttribute("label") || "Edit on GitHub";
// protect against strigified "undefined"; occurs when the prop value is undefined in JS, but a string in HTML
const label =
this.hasAttribute("label") && this.getAttribute("label") !== "undefined"
? this.getAttribute("label")
: "Edit on GitHub";
const route = this.getAttribute("route");
const href = `${REPO_PREFIX}${convertRouteToSubLink(route)}`;

Expand Down
47 changes: 45 additions & 2 deletions src/components/edit-on-github/edit-on-github.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import pages from "../../stories/mocks/graph.json";

export default {
title: "Components/Edit on GitHub",
component: "app-edit-on-github",
parameters: {
fetchMock: {
mocks: [
Expand All @@ -19,6 +20,48 @@ export default {
},
};

const Template = () => "<app-edit-on-github route='/guides/getting-started/'></app-edit-on-github>";
const Template = (props) => {
return `
<div style="margin:1em 0;"><p>Linked File: ${props.args.route}</p></div>
<app-edit-on-github label="${props.args.label}" route="${props.args.route}"></app-edit-on-github>
`;
};

export const DefaultLabel = Template.bind(
{},
{
args: {
route: "/",
},
},
);

export const Root = Template.bind(
{},
{
args: {
route: "/",
label: "Edit Root Page",
},
},
);

export const Directory = Template.bind(
{},
{
args: {
route: "/guides/hosting/",
label: "Edit Directory Page",
},
},
);

export const Primary = Template.bind({});
export const Static = Template.bind(
{},
{
args: {
route: "/guides/hosting/netlify",
label: "Edit Static Page",
},
},
);

0 comments on commit 933fd6a

Please sign in to comment.