-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial setup of button classes (#48)
Co-authored-by: Fabian Gaukler <fabian.gaukler@holisticon.de>
- Loading branch information
1 parent
67c25a2
commit d340105
Showing
12 changed files
with
507 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/documentation/src/elements/button/button-story-helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
packages/documentation/src/elements/button/button.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> |
Oops, something went wrong.