This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
feat(Tooltip): base implementation #1455
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
0f6499c
-wip
26721b9
-simplified the Tooltip component
a8a5cfb
-extracted pointer styles
da353bb
-fixed examples
4a2478e
-fixed steps
2905fd0
-fixed steps
28c148d
-simplified Tooltip
81859ee
-updated changelog
2b2a00c
-removed Tooltip test, we need a custom one for this component
42464e0
-added test
2196c15
-fixed screenshot test
2ab417c
-addressing PR comments
fb8547a
-simplified HC theme variables
5cb7648
-make the tooltip always to be present in the DOM, and show it only i…
8e92799
Merge branch 'master' into feat/tooltip-base-component
42ce5f3
-addressing PR comments
5ff9f95
-addressing PR comments
5eaa136
-fixed RTL issues
2cf2389
-addressing more PR comments
b90b17d
-renamed SimplifiedPositioningProps to BasicPositioningProps
b92e8e7
-improved controlled tooltip example
95d54ed
-removed console log
0f40c02
-fixed custom target example
5a8ce1c
Addressed PR comments
5079968
-fixed target example, added steps for it
d0200a2
-fixed open examples
421dbf9
Merge branch 'master' into feat/tooltip-base-component
3097b28
-fixed pointing examples
f15652e
-reverted changes in the test
7220aa3
-fixed tooltip test
c7b0428
Merge branch 'master' into feat/tooltip-base-component
mnajdova 3047a30
-addressing comments
2d0079d
-added box shadow variables
57a6879
-changed screener step
05bb166
Merge branch 'master' into feat/tooltip-base-component
mnajdova 38c0e6f
Merge branch 'master' into feat/tooltip-base-component
mnajdova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions
7
docs/src/examples/components/Tooltip/Rtl/TooltipExample.rtl.steps.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Button } from '@stardust-ui/react' | ||
|
||
const config: ScreenerTestsConfig = { | ||
steps: [builder => builder.hover(`.${Button.className}`).snapshot('RTL: Shows tooltip')], | ||
} | ||
|
||
export default config |
21 changes: 21 additions & 0 deletions
21
docs/src/examples/components/Tooltip/Rtl/TooltipExample.rtl.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,21 @@ | ||
import * as React from 'react' | ||
import { Button, Tooltip, Text } from '@stardust-ui/react' | ||
|
||
const TooltipExampleRtl = () => ( | ||
<Tooltip | ||
trigger={<Button content="ا يجلبه إلينا الأس" />} | ||
content={{ | ||
content: ( | ||
<> | ||
<Text as="div">English text!</Text> | ||
<Text as="div"> | ||
ينا الألم. في بعض الأحيان ونظراً للالتزامات التي يفرضها علينا الواجب والعمل سنتنازل | ||
غالباً ونرفض الشعور | ||
</Text> | ||
</> | ||
), | ||
}} | ||
/> | ||
) | ||
|
||
export default TooltipExampleRtl |
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,12 @@ | ||
import * as React from 'react' | ||
|
||
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
import NonPublicSection from 'docs/src/components/ComponentDoc/NonPublicSection' | ||
|
||
const Rtl = () => ( | ||
<NonPublicSection title="Rtl"> | ||
<ComponentExample examplePath="components/Tooltip/Rtl/TooltipExample.rtl" /> | ||
</NonPublicSection> | ||
) | ||
|
||
export default Rtl |
18 changes: 18 additions & 0 deletions
18
docs/src/examples/components/Tooltip/States/TooltipOpenControlledExample.shorthand.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,18 @@ | ||
import * as React from 'react' | ||
import { Button, Tooltip } from '@stardust-ui/react' | ||
import { useBooleanKnob } from '@stardust-ui/docs-components' | ||
|
||
const TooltipOpenExample = () => { | ||
const [open, setOpen] = useBooleanKnob({ name: 'open-c', initialValue: true }) | ||
|
||
return ( | ||
<Tooltip | ||
open={open} | ||
onOpenChange={(e, data) => setOpen(data.open)} | ||
trigger={<Button icon="expand" />} | ||
content="This is a controlled Tooltip" | ||
/> | ||
) | ||
} | ||
|
||
export default TooltipOpenExample |
19 changes: 19 additions & 0 deletions
19
docs/src/examples/components/Tooltip/States/TooltipOpenControlledExample.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,19 @@ | ||||||
import * as React from 'react' | ||||||
import { Button, Tooltip } from '@stardust-ui/react' | ||||||
import { useBooleanKnob } from '@stardust-ui/docs-components' | ||||||
|
||||||
const TooltipOpenExample = () => { | ||||||
const [open, setOpen] = useBooleanKnob({ name: 'open-c', initialValue: true }) | ||||||
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.
Suggested change
After #1489 will be merged |
||||||
|
||||||
return ( | ||||||
<Tooltip | ||||||
open={open || undefined} | ||||||
onOpenChange={(e, data) => setOpen(data.open)} | ||||||
content="This is a controlled Tooltip" | ||||||
> | ||||||
<Button icon="expand" /> | ||||||
</Tooltip> | ||||||
) | ||||||
} | ||||||
|
||||||
export default TooltipOpenExample |
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,16 @@ | ||
import * as React from 'react' | ||
|
||
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
||
const States = () => ( | ||
<ExampleSection title="States"> | ||
<ComponentExample | ||
title="Open" | ||
description="The Tooltip's open state can be controlled. Note that if Tooltip is controlled, then its 'open' prop value could be changed either by parent component, or by user actions (e.g. key press) - thus it is necessary to handle 'onOpenChange' event." | ||
examplePath="components/Tooltip/States/TooltipOpenControlledExample" | ||
/> | ||
</ExampleSection> | ||
) | ||
|
||
export default States |
11 changes: 11 additions & 0 deletions
11
docs/src/examples/components/Tooltip/Types/TooltipExample.shorthand.steps.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Button } from '@stardust-ui/react' | ||
|
||
const config: ScreenerTestsConfig = { | ||
themes: ['teams', 'teamsDark', 'teamsHighContrast'], | ||
steps: [ | ||
builder => builder.hover(`.${Button.className}`).snapshot('Shows tooltip'), | ||
builder => builder.hover('body'), // we need the mouse to be moved out of the button for the next test | ||
], | ||
} | ||
|
||
export default config |
8 changes: 8 additions & 0 deletions
8
docs/src/examples/components/Tooltip/Types/TooltipExample.shorthand.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,8 @@ | ||
import * as React from 'react' | ||
import { Button, Tooltip } from '@stardust-ui/react' | ||
|
||
const TooltipExample = () => ( | ||
<Tooltip trigger={<Button icon="expand" />} content="Hello from tooltip!" /> | ||
) | ||
|
||
export default TooltipExample |
10 changes: 10 additions & 0 deletions
10
docs/src/examples/components/Tooltip/Types/TooltipExample.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,10 @@ | ||
import * as React from 'react' | ||
import { Button, Tooltip } from '@stardust-ui/react' | ||
|
||
const TooltipExample = () => ( | ||
<Tooltip content="Hello from tooltip!"> | ||
<Button icon="expand" /> | ||
</Tooltip> | ||
) | ||
|
||
export default TooltipExample |
8 changes: 8 additions & 0 deletions
8
docs/src/examples/components/Tooltip/Types/TooltipExamplePointing.shorthand.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,8 @@ | ||
import * as React from 'react' | ||
import { Button, Tooltip } from '@stardust-ui/react' | ||
|
||
const TooltipExamplePointing = () => ( | ||
<Tooltip open pointing trigger={<Button icon="expand" />} content="The tooltip is pointing." /> | ||
) | ||
|
||
export default TooltipExamplePointing |
10 changes: 10 additions & 0 deletions
10
docs/src/examples/components/Tooltip/Types/TooltipExamplePointing.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,10 @@ | ||
import * as React from 'react' | ||
import { Button, Tooltip } from '@stardust-ui/react' | ||
|
||
const TooltipExamplePointing = () => ( | ||
<Tooltip open pointing content="The tooltip is pointing."> | ||
<Button icon="expand" /> | ||
</Tooltip> | ||
) | ||
|
||
export default TooltipExamplePointing |
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,21 @@ | ||
import * as React from 'react' | ||
|
||
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
||
const Types = () => ( | ||
<ExampleSection title="Types"> | ||
<ComponentExample | ||
title="Default" | ||
description="A default tooltip." | ||
examplePath="components/Tooltip/Types/TooltipExample" | ||
/> | ||
<ComponentExample | ||
title="Pointing" | ||
description="A tooltip can have a pointer." | ||
examplePath="components/Tooltip/Types/TooltipExamplePointing" | ||
/> | ||
</ExampleSection> | ||
) | ||
|
||
export default Types |
9 changes: 9 additions & 0 deletions
9
docs/src/examples/components/Tooltip/Usage/TooltipExampleTarget.shorthand.steps.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Button } from '@stardust-ui/react' | ||
|
||
const config: ScreenerTestsConfig = { | ||
steps: [ | ||
builder => builder.hover(`.${Button.className}`).snapshot('Custom target: Shows tooltip'), | ||
], | ||
} | ||
|
||
export default config |
30 changes: 30 additions & 0 deletions
30
docs/src/examples/components/Tooltip/Usage/TooltipExampleTarget.shorthand.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,30 @@ | ||
import * as React from 'react' | ||
import { Button, Divider, Grid, Ref, Text, Tooltip } from '@stardust-ui/react' | ||
|
||
const TooltipExampleTarget = () => { | ||
const [target, setTarget] = React.useState<HTMLElement>(null) | ||
|
||
return ( | ||
<Grid columns="auto 1fr"> | ||
{/* CUSTOM DOM ELEMENT is used as target for Tooltip */} | ||
<Tooltip | ||
target={target} | ||
trigger={<Button icon="question" circular styles={{ cursor: 'pointer' }} />} | ||
content="well, yes, I am just a garbish text ¯\_(ツ)_/¯" | ||
position="below" | ||
/> | ||
<div style={{ marginLeft: 10 }}> | ||
<Text>Could you guess what does this text means? :)</Text> | ||
<Divider /> | ||
<Ref innerRef={setTarget}> | ||
<Text> | ||
"To the lascivious looking-glass I, that love's majesty to strut before a want love's | ||
majesto, to the souls of York." | ||
</Text> | ||
</Ref> | ||
</div> | ||
</Grid> | ||
) | ||
} | ||
|
||
export default TooltipExampleTarget |
31 changes: 31 additions & 0 deletions
31
docs/src/examples/components/Tooltip/Usage/TooltipExampleTarget.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,31 @@ | ||
import * as React from 'react' | ||
import { Button, Divider, Grid, Ref, Text, Tooltip } from '@stardust-ui/react' | ||
|
||
const TooltipExampleTarget = () => { | ||
const [target, setTarget] = React.useState<HTMLElement>(null) | ||
|
||
return ( | ||
<Grid columns="auto 1fr"> | ||
{/* CUSTOM DOM ELEMENT is used as target for Tooltip */} | ||
<Tooltip | ||
target={target} | ||
content="well, yes, I am just a garbish text ¯\_(ツ)_/¯" | ||
position="below" | ||
> | ||
<Button icon="question" circular styles={{ cursor: 'pointer' }} /> | ||
</Tooltip> | ||
<div style={{ marginLeft: 10 }}> | ||
<Text>Could you guess what does this text means? :)</Text> | ||
<Divider /> | ||
<Ref innerRef={setTarget}> | ||
<Text> | ||
"To the lascivious looking-glass I, that love's majesty to strut before a want love's | ||
majesto, to the souls of York." | ||
</Text> | ||
</Ref> | ||
</div> | ||
</Grid> | ||
) | ||
} | ||
|
||
export default TooltipExampleTarget |
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,16 @@ | ||
import * as React from 'react' | ||
|
||
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
||
const Usage = () => ( | ||
<ExampleSection title="Usage"> | ||
<ComponentExample | ||
title="Custom Target" | ||
description="By default Tooltip uses trigger element as the one it is displayed for, but it is possible to provide any DOM element as tooltip's target." | ||
examplePath="components/Tooltip/Usage/TooltipExampleTarget" | ||
/> | ||
</ExampleSection> | ||
) | ||
|
||
export default Usage |
66 changes: 66 additions & 0 deletions
66
docs/src/examples/components/Tooltip/Variations/TooltipExamplePosition.shorthand.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,66 @@ | ||||||
import * as React from 'react' | ||||||
import * as _ from 'lodash' | ||||||
import { Button, Grid, Tooltip, Alignment, Position } from '@stardust-ui/react' | ||||||
import { useSelectKnob } from '@stardust-ui/docs-components' | ||||||
|
||||||
const TooltipExamplePosition = () => { | ||||||
const [positionAndAlign] = useSelectKnob({ | ||||||
name: 'position-align-s', | ||||||
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.
Suggested change
After #1489 will be merged |
||||||
initialValue: 'above-start', | ||||||
values: positionAndAlignValues, | ||||||
}) | ||||||
|
||||||
const [position, align] = _.split(positionAndAlign, '-') as [Position, Alignment] | ||||||
const buttonStyles = { padding: paddings[positionAndAlign], height: '38px', minWidth: '64px' } | ||||||
|
||||||
return ( | ||||||
<Grid columns="1" variables={{ padding: '100px 0' }} styles={{ justifyItems: 'center' }}> | ||||||
<Tooltip | ||||||
open | ||||||
align={align} | ||||||
position={position} | ||||||
trigger={<Button icon={icons[position]} styles={buttonStyles} />} | ||||||
content={`The tooltip is rendered ${position} the trigger, aligned to the ${align}.`} | ||||||
/> | ||||||
</Grid> | ||||||
) | ||||||
} | ||||||
|
||||||
export default TooltipExamplePosition | ||||||
|
||||||
const positionAndAlignValues = [ | ||||||
'above-start', | ||||||
'above-center', | ||||||
'above-end', | ||||||
'below-start', | ||||||
'below-center', | ||||||
'below-end', | ||||||
'before-top', | ||||||
'before-center', | ||||||
'before-bottom', | ||||||
'after-top', | ||||||
'after-center', | ||||||
'after-bottom', | ||||||
] | ||||||
|
||||||
const icons: Record<Position, string> = { | ||||||
above: 'arrow circle up', | ||||||
below: 'arrow circle down', | ||||||
before: 'arrow circle left', | ||||||
after: 'arrow circle right', | ||||||
} | ||||||
|
||||||
const paddings: Record<string, React.CSSProperties['padding']> = { | ||||||
'above-start': '5px 42px 18px 5px', | ||||||
'above-center': '5px 5px 18px 5px', | ||||||
'above-end': '5px 5px 18px 42px', | ||||||
'below-start': '18px 42px 5px 5px', | ||||||
'below-center': '18px 5px 5px 5px', | ||||||
'below-end': '18px 5px 5px 42px', | ||||||
'before-top': '5px 42px 18px 5px', | ||||||
'before-center': '5px 42px 5px 5px', | ||||||
'before-bottom': '18px 42px 5px 5px', | ||||||
'after-top': '5px 5px 18px 42px', | ||||||
'after-center': '5px 5px 5px 42px', | ||||||
'after-bottom': '18px 5px 5px 42px', | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
After #1489 will be merged