Skip to content
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

Update Tooltip story #1181

Merged
merged 5 commits into from
Mar 29, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 60 additions & 17 deletions libraries/core-react/stories/components/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import React, { useState, useRef } from 'react'
import styled from 'styled-components'
import { Tooltip, TooltipProps, Typography, Button, Table } from '@components'
import {
Tooltip,
TooltipProps,
Typography,
Button,
Table,
Icon,
} from '@components'
import { data, columns } from './helpers/data'
import { toCellValues } from './helpers/toCellValues'
import { Story, Meta } from '@storybook/react'

import { chrome, explore } from '@equinor/eds-icons'

const icons = {
chrome,
explore,
}

Icon.add(icons)

const Body = styled.div`
margin: 42px;
display: grid;
Expand All @@ -28,36 +44,43 @@ export default {
component: Tooltip,
argTypes: {
title: {
defaultValue: 'Tooltip title',
defaultValue: 'This is the tooltip title',
},
},
} as Meta

export const Default: Story<TooltipProps> = (args) => {
const [openState, setOpenState] = useState(false)

let timer: ReturnType<typeof setTimeout>

const handleOpen = () => {
setOpenState(true)
timer = setTimeout(() => {
setOpenState(true)
}, 300)
}

const handleClose = () => {
clearTimeout(timer)
setOpenState(false)
}

const referenceElement = useRef(null)

return (
<div style={{ margin: '3rem 10rem' }}>
<Button
<Typography
link
href="#"
ref={referenceElement}
aria-describedby="tooltip"
onMouseEnter={handleOpen}
onMouseOver={handleOpen}
onMouseLeave={handleClose}
onFocus={handleOpen}
onBlur={handleClose}
>
Hover me!
</Button>
</Typography>
<Tooltip
open={openState}
id="tooltip"
Expand All @@ -71,11 +94,16 @@ export const Default: Story<TooltipProps> = (args) => {
export const WithDisabledElements: Story<TooltipProps> = () => {
const [openState, setOpenState] = useState(null)

let timer: ReturnType<typeof setTimeout> = null

const handleOpen = (num: 1 | 2) => {
setOpenState(num)
timer = setTimeout(() => {
setOpenState(num)
}, 300)
}

const handleClose = () => {
clearTimeout(timer)
setOpenState(null)
}

Expand All @@ -102,18 +130,19 @@ export const WithDisabledElements: Story<TooltipProps> = () => {
<Wrapper>
<Button
disabled
variant="ghost_icon"
aria-describedby="tooltip-disabled-chrome"
ref={referenceElementOne}
onPointerEnter={() => handleOpen(1)}
onPointerLeave={handleClose}
>
Disabled, but hover works!
<Icon title="Chrome disabled button has Tooltip" name="chrome"></Icon>
</Button>

<Tooltip
id="tooltip-disabled-chrome"
open={openState === 1}
title="Tooltip works!"
title="Disabled button, but hover works"
anchorEl={referenceElementOne.current}
/>

Expand All @@ -123,15 +152,22 @@ export const WithDisabledElements: Story<TooltipProps> = () => {
onPointerLeave={handleClose}
aria-describedby="tooltip-disabled-safari"
>
<Button disabled style={{ pointerEvents: 'none' }}>
Just Safari example
<Button
disabled
style={{ pointerEvents: 'none' }}
variant="ghost_icon"
>
<Icon
title="Safari disabled button has Tooltip"
name="explore"
></Icon>
</Button>
</div>

<Tooltip
id="tooltip-disabled-safari"
open={openState === 2}
title="Tooltip works!"
title="Disabled button, but hover works"
anchorEl={referenceElementTwo.current}
/>
</Wrapper>
Expand All @@ -149,14 +185,19 @@ export const TableCellsWithTooltip: Story<TooltipProps> = () => {
openCell: null,
})

let timer: ReturnType<typeof setTimeout>
pomfrida marked this conversation as resolved.
Show resolved Hide resolved

const handleOpen = (openRow: number, openCell: number) => {
setState({
openRow,
openCell,
})
timer = setTimeout(() => {
setState({
openRow,
openCell,
})
}, 300)
}

const handleClose = () => {
clearTimeout(timer)
setState({ openRow: null, openCell: null })
}

Expand All @@ -183,8 +224,10 @@ export const TableCellsWithTooltip: Story<TooltipProps> = () => {
<Table.Cell key={cellValue}>
<span
ref={createdRef}
onMouseEnter={() => handleOpen(rowIndex, cellIndex)}
onMouseOver={() => handleOpen(rowIndex, cellIndex)}
onMouseLeave={handleClose}
onFocus={() => handleOpen(rowIndex, cellIndex)}
onBlur={handleClose}
style={{
position: 'relative',
display: 'inline-block',
Expand Down