diff --git a/packages/v2/gui/src/storybook/asyncAction.ts b/packages/v2/gui/src/storybook/asyncAction.ts new file mode 100644 index 0000000000..afc3a6cde0 --- /dev/null +++ b/packages/v2/gui/src/storybook/asyncAction.ts @@ -0,0 +1,12 @@ +import { action, type ActionOptions, type HandlerFunction } from '@storybook/addon-actions'; + +export type AsyncHandlerFunction = (...args: Parameters) => Promise>; + +/** + * Kan brukast i storybook istadenfor standard action, når funksjonen ein skal erstatte er async. + * Unngår med dette typescript klaging. + */ +export const asyncAction = (name: string, options: ActionOptions = {}): AsyncHandlerFunction => { + const handler = action(name, options); + return async (...args: Parameters) => handler(...args); +};