-
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.
- Loading branch information
Fabian Gaukler
committed
Jan 2, 2025
1 parent
6d9ed2b
commit 1cd8d21
Showing
5 changed files
with
166 additions
and
29 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
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
41 changes: 41 additions & 0 deletions
41
packages/documentation/src/elements/icon/icon-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,41 @@ | ||
import type { ArgTypes } from "@storybook/web-components"; | ||
import { html } from "lit"; | ||
|
||
export const iconArgs = ( | ||
iconNames: string[], | ||
size: string, | ||
// default values for stroke according to design | ||
strokeWidth = 1.5, | ||
strokeOpacity = 0.8, | ||
): IconArgs => ({ | ||
iconNames, | ||
size, | ||
strokeWidth, | ||
strokeOpacity, | ||
}); | ||
|
||
export const iconArgTypes: Partial<ArgTypes<IconArgs>> = { | ||
size: { | ||
control: { type: "select" }, | ||
options: ["default", "small"], | ||
}, | ||
}; | ||
|
||
export interface IconArgs { | ||
iconNames: string[]; | ||
size: string; | ||
strokeWidth: number; | ||
strokeOpacity: number; | ||
} | ||
|
||
export const renderIcons = (args: IconArgs) => html` | ||
${args.iconNames.map((iconName) => html`<i data-lucide=${iconName}></i>`)} | ||
`; | ||
|
||
export const mapIconSizeToPx = (size: string): string => { | ||
if (size === "small") { | ||
return "16px"; | ||
} | ||
|
||
return "24px"; | ||
}; |
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,87 @@ | ||
import type { Meta, StoryObj } from "@storybook/web-components"; | ||
import { html } from "lit"; | ||
import { createIcons, icons } from "lucide"; | ||
import { | ||
iconArgs, | ||
iconArgTypes, | ||
mapIconSizeToPx, | ||
renderIcons, | ||
type IconArgs, | ||
} from "./icon-story-helpers.js"; | ||
|
||
const iconList = [ | ||
"check", | ||
"arrow-right", | ||
"arrow-left", | ||
"arrow-down", | ||
"arrow-up", | ||
"arrow-up-right", | ||
"arrow-down-right", | ||
"arrow-down-left", | ||
"arrow-down-up", | ||
"circle-x", | ||
"chevron-down", | ||
"chevron-up", | ||
"chevron-left", | ||
"chevron-right", | ||
"plus", | ||
"log-out", | ||
"shopping-cart", | ||
"user-round", | ||
"clock", | ||
"menu", | ||
"search", | ||
"eye", | ||
"circle-alert", | ||
"code", | ||
"copy", | ||
"circle-play", | ||
"circle-help", | ||
"settings", | ||
"bell", | ||
"building-2", | ||
"file", | ||
"calendar", | ||
"trash-2", | ||
"eye-off", | ||
"sparkles", | ||
"info", | ||
"megaphone", | ||
"circle-check", | ||
"folder-open", | ||
"mail", | ||
"download", | ||
"lock", | ||
]; | ||
|
||
const meta: Meta<IconArgs> = { | ||
argTypes: iconArgTypes, | ||
|
||
render: (args) => | ||
// html`<div style="display:flex;gap:1rem; flex-wrap:wrap"> | ||
html`<div | ||
style="display:grid;grid-template-columns: repeat(14, max-content);gap:40px" | ||
> | ||
${renderIcons(args)} | ||
</div>`, | ||
play: (args) => { | ||
createIcons({ | ||
icons, | ||
attrs: { | ||
"stroke-width": args.initialArgs.strokeWidth, | ||
"stroke-opacity": args.initialArgs.strokeOpacity, | ||
height: mapIconSizeToPx(args.initialArgs.size), | ||
width: mapIconSizeToPx(args.initialArgs.size), | ||
// TODO should stroke color be declared in CSS directly? | ||
color: "#141419CC", | ||
}, | ||
}); | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
export type Story = StoryObj<IconArgs>; | ||
|
||
export const IconsDefault: Story = { args: iconArgs(iconList, "default") }; | ||
export const IconsSmall: Story = { args: iconArgs(iconList, "small") }; |
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