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

Tooltip component #27

Merged
merged 15 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules
/packages/*/lib
/packages/*/coverage
*.tsbuildinfo
.npmrc
.npmrc
.DS_Store
32 changes: 27 additions & 5 deletions packages/test-helpers/src/enzyme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MountRendererProps, mount } from 'enzyme'
import { MountRendererProps, mount, ReactWrapper } from 'enzyme'
import { axe, JestAxe, toHaveNoViolations } from 'jest-axe'
import { ReactElement } from 'react'
import { act } from 'react-dom/test-utils'

expect.extend(toHaveNoViolations)

Expand All @@ -14,16 +15,37 @@ export const axeDefaultOptions: AxeOptions = {
},
}

export interface MountOptions {
mountOptions?: MountRendererProps
axeOptions?: AxeOptions
act?: 'sync' | 'async'
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const mountAndCheckA11Y = async <P>(
node: ReactElement<P>,
{ mountOptions, axeOptions = axeDefaultOptions }: { mountOptions?: MountRendererProps; axeOptions?: AxeOptions } = {},
{ mountOptions, axeOptions = axeDefaultOptions, act: actOption = 'async' }: MountOptions = {},
) => {
const wrapper = mount(node, mountOptions)
let wrapper: ReactWrapper<P>

if (actOption === 'sync') {
act(() => {
wrapper = mount(node, mountOptions)
})
} else if (actOption === 'async') {
// eslint-disable-next-line @typescript-eslint/require-await
await act(async () => {
wrapper = mount(node, mountOptions)
})
} else {
wrapper = mount(node, mountOptions)
}

const results = await axe(wrapper.getDOMNode(), axeOptions)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const results = await axe(wrapper!.getDOMNode(), axeOptions)

expect(results).toHaveNoViolations()

return wrapper
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return wrapper!
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
248 changes: 248 additions & 0 deletions packages/ui/__stories__/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
import React from 'react'
import { Button } from '../src/Button'

import { Tooltip } from '../src/Tooltip'

import utilStyles from './utils.scss'

export default {
title: 'Components/Tooltip',
component: Tooltip,
}

export const Default = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-default" content={'Tooltip content'}>
jozefhruska marked this conversation as resolved.
Show resolved Hide resolved
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-default">
Hover me
</Button>
)}
</Tooltip>
</div>
)

Default.parameters = {
design: {
type: 'figma',
url: 'https://www.figma.com/file/kaC3jgqMSgqMEgnv7TIse1/%F0%9F%93%90Sign-in-flow?node-id=118%3A2349',
},
}

export const AutoPlacement = () => (
<div className={utilStyles.wrapperCentered}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add more padding so the screenshots are not cropped?

<Tooltip id="tooltip-placement-auto" placement="auto" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-auto">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const AutoStartPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-auto-start" placement="auto-start" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-auto-start">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const AutoEndPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-auto-end" placement="auto-end" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-auto-end">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const TopPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-top" placement="top" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-top">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const TopStartPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-top-start" placement="top-start" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-top-start">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const TopEndPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-top-end" placement="top-end" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-top-end">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const RightPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-right" placement="right" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-right">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const RightStartPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-right-start" placement="right-start" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-right-start">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const RightEndPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-right-end" placement="right-end" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-right-start">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const BottomPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-bottom" placement="bottom" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-bottom">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const BottomStartPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-bottom-start" placement="bottom-start" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-bottom-start">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const BottomEndPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-bottom-end" placement="bottom-end" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-bottom-end">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const LeftPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-left" placement="left" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-left">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const LeftStartPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-left-start" placement="left-start" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-left-start">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const LeftEndPlacement = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-placement-left-end" placement="left-end" content={'Tooltip content'} visible>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-placement-left-end">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const InteractiveContent = () => (
<div className={utilStyles.wrapperCentered} style={{ minHeight: '250px' }}>
<Tooltip
id="tooltip-interactive-content"
content={
<>
<p>
Parley come about mutiny swing the lead to go on account run a shot across the bow schooner fathom bounty carouser. Maroon
killick keel driver scourge of the seven seas Jolly Roger hands spyglass Brethren of the Coast booty. Boom rigging gally Plate
Fleet pink dance the hempen jig bilge water measured fer yer chains take a caulk tender.
</p>

<Button>Aye Captain!</Button>
</>
}
visible
>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-interactive-content">
Hover me
</Button>
)}
</Tooltip>
</div>
)

export const VisibleFalse = () => (
<div className={utilStyles.wrapperCentered}>
<Tooltip id="tooltip-disabled" content={'Tooltip content'} visible={false}>
{(ref) => (
<Button ref={ref} aria-labelledby="tooltip-disabled">
Hover me
</Button>
)}
</Tooltip>
</div>
)
5 changes: 5 additions & 0 deletions packages/ui/__stories__/utils.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.wrapperCentered {
jankoritak marked this conversation as resolved.
Show resolved Hide resolved
display: flex;
flex-direction: column;
align-items: center;
}
11 changes: 6 additions & 5 deletions packages/ui/__tests__/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import { X } from 'react-feather'

import { mountAndCheckA11Y } from '@hazelcast/test-helpers'

import { Tooltip } from '../src/Tooltip'
Expand Down Expand Up @@ -104,14 +103,16 @@ describe('Button', () => {
const disabledTooltip = 'Disabled tooltip'

const wrapper = await mountAndCheckA11Y(
<Button disabled disabledTooltip={disabledTooltip}>
{label}
</Button>,
<div>
<Button disabled disabledTooltip={disabledTooltip}>
{label}
</Button>
</div>,
)

expect(wrapper.find('button').prop('disabled')).toBe(true)
expect(wrapper.find(Tooltip).at(0).props()).toMatchObject({
overlay: disabledTooltip,
content: disabledTooltip,
})
})
})
3 changes: 1 addition & 2 deletions packages/ui/__tests__/Toast.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react'
import { act } from 'react-dom/test-utils'

import { AlertTriangle, CheckCircle, Info, AlertCircle } from 'react-feather'
jozefhruska marked this conversation as resolved.
Show resolved Hide resolved
import { mountAndCheckA11Y } from '@hazelcast/test-helpers'

import { AlertTriangle, CheckCircle, Info, AlertCircle } from 'react-feather'
import { Toast, ToastType, IconDescriptor } from '../src/Toast'

const content = 'Toast Content'
Expand Down