mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
refactor(tooltip): rename showIcon prop
Remove triggerClass prop.
This commit is contained in:
parent
dd5a395659
commit
28a5100e6f
3 changed files with 20 additions and 22 deletions
|
@ -58,7 +58,7 @@
|
||||||
Show
|
Show
|
||||||
</Button>
|
</Button>
|
||||||
<div style="padding: 15px 20px; margin: 4px 20px">
|
<div style="padding: 15px 20px; margin: 4px 20px">
|
||||||
<Tooltip {...$$props} bind:open showIcon={false}>
|
<Tooltip {...$$props} bind:open hideIcon>
|
||||||
<div slot="triggerText">My text wrapped with tooltip</div>
|
<div slot="triggerText">My text wrapped with tooltip</div>
|
||||||
Tooltip content
|
Tooltip content
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
|
@ -23,7 +23,7 @@ export const NoIcon = () => ({
|
||||||
Component,
|
Component,
|
||||||
props: {
|
props: {
|
||||||
story: 'no icon',
|
story: 'no icon',
|
||||||
showIcon: false,
|
hideIcon: true,
|
||||||
direction: select('Tooltip direction (direction)', directions, 'bottom'),
|
direction: select('Tooltip direction (direction)', directions, 'bottom'),
|
||||||
triggerText: text('Trigger text (triggerText)', 'Tooltip label'),
|
triggerText: text('Trigger text (triggerText)', 'Tooltip label'),
|
||||||
tabindex: text('Tab index (tabindex in <Tooltip>)', '0')
|
tabindex: text('Tab index (tabindex in <Tooltip>)', '0')
|
||||||
|
@ -45,7 +45,6 @@ export const CustomIconOnly = () => ({
|
||||||
Component,
|
Component,
|
||||||
props: {
|
props: {
|
||||||
story: 'custom icon only',
|
story: 'custom icon only',
|
||||||
showIcon: true,
|
|
||||||
direction: select('Tooltip direction (direction)', directions, 'bottom'),
|
direction: select('Tooltip direction (direction)', directions, 'bottom'),
|
||||||
iconDescription: 'Helpful Information',
|
iconDescription: 'Helpful Information',
|
||||||
tabindex: text('Tab index (tabindex in <Tooltip>)', '0')
|
tabindex: text('Tab index (tabindex in <Tooltip>)', '0')
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
<script>
|
<script>
|
||||||
let className = undefined;
|
let className = undefined;
|
||||||
export { className as class };
|
export { className as class };
|
||||||
export let triggerText = ''; // TODO: support slot?
|
|
||||||
export let triggerId = Math.random();
|
|
||||||
export let tooltipId = Math.random();
|
|
||||||
export let triggerClass = undefined;
|
|
||||||
export let open = false;
|
|
||||||
export let direction = 'bottom';
|
export let direction = 'bottom';
|
||||||
|
export let hideIcon = false;
|
||||||
export let icon = Information16;
|
export let icon = Information16;
|
||||||
export let showIcon = true; // TODO: change to hideIcon
|
|
||||||
export let iconName = '';
|
|
||||||
export let iconDescription = '';
|
export let iconDescription = '';
|
||||||
export let tabindex = '0';
|
export let iconName = '';
|
||||||
|
export let open = false;
|
||||||
export let style = undefined;
|
export let style = undefined;
|
||||||
|
export let tabindex = '0';
|
||||||
|
export let tooltipId = Math.random();
|
||||||
|
export let triggerId = Math.random();
|
||||||
|
export let triggerText = '';
|
||||||
|
|
||||||
import { createEventDispatcher, afterUpdate } from 'svelte';
|
import { createEventDispatcher, afterUpdate } from 'svelte';
|
||||||
import Information16 from 'carbon-icons-svelte/lib/Information16';
|
import Information16 from 'carbon-icons-svelte/lib/Information16';
|
||||||
import { cx } from '../../lib';
|
import { cx, css } from '../../lib';
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
@ -71,7 +70,7 @@
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case 'bottom':
|
case 'bottom':
|
||||||
if (!showIcon) {
|
if (hideIcon) {
|
||||||
offsetX = -1 * (tooltip.width / 2 - button.width / 2);
|
offsetX = -1 * (tooltip.width / 2 - button.width / 2);
|
||||||
} else {
|
} else {
|
||||||
offsetX = -1 * (tooltip.width / 2 - button.width + iconWidth / 2);
|
offsetX = -1 * (tooltip.width / 2 - button.width + iconWidth / 2);
|
||||||
|
@ -83,7 +82,7 @@
|
||||||
offsetY = -1 * (tooltip.height / 2 + iconWidth / 2 - 3);
|
offsetY = -1 * (tooltip.height / 2 + iconWidth / 2 - 3);
|
||||||
break;
|
break;
|
||||||
case 'left':
|
case 'left':
|
||||||
if (!showIcon) {
|
if (hideIcon) {
|
||||||
offsetX = -1 * (tooltip.width + 6 + 1);
|
offsetX = -1 * (tooltip.width + 6 + 1);
|
||||||
} else {
|
} else {
|
||||||
offsetX = -1 * (tooltip.width - button.width + iconWidth + 8);
|
offsetX = -1 * (tooltip.width - button.width + iconWidth + 8);
|
||||||
|
@ -91,7 +90,7 @@
|
||||||
offsetY = -1 * (tooltip.height / 2 + button.height) - 2;
|
offsetY = -1 * (tooltip.height / 2 + button.height) - 2;
|
||||||
break;
|
break;
|
||||||
case 'top':
|
case 'top':
|
||||||
if (!showIcon) {
|
if (hideIcon) {
|
||||||
offsetX = -1 * (tooltip.width / 2 - button.width / 2);
|
offsetX = -1 * (tooltip.width / 2 - button.width / 2);
|
||||||
} else {
|
} else {
|
||||||
offsetX = -1 * (tooltip.width / 2 - button.width + iconWidth / 2 + 1);
|
offsetX = -1 * (tooltip.width / 2 - button.width + iconWidth / 2 + 1);
|
||||||
|
@ -111,14 +110,14 @@
|
||||||
$: buttonProps = {
|
$: buttonProps = {
|
||||||
role: 'button',
|
role: 'button',
|
||||||
'aria-haspopup': 'true',
|
'aria-haspopup': 'true',
|
||||||
id: showIcon ? undefined : triggerId,
|
id: hideIcon ? triggerId : undefined,
|
||||||
class: showIcon ? cx('--tooltip__trigger') : cx('--tooltip__label', triggerClass),
|
class: hideIcon ? cx('--tooltip__label') : cx('--tooltip__trigger'),
|
||||||
'aria-expanded': open,
|
'aria-expanded': open,
|
||||||
'aria-describedby': open ? tooltipId : undefined,
|
'aria-describedby': open ? tooltipId : undefined,
|
||||||
'aria-labelledby': triggerText ? triggerId : undefined,
|
'aria-labelledby': triggerText ? triggerId : undefined,
|
||||||
'aria-label': triggerText ? iconDescription : undefined,
|
'aria-label': triggerText ? iconDescription : undefined,
|
||||||
tabindex,
|
tabindex,
|
||||||
style: showIcon ? undefined : style
|
style: hideIcon ? style : undefined
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -129,9 +128,9 @@
|
||||||
}
|
}
|
||||||
}} />
|
}} />
|
||||||
|
|
||||||
<div style="position: relative">
|
<div class={className} style={css([style, ['position', 'relative']])}>
|
||||||
{#if showIcon}
|
{#if !hideIcon}
|
||||||
<div bind:this={buttonRef} id={triggerId} class={cx('--tooltip__label', triggerClass)} {style}>
|
<div bind:this={buttonRef} id={triggerId} class={cx('--tooltip__label')} {style}>
|
||||||
<slot name="triggerText">{triggerText}</slot>
|
<slot name="triggerText">{triggerText}</slot>
|
||||||
<div
|
<div
|
||||||
bind:this={iconRef}
|
bind:this={iconRef}
|
||||||
|
@ -163,7 +162,7 @@
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
id={tooltipId}
|
id={tooltipId}
|
||||||
data-floating-menu-direction={direction}
|
data-floating-menu-direction={direction}
|
||||||
class={cx('--tooltip', open && '--tooltip--shown', className)}
|
class={cx('--tooltip', open && '--tooltip--shown')}
|
||||||
on:blur={closeMenu}>
|
on:blur={closeMenu}>
|
||||||
<span class={cx('--tooltip__caret')} />
|
<span class={cx('--tooltip__caret')} />
|
||||||
<slot />
|
<slot />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue