-
Notifications
You must be signed in to change notification settings - Fork 842
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
[CSS-in-JS] Convert EuiMark
#4575
Changes from 13 commits
762d4ca
0b32834
96ec57b
c6c80b3
7c59f02
8cd5225
90614e7
659d267
7bbfbbb
de1278b
3a20670
cf363df
68f2bcd
48c9d84
1f42724
833cd79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiHighlight behavior loose matching matches strings with different casing 1`] = ` | ||
.emotion-0 { | ||
background-color: rgba(0,119,204,0.1); | ||
font-weight: 700; | ||
color: #343741; | ||
} | ||
Comment on lines
+4
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can come back to this in another PR, but I think we'll find having these styles output into the snapshots are going to weight heavy on larger components. |
||
|
||
<span> | ||
different | ||
<mark | ||
class="euiMark" | ||
class="euiMark emotion-0" | ||
> | ||
case | ||
</mark> | ||
|
@@ -13,31 +19,43 @@ exports[`EuiHighlight behavior loose matching matches strings with different cas | |
`; | ||
|
||
exports[`EuiHighlight behavior matching applies to all matches 1`] = ` | ||
.emotion-0 { | ||
background-color: rgba(0,119,204,0.1); | ||
font-weight: 700; | ||
color: #343741; | ||
} | ||
|
||
<span> | ||
<mark | ||
class="euiMark" | ||
class="euiMark emotion-0" | ||
> | ||
match | ||
</mark> | ||
|
||
<mark | ||
class="euiMark" | ||
class="euiMark emotion-0" | ||
> | ||
match | ||
</mark> | ||
|
||
<mark | ||
class="euiMark" | ||
class="euiMark emotion-0" | ||
> | ||
match | ||
</mark> | ||
</span> | ||
`; | ||
|
||
exports[`EuiHighlight behavior matching only applies to first match 1`] = ` | ||
.emotion-0 { | ||
background-color: rgba(0,119,204,0.1); | ||
font-weight: 700; | ||
color: #343741; | ||
} | ||
|
||
<span> | ||
<mark | ||
class="euiMark" | ||
class="euiMark emotion-0" | ||
> | ||
match | ||
</mark> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,6 @@ | |
@import 'list_group/index'; | ||
@import 'loading/index'; | ||
@import 'markdown_editor/index'; | ||
@import 'mark/index'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely seems like a breaking change 🤔 Just to clarify, are we merging all conversions into a feature branch (rather than main) and then flipping the switch on removing the legacy Sass theme all at once? (+ coordinating with Kibana so they remove the option to switch back to the legacy theme?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think only the first few will go into the feature branch while we establish various patterns. After that we can go straight to main.
I think legacy has been removed entirely from Kibana already. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh nice! So it's just a question of removing the legacy theme in our own docs site, then? Should we deprecate the legacy toggle at the same time we start merging these changes into main? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, we should just open a PR to remove the legacy theme entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, I think we should just merge this PR into And yes it's a "breaking" change, but only to the Legacy theme that we should be removing very soon, so not all these following conversions will be breaking. |
||
@import 'modal/index'; | ||
@import 'notification/index'; | ||
@import 'overlay_mask/index'; | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { css } from '@emotion/react'; | ||
import { UseEuiTheme, transparentize } from '../../services'; | ||
|
||
export const euiMarkStyles = ({ euiTheme, colorMode }: UseEuiTheme) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Result of |
||
// TODO: Was $euiFocusBackgroundColor | ||
const transparency = { LIGHT: 0.1, DARK: 0.3 }; | ||
cee-chen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return css` | ||
background-color: ${transparentize( | ||
euiTheme.colors.primary, | ||
transparency[colorMode] | ||
)}; | ||
font-weight: ${euiTheme.font.weight.bold}; | ||
// Override the browser's black color. | ||
// Can't use 'inherit' because the text to background color contrast may not be sufficient | ||
color: ${euiTheme.colors.text}; | ||
`; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,10 @@ | |
*/ | ||
|
||
import React, { HTMLAttributes, FunctionComponent, ReactNode } from 'react'; | ||
import { CommonProps } from '../common'; | ||
import classNames from 'classnames'; | ||
import { CommonProps } from '../common'; | ||
import { useEuiTheme } from '../../services'; | ||
import { euiMarkStyles } from './mark.styles'; | ||
export type EuiMarkProps = HTMLAttributes<HTMLElement> & | ||
CommonProps & { | ||
/** | ||
|
@@ -22,10 +24,12 @@ export const EuiMark: FunctionComponent<EuiMarkProps> = ({ | |
className, | ||
...rest | ||
}) => { | ||
const useTheme = useEuiTheme(); | ||
const styles = euiMarkStyles(useTheme); | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DevEx question: why pass a hook into a separate file? Why not just make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, to be clear, I'm proposing this instead: // mark.tsx
const styles = useEuiMarkStyles();
// mark.styles.ts
import { css } from '@emotion/react';
import { useEuiTheme, transparentize } from '../../services';
export const useEuiMarkStyles = () => {
const { euiTheme, colorMode } = useEuiTheme();
return css `// ... etc`;
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sorry, I see you addressed this in https://github.com/elastic/eui/pull/4575/files#r808436110 - I'm still not totally clear on the rationale behind that comment though. Is it a bad thing for a style file to be dependent on React context? TBH, keeping our usage of EUI theming to the style-focused file makes more sense to me from a developer POV. I'm also very curious what usage would look like with a traditional class component (i.e.: can't use hooks) vs. a functional component. Do we have an example of that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this so that it's possible to just pass in a theme shaped object and get styles, without needing the full React context. No reason we can't do a two-step thing for internal use. That is, keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In more complex cases, we'll probably need to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha! I think the benefits will be clearer with a dynamic styles example + a class component example (I assume we will need to use a HOC for class components). If we could add those examples to the TBD wiki section along with a basic example that would be amazing! |
||
const classes = classNames('euiMark', className); | ||
|
||
return ( | ||
<mark className={classes} {...rest}> | ||
<mark css={[styles]} className={classes} {...rest}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok so the output class list is now: Seems like a lot of variations of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, we can reduce the verbosity if deemed necessary. These are only referential so no changes will ever be breaking. |
||
{children} | ||
</mark> | ||
); | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the long-form class name defined by
labelFormat
in dev and prod environments (prod would use a short, mangled string otherwise).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little confused here because you mention "in dev and prod environments" but then say that prod would use the short/uglified string. Just to clarify, the long-form string is in dev only, and the short-form string is prod only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The properties are confusing, yes.
"autoLabel": "always"
makes it so that the long-form string is used in both prod and dev environments. We don't want to use the short-form string in any case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh my reading comprehension is at an all time low today 🤦 Sorry, I totally missed the "otherwise" in that parentheses! Alrighty, I get it now, so always a long-form string.