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

Moving EuiBreadcrumb styles to Emotion. #5934

Merged
merged 25 commits into from
Jul 28, 2022

Conversation

1Copenut
Copy link
Contributor

@1Copenut 1Copenut commented May 27, 2022

Summary

Moved the EuiBreadcrumb to Emotion CSS-in-JS. @cchaos mentioned to split the PR for breadcrumbs and page header breadcrumbs. I'll review this before moving the PR out of draft, but it appears the core breadcrumb CSS was transferring to the page header. I couldn't see any visual differences between my local server and the published version.

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

* Adding basic Emotion styles for links and content.
* Adding the truncated link and content styles to Emotion.
* Added all rules to Emotion. Testing for visual regression.
* Fixed the focus halo for overflow:hidden declarations.
* Removed breadcrumb overrides from Amsterdam theme.
* Added last styles for individual truncated content.
* Final Emotion style updates and a11y QA testing complete.
* Updating snapshot tests for breadcrumb Emotion styles.
@1Copenut 1Copenut requested a review from cchaos May 27, 2022 00:38
@1Copenut 1Copenut self-assigned this May 27, 2022
@kibanamachine
Copy link

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

@cchaos
Copy link
Contributor

cchaos commented May 27, 2022

Hey, sorry, not the PageHeader breadcrumbs, the EuiHeaderBreadcrumbs as seen on this page: https://eui.elastic.co/pr_5934/#/layout/header

@kibanamachine
Copy link

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

* Removing first group of SCSS files ahead of Amsterdam overrides.
* Moving Amsterdam overrides to Emotion.
* Added majority of the header breadcrumb styles.
* Header styles are now contained, not casting into regular breadcrumbs.
* Last color and bgColor styles added.
* Removed Amsterdam SCSS overrides file.
* Updating Jest snapshots for Emotion.
* Adding CHANGELOG, final mobile styles.
@1Copenut 1Copenut requested review from elizabetdev and cee-chen July 14, 2022 21:51
@1Copenut 1Copenut marked this pull request as ready for review July 14, 2022 21:52
Copy link
Contributor Author

@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.

Left one comment about the reasoning for having a new prop. LMK what you think.

}
}
`,
isHeaderBreadcrumb: css`
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 EuiHeaderBreadcrumbs didn't have an easy way to cast styles into child elements, so I added a headerBreadcrumb boolean prop so we could target header breadcrumbs.

I don't think this will be a breaking change because I passed the headerBreadcrumb prop into the EUIHeaderBreadcrumbs component, so it'll get picked up automatically and cast the new styles. If the reviewers feel this will be a breaking change, I'm happy to refactor.

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Not a breaking change! I ended up following this pattern and adding another isNested prop (used for breadcrumbs within the collapsed popover - e50a5f9). It's much cleaner to handle this logic via JS rather than nested CSS.

  2. I'm not 100% on this but I'm not a super huge fan of the headerBreadcrumb/isHeaderBreadcrumb var name. It feels super duper specific when there's arguably a use case for the visual style outside of EuiHeader. I'm wondering if a prop name like isBadge or isChevron would be more descriptive. @1Copenut @miukimiu any thoughts here?

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 on board for a more descriptive prop name. I used isHeaderBreadcrumb purely because it fit with the presentation naming / spaces in EUI. I agree that it could be improved on if these styles can exist outside EuiHeader. Great call!

Copy link
Contributor

@cee-chen cee-chen Jul 21, 2022

Choose a reason for hiding this comment

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

It's now a boolean flag, so super easy to see the visual effect on the playground!

screencap

It's just kind of a question of intention in visual language, I suppose. If we're OK with the chevron effect being used in places other than EuiHeader, then it makes sense to name it more generically. If it's only supposed to be used by EuiHeader, then it makes sense to be more specific and document it as such. I don't know for sure though, hence why I'm tagging in our designers.

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's an excellent way to visualize and document the conditional styling.

Copy link
Contributor

Choose a reason for hiding this comment

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

The EuiHeaderBreadcrumb was added by @cchaos and because she didn't add the styles directly in EuiBreadcrumb I'm assuming she intentionally only wanted those styles to appear for EuiHeader.

But that's my assumption... Caroline is back on Monday so I guess we can wait and she let us know. 😄

Copy link
Contributor

@cee-chen cee-chen Jul 22, 2022

Choose a reason for hiding this comment

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

Right, agreed. I want to note that we could move the styles to src/components/header/header_breadcrumbs instead of remaining in src/components/breadcrumb, but there are a few (minor) disadvantages to doing so vs keeping all the styles in breadcrumb.styles.ts:

  1. CSS selector nesting: we would have to do
[class*="euiBreadcrumb"] { ... } // header-specific styles/overrides
[class*="euiBreadcrumb__content"] { ... } // header-specific styles/overrides

Which, if consumers wanted to override those overrides, they would have to do so either via !important or their own nested selector. Not a huge deal, but IIRC we were trying to flatten nested selectors as part of the Emotion conversion.

  1. Developer styling - if I were trying to write new styles for header breadcrumbs and some parent CSS in EuiBreadcrumb was messing with that or causing unexpected effects, it might not be 100% clear where the parent breadcrumb styles live or are coming from (vs being able to skim all styles at once in one file). Again, not a huge or impossible ordeal to surmount.

