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 EuiResizableButton #7081

Merged
merged 12 commits into from
Aug 15, 2023

Conversation

cee-chen
Copy link
Contributor

@cee-chen cee-chen commented Aug 14, 2023

Summary

#6408

  • This PR converts EuiResizableButton to Emotion
    • This PR does not convert EuiResizableCollapseButton. That conversion + this one was getting fairly gnarly, so I opted to leave it separate to make review easier.
  • This PR performs several incidental cleanup items on EuiResizableButton, including adding unit tests that were previously missing, and gets component code coverage up to 100%
  • This PR performs a large CSS refactor (78e57b8) that converts from absolute positioning & transform CSS to using flex CSS instead. This has the major benefit of:
    1. fixing an existing Safari visual bug on production (go to https://eui.elastic.co/v87.0.0/#/layout/resizable-container on Safari and hover over any drag handle), and
    2. also makes the component fully work with logical properties, as transform: translateX/Y currently does not respect direction or writing-mode and flex does.

QA

  • Compare staging against production and confirm the grab handle (not the collapsible button) looks and behaves as before (except on Safari, which has broken CSS transitions on production)
  • Go to http://localhost:8030/#/layout/resizable-container#collapsible-panels-with-external-control
  • Inspect the first resizable button / drag handle in the DOM
  • Click the "Toggle panel 1" button in the demo
  • In the DOM, confirm the button is hidden with display: none
  • Confirm that the now-hidden button cannot be interacted with in any way, e.g. via mouseover or keyboard tab or screen reader navigation

General checklist

  • Checked in both light and dark modes
    - [ ] Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Added or updated jest and cypress tests
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

Emotion checklist

Kibana usage

  • Search Kibana's codebase for {euiComponent}- (case sensitive) to check for usage of modifier classes
    • [ ] If usage exists, consider converting to a data attribute so that consumers still have something to hook into
    • ⚠️ Only one modifier usage exists, and it's one I added earlier to override Sass behavior. It should be completely removable

General

  • Output CSS matches the previous CSS (works as expected in all browsers)
  • Rendered className(s) read as expected in snapshots and browsers
  • [ ] Checked component playground

Unit tests

  • shouldRenderCustomStyles() test was added and passes with parent component and any nested childProps (e.g. tooltipProps)
  • [ ] Removed any mount()ed snapshots in favor of render() or a more specific assertion

Sass/Emotion conversion process

  • Converted all global Sass vars/mixins to JS (e.g. $euiSize to euiTheme.size.base)
  • Removed or converted component-specific Sass vars/mixins to exported JS versions
  • Listed var/mixin removals in changelog
  • [ ] Ran yarn compile-scss to update var/mixin JSON files
  • [ ] Added an @warn deprecation message within the global_styling/mixins/{component}.scss file
  • [ ] Simplified calc() to mathWithUnits if possible (if mixing different unit types, this may not be possible)
  • [ ] Removed component from src/components/index.scss - Not doable yet
  • [ ] Deleted any src/amsterdam/overrides/{component}.scss files (styles within should have been converted to the baseline Emotion styles)

CSS tech debt

  • Wrapped all animations or transitions in euiCanAnimate
  • Used gap property to add margin between items if using flex
  • Converted side specific padding, margin, and position to -inline and -block logical properties (check inline styles as well as CSS)

DOM Cleanup

  • Did NOT remove any block/element classNames (e.g. euiComponent, euiComponent__child)
  • SEARCH KIBANA FIRST: Deleted any modifier classNames or maps if not being used in Kibana.

Kibana due diligence

  • Pre-emptively check how your conversion will impact the next Kibana upgrade. This entails searching/grepping through Kibana (excluding **/target, **/*.snap, **/*.storyshot for less noise) for eui{Component} (case sensitive) to find:
  • Any test/query selectors that will need to be updated - None
  • Any Sass or CSS that will need to be updated, particularly if a component Sass var was deleted - One instance
  • Any direct className usages that will need to be refactored (e.g. someone calling the euiBadge class on a div instead of simply using the EuiBadge component) - No usages

Extras/nice-to-have

  • [ ] Documentation pass:
  • Reduced specificity where possible (usually by reducing nesting and class name chaining)
  • [ ] Check for issues in the backlog that could be a quick fix for that component - Will be opening up a follow-up PR for this
  • [ ] Optional component/code cleanup: consider splitting up the component into multiple children if it's overly verbose or difficult to reason about

- not sure why tsc wasn't picking up on this 🤷
- mostly for custom styles testing, but we might as well write some missing unit tests while we're here
- for code coverage, because I'm incredibly anal

+ misc code cleanup - optional chaining syntax, remove unneccessary fn declarations
in favor of JS logic + HTML attribute

- `hidden` is equivalent to `display: none` and is not overrideable via CSS and thus does not require an important

- this cleanup allows us to remove unnecessary `:disabled` selectors in favor of simpler ones - if the button is disabled, we can assume it's never visible or interactable
+ remove $euiResizableButtonTransitionSpeed
+ Remove all now-unnecessary modifier clases

+ Remove `$euiResizableButtonSize` Sass var
@kibanamachine
Copy link

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

- vs absolute positioning/transforms

Doing this has two major benefits:

- The hover/focus animations were broken on Safari in production, and this fixes that

- CSS transform do not respect logical properties and flex does, so this automatically makes the component fully direction/writing-mode compatible for less code :)
@cee-chen cee-chen force-pushed the emotion/resizable-button branch from 14039f7 to 78e57b8 Compare August 14, 2023 23:27
@kibanamachine
Copy link

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

