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] Convert EuiFormRow #7968

Merged
merged 15 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions packages/eui/changelogs/upcoming/7968.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**CSS-in-JS conversions**

- Converted `EuiFormRow` to Emotion
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`EuiFormRow is rendered 1`] = `
<div
aria-label="aria-label"
class="euiFormRow testClass1 testClass2 emotion-euiTestCss"
class="euiFormRow testClass1 testClass2 emotion-euiFormRow-euiTestCss"
data-test-subj="test subject string"
id="generated-id-row"
>
Expand All @@ -19,7 +19,7 @@ exports[`EuiFormRow is rendered 1`] = `

exports[`EuiFormRow props describedByIds is rendered 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -35,7 +35,7 @@ exports[`EuiFormRow props describedByIds is rendered 1`] = `

exports[`EuiFormRow props display type center is rendered 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -50,7 +50,7 @@ exports[`EuiFormRow props display type center is rendered 1`] = `

exports[`EuiFormRow props display type centerCompressed is rendered 1`] = `
<div
class="euiFormRow euiFormRow--compressed"
class="euiFormRow euiFormRow--compressed emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -65,7 +65,7 @@ exports[`EuiFormRow props display type centerCompressed is rendered 1`] = `

exports[`EuiFormRow props display type columnCompressed is rendered 1`] = `
<div
class="euiFormRow euiFormRow--compressed euiFormRow--horizontal"
class="euiFormRow euiFormRow--compressed euiFormRow--horizontal emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -80,7 +80,7 @@ exports[`EuiFormRow props display type columnCompressed is rendered 1`] = `

exports[`EuiFormRow props display type columnCompressedSwitch is rendered 1`] = `
<div
class="euiFormRow euiFormRow--compressed euiFormRow--horizontal euiFormRow--hasSwitch"
class="euiFormRow euiFormRow--compressed euiFormRow--horizontal euiFormRow--hasSwitch emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -95,7 +95,7 @@ exports[`EuiFormRow props display type columnCompressedSwitch is rendered 1`] =

exports[`EuiFormRow props display type row is rendered 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -110,7 +110,7 @@ exports[`EuiFormRow props display type row is rendered 1`] = `

exports[`EuiFormRow props display type rowCompressed is rendered 1`] = `
<div
class="euiFormRow euiFormRow--compressed"
class="euiFormRow euiFormRow--compressed emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -125,7 +125,7 @@ exports[`EuiFormRow props display type rowCompressed is rendered 1`] = `

exports[`EuiFormRow props error as array is rendered 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand Down Expand Up @@ -155,7 +155,7 @@ exports[`EuiFormRow props error as array is rendered 1`] = `

exports[`EuiFormRow props error as string is rendered 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -178,7 +178,7 @@ exports[`EuiFormRow props error as string is rendered 1`] = `

exports[`EuiFormRow props error is not rendered if isInvalid is false 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -193,7 +193,7 @@ exports[`EuiFormRow props error is not rendered if isInvalid is false 1`] = `

exports[`EuiFormRow props fullWidth is rendered 1`] = `
<div
class="euiFormRow euiFormRow--fullWidth"
class="euiFormRow emotion-euiFormRow-fullWidth"
id="generated-id-row"
>
<div
Expand All @@ -208,9 +208,12 @@ exports[`EuiFormRow props fullWidth is rendered 1`] = `

exports[`EuiFormRow props hasEmptyLabelSpace is rendered 1`] = `
<div
class="euiFormRow euiFormRow--hasEmptyLabelSpace"
class="euiFormRow euiFormRow--hasEmptyLabelSpace emotion-euiFormRow"
id="generated-id-row"
>
<div
class="euiSpacer euiSpacer--m euiFormRow__labelWrapper emotion-euiSpacer-m"
/>
<div
class="euiFormRow__fieldWrapper"
>
Expand All @@ -223,7 +226,7 @@ exports[`EuiFormRow props hasEmptyLabelSpace is rendered 1`] = `

exports[`EuiFormRow props helpText is rendered 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -247,7 +250,7 @@ exports[`EuiFormRow props helpText is rendered 1`] = `

exports[`EuiFormRow props id is rendered 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="id-row"
>
<div
Expand All @@ -262,7 +265,7 @@ exports[`EuiFormRow props id is rendered 1`] = `

exports[`EuiFormRow props isDisabled allows a child to still be disabled manually 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -278,7 +281,7 @@ exports[`EuiFormRow props isDisabled allows a child to still be disabled manuall

exports[`EuiFormRow props isDisabled allows a child's disabled to override 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -293,7 +296,7 @@ exports[`EuiFormRow props isDisabled allows a child's disabled to override 1`] =

exports[`EuiFormRow props isDisabled is passed as disabled to child 1`] = `
<div
class="euiFormRow"
class="euiFormRow emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -309,7 +312,7 @@ exports[`EuiFormRow props isDisabled is passed as disabled to child 1`] = `

exports[`EuiFormRow props isInvalid is rendered 1`] = `
<div
class="euiFormRow euiFormRow--hasLabel"
class="euiFormRow euiFormRow--hasLabel emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -336,7 +339,7 @@ exports[`EuiFormRow props isInvalid is rendered 1`] = `

exports[`EuiFormRow props label append is rendered 1`] = `
<div
class="euiFormRow euiFormRow--hasLabel"
class="euiFormRow euiFormRow--hasLabel emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand Down Expand Up @@ -364,7 +367,7 @@ exports[`EuiFormRow props label append is rendered 1`] = `

exports[`EuiFormRow props label is rendered 1`] = `
<div
class="euiFormRow euiFormRow--hasLabel"
class="euiFormRow euiFormRow--hasLabel emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand All @@ -390,7 +393,7 @@ exports[`EuiFormRow props label is rendered 1`] = `

exports[`EuiFormRow props label renders as a legend and subsquently a fieldset wrapper 1`] = `
<fieldset
class="euiFormRow euiFormRow--hasLabel"
class="euiFormRow euiFormRow--hasLabel emotion-euiFormRow"
id="generated-id-row"
>
<div
Expand Down
56 changes: 0 additions & 56 deletions packages/eui/src/components/form/form_row/_form_row.scss
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
/**
* 1. Coerce inline form elements to behave as block-level elements.
* 2. For inline forms, we need to add margin if the label doesn't exist.
*/
.euiFormRow {
display: flex; /* 1 */
flex-direction: column; /* 1 */
max-width: $euiFormMaxWidth;

+ .euiFormRow,
+ .euiButton {
margin-top: $euiSize;
}
}

.euiFormRow--fullWidth {
max-width: 100%;
}

.euiFormRow--hasEmptyLabelSpace {
margin-top: $euiSize + $euiSizeXS; /* 2 */
// the following ensure that contents that aren't inherently the same height
Expand All @@ -26,37 +10,7 @@
justify-content: center;
}

.euiFormRow__labelWrapper {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-bottom: $euiSizeXS;
}

.euiFormRow--horizontal {
flex-direction: row;
align-items: stretch;

.euiFormRow__label {
hyphens: auto;
}

.euiFormRow__labelWrapper {
display: block;
line-height: $euiFormControlCompressedHeight - 1px; // The 1px less helps the alignment of the text baseline
width: calc(33% - #{$euiSizeS});
margin-right: $euiSizeS;
margin-bottom: 0;
}

.euiFormRow__fieldWrapper {
width: 67%;
}

+ .euiFormRow--horizontal {
margin-top: $euiSizeS;
}

+ .euiFormRow--horizontal.euiFormRow--hasSwitch {
margin-top: $euiSizeM; // More spacing since we reduced the height to match that of the switch
}
Expand Down Expand Up @@ -85,18 +39,8 @@
// stylelint-enable max-nesting-depth
}

.euiFormRow__fieldWrapperDisplayOnly {
min-height: $euiFormControlHeight;
display: flex;
align-items: center;
}

.euiFormRow--compressed {
&.euiFormRow--hasEmptyLabelSpace {
min-height: $euiFormControlCompressedHeight;
}

.euiFormRow__fieldWrapperDisplayOnly {
min-height: $euiFormControlCompressedHeight;
}
}
101 changes: 101 additions & 0 deletions packages/eui/src/components/form/form_row/form_row.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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 { logicalCSS } from '../../../global_styling';
import { euiFormVariables } from '../form.styles';

export const euiFormRowStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;
const { maxWidth, controlHeight, controlCompressedHeight } =
euiFormVariables(euiThemeContext);

return {
euiFormRow: css`
/* Coerce inline form elements to behave as block-level elements */
display: flex;

+ .euiButton {
${logicalCSS('margin-top', euiTheme.size.base)}
}
`,
// Skip css`` to avoid generating an Emotion className
formWidth: `
${logicalCSS('max-width', maxWidth)}
`,
fullWidth: css`
${logicalCSS('max-width', '100%')}
`,

// Skip css`` to avoid generating an extra className
row: `
flex-direction: column;
row-gap: ${euiTheme.size.xs};

.euiFormRow__labelWrapper {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}

+ .euiFormRow {
${logicalCSS('margin-top', euiTheme.size.base)}
}
`,

columnCompressed: css`
flex-direction: row;
align-items: stretch;
column-gap: ${euiTheme.size.s};

.euiFormRow__label {
hyphens: auto;
}

.euiFormRow__labelWrapper {
flex-basis: calc(33% - ${euiTheme.size.s}); /* Account for gap */
${logicalCSS('min-width', 0)}
line-height: ${controlCompressedHeight};
}

.euiFormRow__fieldWrapper {
flex-basis: 67%;
${logicalCSS('min-width', 0)}
}

+ .euiFormRow {
${logicalCSS('margin-top', euiTheme.size.s)}
}
`,

centerDisplayCss: (compressed: boolean) => `
.euiFormRow__fieldWrapperDisplayOnly {
display: flex;
align-items: center;
${logicalCSS(
'min-height',
compressed ? controlCompressedHeight : controlHeight
)}
}
`,
get center() {
Copy link
Member

@tkajtoch tkajtoch Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Not a change request, just trying to understand the exact reason :D] Are these two getters so you can access this.row and this.centerDisplayCss? I'd normally prefer to move centerDisplayCss above this so we could get rid of these getters but since row does the same thing it feels clean to do it like this here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I use getters are for this access/repeating styles: https://github.com/elastic/eui/blob/main/wiki/contributing-to-eui/developing/writing-styles-with-emotion.md#duplicate-styles

And yes, it's essentially repeating row styles hence me trying to write it a bit more DRYly. It's not perfect but to be honest the center display is a little weird and I'd rather get rid of it entirely if we can in the future 🤷

return css`
${this.row}
${this.centerDisplayCss(false)}
`;
},
get centerCompressed() {
return css`
${this.row}
${this.centerDisplayCss(true)}
`;
},
};
};
Loading