mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
feat(tooltip-definition): export open prop, dispatch open/close events (#1057)
This commit is contained in:
parent
8b39ccae89
commit
20e61724c1
5 changed files with 55 additions and 16 deletions
|
@ -4692,6 +4692,7 @@ None.
|
||||||
| Prop name | Kind | Reactive | Type | Default value | Description |
|
| Prop name | Kind | Reactive | Type | Default value | Description |
|
||||||
| :---------- | :--------------- | :------- | :------------------------------------------------ | ------------------------------------------------ | ----------------------------------------------------- |
|
| :---------- | :--------------- | :------- | :------------------------------------------------ | ------------------------------------------------ | ----------------------------------------------------- |
|
||||||
| ref | <code>let</code> | Yes | <code>null | HTMLButtonElement</code> | <code>null</code> | Obtain a reference to the button HTML element |
|
| ref | <code>let</code> | Yes | <code>null | HTMLButtonElement</code> | <code>null</code> | Obtain a reference to the button HTML element |
|
||||||
|
| open | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to open the tooltip |
|
||||||
| tooltipText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the tooltip text |
|
| tooltipText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the tooltip text |
|
||||||
| align | <code>let</code> | No | <code>"start" | "center" | "end"</code> | <code>"center"</code> | Set the alignment of the tooltip relative to the icon |
|
| align | <code>let</code> | No | <code>"start" | "center" | "end"</code> | <code>"center"</code> | Set the alignment of the tooltip relative to the icon |
|
||||||
| direction | <code>let</code> | No | <code>"top" | "bottom"</code> | <code>"bottom"</code> | Set the direction of the tooltip relative to the icon |
|
| direction | <code>let</code> | No | <code>"top" | "bottom"</code> | <code>"bottom"</code> | Set the direction of the tooltip relative to the icon |
|
||||||
|
@ -4706,13 +4707,15 @@ None.
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
| Event name | Type | Detail |
|
| Event name | Type | Detail |
|
||||||
| :--------- | :-------- | :----- |
|
| :--------- | :--------- | :--------------- |
|
||||||
| click | forwarded | -- |
|
| open | dispatched | <code>any</code> |
|
||||||
| mouseover | forwarded | -- |
|
| close | dispatched | <code>any</code> |
|
||||||
| mouseenter | forwarded | -- |
|
| click | forwarded | -- |
|
||||||
| mouseleave | forwarded | -- |
|
| mouseover | forwarded | -- |
|
||||||
| focus | forwarded | -- |
|
| mouseenter | forwarded | -- |
|
||||||
|
| mouseleave | forwarded | -- |
|
||||||
|
| focus | forwarded | -- |
|
||||||
|
|
||||||
## `TooltipFooter`
|
## `TooltipFooter`
|
||||||
|
|
||||||
|
|
|
@ -13110,6 +13110,17 @@
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": false
|
"reactive": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "open",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Set to `true` to open the tooltip",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": "false",
|
||||||
|
"isFunction": false,
|
||||||
|
"isFunctionDeclaration": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "align",
|
"name": "align",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
|
@ -13165,6 +13176,8 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"events": [
|
"events": [
|
||||||
|
{ "type": "dispatched", "name": "open", "detail": "any" },
|
||||||
|
{ "type": "dispatched", "name": "close", "detail": "any" },
|
||||||
{ "type": "forwarded", "name": "click", "element": "button" },
|
{ "type": "forwarded", "name": "click", "element": "button" },
|
||||||
{ "type": "forwarded", "name": "mouseover", "element": "button" },
|
{ "type": "forwarded", "name": "mouseover", "element": "button" },
|
||||||
{ "type": "forwarded", "name": "mouseenter", "element": "button" },
|
{ "type": "forwarded", "name": "mouseenter", "element": "button" },
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
<script>
|
<script>
|
||||||
|
/**
|
||||||
|
* @event {any} open
|
||||||
|
* @event {any} close
|
||||||
|
*/
|
||||||
|
|
||||||
/** Specify the tooltip text */
|
/** Specify the tooltip text */
|
||||||
export let tooltipText = "";
|
export let tooltipText = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to open the tooltip
|
||||||
|
*/
|
||||||
|
export let open = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the alignment of the tooltip relative to the icon
|
* Set the alignment of the tooltip relative to the icon
|
||||||
* @type {"start" | "center" | "end"}
|
* @type {"start" | "center" | "end"}
|
||||||
|
@ -20,15 +30,15 @@
|
||||||
/** Obtain a reference to the button HTML element */
|
/** Obtain a reference to the button HTML element */
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
let visible = false;
|
import { createEventDispatcher } from "svelte";
|
||||||
|
|
||||||
function hide() {
|
const dispatch = createEventDispatcher();
|
||||||
visible = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function show() {
|
const hide = () => (open = false);
|
||||||
visible = true;
|
|
||||||
}
|
const show = () => (open = true);
|
||||||
|
|
||||||
|
$: dispatch(open ? "open" : "close");
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window
|
<svelte:window
|
||||||
|
@ -51,8 +61,8 @@
|
||||||
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="{!visible}"
|
class:bx--tooltip--hidden="{!open}"
|
||||||
class:bx--tooltip--visible="{visible}"
|
class:bx--tooltip--visible="{open}"
|
||||||
class:bx--tooltip--top="{direction === 'top'}"
|
class:bx--tooltip--top="{direction === 'top'}"
|
||||||
class:bx--tooltip--bottom="{direction === 'bottom'}"
|
class:bx--tooltip--bottom="{direction === 'bottom'}"
|
||||||
class:bx--tooltip--align-start="{align === 'start'}"
|
class:bx--tooltip--align-start="{align === 'start'}"
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { TooltipDefinition } from "../types";
|
import { TooltipDefinition } from "../types";
|
||||||
|
|
||||||
|
let open = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<TooltipDefinition
|
<TooltipDefinition
|
||||||
|
bind:open
|
||||||
|
on:open
|
||||||
|
on:close
|
||||||
tooltipText="IBM Corporate Headquarters is based in Armonk, New York."
|
tooltipText="IBM Corporate Headquarters is based in Armonk, New York."
|
||||||
>
|
>
|
||||||
Armonk
|
Armonk
|
||||||
|
|
|
@ -9,6 +9,12 @@ export interface TooltipDefinitionProps
|
||||||
*/
|
*/
|
||||||
tooltipText?: string;
|
tooltipText?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to open the tooltip
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
open?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the alignment of the tooltip relative to the icon
|
* Set the alignment of the tooltip relative to the icon
|
||||||
* @default "center"
|
* @default "center"
|
||||||
|
@ -37,6 +43,8 @@ export interface TooltipDefinitionProps
|
||||||
export default class TooltipDefinition extends SvelteComponentTyped<
|
export default class TooltipDefinition extends SvelteComponentTyped<
|
||||||
TooltipDefinitionProps,
|
TooltipDefinitionProps,
|
||||||
{
|
{
|
||||||
|
open: CustomEvent<any>;
|
||||||
|
close: CustomEvent<any>;
|
||||||
click: WindowEventMap["click"];
|
click: WindowEventMap["click"];
|
||||||
mouseover: WindowEventMap["mouseover"];
|
mouseover: WindowEventMap["mouseover"];
|
||||||
mouseenter: WindowEventMap["mouseenter"];
|
mouseenter: WindowEventMap["mouseenter"];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue