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

[Feature Branch] Convert EuiRange sliders to Emotion and more enhancements #6092

Merged
merged 25 commits into from
Dec 6, 2022

Conversation

elizabetdev
Copy link
Contributor

@elizabetdev elizabetdev commented Jul 29, 2022

Summary

This PR converts EuiRange sliders to Emotion and fixes the following issues:

The following issues are not going to be fixed in this PR.

PRs that were merged into the feature branch

Changelog

  • Implemented new EuiRange and EuiDualRange designs where the levels are now on top of the tracks

CSS-in-JS conversions

  • Converted EuiRange and EuiDualRange to Emotion

Build Preview

The build Preview can be found here: https://eui.elastic.co/pr_6092/#/forms/range-sliders

New levels design

192549635-aa5f4a19-dbb4-4031-a1ca-8436ce51184a

QA

Remove or strikethrough items that do not apply to your PR.

General 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

Emotion conversion checklist

  • Does it work?
  • Output CSS matches the previous CSS / as expected in browsers
  • Rendered className reads as expected in snapshots and in browsers
  • Checked component playground (class components wrapped in withEuiTheme need to pass true as the second argument to its propUtilityForPlayground in src-docs/src/views/{component}/playground.js)
     
  • 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 removals in changelog, and ran yarn compile-scss to update JSON files
  • Simplified calc() to mathWithUnits if possible (if mixing different unit types, this may not be possible)
    - [ ] Added an @warn deprecation message within the global_styling/mixins/{component}.scss file
  • Removed component from src/components/index.scss
  • Deleted any src/amsterdam/overrides/{component}.scss files (styles within should have been converted to the baseline Emotion styles)
     
  • CSS tech debt
  • Reduced specificity where possible (usually by reducing nesting and class name chaining)
  • 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)
  • Deleted any modifier classNames or maps if not being used in Kibana. Before doing this step:
    • Search/grep through Kibana's codebase for {euiComponent}- (case sensitive) to check for source code usage of modifier classes
      - [ ] If usages exist, consider converting to a data attribute so that consumers still have something to hook into
       
  • 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
  • Any Sass or CSS that will need to be updated, particularly if a component Sass var was deleted
  • 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)
     
  • Extras/nice-to-have
  • Documentation pass:
    • Converted any remaining .js docs files to TS
    • Misc cleanup of docs code (e.g. combine imports to single from '../src', replace <React.Fragment> with <>)
  • Check for issues in the backlog that could be a quick fix for that component
  • Optional component/code cleanup: consider splitting up the component into multiple children if it's overly verbose or difficult to reason about

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@elizabetdev elizabetdev mentioned this pull request Sep 19, 2022
11 tasks
* Adding all necessary emotion style files

* WIP styles

* Converted range_label

* Converted range mixins

* Converted dual_rangee

* Converted range_draggable

* Added range_highlight

* Converted range_thumb

* Converted range_tooltip

* Removed EuiRangeTooltip compressed prop

* Moved euiFormControlSize mixin to form.styles.ts

* Added euiFormVariables

* Converted range_slider

* Updating snapshots with 2 tests failing

* sasslint fix

* mark min and max as having default values

* selector fix

* compressed types fix

* snapshot updates

* Fixing range track top position

* Revert ticks example

* Fix logical css

* Removing unnecessary styles

* Remove trailing slash from import statements, update dtsgenerator script to remove trailing slashes from imports

* Converting px to variables and adding `shouldRenderCustomStyles`

* Adding custom thumbs so that we can have z-index and put them above levels

* Adding aria label on custom thumb

* use default input thumb

* Improving comments. Some styles fixes.

* Adressing PR review

Co-authored-by: Greg Thompson <thompson.glowe@gmail.com>
Co-authored-by: Chandler Prall <chandler.prall@gmail.com>
@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

elizabetdev and others added 2 commits October 27, 2022 11:42
* Adding liner gradient on top of levels

* Styling highlight with levels

* Fix level range not showing for single ranges

* thumb colors match levels

* update snapshot

* Fix focus issue

* Fixed levels position when no ticks are available

* Update src/components/form/range/range_levels.styles.ts

Co-authored-by: Constance <constancecchen@users.noreply.github.com>

* Adressing PR review

* Converting some range highlight inline styles to Emotion

* Getting levels colors in thumb as `currentcolor`

* [misc] DRY out color array

* [cleanup] DRY out various consts, types, & utils around range level colors to new file