We can definitely wait for Caroline to get back for clarity. In the interim I pushed up 6051809 to hide the new internal props from the props table, and renamed them more specifically/added comments as to their internal nature

Copy link
Contributor

Choose a reason for hiding this comment

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

The way I look at it is that no matter how we obfuscate the new prop, consumers can still use EuiHeaderBreadcrumbs anywhere they want. In this PR, the only header-specific styles applied to EuiBreadcrumbs is to enforce truncation and spacing when within the context of EuiHeader. If a consumer wants the look of EuiHeaderBreadcrumbs outside of EuiHeader, they'll most likely be fighting with these extra styles.

Therefore, I suggest keeping this new prop visible to all consumers so they can attain this look anywhere. But I think the name isInEuiHeader is a bit awkward and a pattern we haven't established. I would consider naming it something that points to the purpose of the style and make it an enum, maybe something like type: 'page' | 'application'. And commenting that there should really only be on application style breadcrumb per view.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, yes, isInEuiHeader is overly explicit/awkward and is only what I would have named it if we weren't going to publicly expose the prop. I like the type prop instead for helping designate the purpose!

Copy link
Contributor

Choose a reason for hiding this comment

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

a686260 & 734690e - both new props should now be documented and testable in the playground.

screencap

@cchaos @miukimiu, do either of you want to do a pass on this before merging? From an engineering review POV, this is good to go.

@kibanamachine
Copy link

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

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.

Logical CSS properties pass

src/components/breadcrumbs/breadcrumbs.styles.ts Outdated Show resolved Hide resolved
src/components/breadcrumbs/breadcrumbs.styles.ts Outdated Show resolved Hide resolved
src/components/breadcrumbs/breadcrumbs.styles.ts Outdated Show resolved Hide resolved
src/components/breadcrumbs/breadcrumbs.styles.ts Outdated Show resolved Hide resolved
src/components/breadcrumbs/breadcrumbs.styles.ts Outdated Show resolved Hide resolved
src/components/breadcrumbs/breadcrumbs.styles.ts Outdated Show resolved Hide resolved
src/components/breadcrumbs/breadcrumbs.styles.ts Outdated Show resolved Hide resolved
@1Copenut
Copy link
Contributor Author

I'll get these values converted to logicalCSS late today and re-up the PR.

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

cee-chen added 9 commits July 20, 2022 18:19
- for easier dev readability and testing

+ remove unnecessary classNames modifiers - they're not used in Kibana anywhere
- pass `maxWidth` to text truncation util

- instead of using `> a` or `> span` selectors, just set the styles directly on the content child + use JS to conditionally skip the last breadcrumb

- remove `isTruncated` on parent li, it's no longer needed
- they're already handled in the content CSS and incidentally also in EuiLink styles
- apply nested CSS to .euiBreadcrumb__content directly instead of using nested selectors

- use a nested object and conditional JS logic (vs first/only/last-child) to flatten and DRY out CSS
- Remove unnecessary `--collapsed` modifier class

- DRY out `<li>` and `__content` logic/styles by reusing the `EuiBreadcrumb` and `EuiBreadcrumbContent` components, passing props/overrides as necessary

- Allow any children as `EuiBreadcrumb` child to support this behavior/the popover

- Pass EuiBreadcrumbContent in at the EuiBreadcrumbs level as a result
- in favor of JS logic instead
- remove unnecessary `--truncate` modifier - not used in Kibana
- For easier dev readability / testing

+ microperf optimization onWindowResize: move declaration to useEffect so it's only declared every time `responsive` changes instead of on every rerender
+ remove unnecessary conditional around state setter, React already does its own optimization around values that stay the same
- Move to separate util for easier reading / testing

- Memoize both limitBreadcrumb and breadcrumb mapping so arrays aren't being traversed on every rerender

- refactor: instead of potentially rendering a bunch of hidden breadcrumb elements that never get displayed, splice the breadcrumbs array first, insert a custom object that signifies the EuiBreadcrumbCollapsed button, and then have the element traversal map handle conditionally rendering the collapse button in-place
@cee-chen
Copy link
Contributor

@1Copenut The component split was super helpful in mentally organizing and cleaning up a lot of the nested styles. I should have pushed almost all of the refactors I wanted to make (see previous comment about isHeaderBreadcrumb naming, that's probably my only nit left). Let me know what you think!

@kibanamachine
Copy link

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

- rename both props to be more specific, since they're now internal only / used for a specific purpose

- move both props to an underscore prefixed type and modify props table and playground to not display them
@kibanamachine
Copy link

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

cee-chen added 4 commits July 25, 2022 13:28
- This may be useful to other consumers where their last breadcrumb is not the current page

+ tweak styling to show color difference for both `span`s and `a` tags - using JS `color` props instead of CSS

+ fix `color` prop being passed to underlying span tags
- the `<li>` parent still needs an overflow hidden as it turns out

- the last breadcrumb also still needs text truncation styles, it's just max-width should be set ot none
@kibanamachine
Copy link

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

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.

@kibanamachine
Copy link

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

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