From d6ccc8d7911ea297c4b5bce4924c56291aa7495b Mon Sep 17 00:00:00 2001
From: Andrew Holloway
Date: Mon, 10 Jun 2024 15:05:15 -0500
Subject: [PATCH] feat(Tooltip): add inverse variant (#1984)
- support variants (default and inverse)
- add tests and snapshots
- also add background color treatments thru storybook config
- add more chromatic delay to avoid some test jittering
---
.storybook/preview.tsx | 9 +++
src/components/Tooltip/Tooltip-v2.module.css | 19 ++++--
src/components/Tooltip/Tooltip-v2.stories.tsx | 12 +++-
src/components/Tooltip/Tooltip-v2.tsx | 15 ++++-
.../__snapshots__/Tooltip-v2.test.tsx.snap | 63 +++++++++++++++++--
5 files changed, 106 insertions(+), 12 deletions(-)
diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx
index 783952da7..cbac9a065 100644
--- a/.storybook/preview.tsx
+++ b/.storybook/preview.tsx
@@ -64,6 +64,7 @@ export const parameters = {
},
backgrounds: {
values: [
+ // TODO: remove the following three when the last 1.0 components have been migrated
{
name: 'eds-color-neutral-white',
value: '#ffffff',
@@ -76,6 +77,14 @@ export const parameters = {
name: 'eds-color-neutral-700',
value: '#21272D',
},
+ {
+ name: 'background-utility-default-high-emphasis',
+ value: '#0F2163',
+ },
+ {
+ name: 'background-utility-inverse-high-emphasis',
+ value: '#FFFFFF',
+ },
],
},
badgesConfig: {
diff --git a/src/components/Tooltip/Tooltip-v2.module.css b/src/components/Tooltip/Tooltip-v2.module.css
index 340ddf718..b6cf7191d 100644
--- a/src/components/Tooltip/Tooltip-v2.module.css
+++ b/src/components/Tooltip/Tooltip-v2.module.css
@@ -12,11 +12,6 @@
@media (prefers-reduced-motion) {
transition: none;
}
-
- border-color: var(--eds-theme-color-background-utility-default-high-emphasis);
- color: var(--eds-theme-color-text-utility-inverse);
- background-color: var(--eds-theme-color-background-utility-default-high-emphasis);
- --arrow-color: var(--eds-theme-color-background-utility-default-high-emphasis);
}
/**
@@ -106,3 +101,17 @@
border-left-width: 0;
left: -7px;
}
+
+.tooltip--variant-default {
+ color: var(--eds-theme-color-text-utility-inverse);
+ border-color: var(--eds-theme-color-background-utility-default-high-emphasis);
+ --arrow-color: var(--eds-theme-color-background-utility-default-high-emphasis);
+ background-color: var(--eds-theme-color-background-utility-default-high-emphasis);
+}
+
+.tooltip--variant-inverse {
+ color: var(--eds-theme-color-text-utility-default-primary);
+ border-color: var(--eds-theme-color-background-utility-inverse-high-emphasis);
+ --arrow-color: var(--eds-theme-color-background-utility-inverse-high-emphasis);
+ background-color: var(--eds-theme-color-background-utility-inverse-high-emphasis);
+}
\ No newline at end of file
diff --git a/src/components/Tooltip/Tooltip-v2.stories.tsx b/src/components/Tooltip/Tooltip-v2.stories.tsx
index d351883a8..b1cd9a245 100644
--- a/src/components/Tooltip/Tooltip-v2.stories.tsx
+++ b/src/components/Tooltip/Tooltip-v2.stories.tsx
@@ -51,7 +51,7 @@ export default {
layout: 'centered',
badges: ['intro-1.0', 'current-2.0'],
chromatic: {
- delay: 300,
+ delay: 500,
diffThreshold,
diffIncludeAntiAliasing: false,
},
@@ -106,6 +106,16 @@ export const LongTriggerText: Story = {
},
};
+export const InverseVariant: Story = {
+ args: {
+ ...LeftPlacement.args,
+ variant: 'inverse',
+ },
+ parameters: {
+ backgrounds: { default: 'background-utility-default-high-emphasis' },
+ },
+};
+
/**
* Hover over the button to make the tooltip appear.
*/
diff --git a/src/components/Tooltip/Tooltip-v2.tsx b/src/components/Tooltip/Tooltip-v2.tsx
index 919a01d75..d1382f179 100644
--- a/src/components/Tooltip/Tooltip-v2.tsx
+++ b/src/components/Tooltip/Tooltip-v2.tsx
@@ -85,6 +85,12 @@ type TooltipProps = {
* The content of the tooltip bubble.
*/
text?: string;
+ /**
+ * The variant treatment for tooltips
+ *
+ * **Default is `"default"`**.
+ */
+ variant?: 'default' | 'inverse';
} & TippyProps &
HTMLAttributes;
@@ -106,6 +112,7 @@ export const Tooltip = ({
duration = 200,
placement = 'auto',
text,
+ variant = 'default',
...rest
}: TooltipProps) => {
// Hides tooltip when escape key is pressed, following:
@@ -151,10 +158,16 @@ export const Tooltip = ({
);
+ const tooltipClassNames = clsx(
+ styles['tooltip'],
+ variant && styles[`tooltip--variant-${variant}`],
+ className,
+ );
+
// TODO: figure out why the modifiers don't seem to get applied
return (
(v2) BottomPlacement story renders snapshot 1`] = `
style="pointer-events: none; z-index: 9999; visibility: visible; min-width: 0px; position: absolute; left: 0px; top: 0px; margin: 0px; transform: translate(0px, 12px);"
>
(v2) InteractiveDisabled story renders snapshot 1`] = `
+
+
+
@@ -110,7 +163,7 @@ exports[`
(v2) LeftPlacement story renders snapshot 1`] = `
style="pointer-events: none; z-index: 9999; visibility: visible; min-width: 0px; position: absolute; left: 0px; top: 0px; margin: 0px; right: 0px; transform: translate(-12px, 0px);"
>
(v2) LongText story renders snapshot 1`] = `
style="pointer-events: none; z-index: 9999; visibility: visible; min-width: 0px; position: absolute; left: 0px; top: 0px; margin: 0px; transform: translate(12px, 0px);"
>
(v2) LongTriggerText story renders snapshot 1`] = `
style="pointer-events: none; z-index: 9999; visibility: visible; min-width: 0px; position: absolute; left: 0px; top: 0px; margin: 0px; transform: translate(12px, 0px);"
>
(v2) TopPlacement story renders snapshot 1`] = `
style="pointer-events: none; z-index: 9999; visibility: visible; min-width: 0px; position: absolute; left: 0px; top: 0px; margin: 0px; bottom: 0px; transform: translate(0px, -12px);"
>