The `hidden` attribute sadly gets overridden by the new `display: flex`, so we need to restore the `:disabled { display: none }` selector
@cee-chen cee-chen marked this pull request as ready for review August 15, 2023 01:42
@cee-chen cee-chen requested review from a team and breehall August 15, 2023 01:42
@cee-chen
Copy link
Contributor Author

As a heads up, I'm planning on following up this PR not just with another EuiResizableCollapse button conversion, but also with the following backlog items for EuiResizableButton:

@kibanamachine
Copy link

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

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

Copy link
Contributor

@breehall breehall left a comment

Choose a reason for hiding this comment

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

Hey Cee, I just have a question here about the decision to hide the resizable button when not in use. Other than that, this conversion looks good. Here was my review process:

  • Reviewed the Sass conversion to ensure it's in parody with production. Loved the CSS refactor with flex
  • Ensured the resizable button is hidden in the DOM when a panel is toggled off in the docs
  • Observed improved transitions in Safari due to the CSS refactor

Comment on lines 41 to 47
it('renders as disabled if the disabled prop is passed', () => {
const { container } = render(<EuiResizableButton disabled />, {
wrapper,
});

expect(container.firstChild).toBeDisabled();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can I ask why we choose to render the button as disabled with the style display:none instead of removing it from the DOM when it's not in use by a resizable panel?

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'm honestly not sure - I think it was part of the original component design and I can't say exactly why those devs chose to go with display: none vs simply not rendering anything.

I did play around with returning null if disabled, but in the end I decided against it - the potential for downstream impacts felt too large for what was supposed to be "just" an Emotion conversion. Also, the 'collapsed' content uses a similar paradigm (display: none on all children) so I felt like it made sense to keep that for now so they stay in-line with one another.

Copy link
Contributor

Choose a reason for hiding this comment

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

the potential for downstream impacts felt too large for what was supposed to be "just" an Emotion conversion

Totally makes sense, I was just curious!

Comment on lines 29 to 44
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
gap: ${mathWithUnits(grabHandleHeight, (x) => x * 2)};

/* 1 */
&:hover,
&:focus {
gap: 0;
justify-content: center;
}

${euiCanAnimate} {
transition: gap ${transition}, justify-content ${transition};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

[Attaching to closes code snippet] This is a nice update. Flex is easier to visualize and understand when looking at the code (at least for me)!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, it makes the code way cleaner!

Comment on lines +68 to +70
const {
registry: { resizers } = { resizers: {} } as EuiResizableContainerRegistry,
} = useEuiResizableContainerContext();
Copy link
Contributor

Choose a reason for hiding this comment

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

Odd that VSCode would flag this and not our linter

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've had 1:1 disparities between vscode types and CLI tsc in the past, so it's not terribly uncommon, but it is mildly annoying. I think vscode is a bit more opinionated than the CLI is. 🤷

Copy link
Contributor

@breehall breehall left a comment

Choose a reason for hiding this comment

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

Thank you for taking a look at my question. Everything has been answered and I have no further questions.

@cee-chen
Copy link
Contributor Author

Thanks Bree!

@cee-chen cee-chen merged commit 6a30eba into elastic:main Aug 15, 2023
@cee-chen cee-chen deleted the emotion/resizable-button branch August 15, 2023 19:40
breehall added a commit to elastic/kibana that referenced this pull request Aug 23, 2023
`87.1.0` ➡️ `87.2.0`

## [`87.2.0`](https://github.com/elastic/eui/tree/v87.2.0)

- `EuiResizableButton` is now available as a generic top-level export
([#7087](elastic/eui#7087))
- Added new `alignIndicator` prop to `EuiResizableButton`. Defaults to
`center`, and can now additionally be configured to `start` and `end`
([#7087](elastic/eui#7087))
- Updated `useGeneratedHtmlId` hook to use `React.useId` as the source
of unique identifiers when available
([#7095](elastic/eui#7095))

**CSS-in-JS conversions**

- Converted `EuiResizableButton` to Emotion; Removed
`$euiResizableButtonTransitionSpeed` and `$euiResizableButtonSize`
([#7081](elastic/eui#7081))
- Converted `EuiResizableCollapseButton` to Emotion
([#7091](elastic/eui#7091))

---------

Co-authored-by: Cee Chen <constance.chen@elastic.co>
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.

4 participants