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 EuiFormLabel and EuiFormLegend #7967

Merged
merged 8 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -125,7 +125,7 @@ export const euiFormControlLayoutSideNodeStyles = (

${text} {
/* Override .euiFormLabel CSS */
cursor: default !important; /* stylelint-disable-line declaration-no-important */
cursor: default;
}

/* Account for button padding when spacing children */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@
exports[`EuiFormLabel is rendered 1`] = `
<label
aria-label="aria-label"
class="euiFormLabel testClass1 testClass2 emotion-euiTestCss"
class="euiFormLabel testClass1 testClass2 emotion-euiFormLabel-euiTestCss"
data-test-subj="test subject string"
/>
`;

exports[`EuiFormLabel props isDisabled is rendered 1`] = `
<label
class="euiFormLabel euiFormLabel-isDisabled"
class="euiFormLabel euiFormLabel-isDisabled emotion-euiFormLabel"
/>
`;

exports[`EuiFormLabel props isDisabled is still disabled with for attribute 1`] = `
<label
class="euiFormLabel euiFormLabel-isDisabled"
class="euiFormLabel euiFormLabel-isDisabled emotion-euiFormLabel"
for=""
/>
`;

exports[`EuiFormLabel props isFocused is rendered 1`] = `
<label
class="euiFormLabel euiFormLabel-isFocused"
class="euiFormLabel euiFormLabel-isFocused emotion-euiFormLabel-focused"
/>
`;

exports[`EuiFormLabel props isInvalid is rendered 1`] = `
<label
class="euiFormLabel euiFormLabel-isInvalid"
class="euiFormLabel euiFormLabel-isInvalid emotion-euiFormLabel-invalid"
/>
`;

exports[`EuiFormLabel props type can be changed to legend 1`] = `
<legend
class="euiFormLabel"
class="euiFormLabel emotion-euiFormLabel"
/>
`;
24 changes: 0 additions & 24 deletions packages/eui/src/components/form/form_label/_form_label.scss
Original file line number Diff line number Diff line change
@@ -1,24 +0,0 @@
/**
* 1. Focused state overrides invalid state.
* 2. Disabled state overrides pointer.
*/
.euiFormLabel {
Copy link
Member

Choose a reason for hiding this comment

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

When we remove this from our sass files ... is it still available globally for use like this? Or will that cause an issue: https://github.com/elastic/kibana/blob/main/x-pack/plugins/cases/public/components/configure_cases/field_mapping.tsx#L35

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, it will cause an issue! I'll change their usage to the EuiFormLabel component directly

display: inline-block;
transition: all $euiAnimSpeedFast $euiAnimSlightResistance;

&.euiFormLabel-isInvalid {
color: $euiColorDanger; /* 1 */
}

&.euiFormLabel-isFocused {
color: $euiColorPrimary; /* 1 */
}

&[for] {
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
cursor: pointer; /* 2 */
}

&[for].euiFormLabel-isDisabled {
cursor: default; /* 2 */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { css } from '@emotion/react';
import { serializeStyles, type CSSObject } from '@emotion/serialize';

import { UseEuiTheme } from '../../../services';
import { euiTextBreakWord } from '../../../global_styling';
import { euiCanAnimate, euiTextBreakWord } from '../../../global_styling';
import { euiTitle } from '../../title/title.styles';

export const euiFormLabel = (euiThemeContext: UseEuiTheme) => {
Expand All @@ -29,9 +29,31 @@ export const euiFormLabel = (euiThemeContext: UseEuiTheme) => {
};

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

return {
euiFormLabel: css`
${euiFormLabel(euiThemeContext)}
display: inline-block;

${euiCanAnimate} {
transition: color ${euiTheme.animation.fast}
${euiTheme.animation.resistance};
}
`,
// Skip css`` to avoid generating an extra Emotion className
// Use :where to reduce specificity & make the CSS easier to override by prepend/append nodes
notDisabled: `
&:where([for]) {
cursor: pointer;
}
`,
invalid: css`
color: ${euiTheme.colors.danger};
`,
// Focused state should override invalid state
focused: css`
color: ${euiTheme.colors.primary};
`,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export const EuiFormLabel: FunctionComponent<EuiFormLabelProps> = ({
...rest
}: EuiFormLabelProps) => {
const styles = useEuiMemoizedStyles(euiFormLabelStyles);
const cssStyles = [styles.euiFormLabel];
const cssStyles = [
styles.euiFormLabel,
!isDisabled && styles.notDisabled,
isInvalid && styles.invalid,
isFocused && styles.focused,
];

const classes = classNames('euiFormLabel', className, {
'euiFormLabel-isFocused': isFocused,
Expand Down