Skip to content

Commit 2540751

Browse files
committed
feat(Tooltip): Add Tooltip.rich
Use rich tooltip by setting Tooltip.rich true
1 parent 6f23623 commit 2540751

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

components/mdc/Tooltip/Tooltip.svelte

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export let tooltipID
99
export let positionX = undefined
1010
/** @type {string} can be one of: "above" or "below" */
1111
export let positionY = undefined
12+
/** @type {boolean} whether to show a rich tooltip */
13+
export let rich = false
1214
1315
let element = {}
1416
let mdcToolTip = {}
@@ -35,8 +37,20 @@ onMount(() => {
3537
})
3638
</script>
3739

38-
<div bind:this={element} id={tooltipID} class="mdc-tooltip" role="tooltip" aria-hidden="true">
39-
<div class="mdc-tooltip__surface mdc-tooltip__surface-animation {$$props.class || ''}">
40-
<slot />
40+
{#if rich}
41+
<div bind:this={element} id={tooltipID} class="mdc-tooltip mdc-tooltip--rich" aria-hidden="true" role="tooltip">
42+
<div class="mdc-tooltip__surface mdc-tooltip__surface-animation {$$props.class || ''}">
43+
<p class="mdc-tooltip__content">
44+
<slot />
45+
</p>
46+
</div>
4147
</div>
42-
</div>
48+
{:else}
49+
<div bind:this={element} id={tooltipID} class="mdc-tooltip" role="tooltip" aria-hidden="true">
50+
<div class="mdc-tooltip__surface mdc-tooltip__surface-animation {$$props.class || ''}">
51+
<span class="mdc-tooltip__label">
52+
<slot />
53+
</span>
54+
</div>
55+
</div>
56+
{/if}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<script>
22
/** @type {string} The id of the element that describes the tooltip. */
33
export let ariaDescribedBy
4+
/** @type {string} If the tooltip is rich set this to rich as well */
5+
export let rich = false
46
</script>
57

6-
<div class={$$props.class || ''} aria-describedby={ariaDescribedBy}>
8+
<div class={(rich ? 'mdc-tooltip-wrapper--rich' : '') + ($$props.class || '')} aria-describedby={ariaDescribedBy}>
79
<slot />
810
</div>

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,15 @@ declare module '@silintl/ui-components' {
306306
tooltipID?: string
307307
positionX?: 'start' | 'center' | 'end'
308308
positionY?: 'above' | 'below'
309+
rich?: boolean
309310
class?: string
310311
}
311312
export class Tooltip extends SvelteComponentTyped<TooltipProps> {}
312313

313314
export namespace Tooltip {
314315
interface TooltipWrapperProps {
315316
ariaDescribedBy?: string
317+
rich?: boolean
316318
class?: string
317319
}
318320
export class Wrapper extends SvelteComponentTyped<TooltipWrapperProps> {}

stories/Tooltip.stories.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const args = {
1313

1414
<Template let:args>
1515
<div class="flex justify-center my-4">
16-
<Tooltip.Wrapper ariaDescribedBy={args.tooltipID}>wrapper slot</Tooltip.Wrapper>
16+
<Tooltip.Wrapper rich={args.rich} ariaDescribedBy={args.tooltipID}>wrapper slot</Tooltip.Wrapper>
1717
</div>
1818

1919
<Tooltip {...args}>Tooltip main slot here</Tooltip>
@@ -22,3 +22,5 @@ const args = {
2222
<Story name="Default" {args} />
2323

2424
<Story name="Position" args={copyAndModifyArgs(args, { positionX: 'start', positionY: 'above' })} />
25+
26+
<Story name="Rich" args={copyAndModifyArgs(args, { rich: true })} />

0 commit comments

Comments
 (0)