-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basically entirely replacing the actions addon ArgsEnhancers with our own that also add inlineQrl so it works with Qwik.
- Loading branch information
1 parent
3e799a8
commit c0ba17f
Showing
12 changed files
with
157 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Meta, StoryObj } from "storybook-framework-qwik"; | ||
import type { ButtonProps } from "./button"; | ||
import { Button } from "./button"; | ||
|
||
const meta = { | ||
title: "Button", | ||
args: {}, | ||
argTypes: { | ||
onClick$: { action: "onClick" }, | ||
}, | ||
component: Button, | ||
} satisfies Meta<ButtonProps>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<ButtonProps>; | ||
|
||
// More on writing stories with args: https://storybook.js.org/docs/7.0/react/writing-stories/args | ||
export const Primary: Story = {}; |
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,21 @@ | ||
import type { PropFunction } from "@builder.io/qwik"; | ||
import { component$ } from "@builder.io/qwik"; | ||
|
||
export interface ButtonProps { | ||
/** | ||
* Button contents | ||
*/ | ||
label: string; | ||
/** | ||
* Optional click handler | ||
*/ | ||
onClick$?: PropFunction<onClickEvent> | undefined; | ||
} | ||
|
||
export type onClickEvent = (event: MouseEvent, element: Element) => void; | ||
|
||
export const Button = component$<ButtonProps>( | ||
({ label = "click me!", onClick$ }) => { | ||
return <button onClick$={onClick$}>{label}</button>; | ||
}, | ||
); |
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,69 @@ | ||
// This file is entirely copied from @storybook/addon-actions (changing the action import) | ||
|
||
import type { Args, Renderer, ArgsEnhancer } from "@storybook/types"; | ||
import { action } from "@storybook/addon-actions"; | ||
|
||
// interface ActionsParameter { | ||
// disable?: boolean; | ||
// argTypesRegex?: RegExp; | ||
// } | ||
|
||
const isInInitialArgs = (name: string, initialArgs: Args) => | ||
typeof initialArgs[name] === "undefined" && !(name in initialArgs); | ||
|
||
/** | ||
* Automatically add action args for argTypes whose name | ||
* matches a regex, such as `^on.*` for react-style `onClick` etc. | ||
*/ | ||
|
||
export const inferActionsFromArgTypesRegex: ArgsEnhancer<Renderer> = ( | ||
context, | ||
) => { | ||
const { | ||
initialArgs, | ||
argTypes, | ||
parameters: { actions }, | ||
} = context; | ||
if (!actions || actions.disable || !actions.argTypesRegex || !argTypes) { | ||
return {}; | ||
} | ||
|
||
const argTypesRegex = new RegExp(actions.argTypesRegex); | ||
const argTypesMatchingRegex = Object.entries(argTypes).filter( | ||
([name]) => !!argTypesRegex.test(name), | ||
); | ||
|
||
return argTypesMatchingRegex.reduce((acc, [name, argType]) => { | ||
if (isInInitialArgs(name, initialArgs)) { | ||
acc[name] = action(name); | ||
} | ||
return acc; | ||
}, {} as Args); | ||
}; | ||
|
||
/** | ||
* Add action args for list of strings. | ||
*/ | ||
export const addActionsFromArgTypes: ArgsEnhancer<Renderer> = (context) => { | ||
const { | ||
initialArgs, | ||
argTypes, | ||
parameters: { actions }, | ||
} = context; | ||
if (actions?.disable || !argTypes) { | ||
return {}; | ||
} | ||
|
||
const argTypesWithAction = Object.entries(argTypes).filter( | ||
([name, argType]) => !!argType["action"], | ||
); | ||
|
||
return argTypesWithAction.reduce((acc, [name, argType]) => { | ||
if (isInInitialArgs(name, initialArgs)) { | ||
acc[name] = action( | ||
typeof argType["action"] === "string" ? argType["action"] : name, | ||
); | ||
} | ||
return acc; | ||
}, {} as Args); | ||
}; |
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
14 changes: 3 additions & 11 deletions
14
packages/storybook-framework-qwik/template/cli/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
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
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