mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
refactor(tooltip-definition): remove hidden variable
This commit is contained in:
parent
350aad83e0
commit
6ae0e31011
2 changed files with 21 additions and 18 deletions
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue