Skip to content

[CSS-in-JS] Add utility for converting style to logical properties#6426

Merged
cee-chen merged 4 commits intoelastic:mainfrom
cee-chen:logicals-2
Dec 2, 2022
Merged

[CSS-in-JS] Add utility for converting style to logical properties#6426
cee-chen merged 4 commits intoelastic:mainfrom
cee-chen:logicals-2

Conversation

@cee-chen
Copy link
Copy Markdown
Contributor

@cee-chen cee-chen commented Nov 22, 2022

Summary

This utility allows us to convert any style object to use corresponding logical properties instead of, e.g. width, height, etc. It checks the entire style obj for keys that have corresponding logical properties and converts them if so. It's particular desired for anywhere we use a virtualization library.

The example/snapshot change for EuiCodeBlock most clearly illustrates what this utility accomplishes.

This is very much a "nice to have" util and doesn't necessarily exactly work 100% as expected in react-window in actual direction: rtl or writing-mode: vertical-rl prod behavior (although it's hard to tell if this is because EUI as a whole is not fully converted to logical properties yet).

It also contains an incidental test cleanup commit.

QA

General checklist

  • Checked in Chrome, Safari, Edge, and Firefox
  • Added or updated jest and cypress tests
  • A changelog entry exists and is marked appropriately

- they're vanilla JS functions, they aren't hooks
- for converting an entire `style` obj (of unknown properties) to logical properties, rather than manually passing properties
@kibanamachine
Copy link
Copy Markdown

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

@cee-chen cee-chen requested a review from 1Copenut December 2, 2022 15:52
@cee-chen
Copy link
Copy Markdown
Contributor Author

cee-chen commented Dec 2, 2022

@1Copenut, do you mind giving this a review when you have a chance?

Copy link
Copy Markdown
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!

});
});

describe('logicalStyles returns an object property', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These tests are so helpful in communicating intent. 💯

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Test-driven development y'all! 🎉

@cee-chen cee-chen merged commit 345cc18 into elastic:main Dec 2, 2022
@cee-chen cee-chen deleted the logicals-2 branch December 2, 2022 18: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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants