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";
|
import Preview from "../../components/Preview.svelte";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
### Default ("bottom" direction, "center" aligned)
|
### Default
|
||||||
|
|
||||||
<TooltipDefinition tooltipText="IBM Corporate Headquarters is based in Armonk, New York.">
|
<TooltipDefinition tooltipText="IBM Corporate Headquarters is based in Armonk, New York.">
|
||||||
Armonk
|
Armonk
|
||||||
</TooltipDefinition>
|
</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.">
|
<TooltipDefinition direction="top" align="start" tooltipText="IBM Corporate Headquarters is based in Armonk, New York.">
|
||||||
Armonk
|
Armonk
|
||||||
|
|
|
@ -29,28 +29,28 @@
|
||||||
*/
|
*/
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
$: hidden = false;
|
let visible = false;
|
||||||
$: visible = false;
|
|
||||||
|
function hide() {
|
||||||
|
visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
visible = true;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:body
|
<svelte:body
|
||||||
on:keydown="{({ key }) => {
|
on:keydown="{({ key }) => {
|
||||||
if (key === 'Escape') {
|
if (key === 'Escape') hide();
|
||||||
hidden = true;
|
|
||||||
}
|
|
||||||
}}" />
|
}}" />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class:bx--tooltip--definition="{true}"
|
class:bx--tooltip--definition="{true}"
|
||||||
class:bx--tooltip--a11y="{true}"
|
class:bx--tooltip--a11y="{true}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
on:mouseenter="{() => {
|
on:mouseenter="{show}"
|
||||||
hidden = false;
|
on:mouseleave="{hide}"
|
||||||
visible = true;
|
|
||||||
}}"
|
|
||||||
on:mouseleave="{() => {
|
|
||||||
visible = false;
|
|
||||||
}}"
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
bind:this="{ref}"
|
bind:this="{ref}"
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
class:bx--tooltip--a11y="{true}"
|
class:bx--tooltip--a11y="{true}"
|
||||||
class:bx--tooltip__trigger="{true}"
|
class:bx--tooltip__trigger="{true}"
|
||||||
class:bx--tooltip__trigger--definition="{true}"
|
class:bx--tooltip__trigger--definition="{true}"
|
||||||
class:bx--tooltip--hidden="{hidden}"
|
class:bx--tooltip--hidden="{!visible}"
|
||||||
class:bx--tooltip--visible="{visible}"
|
class:bx--tooltip--visible="{visible}"
|
||||||
class="{direction && `bx--tooltip--${direction}`}
|
class="{direction && `bx--tooltip--${direction}`}
|
||||||
{align && `bx--tooltip--align-${align}`}"
|
{align && `bx--tooltip--align-${align}`}"
|
||||||
|
@ -67,9 +67,8 @@
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
on:mouseleave
|
on:mouseleave
|
||||||
on:focus
|
on:focus
|
||||||
on:focus="{() => {
|
on:focus="{show}"
|
||||||
hidden = false;
|
on:blur="{hide}"
|
||||||
}}"
|
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue