Skip to content

Commit

Permalink
feat: allow to add custom classes to tip
Browse files Browse the repository at this point in the history
Signed-off-by: lstocchi <[email protected]>
  • Loading branch information
lstocchi committed May 10, 2024
1 parent cbd777c commit 034d646
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/ui/src/lib/tooltip/Tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ test('Expect basic styling', async () => {
expect(element).toHaveClass('text-white');
});

test('Expect custom tip styling', async () => {
render(Tooltip, { tip, tipClass: 'text-pretty w-64' });

const element = screen.getByLabelText('tooltip');
expect(element).toBeInTheDocument();
expect(element.parentElement).toHaveClass('text-pretty w-64');
});

function createTest(props: Record<string, boolean>, locationName: string, expectedStyle = locationName): void {
test(`Expect property ${locationName} to add ${expectedStyle} class to parent element`, () => {
render(Tooltip, { tip, ...props });
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/lib/tooltip/Tooltip.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ export let bottom = false;
export let bottomLeft = false;
export let bottomRight = false;
export let left = false;
export let tipClass = '';
</script>

<div class="relative inline-block">
<span class="group tooltip-slot {$$props.class}">
<slot />
</span>
<div
class="whitespace-nowrap absolute tooltip opacity-0 inline-block transition-opacity duration-150 ease-in-out pointer-events-none z-[10]"
class="whitespace-nowrap absolute tooltip opacity-0 inline-block transition-opacity duration-150 ease-in-out pointer-events-none z-[10] {tipClass}"
class:left="{left}"
class:right="{right}"
class:bottom="{bottom}"
Expand Down

0 comments on commit 034d646

Please sign in to comment.