Skip to content

Commit 90a1ba7

Browse files
authored
refactor(legend): remove visibility button (#252)
the visibility button is removed in favour of clicking on the legend item title BREAKING CHANGE: the `onLegendItemClick` click handler is no longer applied when clicking on the title. Instead a simple visibility change is applied.
1 parent 8551baa commit 90a1ba7

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/components/legend/_legend_item.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
@include euiTextTruncate;
3333
margin-right: $euiSizeXS;
3434
flex: 1;
35+
&:hover {
36+
cursor: pointer;
37+
}
3538
}
3639

3740
.echLegendItem__title--selected {
@@ -53,3 +56,7 @@
5356
display: none;
5457
}
5558
}
59+
60+
.echLegendItem-isHidden {
61+
color: $euiColorDarkShade;
62+
}

src/components/legend/legend_item.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,35 @@ class LegendItemComponent extends React.Component<LegendItemProps, LegendItemSta
4646
const { legendItemKey } = this.props;
4747
const { color, label, isSeriesVisible, displayValue, onMouseEnter, onMouseLeave } = this.props;
4848

49-
const onTitleClick = this.onLegendTitleClick(legendItemKey);
49+
const onTitleClick = this.onVisibilityClick(legendItemKey);
5050

5151
const showLegendDisplayValue = this.props.chartStore!.showLegendDisplayValue.get();
5252
const isSelected = legendItemKey === this.props.chartStore!.selectedLegendItemKey.get();
5353
const hasDisplayValue = this.props.chartStore!.showLegendDisplayValue.get();
5454
const hasTitleClickListener = Boolean(this.props.chartStore!.onLegendItemClickListener);
55+
const itemClasses = classNames('echLegendItem', {
56+
'echLegendItem-isHidden': !isSeriesVisible,
57+
});
5558
return (
56-
<div className="echLegendItem" onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
57-
{this.renderColor(this.toggleColorPicker, color)}
58-
{this.renderVisibilityButton(legendItemKey, isSeriesVisible)}
59+
<div className={itemClasses} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
60+
{this.renderColor(this.toggleColorPicker, color, isSeriesVisible)}
5961
{this.renderTitle(label, onTitleClick, hasTitleClickListener, isSelected, hasDisplayValue)}
6062
{this.renderDisplayValue(displayValue, showLegendDisplayValue, isSeriesVisible)}
6163
</div>
6264
);
6365
}
64-
renderColor(colorClickAction: () => void, color: string | undefined) {
66+
renderColor(colorClickAction: () => void, color?: string, isSeriesVisible: boolean = true) {
6567
if (!color) {
6668
return null;
6769
}
68-
// TODO add color picler
70+
// TODO add color picker
71+
const iconType = isSeriesVisible ? 'dot' : 'eyeClosed';
72+
const iconColor = isSeriesVisible ? color : undefined;
73+
const title = isSeriesVisible ? 'series color' : 'series hidden';
74+
const viewBox = isSeriesVisible ? undefined : '-3 -3 22 22';
6975
return (
70-
<div className="echLegendItem__color">
71-
<Icon type="dot" aria-label="series color" color={color} onClick={colorClickAction} />
76+
<div className="echLegendItem__color" aria-label={title} title={title}>
77+
<Icon type={iconType} color={iconColor} onClick={colorClickAction} viewBox={viewBox} />
7278
</div>
7379
);
7480
}
@@ -84,7 +90,7 @@ class LegendItemComponent extends React.Component<LegendItemProps, LegendItemSta
8490

8591
renderTitle(
8692
title: string | undefined,
87-
onTitleClick: () => void,
93+
onTitleClick: (event: React.MouseEvent<Element, MouseEvent>) => void,
8894
hasTitleClickListener: boolean,
8995
isSelected: boolean,
9096
hasDisplayValue: boolean,
@@ -153,7 +159,7 @@ class LegendItemComponent extends React.Component<LegendItemProps, LegendItemSta
153159
// );
154160
// }
155161

156-
private onVisibilityClick = (legendItemKey: string) => (event: React.MouseEvent<SVGElement>) => {
162+
private onVisibilityClick = (legendItemKey: string) => (event: React.MouseEvent) => {
157163
if (event.shiftKey) {
158164
this.props.chartStore!.toggleSingleSeries(legendItemKey);
159165
} else {

0 commit comments

Comments
 (0)