- nb: separate file is required for webpack to not throw a fit over circular dependencies

* [more cleanup] move new level color util to new file

* [misc linting] remove unnecessary newlints from single-line strings

+ remove extra semicolons, since the utils already contain ending semicolons

Co-authored-by: Greg Thompson <thompson.glowe@gmail.com>
Co-authored-by: Constance <constancecchen@users.noreply.github.com>
Co-authored-by: Constance Chen <constance.chen.3@gmail.com>
@kibanamachine
Copy link

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

* [Range sliders docs] Add non linear example

* Changing examples source types to TSX

* [PR feedback] Remove typescript need for any

- using `event.currentTarget` over `target` solves most of the single range issues

+ refactor single instances of callbacks to be inline instead of instantiating a var

Co-authored-by: Constance Chen <constance.chen.3@gmail.com>
@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@daveyholler daveyholler mentioned this pull request Nov 18, 2022
31 tasks
@elizabetdev elizabetdev mentioned this pull request Nov 23, 2022
38 tasks
@kibanamachine
Copy link

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

* Fix tests and `fullWidth`

* Simplified `calc()` to `mathWithUnits`

* Wrapped atransition in `euiCanAnimate`

* Replaced `<Fragment/>` with `</>`

* Removed unnecessary class names

* Fixing but with `repeating-linear-gradient` in Safari

* Encoded SVGs again to avoid masks than could lead to possible IDs conflicts

* `fullWidth` PR feedback

- remove need for modifier class + update snapshots

- prefer not to pass `fullWidth` as an arg into param - let there be a 2nd max-width property override instead

* Explain why style is being skipped

* [PR feedback] Remove need to pass `disabled` to inner style fn

+ fix typo on className

* Remove unnecessary `classNames()` around static classes

* Remove `.euiRangeLevels--` modifier classes

- existing Kibana selectors can use `[class*="euiRangeLevels-color"]` instead

* Remove unnecessary `.euiRangeTooltip__value` modifier class

if values can only be left or right, there's no point to targeting both - just target the main `__` class

* Fix overflow-x/y on non-FF browsers

* Clean up pseudo tick CSS

