-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ToolTip: Remove knobs in stories #46515
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,14 +1,3 @@ | ||||||||
/** | ||||||||
* External dependencies | ||||||||
*/ | ||||||||
import styled from '@emotion/styled'; | ||||||||
import { text, select, number } from '@storybook/addon-knobs'; | ||||||||
|
||||||||
/** | ||||||||
* WordPress dependencies | ||||||||
*/ | ||||||||
import { useState } from '@wordpress/element'; | ||||||||
|
||||||||
/** | ||||||||
* Internal dependencies | ||||||||
*/ | ||||||||
|
@@ -17,79 +6,80 @@ import Tooltip from '../'; | |||||||
export default { | ||||||||
title: 'Components/ToolTip', | ||||||||
component: Tooltip, | ||||||||
argTypes: { | ||||||||
delay: { control: 'number' }, | ||||||||
position: { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we default to
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||||||||
control: { | ||||||||
type: 'select', | ||||||||
options: [ | ||||||||
'top left', | ||||||||
'top center', | ||||||||
'top right', | ||||||||
'bottom left', | ||||||||
'bottom center', | ||||||||
'bottom right', | ||||||||
], | ||||||||
}, | ||||||||
}, | ||||||||
text: { control: 'text' }, | ||||||||
}, | ||||||||
parameters: { | ||||||||
knobs: { disable: false }, | ||||||||
docs: { source: { state: 'open' } }, | ||||||||
}, | ||||||||
}; | ||||||||
|
||||||||
export const _default = () => { | ||||||||
const positionOptions = { | ||||||||
'top left': 'top left', | ||||||||
'top center ': 'top center', | ||||||||
'top right': 'top right', | ||||||||
'bottom left': 'bottom left', | ||||||||
'bottom center ': 'bottom center', | ||||||||
'bottom right': 'bottom right', | ||||||||
}; | ||||||||
const tooltipText = text( 'Text', 'More information' ); | ||||||||
const position = select( 'Position', positionOptions, 'top center' ); | ||||||||
const delay = number( 'Delay', 700 ); | ||||||||
return ( | ||||||||
<> | ||||||||
<Tooltip text={ tooltipText } position={ position } delay={ delay }> | ||||||||
<div | ||||||||
style={ { | ||||||||
margin: '50px auto', | ||||||||
width: '200px', | ||||||||
padding: '20px', | ||||||||
textAlign: 'center', | ||||||||
border: '1px solid #ccc', | ||||||||
} } | ||||||||
> | ||||||||
Hover for more information | ||||||||
</div> | ||||||||
</Tooltip> | ||||||||
<Tooltip text={ tooltipText } position={ position } delay={ delay }> | ||||||||
<div | ||||||||
style={ { | ||||||||
margin: '50px auto', | ||||||||
width: 'min-content', | ||||||||
padding: '4px', | ||||||||
textAlign: 'center', | ||||||||
border: '1px solid #ccc', | ||||||||
} } | ||||||||
> | ||||||||
Small target | ||||||||
</div> | ||||||||
</Tooltip> | ||||||||
</> | ||||||||
); | ||||||||
const Template = ( args ) => { | ||||||||
return <Tooltip { ...args } />; | ||||||||
}; | ||||||||
|
||||||||
const Button = styled.button` | ||||||||
margin: 0 10px; | ||||||||
`; | ||||||||
export const Default = Template.bind( {} ); | ||||||||
Default.args = { | ||||||||
text: 'More information', | ||||||||
children: ( | ||||||||
<div | ||||||||
style={ { | ||||||||
margin: '50px auto', | ||||||||
width: '200px', | ||||||||
padding: '20px', | ||||||||
textAlign: 'center', | ||||||||
border: '1px solid #ccc', | ||||||||
} } | ||||||||
> | ||||||||
Hover for more information | ||||||||
</div> | ||||||||
), | ||||||||
}; | ||||||||
|
||||||||
export const DisabledElement = () => { | ||||||||
const [ showMessage, toggleMessage ] = useState( false ); | ||||||||
export const SmallTarget = Template.bind( {} ); | ||||||||
SmallTarget.args = { | ||||||||
...Default.args, | ||||||||
children: ( | ||||||||
<div | ||||||||
style={ { | ||||||||
margin: '50px auto', | ||||||||
width: 'min-content', | ||||||||
padding: '4px', | ||||||||
textAlign: 'center', | ||||||||
border: '1px solid #ccc', | ||||||||
} } | ||||||||
> | ||||||||
Small target | ||||||||
</div> | ||||||||
), | ||||||||
}; | ||||||||
|
||||||||
return ( | ||||||||
<> | ||||||||
<Tooltip text="Hey, I am tooltip" position="bottom center"> | ||||||||
<Button onClick={ () => toggleMessage( ! showMessage ) }> | ||||||||
Hover me! | ||||||||
</Button> | ||||||||
</Tooltip> | ||||||||
<Tooltip text="Hey, I am tooltip" position="bottom center"> | ||||||||
<Button | ||||||||
disabled | ||||||||
onClick={ () => toggleMessage( ! showMessage ) } | ||||||||
> | ||||||||
Hover me, but I am disabled | ||||||||
</Button> | ||||||||
</Tooltip> | ||||||||
<br /> | ||||||||
{ showMessage ? <p>Hello World!</p> : null } | ||||||||
</> | ||||||||
); | ||||||||
export const DisabledChild = Template.bind( {} ); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this story can be removed because it's basically just a mock for manual testing (that is already covered in unit tests #35254) 🤔 I'm fine with leaving it in for now though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with leaving it as well, I guess someone could find it useful. |
||||||||
DisabledChild.args = { | ||||||||
...Default.args, | ||||||||
children: ( | ||||||||
<button | ||||||||
disabled | ||||||||
onClick={ () => | ||||||||
// eslint-disable-next-line no-alert | ||||||||
window.alert( 'This alert should not be triggered' ) | ||||||||
} | ||||||||
> | ||||||||
Hover me, but I am disabled | ||||||||
</button> | ||||||||
), | ||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add a
defaultValue
of700
to keep the default value that was there when we used knobs?Feel free to place it in
Default.args
if that makes more sense for you.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general we've been taking the direction of not re-specifying default values in Storybook, so we can showcase the actual defaults that are coming from the component code.
The props table will show descriptions and default values once this is converted to TypeScript, which will also help.