Skip to content

Commit

Permalink
feat: Add support for transition attribute to accept number
Browse files Browse the repository at this point in the history
  • Loading branch information
tjtanjin committed Sep 14, 2024
1 parent 7c2ef1b commit 4899665
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/services/BlockService/TransitionProcessor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export const processTransition = async (flow: Flow, path: keyof Flow, params: Pa
transitionDetails = transitionAttr;
}

// if number provided, transform to object with default values
if (typeof transitionDetails === "number") {
transitionDetails = {duration: transitionDetails};
}

// cannot transition if details are not present
if (!transitionDetails || transitionDetails instanceof Promise) {
return;
Expand All @@ -44,7 +49,7 @@ export const processTransition = async (flow: Flow, path: keyof Flow, params: Pa
}

// defaults interruptable to false if not found
if (!transitionDetails.interruptable) {
if (transitionDetails.interruptable == null) {
transitionDetails.interruptable = false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/types/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export type Block = {
((params: Params) => Promise<JSX.Element | void>);
chatDisabled?: boolean | ((params: Params) => boolean) | ((params: Params) => Promise<boolean>);
isSensitive?: boolean | ((params: Params) => boolean) | ((params: Params) => Promise<boolean>);
transition?: {duration: number, interruptable?: boolean} | void |
((params: Params) => {duration: number, interruptable?: boolean} | void) |
((params: Params) => Promise<{duration: number, interruptable?: boolean} | void>);
transition?: number | {duration: number, interruptable?: boolean} | void |
((params: Params) => number | {duration: number, interruptable?: boolean} | void) |
((params: Params) => Promise<number | {duration: number, interruptable?: boolean} | void>);

// post-processing attributes (runs after user input)
function?: ((params: Params) => void) | ((params: Params) => Promise<void>);
Expand Down

0 comments on commit 4899665

Please sign in to comment.