- remove unnecessary border CSS (not sure what it's doing?) and add clarifying CSS comment

- simplify various Emotion conditionals to ternaries

* Convert various inline style positioning to logical properties

* Clean up unnecessary `calc`s in favor of `mathWithUnits`

* Remove unused `::-ms-track` browser CSS

- We no longer support IE and Edge does not appear to need this styling

* DRY out various static `px` width

- most notable one: we're calling small `2px`-based border widths all over the place, which should get its own `thumbBorderWidth` var

+ reorder several properties - prefer display/flow properties first, then color/appearance

* DRY out EuiRangeTooltip CSS

- remove `transition` - `box-shadow` doesn't even exist on the tooltip and `transform` is not meaningfully changing

- remove both double pseudo element selectors - there isn't a need for 2 elements to represent 1 arrow
+ combine just `::before` selector

- DRY out various CSS being applied to both left and right CSS - if it's being applied to both, it can just go on the base CSS

- tweak positioning of tooltip arrow - 1px offset does not appear to be needed any longer

- DRY out use of `euiFontSize`

+ reorder several properties - prefer display/flow properties first, then color/appearance

* EuiRangeTicks - fixes & cleanup

- Fix `selected` styling never actually correctly applying (already occurring in prod)

+ remove duplicate/unused border-radius property

+ remove duplicate `::before` pseudo selector CSS - it's already being set in `hasPseudoTickMark` via `tickStyles`

* Restore thumb focus color to prod appearance

- the black focus color does not match the primary color we use for the rest of the thumb/track

* Fix tick marks not being correctly centered on the thumb

- 2px is what's on prod, not 4px - i think this is supposed to line up with the border width?

* Revert SVG stripes change

+ make stripe size dynamic to match custom border width changes

* Actually fix stripe gradient issue for Safari

see https://css-tricks.com/stripes-css/#aa-funky-town - using percentages and then `background-size` appears to solve the issue

* Clean up draggable CSS

- other focus selectors are not having any visible difference whatsoever in latest FF/Edge/Safari

* Massively clean up focus styles

- now that we no longer have to support IE and can use `:focus-visible` on its own, there's a whole lot of cruft we can remove, including JS `hasFocus` tracking (vs CSS built-in focus)

- Move highlight range to last DOM item- some CSS used in place of the JS `hasFocus` requires the `~` sibling selector

- make the focus color a variable so that it can be changed in one place if needed

+ clean up reset styles - half of them aren't needed (tested in FF+Edge+Safari)

* Remove functionally unused `euiRangeTrackSize` fns

- if it's not being used in more than one place, it doesn't really need to be a fn/isn't DRYing anything out

* Remove unused group CSS

- it's not doing anything that I can tell with prepend/append

* Misc CSS cleanup

- remove not-especially-helpful comments

- remove unnecessary syntax

- remove unnecessary !important

- DRY out logical properties usage applicable

Co-authored-by: Constance Chen <constance.chen.3@gmail.com>
@cee-chen cee-chen marked this pull request as ready for review December 3, 2022 03:14
@cee-chen
Copy link
Contributor

cee-chen commented Dec 3, 2022

@breehall I know this is blocking the release and your Kibana upgrade, so just wanted to give you a quick status update - I'm doing a final pass on the docs page before I merge this in. In particular I'm looking at the playground flyouts - I'm not super happy with their current usability; it feels annoyingly hard to get things in a easy to test state.

Once that's done on either Monday or Tuesday, I was hoping to get your and @1Copenut's eyes on this to QA various input states and help test mouse vs keyboard focus, etc. The more bugs we potentially catch pre-release, the fewer backports we have to do!

@kibanamachine
Copy link

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

- most vars/mixins were left intact due to `EuiColorStop` usage - they should be removed after either EuiColorStop is migrated or all EuiForm components are migrated
+ optimize via useMemo

+ address TODO via useEffect

+ switch to RTL over Enzyme - Enzyme can't process the `useEffect` behavior in render/shallow
+ split out logic into internal only sub-component with its own memoization logic

+ split out validation fn to separate const to match other files

+ switch to RTL over Enzyme - Enzyme can't process the `useEffect` behavior in render/shallow
- useCallback doesn't work on refs / causes them to stop working, so let's improve perf by not watching/setting state on 3 diff nodes within EuiRange

- make `EuiRangeTrack` in charge of the single ref and pass the value down as an optional render fn

- I strongly recommend turning off whitespace changes when viewing this diff
- Fix `EuiRangeWrapper` to actually change height on `compressed` flag

- `EuiRangeLevels`, `EuiRangeHighlight`, `EuiRangeSlider`, and `EuiRangeDraggable` do nothing with `compressed` and don't need to be passed the prop

- in the case of `EuiRangeTicks`, compressed is used but is already defined in the ...rest spread and initial types def and doesn't need to be re-defined
…prop behavior

- We're repeating a lot of the same types over and over and if our types ever change for whatever reason it's going to be annoying to update 5+ files

- More importantly, we're also (incorrectly) repeating type/prop docs between both EuiRange and EuiDualRange and this way / putting them in one place makes it much easier to compare and contrast docs

- NOTE: Kibana imports of `EuiRangeTicks` should now import directly from `@elastic/eui` and not reach into the component

+ DRY out EuiDualRange tests & remove `requiredProps` where it's not relevant ot the test
- it's not clear to me why `min`/`max` isn't required on EuiDualRange when it's documented as such & has the same default behavior as EuiRange

+ clean up tests
- currently there's a whole bunch of errors thrown if you just try to do something like toggle `showTicks` - this should resolve that frustrating experience

- the types cleanup in a previous commit should also have resolved many unnecessary/incorrect props showing up in the playground
@kibanamachine
Copy link

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

@breehall
Copy link
Contributor

breehall commented Dec 6, 2022

👋🏾 Here are a few questions / comments I had after QA-ing:

  1. I'm noticing that the Playground is a little buggy. It's probably site wide and not just with this component, but a few things that stood out to me:
  • Should I be able to click and drag the range slider from the Playground? This can't be done in the current version either (just as a note).
  • Some prop combinations make the range slider disappear from the Playground all together. Some of these include:
    • Increasing step to 3 or above
    • Sometimes activating showTicks - I see that there was a commit to address this (5a10a0c). I think this one might just be funky?
  1. It looks like the input that appears when showInput may need to be extended. When isInvalid is true and compressed is false, the numeric value within the input is cut off and can't been seen.

image

Other than those two things, this looks good. I tested the page with mouse and keyboard controls and keyboard controls successfully as well.

@cee-chen
Copy link
Contributor

cee-chen commented Dec 6, 2022

Should I be able to click and drag the range slider from the Playground? This can't be done in the current version either (just as a note).

This is intentional as the onChange is a no-op and is not intended to change the value. This simulated onChange fn is a pattern across multiple playgrounds. Whether or not that's confusing UX is definitely worth discussing but it's definitely something that should be resolved across all playgrounds in a separate concern rather than just this one.

Some prop combinations make the range slider disappear from the Playground all together

Oh interesting. So if you do this on local, you get a very handy error pane that covers the entire screen:

But on staging/prod the message only shows in console logs:

Either way, these are a series of very intentionally thrown errors (that have unit tests written for them) so I'll write it off for now (working the same as production), but I think we should find some way of wrapping an EuiErrorBoundary around the playground or similar.

It looks like the input that appears when showInput may need to be extended. When isInvalid is true and compressed is false, the numeric value within the input is cut off and can't been seen.

Totally agreed! This is already an issue on production it looks like so my preference would be to file an issue + follow up in a separate PR (since changing the width of the input could have unintended effects on the range slider, and @miukimiu may have different ideas on how to resolve the problem).

Thanks for the super thorough QA Bree!!! These are all great items I'd love to see us tackle in the future.

@cee-chen cee-chen enabled auto-merge (squash) December 6, 2022 19:31
@kibanamachine
Copy link

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

Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

:shipit:

@cee-chen cee-chen merged commit 1e5ffb2 into main Dec 6, 2022
@cee-chen cee-chen deleted the feature/emotion-range-sliders branch December 6, 2022 20:14
jbudz pushed a commit to elastic/kibana that referenced this pull request Dec 19, 2022
eui@70.4.0 ⏩ eui@71.0.0

---

## [`71.0.0`](https://github.com/elastic/eui/tree/v71.0.0)

- Implemented new `EuiRange` and `EuiDualRange` designs where the
`levels` are now on top of the tracks
([#6092](elastic/eui#6092))
- Added `discuss` and `dotInCircle` glyphs to `EuiIcon`
([#6434](elastic/eui#6434))
- Added `article` glyph to `EuiIcon`
([#6437](elastic/eui#6437))
- Changed the `EuiProvider` usage warnings to not rely on development
mode. ([#6451](elastic/eui#6451))

**Breaking changes**

- `EuiDualRange` now explicitly requires both `min` and `max` via props
types, to match `EuiRange`
([#6092](elastic/eui#6092))
- `EuiRange` and `EuiDualRange`'s `compressed` size no longer impacts
track or level sizes, but continues to compress tick and input sizes.
([#6092](elastic/eui#6092))
- Removed all variables for the following components from EUI's theme
JSON files: ([#6443](elastic/eui#6443))
  - `euiCollapsibleNav*`
  - `euiColorPicker*`
  - `euiContextMenu*`
  - `euiControlBar*`
  - `euiDataGrid* `(except for z-indices and cell padding sizes)
  - `euiDatePicker*`
  - `euiSuperDatePicker*`
  - `euiDragAndDrop*`
  - `euiEuiEmptyPrompt*`
  - `euiFilePicker*`
  - `euiRange*`
  - `euiHeaderLinks*`
  - `euiKeyPad*`
  - `euiMarkdownEditor*`
  - `euiResizable*`
  - `euiSelectable*`
  - `euiSideNav*`
  - `euiStep*`
  - `euiSuggest*`
  - `euiTable*` (except for color variables)
  - `euiTooltip*`
- `euiButtonFontWeight`, `euiButtonDefaultTransparency`, and
`euiButtonMinWidth`
- If you were importing any of the above removed JSON variables, we
strongly recommend using generic color or sizing variables from
`useEuiTheme()` instead.
([#6443](elastic/eui#6443))

**CSS-in-JS conversions**

- Converted `EuiRange` and `EuiDualRange` to Emotion; Removed
`$euiRangeThumbRadius`
([#6092](elastic/eui#6092))
- Added a new `logicalStyles` utility that automatically converts all
non-logical properties in a `style` object to their corresponding
logical properties ([#6426](elastic/eui#6426))
- Added a new `logicalShorthandCSS` utility that automatically converts
`margin`, `padding`, and other 4-sided shorthands to their corresponding
logical properties ([#6429](elastic/eui#6429))
- Added a new `logicalBorderRadiusCSS` utility that automatically
converts `border-radius` to corresponding logical properties
([#6429](elastic/eui#6429))

Co-authored-by: Constance Chen <constance.chen@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues or PRs that only affect documentation - will not need changelog entries emotion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants