Skip to content

Commit

Permalink
Add args parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Jan 10, 2025
1 parent 3597d68 commit dea2d7b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@ export const Default: Story = {
render: (args) => ({
components: { VImageResult },
setup() {
const urlParams = new URLSearchParams(window.location.search)
const urlArgs =
urlParams
.get("args")
?.split(";")
.map((arg) => arg.split(":")) ?? []
const storyArgs = { ...args } as Record<string, unknown>
for (const [key, value] of urlArgs) {
storyArgs[key] = value
}
return () =>
h("div", { class: "p-4 image-wrapper max-w-80" }, [
h("ol", { class: "flex flex-wrap gap-4" }, [h(VImageResult, args)]),
h("ol", { class: "flex flex-wrap gap-4" }, [
h(VImageResult, storyArgs as typeof args),
]),
])
},
}),
Expand Down
19 changes: 14 additions & 5 deletions frontend/src/components/meta/VButton.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ export default {
const Template = (args) => ({
components: { VButton },
setup() {
const { size, variant, ...rest } = args
const urlParams = new URLSearchParams(window.location.search)
const urlArgs =
urlParams
.get("args")
?.split(";")
.map((arg) => arg.split(":")) ?? []
const storyArgs = { ...args }
for (const [key, value] of urlArgs) {
storyArgs[key] = value
}
return () =>
h("div", { class: "flex" }, [
h(
Expand All @@ -60,18 +69,18 @@ const Template = (args) => ({
id: "wrapper",
class: [
"px-4 h-16 flex items-center justify-center",
variant.startsWith("transparent") ? "bg-surface" : "bg-default",
args.variant.startsWith("transparent")
? "bg-surface"
: "bg-default",
],
},
[
h(
VButton,
{
size,
variant,
class: "description-bold",
href: "/",
...rest,
...storyArgs,
},
() => "Code is Poetry"
),
Expand Down

0 comments on commit dea2d7b

Please sign in to comment.