Skip to content

Commit f307192

Browse files
authored
Merge pull request #20 from svelte-plugins/add-prop-driven-visibility
refactor(tooltips): add show prop to interface for manual control of showing/hiding
2 parents cb9068c + 934079a commit f307192

11 files changed

+359
-241
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ Checkout out my <u use:tooltip={{ content: 'Hello World!' }}>tooltip</u>
4242
### Props
4343
| Prop | Description | Value |
4444
| :----------- | :------------------------------------------------------------------ | :---------------------------------------------- |
45-
| action | The action that triggers the tooltip (hover | click) | `string` (default: `hover`) |
45+
| action | The action that triggers the tooltip (hover | click | prop) | `string` (default: `hover`) |
4646
| animation | The animation to apply to the tooltip | `string` (default: ``) |
4747
| arrow | If `false`, the tooltip arrow will not be shown. | `boolean` (default: `true`) |
4848
| autoPosition | Adjust tooltip position if viewport clipping occurs | `string` (default: `false`) |
4949
| content | The string or object containing componentref and props | `string` | `object` component (default: ``) |
5050
| maxWidth | The max allowable width of the tooltip content | `number` (default: `200`) |
5151
| position | The position where the tooltip should appear relative to its parent | `string` (default: `top`) |
5252
| theme | The CSS theme class name | `string` (default: ``) |
53+
| show | Allows you to manually control the tooltip visibility | `boolean` (default: `false`) |
5354
| style | The object containing theme variable overrides | `object` (default: `null`) |
5455

5556
#### Using components as content

docs/src/App.svelte

+34-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import Prism from 'svelte-prismjs';
33
import { Tooltip, tooltip } from '@svelte-plugins/tooltips';
44
import ComponentAsContent from './ComponentAsContent.svelte';
5+
6+
let showTooltip = false;
57
</script>
68

79
<main>
@@ -54,7 +56,7 @@
5456
</div>
5557

5658
<div class="example">
57-
<p>This tooltip should appear to the <u use:tooltip={{ content: { component: ComponentAsContent, props: { title: 'Title from props' }}, position: 'left', style: { backgroundColor: 'blue' } }}>left</u> and render the passed component as the tooltip content.</p>
59+
<p>This tooltip should appear to the <u use:tooltip={{ content: { component: ComponentAsContent, props: { title: 'Title from props' }}, position: 'left', animation: 'slide', style: { backgroundColor: 'blue' } }}>left</u> and render the passed component as the tooltip content.</p>
5860
<Prism showLineNumbers={true} code={`
5961
<script>
6062
import ComponentAsContent from './ComponentAsContent.svelte';
@@ -86,6 +88,35 @@
8688
This tooltip should appear on the <Tooltip content="<b>Tooltip Top</b><p>This is an example of using HTML and content wrapping.</p>" position="top" animation="slide" arrow={false}><i>top</i></Tooltip> when you hover.
8789
</div>
8890

91+
<div class="example">
92+
This tooltip should appear <Tooltip content="<b>Tooltip Top</b><p>This is an example of using the 'show' prop.</p>" position="top" animation="slide" bind:show={showTooltip} autoPosition arrow={false} action="prop">on top</Tooltip> when the show button is clicked
93+
<button on:click={() => (showTooltip = true)}>Show</button>
94+
<button on:click={() => (showTooltip = false)}>Hide</button>
95+
96+
<Prism showLineNumbers={true} code={`
97+
98+
<script>
99+
import { Tooltip } from '@svelte-plugins/tooltips';
100+
101+
let showTooltip = false;
102+
</script>
103+
104+
<Tooltip
105+
content="<b>Tooltip Top</b><p>This is an example of using the 'show' prop.</p>"
106+
position="top"
107+
animation="slide"
108+
bind:show={showTooltip}
109+
autoPosition
110+
arrow={false}
111+
action="prop">
112+
Should show here
113+
</Tooltip>
114+
115+
<button on:click={() => (showTooltip = true)}>Show</button>
116+
<button on:click={() => (showTooltip = false)}>Hide</button>
117+
`} />
118+
</div>
119+
89120
<div class="example">
90121
<p>
91122
This tooltip should appear to the
@@ -94,8 +125,9 @@
94125
position="right"
95126
action="click"
96127
theme="tooltip-theme">
97-
<b>right</b> when clicked.
128+
<b>right</b>
98129
</Tooltip>
130+
when clicked.
99131
</p>
100132
<Prism showLineNumbers={true} code={`
101133
<Tooltip

0 commit comments

Comments
 (0)