Skip to content

Commit f5eecac

Browse files
committed
refactor: add shared arrow styles on range tooltip
1 parent 6973ab7 commit f5eecac

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

packages/eui/src/components/form/range/__snapshots__/range.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports[`EuiRange allows value prop to accept a number 1`] = `
2222
class="euiRangeTooltip emotion-euiRangeTooltip"
2323
>
2424
<output
25-
class="euiRangeTooltip__value emotion-euiRangeTooltip__value-right"
25+
class="euiRangeTooltip__value emotion-euiRangeTooltip__value-right-right"
2626
style="inset-inline-start: 8%;"
2727
>
2828
8
@@ -619,7 +619,7 @@ exports[`EuiRange props value should render 1`] = `
619619
class="euiRangeTooltip emotion-euiRangeTooltip"
620620
>
621621
<output
622-
class="euiRangeTooltip__value emotion-euiRangeTooltip__value-left"
622+
class="euiRangeTooltip__value emotion-euiRangeTooltip__value-left-left"
623623
style="inset-inline-end: 0%;"
624624
>
625625
before

packages/eui/src/components/form/range/range_tooltip.styles.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
import { css } from '@emotion/react';
1010
import { UseEuiTheme } from '../../../services';
11-
import { euiRangeVariables } from './range.styles';
1211
import { euiFontSize, mathWithUnits } from '../../../global_styling';
12+
import { _popoverArrowStyles } from '../../../services/popover';
13+
import { euiRangeVariables } from './range.styles';
1314

1415
export const euiRangeTooltipStyles = (euiThemeContext: UseEuiTheme) => {
1516
const range = euiRangeVariables(euiThemeContext);
@@ -32,13 +33,15 @@ export const euiRangeTooltipStyles = (euiThemeContext: UseEuiTheme) => {
3233

3334
export const euiRangeTooltipValueStyles = (euiThemeContext: UseEuiTheme) => {
3435
const range = euiRangeVariables(euiThemeContext);
35-
const { euiTheme } = euiThemeContext;
36-
37-
const arrowSize = euiTheme.size.m;
38-
const arrowSizeInt = parseInt(arrowSize, 10);
39-
const arrowMinusSize = `${(arrowSizeInt / 2 - 1) * -1}px`; // Shift arrow 1px more than half its size to account for border radius
36+
const { euiTheme, colorMode } = euiThemeContext;
4037

4138
const toolTipBackgroundColor = euiTheme.components.tooltipBackground;
39+
const borderColor =
40+
colorMode === 'DARK' ? toolTipBackgroundColor : 'transparent';
41+
42+
const arrowSize = euiTheme.size.m;
43+
const arrowOffset = euiTheme.size.l;
44+
const arrowStyles = _popoverArrowStyles(euiThemeContext, arrowSize);
4245

4346
return {
4447
euiRangeTooltip__value: css`
@@ -47,42 +50,39 @@ export const euiRangeTooltipValueStyles = (euiThemeContext: UseEuiTheme) => {
4750
max-inline-size: ${mathWithUnits(euiTheme.size.base, (x) => x * 16)};
4851
padding-block: ${euiTheme.size.xxs};
4952
padding-inline: ${euiTheme.size.s};
50-
transform: translateX(0) translateY(-50%);
53+
transform: translateY(-50%);
5154
5255
${euiFontSize(euiThemeContext, 's')}
5356
line-height: ${euiFontSize(euiThemeContext, 's').lineHeight};
5457
color: ${euiTheme.colors.ghost};
5558
background-color: ${toolTipBackgroundColor};
5659
border: ${euiTheme.border.width.thin} solid ${toolTipBackgroundColor};
60+
border: ${euiTheme.border.width.thin} solid ${borderColor};
5761
border-radius: ${euiTheme.border.radius.small};
5862
5963
&::before {
6064
content: '';
61-
position: absolute;
62-
inset-block-end: 50%;
63-
inline-size: ${arrowSize};
64-
block-size: ${arrowSize};
65-
transform-origin: center;
66-
transform: translateY(50%) rotateZ(45deg);
67-
background-color: ${toolTipBackgroundColor};
68-
border-radius: ${mathWithUnits(
69-
euiTheme.border.radius.small,
70-
(x) => x / 2
71-
)};
65+
${arrowStyles._arrowStyles}
66+
inset-block-start: 50%;
67+
margin-block-start: ${mathWithUnits(arrowSize, (x) => x / -2)};
68+
background-color: inherit;
69+
border: inherit;
7270
}
7371
`,
7472
left: css`
75-
margin-inline-end: ${euiTheme.size.l};
73+
margin-inline-end: ${arrowOffset};
7674
7775
&::before {
78-
inset-inline-end: ${arrowMinusSize};
76+
${arrowStyles.positions.left}
77+
inset-inline-start: 100%;
7978
}
8079
`,
8180
right: css`
82-
margin-inline-start: ${euiTheme.size.l};
81+
margin-inline-start: ${arrowOffset};
8382
8483
&::before {
85-
inset-inline-start: ${arrowMinusSize};
84+
${arrowStyles.positions.right}
85+
inset-inline-end: 100%;
8686
}
8787
`,
8888
hasTicks: css`

0 commit comments

Comments
 (0)