Skip to content

Commit e2f0b1e

Browse files
[favorites] Split CSS helper into module to break SVG leak (#270495)
1 parent f90593e commit e2f0b1e

4 files changed

Lines changed: 53 additions & 34 deletions

File tree

src/platform/packages/shared/content-management/favorites/favorites_public/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ export { type FavoritesClientPublic, FavoritesClient } from './src/favorites_cli
1111
export { FavoritesContextProvider } from './src/favorites_context';
1212
export { useFavorites } from './src/favorites_query';
1313

14-
export {
15-
FavoriteButton,
16-
type FavoriteButtonProps,
17-
cssFavoriteHoverWithinEuiTableRow,
18-
} from './src/components/favorite_button';
14+
export { FavoriteButton, type FavoriteButtonProps } from './src/components/favorite_button';
15+
16+
export { cssFavoriteHoverWithinEuiTableRow } from './src/components/favorite_button_table_row_styles';
1917
export { StardustWrapper } from './src/components/stardust_wrapper';
2018
export { FavoritesEmptyState } from './src/components/favorites_empty_state';

src/platform/packages/shared/content-management/favorites/favorites_public/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"name": "@kbn/content-management-favorites-public",
33
"private": true,
44
"version": "1.0.0",
5-
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0"
5+
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0",
6+
"sideEffects": false
67
}

src/platform/packages/shared/content-management/favorites/favorites_public/src/components/favorite_button.tsx

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
import React from 'react';
1111
import { i18n } from '@kbn/i18n';
1212
import classNames from 'classnames';
13-
import type { EuiThemeComputed } from '@elastic/eui';
14-
import { EuiButtonIcon, euiCanAnimate } from '@elastic/eui';
15-
import { css } from '@emotion/react';
13+
import { EuiButtonIcon } from '@elastic/eui';
1614
import { useAddFavorite, useFavorites, useRemoveFavorite } from '../favorites_query';
1715
import { useFavoritesClient } from '../favorites_context';
1816
import { StardustWrapper } from './stardust_wrapper';
@@ -30,7 +28,9 @@ export const FavoriteButton = ({ id, className }: FavoriteButtonProps) => {
3028

3129
const favoritesClient = useFavoritesClient();
3230

33-
if (!data) return null;
31+
if (!data) {
32+
return null;
33+
}
3434

3535
const isFavorite = data.favoriteIds.includes(id);
3636
const isFavoriteOptimistic = isFavorite || addFavorite.isLoading;
@@ -54,7 +54,9 @@ export const FavoriteButton = ({ id, className }: FavoriteButtonProps) => {
5454
aria-label={title}
5555
iconType={isFavoriteOptimistic ? 'starFill' : 'star'}
5656
onClick={() => {
57-
if (addFavorite.isLoading || removeFavorite.isLoading) return;
57+
if (addFavorite.isLoading || removeFavorite.isLoading) {
58+
return;
59+
}
5860

5961
if (isFavorite) {
6062
favoritesClient?.reportRemoveFavoriteClick();
@@ -73,26 +75,3 @@ export const FavoriteButton = ({ id, className }: FavoriteButtonProps) => {
7375
</StardustWrapper>
7476
);
7577
};
76-
77-
/**
78-
* CSS to apply to euiTable to show the favorite button on hover or when active
79-
* @param euiTheme
80-
*/
81-
export const cssFavoriteHoverWithinEuiTableRow = (euiTheme: EuiThemeComputed) => css`
82-
@media (hover: hover) {
83-
.euiTableRow .cm-favorite-button--empty {
84-
visibility: hidden;
85-
opacity: 0;
86-
${euiCanAnimate} {
87-
transition: opacity ${euiTheme.animation.fast} ${euiTheme.animation.resistance};
88-
}
89-
}
90-
.euiTableRow:hover,
91-
.euiTableRow:focus-within {
92-
.cm-favorite-button--empty {
93-
visibility: visible;
94-
opacity: 1;
95-
}
96-
}
97-
}
98-
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import type { EuiThemeComputed } from '@elastic/eui';
11+
import { euiCanAnimate } from '@elastic/eui';
12+
import { css } from '@emotion/react';
13+
14+
/**
15+
* CSS to apply to a `EuiBasicTable` row container to show the favorite button
16+
* on hover or when active.
17+
*
18+
* Extracted to its own module (no React, no `FavoriteButton` import) so
19+
* consumers that only need the row-hover style don't drag the whole
20+
* `FavoriteButton` + `StardustWrapper` graph into their bundle.
21+
*
22+
* @param euiTheme - resolved EUI theme, typically from `useEuiTheme()`.
23+
*/
24+
export const cssFavoriteHoverWithinEuiTableRow = (euiTheme: EuiThemeComputed) => css`
25+
@media (hover: hover) {
26+
.euiTableRow .cm-favorite-button--empty {
27+
visibility: hidden;
28+
opacity: 0;
29+
${euiCanAnimate} {
30+
transition: opacity ${euiTheme.animation.fast} ${euiTheme.animation.resistance};
31+
}
32+
}
33+
.euiTableRow:hover,
34+
.euiTableRow:focus-within {
35+
.cm-favorite-button--empty {
36+
visibility: visible;
37+
opacity: 1;
38+
}
39+
}
40+
}
41+
`;

0 commit comments

Comments
 (0)