Skip to content

Commit

Permalink
feat: add click event to hot-button element
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Mar 13, 2024
1 parent d45c7e2 commit fd38267
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/button/Button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default meta;

export const Template: StoryObj = {
args: {
children: "Button",
intent: "primary",
disabled: false,
},
Expand All @@ -21,6 +20,25 @@ export const Template: StoryObj = {
},
},
},
render: (args) =>
html`<hot-button ?disabled=${args.disabled}>${args.children}</hot-button>`,
render: (args) => {
let buttonRendered = false;
const handleClick = () => {
// Function required as the click event is triggered once on render
if (buttonRendered) {
alert("Button Clicked");
return;
}
buttonRendered = true;
};

return html`
<hot-button
intent=${args.intent}
?disabled=${args.disabled}
@click=${handleClick}
>
Button
</hot-button>
`;
},
};
4 changes: 4 additions & 0 deletions src/button/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ export class button extends LitElement {
<slot></slot>
</button>`;
}

updated(changedProperties) {
this.dispatchEvent(new Event("click"));
}
}

0 comments on commit fd38267

Please sign in to comment.