+
{this.renderLeftIcons()}
{children}
{this.renderRightIcons()}
From bffd3f1196ce4302390445b2b38a038797d8e17f Mon Sep 17 00:00:00 2001
From: Cee Chen <549407+cee-chen@users.noreply.github.com>
Date: Tue, 4 Jun 2024 09:18:40 -0700
Subject: [PATCH 4/8] [Emotion] Convert EuiFieldNumber, EuiFieldSearch, and
EuiFieldPassword (#7802)
---
packages/eui/changelogs/upcoming/7802.md | 5 +
.../basic_table/in_memory_table.test.tsx | 2 +-
.../quick_select_popover.test.tsx.snap | 4 +-
packages/eui/src/components/form/_index.scss | 3 -
.../__snapshots__/field_number.test.tsx.snap | 16 +--
.../form/field_number/_field_number.scss | 8 --
.../components/form/field_number/_index.scss | 1 -
.../form/field_number/field_number.styles.ts | 59 +++++++++
.../form/field_number/field_number.test.tsx | 2 +-
.../form/field_number/field_number.tsx | 35 +++---
.../field_password.test.tsx.snap | 22 ++--
.../form/field_password/_field_password.scss | 14 ---
.../form/field_password/_index.scss | 1 -
.../field_password/field_password.styles.ts | 59 +++++++++
.../field_password/field_password.test.tsx | 2 +-
.../form/field_password/field_password.tsx | 119 ++++++++++--------
.../__snapshots__/field_search.test.tsx.snap | 16 +--
.../form/field_search/_field_search.scss | 22 ----
.../components/form/field_search/_index.scss | 1 -
.../form/field_search/field_search.styles.ts | 63 ++++++++++
.../form/field_search/field_search.test.tsx | 2 +-
.../form/field_search/field_search.tsx | 38 +++---
.../__snapshots__/dual_range.test.tsx.snap | 16 +--
.../range/__snapshots__/range.test.tsx.snap | 6 +-
.../__snapshots__/range_input.test.tsx.snap | 2 +-
.../__snapshots__/search_bar.test.tsx.snap | 8 +-
.../__snapshots__/search_box.test.tsx.snap | 4 +-
.../__snapshots__/selectable.test.tsx.snap | 2 +-
.../selectable_search.test.tsx.snap | 6 +-
...selectable_template_sitewide.test.tsx.snap | 8 +-
30 files changed, 349 insertions(+), 197 deletions(-)
create mode 100644 packages/eui/changelogs/upcoming/7802.md
delete mode 100644 packages/eui/src/components/form/field_number/_field_number.scss
delete mode 100644 packages/eui/src/components/form/field_number/_index.scss
create mode 100644 packages/eui/src/components/form/field_number/field_number.styles.ts
delete mode 100644 packages/eui/src/components/form/field_password/_field_password.scss
delete mode 100644 packages/eui/src/components/form/field_password/_index.scss
create mode 100644 packages/eui/src/components/form/field_password/field_password.styles.ts
delete mode 100644 packages/eui/src/components/form/field_search/_field_search.scss
delete mode 100644 packages/eui/src/components/form/field_search/_index.scss
create mode 100644 packages/eui/src/components/form/field_search/field_search.styles.ts
diff --git a/packages/eui/changelogs/upcoming/7802.md b/packages/eui/changelogs/upcoming/7802.md
new file mode 100644
index 00000000000..0bc6a6a183a
--- /dev/null
+++ b/packages/eui/changelogs/upcoming/7802.md
@@ -0,0 +1,5 @@
+**CSS-in-JS conversions**
+
+- Converted `EuiFieldNumber` to Emotion
+- Converted `EuiFieldSearch` to Emotion
+- Converted `EuiFieldPassword` to Emotion
diff --git a/packages/eui/src/components/basic_table/in_memory_table.test.tsx b/packages/eui/src/components/basic_table/in_memory_table.test.tsx
index 5aedbd0eddc..6e0371bedfe 100644
--- a/packages/eui/src/components/basic_table/in_memory_table.test.tsx
+++ b/packages/eui/src/components/basic_table/in_memory_table.test.tsx
@@ -947,7 +947,7 @@ describe('EuiInMemoryTable', () => {
// should render with all three results visible
expect(component.find('.testTable EuiTableRow').length).toBe(3);
- const searchField = component.find('EuiFieldSearch input[type="search"]');
+ const searchField = component.find('input.euiFieldSearch');
searchField.simulate('keyUp', {
target: {
diff --git a/packages/eui/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select_popover.test.tsx.snap b/packages/eui/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select_popover.test.tsx.snap
index 6a5fe74e975..6d200d8fb67 100644
--- a/packages/eui/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select_popover.test.tsx.snap
+++ b/packages/eui/src/components/date_picker/super_date_picker/quick_select_popover/__snapshots__/quick_select_popover.test.tsx.snap
@@ -135,7 +135,7 @@ exports[`EuiQuickSelectPanels customQuickSelectPanels should render custom panel
{
+ const formStyles = euiFormControlStyles(euiThemeContext);
+
+ return {
+ euiFieldNumber: css`
+ ${formStyles.shared}
+
+ /* Account for native validity detection as well via [aria-invalid="true"] */
+ &:is(:invalid, [aria-invalid="true"]) {
+ ${formStyles.invalid}
+ }
+
+ &:focus {
+ ${formStyles.focus}
+ }
+
+ &:disabled {
+ ${formStyles.disabled}
+ }
+
+ &[readOnly] {
+ ${formStyles.readOnly}
+ }
+
+ &:autofill {
+ ${formStyles.autoFill}
+ }
+ `,
+
+ // Skip the css() on the default height to avoid generating a className
+ uncompressed: formStyles.uncompressed,
+ compressed: css(formStyles.compressed),
+
+ // Skip the css() on the default width to avoid generating a className
+ formWidth: formStyles.formWidth,
+ fullWidth: css(formStyles.fullWidth),
+
+ // Layout modifiers
+ inGroup: css(formStyles.inGroup),
+ controlOnly: css`
+ .euiFormControlLayout--group & {
+ ${formStyles.inGroup}
+ }
+ `,
+ };
+};
diff --git a/packages/eui/src/components/form/field_number/field_number.test.tsx b/packages/eui/src/components/form/field_number/field_number.test.tsx
index e5870d92c0e..7bb0ff96395 100644
--- a/packages/eui/src/components/form/field_number/field_number.test.tsx
+++ b/packages/eui/src/components/form/field_number/field_number.test.tsx
@@ -113,7 +113,7 @@ describe('EuiFieldNumber', () => {
);
const control = container.querySelector('.euiFieldNumber')!;
- if (!control.classList.contains('euiFieldNumber--fullWidth')) {
+ if (!control.className.includes('fullWidth')) {
throw new Error(
'expected EuiFieldNumber to inherit fullWidth from EuiForm'
);
diff --git a/packages/eui/src/components/form/field_number/field_number.tsx b/packages/eui/src/components/form/field_number/field_number.tsx
index 9b8bc28569a..cdeae657218 100644
--- a/packages/eui/src/components/form/field_number/field_number.tsx
+++ b/packages/eui/src/components/form/field_number/field_number.tsx
@@ -17,7 +17,7 @@ import React, {
} from 'react';
import classNames from 'classnames';
-import { useCombinedRefs } from '../../../services';
+import { useCombinedRefs, useEuiMemoizedStyles } from '../../../services';
import { CommonProps } from '../../common';
import { EuiValidatableControl } from '../validatable_control';
@@ -25,12 +25,10 @@ import {
EuiFormControlLayout,
EuiFormControlLayoutProps,
} from '../form_control_layout';
-import {
- getFormControlClassNameForIconCount,
- isRightSideIcon,
-} from '../form_control_layout/_num_icons';
import { useFormContext } from '../eui_form_context';
+import { euiFieldNumberStyles } from './field_number.styles';
+
export type EuiFieldNumberProps = Omit<
InputHTMLAttributes,
'min' | 'max' | 'readOnly' | 'step'
@@ -136,25 +134,19 @@ export const EuiFieldNumber: FunctionComponent = (
}
}, [value, min, max, step, checkNativeValidity]);
- const hasRightSideIcon = isRightSideIcon(icon);
- const numIconsClass = controlOnly
- ? false
- : getFormControlClassNameForIconCount({
- isInvalid: isInvalid || isNativelyInvalid,
- isLoading,
- icon: hasRightSideIcon,
- });
-
- const classes = classNames('euiFieldNumber', className, numIconsClass, {
- 'euiFieldNumber--fullWidth': fullWidth,
- 'euiFieldNumber--compressed': compressed,
- ...(!controlOnly && {
- 'euiFieldNumber--inGroup': prepend || append,
- 'euiFieldNumber--withIcon': icon && !hasRightSideIcon,
- }),
+ const classes = classNames('euiFieldNumber', className, {
'euiFieldNumber-isLoading': isLoading,
});
+ const styles = useEuiMemoizedStyles(euiFieldNumberStyles);
+ const cssStyles = [
+ styles.euiFieldNumber,
+ compressed ? styles.compressed : styles.uncompressed,
+ fullWidth ? styles.fullWidth : styles.formWidth,
+ !controlOnly && (prepend || append) && styles.inGroup,
+ controlOnly && styles.controlOnly,
+ ];
+
const control = (
= (
placeholder={placeholder}
readOnly={readOnly}
className={classes}
+ css={cssStyles}
ref={combinedRefs}
aria-invalid={isInvalid || isNativelyInvalid}
onKeyUp={(e) => {
diff --git a/packages/eui/src/components/form/field_password/__snapshots__/field_password.test.tsx.snap b/packages/eui/src/components/form/field_password/__snapshots__/field_password.test.tsx.snap
index f09a8f2d420..a6a77aca98d 100644
--- a/packages/eui/src/components/form/field_password/__snapshots__/field_password.test.tsx.snap
+++ b/packages/eui/src/components/form/field_password/__snapshots__/field_password.test.tsx.snap
@@ -23,7 +23,7 @@ exports[`EuiFieldPassword is rendered 1`] = `
@@ -89,7 +89,7 @@ exports[`EuiFieldPassword props dual dual type also renders append 1`] = `
@@ -143,7 +143,7 @@ exports[`EuiFieldPassword props dual dualToggleProps is rendered 1`] = `