mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
Merge branch 'tooltip-definition'
This commit is contained in:
commit
b7dfcecd1d
4 changed files with 89 additions and 30 deletions
|
@ -15506,14 +15506,61 @@
|
||||||
"default": true,
|
"default": true,
|
||||||
"default_value": ""
|
"default_value": ""
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"tooltip",
|
||||||
|
{
|
||||||
|
"attributes": [
|
||||||
|
{
|
||||||
|
"start": 1681,
|
||||||
|
"end": 1695,
|
||||||
|
"type": "Attribute",
|
||||||
|
"name": "name",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"start": 1687,
|
||||||
|
"end": 1694,
|
||||||
|
"type": "Text",
|
||||||
|
"raw": "tooltip",
|
||||||
|
"data": "tooltip"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"start": 1696,
|
||||||
|
"end": 1709,
|
||||||
|
"type": "MustacheTag",
|
||||||
|
"expression": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 1697,
|
||||||
|
"end": 1708,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 76,
|
||||||
|
"column": 26
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 76,
|
||||||
|
"column": 37
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"name": "tooltipText"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"default": false,
|
||||||
|
"default_value": "{tooltipText}\n"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"forwarded_events": [
|
"forwarded_events": [
|
||||||
[
|
[
|
||||||
"click",
|
"click",
|
||||||
{
|
{
|
||||||
"start": 1480,
|
"start": 1457,
|
||||||
"end": 1488,
|
"end": 1465,
|
||||||
"type": "EventHandler",
|
"type": "EventHandler",
|
||||||
"name": "click",
|
"name": "click",
|
||||||
"modifiers": [],
|
"modifiers": [],
|
||||||
|
@ -15523,8 +15570,8 @@
|
||||||
[
|
[
|
||||||
"mouseover",
|
"mouseover",
|
||||||
{
|
{
|
||||||
"start": 1493,
|
"start": 1470,
|
||||||
"end": 1505,
|
"end": 1482,
|
||||||
"type": "EventHandler",
|
"type": "EventHandler",
|
||||||
"name": "mouseover",
|
"name": "mouseover",
|
||||||
"modifiers": [],
|
"modifiers": [],
|
||||||
|
@ -15534,8 +15581,8 @@
|
||||||
[
|
[
|
||||||
"mouseenter",
|
"mouseenter",
|
||||||
{
|
{
|
||||||
"start": 1510,
|
"start": 1487,
|
||||||
"end": 1523,
|
"end": 1500,
|
||||||
"type": "EventHandler",
|
"type": "EventHandler",
|
||||||
"name": "mouseenter",
|
"name": "mouseenter",
|
||||||
"modifiers": [],
|
"modifiers": [],
|
||||||
|
@ -15545,8 +15592,8 @@
|
||||||
[
|
[
|
||||||
"mouseleave",
|
"mouseleave",
|
||||||
{
|
{
|
||||||
"start": 1528,
|
"start": 1505,
|
||||||
"end": 1541,
|
"end": 1518,
|
||||||
"type": "EventHandler",
|
"type": "EventHandler",
|
||||||
"name": "mouseleave",
|
"name": "mouseleave",
|
||||||
"modifiers": [],
|
"modifiers": [],
|
||||||
|
@ -15556,8 +15603,8 @@
|
||||||
[
|
[
|
||||||
"focus",
|
"focus",
|
||||||
{
|
{
|
||||||
"start": 1546,
|
"start": 1523,
|
||||||
"end": 1554,
|
"end": 1531,
|
||||||
"type": "EventHandler",
|
"type": "EventHandler",
|
||||||
"name": "focus",
|
"name": "focus",
|
||||||
"modifiers": [],
|
"modifiers": [],
|
||||||
|
|
|
@ -3,14 +3,27 @@
|
||||||
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
|
||||||
</TooltipDefinition>
|
</TooltipDefinition>
|
||||||
|
|
||||||
|
### Custom tooltip slot
|
||||||
|
|
||||||
|
<TooltipDefinition>
|
||||||
|
Armonk
|
||||||
|
<span slot="tooltip" style="color: red">
|
||||||
|
IBM Corporate Headquarters is based in Armonk, New York.
|
||||||
|
</span>
|
||||||
|
</TooltipDefinition>
|
||||||
|
|
|
@ -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,13 +67,12 @@
|
||||||
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>
|
||||||
<div role="tooltip" id="{id}" class:bx--assistive-text="{true}">
|
<div role="tooltip" id="{id}" class:bx--assistive-text="{true}">
|
||||||
{tooltipText}
|
<slot name="tooltip">{tooltipText}</slot>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
2
types/index.d.ts
vendored
2
types/index.d.ts
vendored
|
@ -5180,7 +5180,7 @@ export class TooltipDefinition extends CarbonSvelteComponent {
|
||||||
ref?: null | HTMLButtonElement;
|
ref?: null | HTMLButtonElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
$$slot_def: { default: {} };
|
$$slot_def: { default: {}; tooltip: {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TooltipIcon extends CarbonSvelteComponent {
|
export class TooltipIcon extends CarbonSvelteComponent {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue