Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions components/mdc/Tooltip/Tooltip.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export let tooltipID
export let positionX = undefined
/** @type {string} can be one of: "above" or "below" */
export let positionY = undefined
/** @type {boolean} whether to show a rich tooltip */
export let rich = false

let element = {}
let mdcToolTip = {}
Expand All @@ -35,8 +37,20 @@ onMount(() => {
})
</script>

<div bind:this={element} id={tooltipID} class="mdc-tooltip" role="tooltip" aria-hidden="true">
<div class="mdc-tooltip__surface mdc-tooltip__surface-animation {$$props.class || ''}">
<slot />
{#if rich}
<div bind:this={element} id={tooltipID} class="mdc-tooltip mdc-tooltip--rich" aria-hidden="true" role="tooltip">
<div class="mdc-tooltip__surface mdc-tooltip__surface-animation {$$props.class || ''}">
<p class="mdc-tooltip__content">
<slot />
</p>
</div>
</div>
</div>
{:else}
<div bind:this={element} id={tooltipID} class="mdc-tooltip" role="tooltip" aria-hidden="true">
<div class="mdc-tooltip__surface mdc-tooltip__surface-animation {$$props.class || ''}">
<span class="mdc-tooltip__label">
<slot />
</span>
</div>
</div>
{/if}
4 changes: 3 additions & 1 deletion components/mdc/Tooltip/Wrapper.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<script>
/** @type {string} The id of the element that describes the tooltip. */
export let ariaDescribedBy
/** @type {string} If the tooltip is rich set this to rich as well */
export let rich = false
</script>

<div class={$$props.class || ''} aria-describedby={ariaDescribedBy}>
<div class={(rich ? 'mdc-tooltip-wrapper--rich' : '') + ($$props.class || '')} aria-describedby={ariaDescribedBy}>
<slot />
</div>
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,15 @@ declare module '@silintl/ui-components' {
tooltipID?: string
positionX?: 'start' | 'center' | 'end'
positionY?: 'above' | 'below'
rich?: boolean
class?: string
}
export class Tooltip extends SvelteComponentTyped<TooltipProps> {}

export namespace Tooltip {
interface TooltipWrapperProps {
ariaDescribedBy?: string
rich?: boolean
class?: string
}
export class Wrapper extends SvelteComponentTyped<TooltipWrapperProps> {}
Expand Down
4 changes: 3 additions & 1 deletion stories/Tooltip.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const args = {

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

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

<Story name="Position" args={copyAndModifyArgs(args, { positionX: 'start', positionY: 'above' })} />

<Story name="Rich" args={copyAndModifyArgs(args, { rich: true })} />