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 EuiFacetButton and EuiFacetGroup #5878

Merged
merged 49 commits into from
Jun 8, 2022

Conversation

miukimiu
Copy link
Contributor

@miukimiu miukimiu commented May 5, 2022

Summary

Converted both EuiFacetButton and EuiFacetGroup to Emotion. The horizontal EuiFacetGroup is no longer using negative margins. It was converted to use flex and gap.

Facet in Emotion

With the use of gap the sizes of the components changes a little. Because we no longer have the margin top and bottom for each button.

facet-group-01@2x

facet-group-02@2x

Facet layout example

I deleted one of the examples in Facet Layout section. It was repeated:

facet-layouts@2x

Deprecated EuiButtonDisplay in favor of a new EuiButtonDisplay

The EuiFacetButton is a button so it makes sense to use the EuiButtonDisplay instead of a custom button with some CSS styles. But to use the EuiButtonDisplay I found some issues:

  • It required a baseClassName.
  • If no color is passed it creates a ${baseClassName}${colorToClassNameMap.primary}.
  • The component uses Sass
  • The children was being wrapped with a span and expected to receive text.
  • The component only expects to have one icon.

So I decided to set this component to be deprecated. To do this I renamed the component toEuiButtonDisplayDeprecated.

The new component is meant to internal use only and for now it lives in src/components/button/button_display/_button_display.tsx:

  • This component is basically a conversion from the old component to use Emotion
  • The goal of the component is to be less strict and more reusable so for example we can pass custom children. If a children is not a string we assume is not text and the content is not wrapped in a span. This way it's easier to account for button components that don't follow the normal button structure (1 icon and text).
  • The color prop was omitted because the old logic to apply colors to button components has to be rethought. Buttons that don't have a background color should also use this component. This logic should be thought of when we start converting other buttons that require backgrounds.
  • All the EuiButtonProps types were copied to this new file and renamed as EuiButtonDisplayProps. I believe this component should have the common button props.

Deprecated EuiButtonContent in favour of EuiButtonDisplayContent

The idea of this component is to replace the EuiButtonContent. I called it EuiButtonDisplayContent because the way I see it in the future is this component to be an inner component of the EuiButtonDisplay. So we would always use the EuiButtonDisplay.

For example, the EuiButtonEmpty uses the EuiButtonContent but in the future, it could use the EuiButtonDisplay.

return (
<button
disabled={buttonIsDisabled}
className={classes}
type={type}
ref={buttonRef as Ref<HTMLButtonElement>}
aria-pressed={isSelected}
{...(rest as EuiButtonEmptyPropsForButton)}
>
{innerNode}
</button>
);

As we can see the EuiButtonEmpty could use the EuiButtonDisplay. No need to create a custom button and pass the the innerNode that is a EuiButtonContent.

EuiFacetButton is now using the new EuiButtonDisplay

With the new EuiButtonDisplay the goal is for all EUI button components to use the EuiButtonDisplay as a building block. So the new EuiFacetButton is now using this component.

EuiLoadingSpinner accepts new color prop

It's now possible to configure the EuiLoadingSpinner color. The new EuiButtonDisplayContent uses a EuiLoadingSpinner with this new color prop.

Screenshot 2022-06-03 at 16 16 40

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
  • [ ] Added 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 global Sass vars to JS version like sizing
  • [ ] Convert component-specific Sass vars to exported JS versions
  • Convert side specific padding, margin, and position to -inline and -block (Logical properties)
  • [ ] Reduce specificity where possible (usually by reducing class name chaining)
  • Use gap property to add margin between items if using flex
  • [ ] Can any still existing .js files be converted to TS?
  • All animations or transitions are wrapped in euiCanAnimate

QA

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

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

className: classNames(icon.props.className, 'euiFacetButton__icon'),
buttonIcon = cloneElementWithCss(icon, {
css: cssIconStyles,
className: 'euiFacetButton__icon',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In use in Kibana.

<span
css={cssTextStyles}
className="euiFacetButton__text"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In use in Kibana.

@miukimiu miukimiu marked this pull request as ready for review May 6, 2022 15:06
@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@miukimiu miukimiu requested a review from cchaos May 16, 2022 11:32
@kibanamachine
Copy link

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

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Getting close, I didn't realize how involved this component is. But we should also make sure we're cleaning up any unused exports or unnecessary mixins. I'll leave the deprecation naming question to the engineers.

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@miukimiu
Copy link
Contributor Author

miukimiu commented Jun 3, 2022

@cchaos I went through your review:

  • Deleted all the types that were not being used in the new EuiButtonDisplay.
  • Added a color prop to EuiLoadingSpinner

@thompsongl I renamed both deprecated components to EuiButtonDisplayDeprecated and EuiButtonContentDeprecated. No more _Deprecated on both names.

I updated the PR description to add the new changes.

@kibanamachine
Copy link

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

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

LGTM, I just had a few last nits. But overall I think it's good to go.

src/components/loading/loading_spinner.tsx Outdated Show resolved Hide resolved
src/components/loading/loading_spinner.tsx Outdated Show resolved Hide resolved
upcoming_changelogs/5878.md Outdated Show resolved Hide resolved
upcoming_changelogs/5878.md Outdated Show resolved Hide resolved
src/components/button/button_display/_button_display.tsx Outdated Show resolved Hide resolved
@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@miukimiu miukimiu merged commit 2e836f6 into elastic:main Jun 8, 2022
chandlerprall added a commit that referenced this pull request Jun 13, 2022
This reverts commit 2e836f6 to help release a patch release.
chandlerprall added a commit that referenced this pull request Jun 13, 2022
#5878)""

This reverts commit 469cee1, re-adding #5878 to the main branch.
@kibanamachine
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants