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 EuiCallOut #5870

Merged
merged 7 commits into from
May 6, 2022
Merged

[Emotion] Convert EuiCallOut #5870

merged 7 commits into from
May 6, 2022

Conversation

cchaos
Copy link
Contributor

@cchaos cchaos commented May 4, 2022

Summary

Converts EuiCallOut to remove custom styles but instead directly use EuiPanel as the parent component, and EuiTitle for the heading. I'll make in-code comments about the rest of the changes.

Also fixes callout portion of #5111 by moving the icon inline with the heading text and just letting the text wrap:

image

Also increased the default contrast ratio to 4.85

This is a very slight change mainly to fix our primary text which was not getting calculated high enough to be able to display on top of the primary panel background:
Screen Shot 2022-05-04 at 18 42 11 PM

So instead of trying to do specific calculations for callout, I opted for just increasing the minimum contrast for all text calculations since we'll likely see more and more uses of theses shaded backgrounds. The visible changes are very minimal and have most effect on the primary color:

image

The good news is that now we can be pretty certain that if anyone uses these background colors and the text colors together, they'll pretty much all work.

image

Checklist

  • Checked in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • [ ] Props have proper autodocs and playground toggles
  • Updated documentation
  • [ ] Checked Code Sandbox works for any docs examples
  • Added or updated jest and cypress tests
  • [ ] Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • Updated the Figma library counterpart
  • A changelog entry exists and is marked appropriately

Things to look out for when moving styles

  • Anything in the backlog that could be a quick fix for that component?
  • Convert side specific padding, margin, and position to -inline and -block (Logical properties)
  • Reduce specificity where possible (usually by reducing class name chaining)
  • Can any still existing .js files be converted to TS?

QA

  • Does the output CSS match the previous CSS / as expected
  • Does the rendered class read as expected

Comment on lines +1 to 5
// Kibana's Ace Editor uses this function, can't remove yet
// https://github.com/elastic/kibana/blob/main/src/core/public/styles/_ace_overrides.scss
// As well as deprecation notices
// https://github.com/elastic/kibana/blob/main/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/_step_progress.scss
@function euiCallOutColor($type: 'primary', $returnBackgroundOrForeground: 'background') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if we want to leave comments specifically pointing to Kibana files, but figured since I found them anyway?

return {
euiCallOutHeader: css`
font-weight: ${euiTheme.font.weight.medium};
margin-bottom: 0 !important; // In case it's nested inside EuiText
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specificity shot me on this one

Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes an !important tag is what's needed.

headerStyles.euiCallOutHeader,
headerStyles[color],
];

const classes = classNames(
'euiCallOut',
colorToClassNameMap[color],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I couldn't get rid of the color class name because a lot of tests were specifically pointing to these

{children}
</EuiText>
);
}

const H: any = heading ? `${heading}` : 'span';
const H: any = heading ? `${heading}` : 'p';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the default heading here to p because it felt odd to not have text in something text-like especially if it's then followed by more text.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this, you can just pick heading = 'p', as the default prop. The same way we're doing with color = 'primary':

export const EuiCallOut = forwardRef<HTMLDivElement, EuiCallOutProps>(
(
{
title,
color = 'primary',
size = 'm',
iconType,
children,
className,
heading,
...rest
},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 8cde1f1
Screen Shot 2022-05-05 at 14 18 51 PM

<H className="euiCallOutHeader__title">{title}</H>
</div>
<EuiTitle size={size === 's' ? 'xxs' : 'xs'} css={cssHeaderStyles}>
<H className="euiCallOutHeader__title">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This className too is targeted a lot in tests ☹️

Comment on lines 125 to 126
// @ts-expect-error Help with forward ref
ref={ref}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

Nightmaref! 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😦 @thompsongl Maybe you can help?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in 6a85444

EuiPanel takes panelRef instead of ref

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♀️ Oh boy... TY!!!

@cchaos cchaos added the deprecations Contains deprecations. Add them to the deprecations meta ticket after merge. label May 4, 2022
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5870/

@cchaos cchaos mentioned this pull request May 5, 2022
49 tasks
@miukimiu miukimiu self-requested a review May 5, 2022 15:18
Copy link
Contributor

@miukimiu miukimiu left a comment

Choose a reason for hiding this comment

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

Thanks, @cchaos. The icon inline with the heading text looks much better! 😍

Tested in Chrome, Safari, Edge, and Firefox. LGTM! 🎉

{children}
</EuiText>
);
}

const H: any = heading ? `${heading}` : 'span';
const H: any = heading ? `${heading}` : 'p';
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this, you can just pick heading = 'p', as the default prop. The same way we're doing with color = 'primary':

export const EuiCallOut = forwardRef<HTMLDivElement, EuiCallOutProps>(
(
{
title,
color = 'primary',
size = 'm',
iconType,
children,
className,
heading,
...rest
},

Comment on lines 125 to 126
// @ts-expect-error Help with forward ref
ref={ref}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nightmaref! 😆

@cchaos cchaos requested a review from 1Copenut May 5, 2022 18:53
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5870/

@cchaos
Copy link
Contributor Author

cchaos commented May 5, 2022

Flakey?

Jenkins, test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5870/

Copy link
Contributor

@1Copenut 1Copenut left a comment

Choose a reason for hiding this comment

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

LGTM! One suggested change with a case for why, but I'm okay leaving as is.

return {
euiCallOutHeader: css`
font-weight: ${euiTheme.font.weight.medium};
margin-bottom: 0 !important; // In case it's nested inside EuiText
Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes an !important tag is what's needed.

@@ -52,15 +52,26 @@ export const EuiCallOut = forwardRef<HTMLDivElement, EuiCallOutProps>(
iconType,
children,
className,
heading,
heading = 'p',
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about defaulting this heading to h2 ? If it won't cause a style break, I'd like to consider it for accessibility. Screen reader users often navigate pages asynchronously using headings and it'd be a nice addition. If p is the best default, I'm good leaving as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is context. We have no idea where this will be placed (what if it came after an h3?). They're all over the place and my guess that could be a big breaking change in a11y tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I agree p is not as good here and a heading. Can you make an issue to address this specifically. I don't want to make that call in a conversion PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Strong point about context. You're right, we don't know where it'll be used and we do not want to accidentally start nesting H2s inside H3, H4, etc. That'd be worse than no heading. I'll add a ticket to address this. Maybe as simple as an ahem, callout in our docs page that the consuming app should look at heading structure and use that as a guide for the prop value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++ That and/or we can eventually make that property required by the consumer. That way they always have to make the consideration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Filed #5884 for future work.

@cchaos cchaos enabled auto-merge (squash) May 6, 2022 15:15
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5870/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecations Contains deprecations. Add them to the deprecations meta ticket after merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants