-
-
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 #5 from storybookjs/feat/subnavigation
feat: subnav
- Loading branch information
Showing
7 changed files
with
241 additions
and
75 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
18 changes: 6 additions & 12 deletions
18
addons/interactions/src/components/StatusBadge/StatusBadge.tsx
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
50 changes: 50 additions & 0 deletions
50
addons/interactions/src/components/Subnav/Subnav.stories.tsx
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,50 @@ | ||
import { CallState } from '../../types'; | ||
import { Subnav } from './Subnav'; | ||
|
||
export default { | ||
title: 'Subnav', | ||
component: Subnav, | ||
args: { | ||
onPrevious: () => {}, | ||
onNext: () => {}, | ||
onReplay: () => {}, | ||
goToEnd: () => {}, | ||
storyFileName: 'Subnav.stories.tsx', | ||
hasNext: true, | ||
hasPrevious: true, | ||
}, | ||
}; | ||
|
||
export const Pass = { | ||
args: { | ||
status: CallState.DONE, | ||
}, | ||
}; | ||
|
||
export const Fail = { | ||
args: { | ||
status: CallState.ERROR, | ||
}, | ||
}; | ||
|
||
export const Runs = { | ||
args: { | ||
status: CallState.PENDING, | ||
}, | ||
}; | ||
|
||
export const AtTheBeginning = { | ||
name: 'at the beginning', | ||
args: { | ||
status: CallState.DONE, | ||
hasPrevious: false, | ||
}, | ||
}; | ||
|
||
export const AtTheEnd = { | ||
name: 'at the end', | ||
args: { | ||
status: CallState.DONE, | ||
hasNext: false, | ||
}, | ||
}; |
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,144 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Icons, Separator, P } from '@storybook/components'; | ||
import { styled } from '@storybook/theming'; | ||
import { CallState } from '../../types'; | ||
import { StatusBadge } from '../StatusBadge/StatusBadge'; | ||
import { transparentize } from 'polished'; | ||
import { ButtonProps } from '@storybook/components/dist/ts3.9/Button/Button'; | ||
|
||
const StyledSubnav = styled.nav(({ theme }) => ({ | ||
background: theme.background.app, | ||
borderBottom: `1px solid ${theme.color.border}`, | ||
height: 40, | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between', | ||
paddingLeft: 15, | ||
position: 'sticky', | ||
top: 0, | ||
zIndex: 1, | ||
})); | ||
|
||
export interface SubnavProps { | ||
status: `${CallState}`; | ||
onPrevious: () => void; | ||
onNext: () => void; | ||
onReplay: () => void; | ||
goToEnd: () => void; | ||
storyFileName?: string; | ||
hasPrevious: boolean; | ||
hasNext: boolean; | ||
} | ||
|
||
const StyledButton = styled(Button)(({ theme }) => ({ | ||
borderRadius: 4, | ||
padding: 6, | ||
color: theme.color.dark, | ||
'&:hover,&:focus-visible': { | ||
color: theme.color.secondary, | ||
}, | ||
})); | ||
|
||
const StyledIconButton = styled(StyledButton)(({ theme }) => ({ | ||
color: theme.color.mediumdark, | ||
margin: '0 3px', | ||
'&:hover,&:focus-visible': { | ||
background: transparentize(0.9, theme.color.secondary), | ||
}, | ||
})); | ||
|
||
interface AnimatedButtonProps extends ButtonProps { | ||
animating?: boolean; | ||
} | ||
const StyledAnimatedIconButton = styled(StyledIconButton)<AnimatedButtonProps>( | ||
({ theme, animating }) => ({ | ||
svg: { | ||
animation: animating && `${theme.animation.rotate360} 1000ms ease-out`, | ||
}, | ||
}) | ||
); | ||
|
||
const StyledSeparator = styled(Separator)({ | ||
marginTop: 0, | ||
}); | ||
|
||
const StyledLocation = styled(P)(({ theme }) => ({ | ||
color: theme.color.dark, | ||
justifyContent: 'flex-end', | ||
textAlign: 'right', | ||
paddingRight: 15, | ||
fontSize: 13, | ||
})); | ||
|
||
const Group = styled.div({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
}); | ||
|
||
const PlaybackButton = styled(StyledIconButton)({ | ||
marginLeft: 9, | ||
}); | ||
|
||
const JumpToEndButton = styled(StyledButton)({ | ||
marginLeft: 9, | ||
marginRight: 9, | ||
}); | ||
|
||
export const Subnav: React.FC<SubnavProps> = ({ | ||
status, | ||
onPrevious, | ||
onNext, | ||
onReplay, | ||
goToEnd, | ||
storyFileName, | ||
hasNext, | ||
hasPrevious, | ||
}) => { | ||
const buttonText = status === CallState.ERROR ? 'Jump to error' : 'Jump to end'; | ||
const [isAnimating, setIsAnimating] = useState(false); | ||
const animateAndReplay = () => { | ||
setIsAnimating(true); | ||
onReplay(); | ||
}; | ||
|
||
return ( | ||
<StyledSubnav> | ||
<Group> | ||
<StatusBadge status={status} /> | ||
|
||
<JumpToEndButton onClick={goToEnd} disabled={!hasNext}> | ||
{buttonText} | ||
</JumpToEndButton> | ||
|
||
<StyledSeparator /> | ||
|
||
<PlaybackButton | ||
containsIcon | ||
title="Previous step" | ||
onClick={onPrevious} | ||
disabled={!hasPrevious} | ||
> | ||
<Icons icon="playback" /> | ||
</PlaybackButton> | ||
<StyledIconButton containsIcon title="Next step" onClick={onNext} disabled={!hasNext}> | ||
<Icons icon="playnext" /> | ||
</StyledIconButton> | ||
<StyledAnimatedIconButton | ||
containsIcon | ||
title="Replay interactions" | ||
onClick={animateAndReplay} | ||
onAnimationEnd={() => setIsAnimating(false)} | ||
animating={isAnimating} | ||
data-test-id="button--replay" | ||
> | ||
<Icons icon="sync" /> | ||
</StyledAnimatedIconButton> | ||
</Group> | ||
{storyFileName && ( | ||
<Group> | ||
<StyledLocation>{storyFileName}</StyledLocation> | ||
</Group> | ||
)} | ||
</StyledSubnav> | ||
); | ||
}; |
Oops, something went wrong.