-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(web-react): Use the new Placement dictionary in
Tooltip
#DS-923
- Loading branch information
1 parent
0cb30d5
commit 07fe0df
Showing
14 changed files
with
279 additions
and
69 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
14 changes: 11 additions & 3 deletions
14
packages/web-react/src/components/Tooltip/__tests__/useTooltipStyleProps.test.ts
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 |
---|---|---|
@@ -1,21 +1,29 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useTooltipStyleProps } from '../useTooltipStyleProps'; | ||
import { PlacementDictionaryType } from '../../../types'; | ||
import { useTooltipStyleProps, UseTooltipStyleProps } from '../useTooltipStyleProps'; | ||
|
||
describe('useTooltipStyleProps', () => { | ||
it('should return defaults', () => { | ||
const { result } = renderHook(() => useTooltipStyleProps({})); | ||
|
||
expect(result.current.classProps).toBeDefined(); | ||
expect(result.current.classProps.rootClassName).toBe('Tooltip Tooltip--bottom'); | ||
expect(result.current.classProps.wrapperClassName).toBe('TooltipWrapper'); | ||
expect(result.current.classProps.arrowClassName).toBe('Tooltip__arrow'); | ||
expect(result.current.classProps.closeButtonClassName).toBe('Tooltip__close'); | ||
}); | ||
|
||
it('should change placement', () => { | ||
const props = { | ||
placement: 'top-right' as PlacementDictionaryType, | ||
} as UseTooltipStyleProps; | ||
const { result } = renderHook(() => useTooltipStyleProps(props)); | ||
|
||
expect(result.current.classProps.rootClassName).toBe('Tooltip Tooltip--topRight'); | ||
}); | ||
|
||
it('should return dismissible class', () => { | ||
const { result } = renderHook(() => useTooltipStyleProps({ isDismissible: true })); | ||
|
||
expect(result.current.classProps).toBeDefined(); | ||
expect(result.current.classProps.rootClassName).toBe('Tooltip Tooltip--bottom Tooltip--dismissible'); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
packages/web-react/src/components/Tooltip/demo/TooltipOnHover.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,46 @@ | ||
import React from 'react'; | ||
import { ButtonLink } from '../../Button'; | ||
import TooltipWrapper from '../TooltipWrapper'; | ||
import Tooltip from '../Tooltip'; | ||
|
||
const TooltipOnHover = () => ( | ||
<> | ||
<TooltipWrapper> | ||
<ButtonLink href="#" aria-describedby="my-tooltip-hover-top" UNSAFE_className="TooltipTarget"> | ||
Tooltip on top | ||
</ButtonLink> | ||
<Tooltip id="my-tooltip-hover-top" placement="top"> | ||
Hello there! | ||
</Tooltip> | ||
</TooltipWrapper> | ||
|
||
<TooltipWrapper> | ||
<ButtonLink href="#" aria-describedby="my-tooltip-hover-right" UNSAFE_className="TooltipTarget"> | ||
Tooltip on right | ||
</ButtonLink> | ||
<Tooltip id="my-tooltip-hover-right" placement="right"> | ||
Hello there! | ||
</Tooltip> | ||
</TooltipWrapper> | ||
|
||
<TooltipWrapper> | ||
<ButtonLink href="#" aria-describedby="my-tooltip-hover-bottom" UNSAFE_className="TooltipTarget"> | ||
Tooltip on bottom | ||
</ButtonLink> | ||
<Tooltip id="my-tooltip-hover-bottom" placement="bottom"> | ||
Hello there! | ||
</Tooltip> | ||
</TooltipWrapper> | ||
|
||
<TooltipWrapper> | ||
<ButtonLink href="#" aria-describedby="my-tooltip-hover-left" UNSAFE_className="TooltipTarget"> | ||
Tooltip on left | ||
</ButtonLink> | ||
<Tooltip id="my-tooltip-hover-left" placement="left"> | ||
Hello there! | ||
</Tooltip> | ||
</TooltipWrapper> | ||
</> | ||
); | ||
|
||
export default TooltipOnHover; |
177 changes: 138 additions & 39 deletions
177
packages/web-react/src/components/Tooltip/demo/TooltipPlacements.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 |
---|---|---|
@@ -1,46 +1,145 @@ | ||
import React from 'react'; | ||
import { ButtonLink } from '../../Button'; | ||
import React, { ChangeEvent, useState } from 'react'; | ||
import DocsBox from '../../../../docs/DocsBox'; | ||
import { PlacementDictionaryType } from '../../../types'; | ||
import { Radio } from '../../Radio'; | ||
import TooltipWrapper from '../TooltipWrapper'; | ||
import Tooltip from '../Tooltip'; | ||
|
||
const TooltipPlacements = () => ( | ||
<> | ||
<TooltipWrapper> | ||
<ButtonLink href="#" aria-describedby="my-tooltip-hover-top" UNSAFE_className="TooltipTarget"> | ||
Tooltip on top | ||
</ButtonLink> | ||
<Tooltip id="my-tooltip-hover-top" placement="top"> | ||
Hello there! | ||
</Tooltip> | ||
</TooltipWrapper> | ||
const TooltipPlacements = () => { | ||
const [placement, setPlacement] = useState<PlacementDictionaryType>('bottom'); | ||
|
||
<TooltipWrapper> | ||
<ButtonLink href="#" aria-describedby="my-tooltip-hover-right" UNSAFE_className="TooltipTarget"> | ||
Tooltip on right | ||
</ButtonLink> | ||
<Tooltip id="my-tooltip-hover-right" placement="right"> | ||
Hello there! | ||
</Tooltip> | ||
</TooltipWrapper> | ||
const handlePlacementChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setPlacement(e.target.value as PlacementDictionaryType); | ||
}; | ||
|
||
<TooltipWrapper> | ||
<ButtonLink href="#" aria-describedby="my-tooltip-hover-bottom" UNSAFE_className="TooltipTarget"> | ||
Tooltip on bottom | ||
</ButtonLink> | ||
<Tooltip id="my-tooltip-hover-bottom" placement="bottom"> | ||
Hello there! | ||
</Tooltip> | ||
</TooltipWrapper> | ||
|
||
<TooltipWrapper> | ||
<ButtonLink href="#" aria-describedby="my-tooltip-hover-left" UNSAFE_className="TooltipTarget"> | ||
Tooltip on left | ||
</ButtonLink> | ||
<Tooltip id="my-tooltip-hover-left" placement="left"> | ||
Hello there! | ||
</Tooltip> | ||
</TooltipWrapper> | ||
</> | ||
); | ||
return ( | ||
<form autoComplete="off" className="mx-auto"> | ||
<div className="Grid Grid--cols-3" style={{ alignItems: 'center', justifyItems: 'center' }}> | ||
<div style={{ gridRow: 1, gridColumn: 2 }}> | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'top-left'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_top_left" | ||
label="top-left" | ||
value="top-left" | ||
/>{' '} | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'top'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_top" | ||
label="top" | ||
value="top" | ||
/>{' '} | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'top-right'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_top_right" | ||
label="top-right" | ||
value="top-right" | ||
/> | ||
</div> | ||
<div style={{ gridRow: 3, gridColumn: 2 }}> | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'bottom-left'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_bottom_left" | ||
label="bottom-left" | ||
value="bottom-left" | ||
/>{' '} | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'bottom'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_bottom" | ||
label="bottom" | ||
value="bottom" | ||
/>{' '} | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'bottom-right'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_bottom_right" | ||
label="bottom-right" | ||
value="bottom-right" | ||
/> | ||
</div> | ||
<div style={{ display: 'flex', flexDirection: 'column', gridRow: 2, gridColumn: 1 }}> | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'left-top'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_left_top" | ||
label="left-top" | ||
value="left-top" | ||
/> | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'left'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_left" | ||
label="left" | ||
value="left" | ||
/> | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'left-bottom'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_left_bottom" | ||
label="left-bottom" | ||
value="left-bottom" | ||
/> | ||
</div> | ||
<div style={{ display: 'flex', flexDirection: 'column', gridRow: 2, gridColumn: 3 }}> | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'right-top'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_right_top" | ||
label="right-top" | ||
value="right-top" | ||
/> | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'right'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_right" | ||
label="right" | ||
value="right" | ||
/> | ||
<Radio | ||
name="placement" | ||
isChecked={placement === 'right-bottom'} | ||
isLabelHidden | ||
onChange={handlePlacementChange} | ||
id="placement_right_bottom" | ||
label="right-bottom" | ||
value="right-bottom" | ||
/> | ||
</div> | ||
<div style={{ gridRow: 2, gridColumn: 2 }}> | ||
<TooltipWrapper UNSAFE_style={{ margin: '6rem auto' }}> | ||
<DocsBox>Click the dots!</DocsBox> | ||
<Tooltip placement={placement as PlacementDictionaryType}>Hello!</Tooltip> | ||
</TooltipWrapper> | ||
</div> | ||
</div> | ||
</form> | ||
); | ||
}; | ||
|
||
export default TooltipPlacements; |
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
Oops, something went wrong.