-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16042 from storybookjs/interactions-rewind
feat: add rewind button to interactions subnav
- Loading branch information
Showing
5 changed files
with
55 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,38 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import { useChannel } from '@storybook/api'; | ||
import { Icons, IconButton } from '@storybook/components'; | ||
import { styled } from '@storybook/theming'; | ||
import { ButtonProps } from '@storybook/components/dist/ts3.9/Button/Button'; | ||
import { EVENTS, TOOL_ID } from './constants'; | ||
|
||
interface AnimatedButtonProps extends ButtonProps { | ||
animating?: boolean; | ||
} | ||
const StyledAnimatedIconButton = styled(IconButton)<AnimatedButtonProps>( | ||
({ theme, animating }) => ({ | ||
svg: { | ||
animation: animating && `${theme.animation.rotate360} 1000ms ease-out`, | ||
}, | ||
}) | ||
); | ||
|
||
export const Tool = () => { | ||
const emit = useChannel({}); | ||
const [isAnimating, setIsAnimating] = useState(false); | ||
const animateAndReplay = () => { | ||
setIsAnimating(true); | ||
emit(EVENTS.RELOAD); | ||
}; | ||
|
||
return ( | ||
<IconButton key={TOOL_ID} title="Rerun story" onClick={() => emit(EVENTS.RELOAD)}> | ||
<StyledAnimatedIconButton | ||
key={TOOL_ID} | ||
title="Rerun interactions" | ||
onClick={animateAndReplay} | ||
onAnimationEnd={() => setIsAnimating(false)} | ||
animating={isAnimating} | ||
> | ||
<Icons icon="sync" /> | ||
</IconButton> | ||
</StyledAnimatedIconButton> | ||
); | ||
}; |
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