Skip to content

Commit

Permalink
feat: initial setup of button classes (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabian Gaukler <fabian.gaukler@holisticon.de>
  • Loading branch information
fabiangaukler and Fabian Gaukler authored Dec 13, 2024
1 parent 67c25a2 commit d340105
Show file tree
Hide file tree
Showing 12 changed files with 507 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/rare-rings-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@holisticon/hap-documentation": minor
"@holisticon/hap-foundation": minor
---

Added buttons and styling for them
42 changes: 39 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"lint-staged": "^15.2.4",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"storybook-addon-pseudo-states": "4.0.2",
"typescript": "^5.4.5",
"typescript-eslint": "^8.0.0-alpha.16"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/documentation/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { StorybookConfig } from "@storybook/web-components-vite";
const config: StorybookConfig = {
framework: "@storybook/web-components-vite",
core: { disableTelemetry: true },
stories: ["../src/**/*.mdx"],
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
stories: ["../src/**/*.mdx", "../src/**/*.stories.ts"],
addons: ["@storybook/addon-essentials", "storybook-addon-pseudo-states"],
};

export default config;
91 changes: 91 additions & 0 deletions packages/documentation/src/elements/button/button-story-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import type { ArgTypes } from "@storybook/web-components";
import { html } from "lit";

type ButtonSize = "default" | "small";
type ButtonVariant = "primary" | "secondary" | "tertiary" | "destructive";
type ButtonIconPosition = "left" | "right";
type ColorScheme = "light" | "dark";

export const buttonArgs = (variant: ButtonVariant): ButtonArgs => ({
variant,
size: "default",
disabled: false,
iconPosition: "left",
label: "",
});

export const buttonArgTypes: Partial<ArgTypes<ButtonArgs>> = {
variant: {
control: { type: "select" },
options: ["primary", "secondary", "tertiary", "destructive"],
},
size: {
control: { type: "select" },
options: ["default", "small"],
},
};

export interface ButtonArgs {
label: string;
variant: ButtonVariant;
size: ButtonSize;
disabled: boolean;
icon?: string;
iconPosition: ButtonIconPosition;
}

export const renderButtons = (args: ButtonArgs, colorScheme: ColorScheme) =>
html`<div
style="display:flex;gap:0.5rem;flex-direction:column;padding:2rem;color-scheme:${colorScheme};background-color:${colorScheme ===
"light"
? "white"
: "black"}"
>
${renderButton({ ...args, size: "default", label: "Default" })}
${renderButton({
...args,
size: "default",
label: "Default",
icon: "[Icon]",
})}
${renderButton({
...args,
size: "default",
label: "Default",
icon: "[Icon]",
iconPosition: "right",
})}
${renderButton({ ...args, size: "small", label: "Small" })}
${renderButton({
...args,
size: "small",
label: "Small",
icon: "[Icon]",
})}
${renderButton({
...args,
size: "small",
label: "Small",
icon: "[Icon]",
iconPosition: "right",
})}
</div> `;

const renderButton = (args: ButtonArgs) => {
return html`
<button
class="hap-button ${args.variant} ${args.size} ${args.disabled
? "disabled"
: ""}"
?disabled=${args.disabled}
>
${args.icon && args.iconPosition === "left"
? html`<span class="icon">${args.icon}</span>`
: ""}
${args.label}
${args.icon && args.iconPosition === "right"
? html`<span class="icon">${args.icon}</span>`
: ""}
</button>
`;
};
26 changes: 26 additions & 0 deletions packages/documentation/src/elements/button/button.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Meta, StoryObj } from "@storybook/web-components";
import { html } from "lit";
import {
buttonArgs,
buttonArgTypes,
renderButtons,
type ButtonArgs,
} from "./button-story-helpers.js";

const meta: Meta<ButtonArgs> = {
argTypes: buttonArgTypes,

render: (args) =>
html`<div style="display:flex;gap:1rem">
${renderButtons(args, "light")}${renderButtons(args, "dark")}
</div>`,
};

export default meta;

export type Story = StoryObj<ButtonArgs>;

export const ButtonPrimary: Story = { args: buttonArgs("primary") };
export const ButtonSecondary: Story = { args: buttonArgs("secondary") };
export const ButtonTertiary: Story = { args: buttonArgs("tertiary") };
export const ButtonDestructive: Story = { args: buttonArgs("destructive") };
24 changes: 24 additions & 0 deletions packages/documentation/src/elements/button/buttons.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Meta, Canvas } from "@storybook/blocks";
import * as ButtonStories from "./button.stories.ts";

<Meta title="Elements/button/Buttons" />

# Buttons

The following kinds of buttons are available.

## Primary Button

<Canvas of={ButtonStories.ButtonPrimary} />

## Secondary Button

<Canvas of={ButtonStories.ButtonSecondary} />

## Tertiary Button

<Canvas of={ButtonStories.ButtonTertiary} />

## Destructive Button

<Canvas of={ButtonStories.ButtonDestructive} />
Loading

0 comments on commit d340105

Please sign in to comment.