Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tooltip): show true opaque colors in tooltips #629

Merged
merged 3 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .playground/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React from 'react';

import { Example } from '../stories/treemap/6_custom_style';
import { Example } from '../stories/stylings/20_partition_background';

export class Playground extends React.Component {
render() {
Expand Down
5 changes: 4 additions & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
'*.{js,ts,tsx}': ['yarn lint:fix'],
// TODO: make this `lint:fix` if ever added to `pre-commit`
// using in `commit-msg` doesn't save fixed changes so
// in the meantime should error on bad linting when committing
'*.{js,ts,tsx}': ['yarn lint'],
};
24 changes: 21 additions & 3 deletions src/components/tooltip/_tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,28 @@

&__item {
display: flex;
padding: 3px;
box-sizing: border-box;
border-left: $euiSizeXS solid transparent;
min-width: 1px;

&--container {
display: flex;
padding: 3px;
padding-left: 0;
min-width: 1px;
}

&--backgroundColor {
position: relative;
width: $euiSizeXS;
margin-right: 3px;
}

&--color {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
}

&__label {
Expand Down
32 changes: 23 additions & 9 deletions src/components/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { TooltipValueFormatter, TooltipSettings, TooltipValue } from '../../spec
import { onPointerMove } from '../../state/actions/mouse';
import { GlobalChartState, BackwardRef } from '../../state/chart_state';
import { getChartRotationSelector } from '../../state/selectors/get_chart_rotation';
import { getChartThemeSelector } from '../../state/selectors/get_chart_theme';
import { getInternalIsInitializedSelector } from '../../state/selectors/get_internal_is_intialized';
import { getInternalIsTooltipVisibleSelector } from '../../state/selectors/get_internal_is_tooltip_visible';
import { getInternalTooltipAnchorPositionSelector } from '../../state/selectors/get_internal_tooltip_anchor_position';
Expand All @@ -48,6 +49,7 @@ interface TooltipStateProps {
settings: TooltipSettings;
rotation: Rotation;
chartId: string;
backgroundColor: string;
}

interface TooltipOwnProps {
Expand All @@ -66,6 +68,7 @@ const TooltipComponent = ({
rotation,
chartId,
onPointerMove,
backgroundColor,
}: TooltipProps) => {
const chartRef = getChartContainerRef();

Expand Down Expand Up @@ -109,15 +112,24 @@ const TooltipComponent = ({
borderLeftColor: color,
}}
>
<span className="echTooltip__label">{label}</span>
<span className="echTooltip__value">{value}</span>
{markValue && (
<span className="echTooltip__markValue">
&nbsp;(
{markValue}
)
</span>
)}
<div className="echTooltip__item--backgroundColor" style={{ backgroundColor }}>
<div
className="echTooltip__item--color"
style={{ backgroundColor: color }}
/>
</div>

<div className="echTooltip__item--container">
<span className="echTooltip__label">{label}</span>
<span className="echTooltip__value">{value}</span>
{markValue && (
<span className="echTooltip__markValue">
&nbsp;(
{markValue}
)
</span>
)}
</div>
</div>
);
},
Expand Down Expand Up @@ -204,6 +216,7 @@ const HIDDEN_TOOLTIP_PROPS = {
settings: {},
rotation: 0 as Rotation,
chartId: '',
backgroundColor: 'transparent',
};

const mapDispatchToProps = (dispatch: Dispatch): TooltipDispatchProps =>
Expand All @@ -221,6 +234,7 @@ const mapStateToProps = (state: GlobalChartState): TooltipStateProps => {
settings: getSettingsSpecSelector(state).tooltip,
rotation: getChartRotationSelector(state),
chartId: state.chartId,
backgroundColor: getChartThemeSelector(state).background.color,
};
};

Expand Down