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 EuiForm help/error text #7966

Merged
merged 8 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to verify: This line-height decrease is expected, correct?

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, expected and more in line with the newest styles!

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.
3 changes: 3 additions & 0 deletions packages/eui/changelogs/upcoming/7966.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**CSS-in-JS conversions**

- Converted `EuiForm`, `EuiFormHelpText`, and `EuiFormErrorText` to Emotion
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ exports[`EuiForm renders with error callout when isInvalid is "true" 1`] = `
Please address the highlighted errors.
</p>
</div>
<div
class="euiSpacer euiSpacer--m emotion-euiSpacer-m"
/>
</div>
`;

Expand Down Expand Up @@ -78,6 +81,9 @@ exports[`EuiForm renders with error callout when isInvalid is "true" and has mul
</ul>
</div>
</div>
<div
class="euiSpacer euiSpacer--m emotion-euiSpacer-m"
/>
</div>
`;

Expand Down Expand Up @@ -115,6 +121,9 @@ exports[`EuiForm renders with error callout when isInvalid is "true" and has one
</ul>
</div>
</div>
<div
class="euiSpacer euiSpacer--m emotion-euiSpacer-m"
/>
</div>
`;

Expand Down
8 changes: 0 additions & 8 deletions packages/eui/src/components/form/_form.scss

This file was deleted.

3 changes: 0 additions & 3 deletions packages/eui/src/components/form/_index.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
@import 'checkbox/index';
@import 'described_form_group/index';
@import 'form';
@import 'form_error_text/index';
@import 'form_fieldset/index';
@import 'form_help_text/index';
@import 'form_label/index';
@import 'form_row/index';
@import 'radio/index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,20 @@ exports[`EuiDescribedFormGroup ties together parts for accessibility 1`] = `
/>
<div
aria-live="polite"
class="euiFormErrorText euiFormRow__text"
class="euiFormErrorText euiFormRow__text emotion-euiFormErrorText"
id="generated-id-error-0"
>
Error one
</div>
<div
aria-live="polite"
class="euiFormErrorText euiFormRow__text"
class="euiFormErrorText euiFormRow__text emotion-euiFormErrorText"
id="generated-id-error-1"
>
Error two
</div>
<div
class="euiFormHelpText euiFormRow__text"
class="euiFormHelpText euiFormRow__text emotion-euiFormHelpText"
id="generated-id-help-0"
>
Help text
Expand Down
32 changes: 19 additions & 13 deletions packages/eui/src/components/form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import React, {
HTMLAttributes,
FormHTMLAttributes,
useCallback,
useMemo,
forwardRef,
} from 'react';
import classNames from 'classnames';

import { CommonProps, ExclusiveUnion } from '../common';
import { EuiCallOut } from '../call_out';
import { EuiI18n } from '../i18n';
import { CommonProps, ExclusiveUnion } from '../common';
import { EuiSpacer } from '../spacer';

import { FormContext, FormContextValue } from './eui_form_context';

Expand Down Expand Up @@ -59,7 +62,7 @@ export const EuiForm = forwardRef<HTMLElement, EuiFormProps>(
},
ref
) => {
const formContext = React.useMemo(
const formContext = useMemo(
(): FormContextValue => ({
defaultFullWidth: fullWidth ?? false,
}),
Expand Down Expand Up @@ -96,17 +99,20 @@ export const EuiForm = forwardRef<HTMLElement, EuiFormProps>(
default="Please address the highlighted errors."
>
{(addressFormErrors: string) => (
<EuiCallOut
tabIndex={-1}
ref={handleFocus}
className="euiForm__errors"
title={addressFormErrors}
color="danger"
role="alert"
aria-live="assertive"
>
{optionalErrors}
</EuiCallOut>
<>
<EuiCallOut
tabIndex={-1}
ref={handleFocus}
className="euiForm__errors"
title={addressFormErrors}
color="danger"
role="alert"
aria-live="assertive"
>
{optionalErrors}
</EuiCallOut>
<EuiSpacer size="m" />
</>
)}
</EuiI18n>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`EuiFormErrorText is rendered 1`] = `
<div
aria-label="aria-label"
aria-live="polite"
class="euiFormErrorText testClass1 testClass2 emotion-euiTestCss"
class="euiFormErrorText testClass1 testClass2 emotion-euiFormErrorText-euiTestCss"
data-test-subj="test subject string"
>
This is an error.
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { euiFontSize, logicalCSS } from '../../../global_styling';

export const euiFormErrorTextStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;

return {
euiFormErrorText: css`
${logicalCSS('padding-top', euiTheme.size.xs)}
${euiFontSize(euiThemeContext, 'xs')}
color: ${euiTheme.colors.danger};
`,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
*/

import React, { FunctionComponent, HTMLAttributes } from 'react';

import classNames from 'classnames';

import { useEuiMemoizedStyles } from '../../../services';
import { CommonProps } from '../../common';

import { euiFormErrorTextStyles } from './form_error_text.styles';

export type EuiFormErrorTextProps = CommonProps &
HTMLAttributes<HTMLDivElement>;

Expand All @@ -20,9 +23,15 @@ export const EuiFormErrorText: FunctionComponent<EuiFormErrorTextProps> = ({
...rest
}) => {
const classes = classNames('euiFormErrorText', className);
const styles = useEuiMemoizedStyles(euiFormErrorTextStyles);

return (
<div className={classes} aria-live="polite" {...rest}>
<div
css={styles.euiFormErrorText}
className={classes}
aria-live="polite"
{...rest}
>
{children}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`EuiFormHelpText is rendered 1`] = `
<div
aria-label="aria-label"
class="euiFormHelpText testClass1 testClass2 emotion-euiTestCss"
class="euiFormHelpText testClass1 testClass2 emotion-euiFormHelpText-euiTestCss"
data-test-subj="test subject string"
>
This is help text.
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { euiFontSize, logicalCSS } from '../../../global_styling';

export const euiFormHelpTextStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;

return {
euiFormHelpText: css`
${logicalCSS('padding-top', euiTheme.size.xs)}
${euiFontSize(euiThemeContext, 'xs')}
color: ${euiTheme.colors.darkShade};
`,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
*/

import React, { FunctionComponent, HTMLAttributes } from 'react';

import classNames from 'classnames';

import { useEuiMemoizedStyles } from '../../../services';
import { CommonProps } from '../../common';

import { euiFormHelpTextStyles } from './form_help_text.styles';

export type EuiFormHelpTextProps = CommonProps & HTMLAttributes<HTMLDivElement>;

export const EuiFormHelpText: FunctionComponent<EuiFormHelpTextProps> = ({
Expand All @@ -19,9 +22,10 @@ export const EuiFormHelpText: FunctionComponent<EuiFormHelpTextProps> = ({
...rest
}) => {
const classes = classNames('euiFormHelpText', className);
const styles = useEuiMemoizedStyles(euiFormHelpTextStyles);

return (
<div className={classes} {...rest}>
<div css={styles.euiFormHelpText} className={classes} {...rest}>
{children}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ exports[`EuiFormRow props error as array is rendered 1`] = `
/>
<div
aria-live="polite"
class="euiFormErrorText euiFormRow__text"
class="euiFormErrorText euiFormRow__text emotion-euiFormErrorText"
id="generated-id-error-0"
>
Error
</div>
<div
aria-live="polite"
class="euiFormErrorText euiFormRow__text"
class="euiFormErrorText euiFormRow__text emotion-euiFormErrorText"
id="generated-id-error-1"
>
Error2
Expand All @@ -371,7 +371,7 @@ exports[`EuiFormRow props error as string is rendered 1`] = `
/>
<div
aria-live="polite"
class="euiFormErrorText euiFormRow__text"
class="euiFormErrorText euiFormRow__text emotion-euiFormErrorText"
id="generated-id-error-0"
>
Error
Expand Down Expand Up @@ -438,7 +438,7 @@ exports[`EuiFormRow props helpText is rendered 1`] = `
id="generated-id"
/>
<div
class="euiFormHelpText euiFormRow__text"
class="euiFormHelpText euiFormRow__text emotion-euiFormHelpText"
id="generated-id-help-0"
>
<span>
Expand Down
Loading