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 4b4fa7d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,22 @@ const Template: StoryTemplate = {
render: (args) => ({
components: { VNotificationBanner },
setup() {
return () => h(VNotificationBanner, { ...args }, { default: () => text })
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(
VNotificationBanner,
{ ...(storyArgs as typeof args) },
{ default: () => text }
)
},
}),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,24 @@ export const Default = {
render: (args) => ({
components: { VSearchTypes },
setup() {
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",
{
style: args.size === "small" ? "width: max-content;" : "",
style: storyArgs.size === "small" ? "width: max-content;" : "",
class: "wrapper p-2",
},
[h(VSearchTypes, args)]
[h(VSearchTypes, storyArgs)]
)
},
}),
Expand Down
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 4b4fa7d

Please sign in to comment.