-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 #15325 from margelo/hanno/change-tooltip-accept-ge…
…neric-content [Web] Change tooltip component to accept generic content
- Loading branch information
Showing
5 changed files
with
167 additions
and
39 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
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React from 'react'; | ||
import Tooltip from '../components/Tooltip'; | ||
|
||
/** | ||
* We use the Component Story Format for writing stories. Follow the docs here: | ||
* | ||
* https://storybook.js.org/docs/react/writing-stories/introduction#component-story-format | ||
*/ | ||
const story = { | ||
title: 'Components/Tooltip', | ||
component: Tooltip, | ||
}; | ||
|
||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
const Template = args => ( | ||
<div style={{ | ||
width: 100, | ||
}} | ||
> | ||
{/* eslint-disable-next-line react/jsx-props-no-spreading */} | ||
<Tooltip {...args} maxWidth={args.maxWidth || undefined}> | ||
<div style={{ | ||
width: 100, | ||
height: 60, | ||
display: 'flex', | ||
backgroundColor: 'red', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}} | ||
> | ||
Hover me | ||
</div> | ||
</Tooltip> | ||
</div> | ||
); | ||
|
||
// Arguments can be passed to the component by binding | ||
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args | ||
const Default = Template.bind({}); | ||
Default.args = { | ||
text: 'Tooltip', | ||
numberOfLines: 1, | ||
maxWidth: 0, | ||
absolute: false, | ||
}; | ||
|
||
const RenderContent = () => { | ||
const [size, setSize] = React.useState(40); | ||
|
||
const renderTooltipContent = () => ( | ||
<div style={{ | ||
width: size, | ||
height: size, | ||
backgroundColor: 'blue', | ||
}} | ||
/> | ||
); | ||
|
||
return ( | ||
<div style={{ | ||
width: 100, | ||
}} | ||
> | ||
{/* eslint-disable-next-line react/jsx-props-no-spreading */} | ||
<Tooltip renderTooltipContent={renderTooltipContent}> | ||
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */} | ||
<div | ||
onClick={() => setSize(size + 25)} | ||
style={{ | ||
width: 100, | ||
height: 60, | ||
display: 'flex', | ||
backgroundColor: 'red', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}} | ||
> | ||
Hover me | ||
{' '} | ||
{'\n'} | ||
Press me change content | ||
</div> | ||
</Tooltip> | ||
</div> | ||
); | ||
}; | ||
|
||
export default story; | ||
export { | ||
Default, | ||
RenderContent, | ||
}; |
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