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

[Emotion] Publicly export cloneElementWithCss service/util #6939

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { ReactElement, FunctionComponent } from 'react';
import classNames from 'classnames';

import { cloneElementWithCss } from '../../../services/theme/clone_element';
import { cloneElementWithCss } from '../../../services';
import { euiScreenReaderOnlyStyles } from './screen_reader_only.styles';

export interface EuiScreenReaderOnlyProps {
Expand Down
7 changes: 5 additions & 2 deletions src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import React, {
import classNames from 'classnames';

import { CommonProps, ExclusiveUnion } from '../common';
import { getSecureRelForTarget, useEuiTheme } from '../../services';
import { cloneElementWithCss } from '../../services/theme/clone_element';
import {
getSecureRelForTarget,
useEuiTheme,
cloneElementWithCss,
} from '../../services';
import { EuiText } from '../text';
import { EuiTitle } from '../title';
import { EuiBetaBadge, EuiBetaBadgeProps } from '../badge/beta_badge';
Expand Down
3 changes: 1 addition & 2 deletions src/components/facet/facet_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { EuiNotificationBadge } from '../badge';
import { EuiLoadingSpinner } from '../loading';
import { EuiInnerText } from '../inner_text';

import { cloneElementWithCss } from '../../services/theme/clone_element';
import { useEuiTheme } from '../../services';
import { useEuiTheme, cloneElementWithCss } from '../../services';
import {
euiFacetButtonStyles,
euiFacetButtonTextStyles,
Expand Down
3 changes: 1 addition & 2 deletions src/components/list_group/list_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import classNames from 'classnames';

import { EuiListGroupItem, EuiListGroupItemProps } from './list_group_item';
import { CommonProps } from '../common';
import { useEuiTheme } from '../../services';
import { cloneElementWithCss } from '../../services/theme/clone_element';
import { useEuiTheme, cloneElementWithCss } from '../../services';
import { logicalStyle } from '../../global_styling';

import { euiListGroupStyles } from './list_group.styles';
Expand Down
7 changes: 5 additions & 2 deletions src/components/list_group/list_group_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ import {
EuiListGroupItemExtraActionProps,
} from './list_group_item_extra_action';

import { getSecureRelForTarget, useEuiTheme } from '../../services';
import { cloneElementWithCss } from '../../services/theme/clone_element';
import {
getSecureRelForTarget,
useEuiTheme,
cloneElementWithCss,
} from '../../services';
import { validateHref } from '../../services/security/href_validator';

import {
Expand Down
2 changes: 1 addition & 1 deletion src/components/text/text_align.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import React, {
isValidElement,
} from 'react';
import { CommonProps } from '../common';
import { cloneElementWithCss } from '../../services/theme/clone_element';
import { cloneElementWithCss } from '../../services';

import { euiTextAlignStyles } from './text_align.styles';

Expand Down
4 changes: 2 additions & 2 deletions src/components/text/text_color.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import React, {
CSSProperties,
isValidElement,
} from 'react';

import { CommonProps } from '../common';
import { cloneElementWithCss } from '../../services/theme/clone_element';
import { useEuiTheme, cloneElementWithCss } from '../../services';

import { useEuiTheme } from '../../services';
import { euiTextColorStyles } from './text_color.styles';

export const COLORS = [
Expand Down
3 changes: 1 addition & 2 deletions src/components/title/title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import { FunctionComponent, ReactElement } from 'react';
import classNames from 'classnames';
import { useEuiTheme } from '../../services';
import { cloneElementWithCss } from '../../services/theme/clone_element';
import { useEuiTheme, cloneElementWithCss } from '../../services';
import { euiTitleStyles } from './title.styles';
import { CommonProps } from '../common';

Expand Down
3 changes: 1 addition & 2 deletions src/components/toast/global_toast_list_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import { FunctionComponent, ReactElement } from 'react';
import classNames from 'classnames';
import { useEuiTheme } from '../../services';
import { cloneElementWithCss } from '../../services/theme/clone_element';
import { useEuiTheme, cloneElementWithCss } from '../../services';
import { CommonProps } from '../common';
import { euiGlobalToastListItemStyles } from './global_toast_list.styles';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import { jsx } from '@emotion/react';
* React.cloneElement does not work if the cloned element does not already have the
* `css` prop - as a result, we need to use `jsx()` to manually clone the element
* See https://github.com/emotion-js/emotion/issues/1404
*
* NOTE: We're still using/testing this utility internally, so this is not yet a public API
*/
export const cloneElementWithCss = (
element: any,
Expand Down
9 changes: 9 additions & 0 deletions src/services/emotion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './clone_element';
1 change: 1 addition & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export { useColorPickerState, useColorStopsState } from './color_picker';
export type { EuiSetColorMethod } from './color_picker';
export * from './console';
export { copyToClipboard } from './copy_to_clipboard';
export * from './emotion';
export * from './findElement';
export {
dateFormatAliases,
Expand Down
2 changes: 1 addition & 1 deletion src/test/internal/render_custom_styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { css } from '@emotion/react';
import { get, set } from 'lodash';

import { render } from '../rtl';
import { cloneElementWithCss } from '../../services/theme/clone_element';
import { cloneElementWithCss } from '../../services';
import { keysOf } from '../../components';

export const customStyles = {
Expand Down
1 change: 1 addition & 0 deletions upcoming_changelogs/6939.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added a new `cloneElementWithCss` Emotion utility