refactor(tooltip-definition): remove hidden variable

This commit is contained in:
Eric Liu 2020-10-20 11:41:45 -07:00
commit 6ae0e31011
2 changed files with 21 additions and 18 deletions

View file

@ -3,13 +3,17 @@
import Preview from "../../components/Preview.svelte";
</script>
### Default ("bottom" direction, "center" aligned)
### Default
<TooltipDefinition tooltipText="IBM Corporate Headquarters is based in Armonk, New York.">
Armonk
</TooltipDefinition>
### Custom direction, alignment
### Custom tooltip direction and alignment
Customize the tooltip menu direction and alignment through the `direction` and `align` props.
By default, `direction` is `"bottom"` and `align` is `"center"`.
<TooltipDefinition direction="top" align="start" tooltipText="IBM Corporate Headquarters is based in Armonk, New York.">
Armonk

View file

@ -29,28 +29,28 @@
*/
export let ref = null;
$: hidden = false;
$: visible = false;
let visible = false;
function hide() {
visible = false;
}
function show() {
visible = true;
}
</script>
<svelte:body
on:keydown="{({ key }) => {
if (key === 'Escape') {
hidden = true;
}
if (key === 'Escape') hide();
}}" />
<div
class:bx--tooltip--definition="{true}"
class:bx--tooltip--a11y="{true}"
{...$$restProps}
on:mouseenter="{() => {
hidden = false;
visible = true;
}}"
on:mouseleave="{() => {
visible = false;
}}"
on:mouseenter="{show}"
on:mouseleave="{hide}"
>
<button
bind:this="{ref}"
@ -58,7 +58,7 @@
class:bx--tooltip--a11y="{true}"
class:bx--tooltip__trigger="{true}"
class:bx--tooltip__trigger--definition="{true}"
class:bx--tooltip--hidden="{hidden}"
class:bx--tooltip--hidden="{!visible}"
class:bx--tooltip--visible="{visible}"
class="{direction && `bx--tooltip--${direction}`}
{align && `bx--tooltip--align-${align}`}"
@ -67,9 +67,8 @@
on:mouseenter
on:mouseleave
on:focus
on:focus="{() => {
hidden = false;
}}"
on:focus="{show}"
on:blur="{hide}"
>
<slot />
</button>