Skip to content

Commit

Permalink
[Emotion] Convert EuiTextArea, EuiSelect, and EuiSuperSelect (#7812)
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen authored Jun 6, 2024
1 parent 5ee7347 commit 5e06197
Show file tree
Hide file tree
Showing 36 changed files with 483 additions and 315 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/eui/changelogs/upcoming/7812.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**CSS-in-JS conversions**

- Converted `EuiTextArea` to Emotion
- Converted `EuiSelect` to Emotion
- Converted `EuiSuperSelect` to Emotion
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports[`EuiColorPalettePicker is rendered 1`] = `
<button
aria-haspopup="listbox"
aria-label="aria-label"
class="euiSuperSelectControl euiFormControlLayout--1icons testClass1 testClass2 emotion-euiTestCss"
class="euiSuperSelectControl testClass1 testClass2 emotion-euiSuperSelect__control-euiTestCss"
data-test-subj="test subject string"
type="button"
/>
Expand Down Expand Up @@ -56,7 +56,7 @@ exports[`EuiColorPalettePicker is rendered with a selected custom text 1`] = `
<button
aria-haspopup="listbox"
aria-label="aria-label"
class="euiSuperSelectControl euiFormControlLayout--1icons testClass1 testClass2 emotion-euiTestCss"
class="euiSuperSelectControl testClass1 testClass2 emotion-euiSuperSelect__control-euiTestCss"
data-test-subj="test subject string"
type="button"
>
Expand Down Expand Up @@ -97,7 +97,7 @@ exports[`EuiColorPalettePicker is rendered with a selected fixed palette 1`] = `
<button
aria-haspopup="listbox"
aria-label="aria-label"
class="euiSuperSelectControl euiFormControlLayout--1icons testClass1 testClass2 emotion-euiTestCss"
class="euiSuperSelectControl testClass1 testClass2 emotion-euiSuperSelect__control-euiTestCss"
data-test-subj="test subject string"
type="button"
>
Expand Down Expand Up @@ -166,7 +166,7 @@ exports[`EuiColorPalettePicker is rendered with a selected gradient palette 1`]
<button
aria-haspopup="listbox"
aria-label="aria-label"
class="euiSuperSelectControl euiFormControlLayout--1icons testClass1 testClass2 emotion-euiTestCss"
class="euiSuperSelectControl testClass1 testClass2 emotion-euiSuperSelect__control-euiTestCss"
data-test-subj="test subject string"
type="button"
>
Expand Down Expand Up @@ -215,7 +215,7 @@ exports[`EuiColorPalettePicker is rendered with a selected gradient palette with
<button
aria-haspopup="listbox"
aria-label="aria-label"
class="euiSuperSelectControl euiFormControlLayout--1icons testClass1 testClass2 emotion-euiTestCss"
class="euiSuperSelectControl testClass1 testClass2 emotion-euiSuperSelect__control-euiTestCss"
data-test-subj="test subject string"
type="button"
>
Expand Down Expand Up @@ -264,7 +264,7 @@ exports[`EuiColorPalettePicker is rendered with the prop selectionDisplay set as
<button
aria-haspopup="listbox"
aria-label="aria-label"
class="euiSuperSelectControl euiFormControlLayout--1icons testClass1 testClass2 emotion-euiTestCss"
class="euiSuperSelectControl testClass1 testClass2 emotion-euiSuperSelect__control-euiTestCss"
data-test-subj="test subject string"
type="button"
>
Expand Down Expand Up @@ -304,7 +304,7 @@ exports[`EuiColorPalettePicker more props are propagated to each option 1`] = `
>
<button
aria-haspopup="listbox"
class="euiSuperSelectControl euiFormControlLayout--1icons euiSuperSelect--isOpen__button"
class="euiSuperSelectControl emotion-euiSuperSelect__control-open"
data-test-subj="colorPalettePicker"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ exports[`EuiQuickSelectPanels customQuickSelectPanels should render custom panel
<select
aria-describedby="generated-id generated-id"
aria-label="Time tense"
class="euiSelect euiFormControlLayout--1icons euiSelect--compressed"
class="euiSelect emotion-euiSelect-compressed"
>
<option
value="last"
Expand Down Expand Up @@ -155,7 +155,7 @@ exports[`EuiQuickSelectPanels customQuickSelectPanels should render custom panel
<select
aria-describedby="generated-id generated-id"
aria-label="Time unit"
class="euiSelect euiFormControlLayout--1icons euiSelect--compressed"
class="euiSelect emotion-euiSelect-compressed"
>
<option
value="s"
Expand Down Expand Up @@ -372,7 +372,7 @@ exports[`EuiQuickSelectPanels customQuickSelectPanels should render custom panel
<select
aria-describedby="generated-id generated-id"
aria-label="Refresh interval units"
class="euiSelect euiFormControlLayout--1icons euiSelect--fullWidth euiSelect--compressed"
class="euiSelect emotion-euiSelect-compressed-fullWidth"
data-test-subj="superDatePickerRefreshIntervalUnitsSelect"
disabled=""
>
Expand Down
6 changes: 0 additions & 6 deletions packages/eui/src/components/form/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
@import 'described_form_group/index';
@import 'file_picker/index';
@import 'form';

// Selects must come before form_control_layout for proper padding
@import 'select/index';
@import 'super_select/index';

@import 'form_control_layout/index';
@import 'form_error_text/index';
@import 'form_fieldset/index';
Expand All @@ -15,4 +10,3 @@
@import 'form_row/index';
@import 'radio/index';
@import 'switch/index';
@import 'text_area/index';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports[`EuiSelect is rendered 1`] = `
<eui-validatable-control>
<select
aria-label="aria-label"
class="euiSelect euiFormControlLayout--1icons testClass1 testClass2 emotion-euiTestCss"
class="euiSelect testClass1 testClass2 emotion-euiSelect-euiTestCss"
data-test-subj="test subject string"
id="id"
name="name"
Expand All @@ -29,7 +29,7 @@ exports[`EuiSelect props disabled options are rendered 1`] = `
>
<eui-validatable-control>
<select
class="euiSelect euiFormControlLayout--1icons"
class="euiSelect emotion-euiSelect"
>
<option
value="1"
Expand All @@ -56,7 +56,7 @@ exports[`EuiSelect props fullWidth is rendered 1`] = `
>
<eui-validatable-control>
<select
class="euiSelect euiFormControlLayout--1icons euiSelect--fullWidth"
class="euiSelect emotion-euiSelect-fullWidth"
/>
</eui-validatable-control>
</eui-form-control-layout>
Expand All @@ -74,7 +74,7 @@ exports[`EuiSelect props isInvalid is rendered 1`] = `
isinvalid="true"
>
<select
class="euiSelect euiFormControlLayout--2icons"
class="euiSelect emotion-euiSelect"
/>
</eui-validatable-control>
</eui-form-control-layout>
Expand All @@ -89,7 +89,7 @@ exports[`EuiSelect props isLoading is rendered 1`] = `
>
<eui-validatable-control>
<select
class="euiSelect euiFormControlLayout--2icons euiSelect-isLoading"
class="euiSelect euiSelect-isLoading emotion-euiSelect"
/>
</eui-validatable-control>
</eui-form-control-layout>
Expand All @@ -104,7 +104,7 @@ exports[`EuiSelect props options are rendered 1`] = `
>
<eui-validatable-control>
<select
class="euiSelect euiFormControlLayout--1icons"
class="euiSelect emotion-euiSelect"
>
<option
value="1"
Expand All @@ -130,7 +130,7 @@ exports[`EuiSelect props value option is rendered 1`] = `
>
<eui-validatable-control>
<select
class="euiSelect euiFormControlLayout--1icons"
class="euiSelect emotion-euiSelect"
>
<option
value="1"
Expand Down
1 change: 0 additions & 1 deletion packages/eui/src/components/form/select/_index.scss

This file was deleted.

42 changes: 0 additions & 42 deletions packages/eui/src/components/form/select/_select.scss

This file was deleted.

13 changes: 7 additions & 6 deletions packages/eui/src/components/form/select/select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { EuiSelect, EuiSelectProps } from './select';
const meta: Meta<EuiSelectProps> = {
title: 'Forms/EuiSelect',
component: EuiSelect,
parameters: {
controls: {
// Excude onMouseUp from controls, as it's not a terribly useful prop to document
exclude: ['onMouseUp'],
},
},
argTypes: {
append: {
control: 'radio',
Expand Down Expand Up @@ -53,18 +59,13 @@ const meta: Meta<EuiSelectProps> = {
},
};
// adding onChange for visibility
enableFunctionToggleControls(meta, ['onChange', 'onMouseUp']);
enableFunctionToggleControls(meta, ['onChange']);
disableStorybookControls(meta, ['inputRef']);

export default meta;
type Story = StoryObj<EuiSelectProps>;

export const Playground: Story = {
parameters: {
controls: {
exclude: ['onMouseUp'],
},
},
args: {
defaultValue: 'option-2',
options: [
Expand Down
67 changes: 67 additions & 0 deletions packages/eui/src/components/form/select/select.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.
*/

import { css } from '@emotion/react';

import { UseEuiTheme } from '../../../services';
import { euiFormControlStyles, euiFormVariables } from '../form.styles';

export const euiSelectStyles = (euiThemeContext: UseEuiTheme) => {
const formStyles = euiFormControlStyles(euiThemeContext);
const formVariables = euiFormVariables(euiThemeContext);

return {
euiSelect: css`
appearance: none;
${formStyles.shared}
&:invalid {
${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),

// Ensure text descenders don't get cut off
// by making line-height match the input height
lineHeight: {
removePadding: `padding-block: 0;`,
uncompressed: `line-height: ${formVariables.controlHeight};`,
compressed: `line-height: ${formVariables.controlCompressedHeight};`,
inGroup: {
uncompressed: `line-height: ${formVariables.controlLayoutGroupInputHeight}`,
compressed: `line-height: ${formVariables.controlLayoutGroupInputCompressedHeight}`,
},
},
};
};
4 changes: 2 additions & 2 deletions packages/eui/src/components/form/select/select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('EuiSelect', () => {
>
 
</option>
`);
`);
});

it('can be reset to an empty initial selection', () => {
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('EuiSelect', () => {
);

const select = container.querySelector('.euiSelect');
expect(select).toHaveClass('euiSelect--fullWidth');
expect(select!.className).toContain('fullWidth');
});
});
});
Loading

0 comments on commit 5e06197

Please sign in to comment.