Skip to content

Commit 19ca30a

Browse files
[Lens] Use EuiContextMenuItem instead of custom ChartOptionWrapper with manually-copied CSS (elastic#270138)
## Summary Closes elastic#268723 In elastic#260949, they introduced changes to EUI selection list components that updated their visual styles: <img width="396" height="386" alt="Screenshot 2026-05-20 at 13 01 09" src="https://github.com/user-attachments/assets/20953dfa-04e3-4b3e-82e9-5d2aca9f8984" /> However, in `x-pack/platform/plugins/shared/lens/public/visualizations/xy/add_layer.tsx`, we created a custom component called`ChartOptionWrapper` that was coping the previous styles so it looked like the before: <img width="417" height="261" alt="Screenshot 2026-05-20 at 13 03 26" src="https://github.com/user-attachments/assets/615748c5-8b79-448c-99ef-8a29d479bc0d" /> This PR uses the `EuiContextMenuItem` component as suggested in elastic#260949 (comment) so there's no need to copy the styles as we use the expected styles out-of-the-box. <img width="353" height="215" alt="Screenshot 2026-05-20 at 13 05 47" src="https://github.com/user-attachments/assets/7ffd10e8-73b1-4d8a-9efa-6718f111b98c" /> This menu is found in: Visualize library > Create visualization > Lens > Add layer > Visualization ## Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels.
1 parent 9d678ec commit 19ca30a

1 file changed

Lines changed: 26 additions & 68 deletions

File tree

  • x-pack/platform/plugins/shared/lens/public/visualizations/xy

x-pack/platform/plugins/shared/lens/public/visualizations/xy/add_layer.tsx

Lines changed: 26 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
*/
77

88
import React, { useState } from 'react';
9-
import type { IconType } from '@elastic/eui';
109
import {
1110
EuiButtonIcon,
1211
EuiPopover,
1312
EuiIcon,
1413
EuiContextMenu,
14+
EuiContextMenuItem,
15+
EuiText,
1516
EuiFlexItem,
1617
EuiFlexGroup,
1718
EuiToolTip,
18-
type UseEuiTheme,
19-
useEuiTheme,
2019
} from '@elastic/eui';
2120
import { i18n } from '@kbn/i18n';
2221
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
@@ -30,7 +29,6 @@ import { visualizationTypes } from './types';
3029
import { isHorizontalChart, isHorizontalSeries, isPercentageSeries } from './state_helpers';
3130
import { getDataLayers } from './visualization_helpers';
3231
import { ExperimentalBadge } from '../../shared_components';
33-
import { ChartOption } from '../../editor_frame_service/editor_frame/config_panel/chart_switch/chart_option';
3432

3533
export interface AddLayerButtonProps {
3634
state: XYVisualizationState;
@@ -226,27 +224,30 @@ export function AddLayerButton({
226224
t.subtypes?.includes(firstLayerSubtype) && !isPercentageSeries(firstLayerSubtype);
227225

228226
return {
229-
renderItem: () => {
230-
return (
231-
<ChartOptionWrapper
232-
type={t.id}
233-
label={t.label}
234-
description={t.description}
235-
icon={t.icon}
236-
onClick={() => {
237-
addLayer(
238-
LayerTypes.DATA,
239-
undefined,
240-
undefined,
241-
canInitializeWithSubtype
242-
? firstLayerSubtype
243-
: (t.subtypes?.[0] as SeriesType)
244-
);
245-
toggleLayersChoice(false);
246-
}}
247-
/>
248-
);
249-
},
227+
renderItem: () => (
228+
<EuiContextMenuItem
229+
icon={<EuiIcon type={t.icon} aria-hidden={true} />}
230+
data-test-subj={`lnsXY_seriesType-${t.id}`}
231+
onClick={() => {
232+
addLayer(
233+
LayerTypes.DATA,
234+
undefined,
235+
undefined,
236+
canInitializeWithSubtype
237+
? firstLayerSubtype
238+
: (t.subtypes?.[0] as SeriesType)
239+
);
240+
toggleLayersChoice(false);
241+
}}
242+
>
243+
<EuiText size="s" data-test-subj="lnsChartSwitch-option-label">
244+
{t.label}
245+
</EuiText>
246+
<EuiText size="xs" color="subdued">
247+
{t.description}
248+
</EuiText>
249+
</EuiContextMenuItem>
250+
),
250251
};
251252
}),
252253
},
@@ -267,46 +268,3 @@ export function AddLayerButton({
267268
</div>
268269
);
269270
}
270-
271-
const ChartOptionWrapper = ({
272-
label,
273-
description,
274-
icon,
275-
onClick,
276-
type,
277-
}: {
278-
label: string;
279-
description: string;
280-
icon: IconType;
281-
onClick: () => void;
282-
type: string;
283-
}) => {
284-
const euiThemeContext = useEuiTheme();
285-
return (
286-
<button
287-
data-test-subj={`lnsXY_seriesType-${type}`}
288-
onClick={onClick}
289-
className="euiContextMenuItem"
290-
css={chartOptionWrapperStyles(euiThemeContext)}
291-
>
292-
<ChartOption option={{ icon, label, description }} />
293-
</button>
294-
);
295-
};
296-
297-
const chartOptionWrapperStyles = ({ euiTheme }: UseEuiTheme) => css`
298-
padding: ${euiTheme.size.s};
299-
border-bottom: ${euiTheme.border.thin};
300-
border-bottom-color: ${euiTheme.colors.backgroundBaseSubdued};
301-
width: 100%;
302-
&:hover,
303-
&:focus {
304-
color: ${euiTheme.colors.primary};
305-
background-color: ${euiTheme.colors.backgroundBasePrimary};
306-
span,
307-
.euiText {
308-
text-decoration: underline;
309-
color: ${euiTheme.colors.primary};
310-
}
311-
}
312-
`;

0 commit comments

Comments
 (0)