Skip to content

Commit 184515f

Browse files
committed
feat(Tooltip): light version
1 parent e114d06 commit 184515f

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

.changeset/khaki-carpets-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Add light version for Tooltip component. Use `isLight` prop to activate it.

src/components/overlays/Tooltip/Tooltip.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ ViaProvider.play = async ({ canvasElement }) => {
6969
await timeout(1000);
7070

7171
const button = await canvas.findByRole('button');
72-
// this is a weird hack that makes tooltip working properly on page load
72+
// this is hack that makes tooltip working properly on page load
7373
await userEvent.unhover(button);
7474
await userEvent.hover(button);
7575

@@ -91,3 +91,7 @@ ViaProviderWithActiveWrap.play = async ({ canvasElement }) => {
9191

9292
await waitFor(() => expect(canvas.getByRole('tooltip')).toBeVisible());
9393
};
94+
95+
export const Light: typeof Template = Template.bind({});
96+
Light.args = { isLight: true };
97+
Light.play = Default.play;

src/components/overlays/Tooltip/Tooltip.tsx

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
forwardRef,
66
useContext,
77
useImperativeHandle,
8+
useMemo,
89
useRef,
910
} from 'react';
1011
import { AriaTooltipProps, useTooltip } from 'react-aria';
@@ -29,8 +30,14 @@ export type { AriaTooltipProps };
2930
const TooltipElement = tasty({
3031
styles: {
3132
display: 'block',
32-
fill: '#dark.85',
33-
color: '#white',
33+
fill: {
34+
'': '#dark.85',
35+
light: '#white',
36+
},
37+
color: {
38+
'': '#white',
39+
light: '#dark-02',
40+
},
3441
width: 'initial 36x max-content',
3542
radius: true,
3643
padding: '.75x 1x',
@@ -41,6 +48,10 @@ const TooltipElement = tasty({
4148
'': 'none',
4249
material: 'auto',
4350
},
51+
filter: {
52+
'': false,
53+
light: 'drop-shadow(0 0 1px rgb(var(--dark-color-rgb) / 20%)',
54+
},
4455
},
4556
});
4657

@@ -50,7 +61,10 @@ const TooltipTipElement = tasty({
5061
width: '1px',
5162
height: '1px',
5263
border: '.5x #clear',
53-
borderTop: '.5x solid #dark.85',
64+
borderTop: {
65+
'': '.5x solid #dark.85',
66+
light: '.5x solid #white',
67+
},
5468
borderBottom: '0',
5569
top: {
5670
'': 'initial',
@@ -100,6 +114,7 @@ export interface CubeTooltipProps
100114
placement?: PlacementAxis;
101115
isMaterial?: boolean;
102116
isOpen?: boolean;
117+
isLight?: boolean;
103118
onOpenChange?: (isOpen: boolean) => void;
104119
defaultOpen?: boolean;
105120
shouldFlip?: boolean;
@@ -116,6 +131,8 @@ function Tooltip(
116131
overlayProps,
117132
minOffset,
118133
minScale,
134+
isMaterial: isMaterialContext,
135+
isLight: isLightContext,
119136
...tooltipProviderProps
120137
} = useContext(TooltipContext);
121138

@@ -130,7 +147,8 @@ function Tooltip(
130147
isOpen,
131148
tipStyles,
132149
showIcon,
133-
isMaterial,
150+
isMaterial = isMaterialContext,
151+
isLight = isLightContext,
134152
...otherProps
135153
} = props;
136154

@@ -149,16 +167,21 @@ function Tooltip(
149167
minScale = String(minScale);
150168
}
151169

170+
const mods = useMemo(() => {
171+
return {
172+
material: isMaterial,
173+
light: isLight,
174+
open: isOpen,
175+
};
176+
}, [isMaterial, isOpen, isLight]);
177+
152178
return (
153179
<StyledTooltipElement
154180
{...tooltipProps}
155181
{...overlayProps}
156182
ref={overlayRef}
157183
styles={styles}
158-
mods={{
159-
open: isOpen,
160-
material: isMaterial,
161-
}}
184+
mods={mods}
162185
data-min-offset={minOffset}
163186
data-min-scale={minScale}
164187
data-placement={placement}
@@ -167,6 +190,7 @@ function Tooltip(
167190
<TooltipTipElement
168191
data-placement={placement}
169192
styles={tipStyles}
193+
mods={mods}
170194
{...arrowProps}
171195
/>
172196
</StyledTooltipElement>

src/components/overlays/Tooltip/TooltipTrigger.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface CubeTooltipTriggerProps extends TooltipTriggerProps {
2323
offset?: number;
2424
placement?: Placement;
2525
isMaterial?: boolean;
26+
isLight?: boolean;
2627
/** Whether the trigger should have an ActiveZone wrap to make sure it's focusable and hoverable.
2728
* Otherwise, tooltip won't work. */
2829
activeWrap?: boolean;
@@ -61,6 +62,7 @@ export function TooltipTrigger(props: CubeTooltipTriggerProps) {
6162
crossOffset = DEFAULT_CROSS_OFFSET,
6263
isDisabled,
6364
isMaterial,
65+
isLight,
6466
offset = DEFAULT_OFFSET,
6567
trigger: triggerAction,
6668
delay = 250,
@@ -127,6 +129,7 @@ export function TooltipTrigger(props: CubeTooltipTriggerProps) {
127129
minOffset: 'var(--gap)',
128130
minScale: '1',
129131
isMaterial,
132+
isLight,
130133
...tooltipProps,
131134
}}
132135
>

src/components/overlays/Tooltip/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface TooltipContextProps {
1313
minScale?: string | number;
1414
minOffset?: string | number;
1515
isMaterial?: boolean;
16+
isLight?: boolean;
1617
}
1718

1819
export const TooltipContext = React.createContext<TooltipContextProps>({});

0 commit comments

Comments
 (0)