-
Notifications
You must be signed in to change notification settings - Fork 841
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 EuiSearchBar #7490
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**CSS-in-JS conversions** | ||
|
||
- Converted `EuiSearchBar` to Emotion |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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 } from '../../services'; | ||
import { euiBreakpoint, logicalCSS, mathWithUnits } from '../../global_styling'; | ||
import { euiFormVariables } from '../form/form.styles'; | ||
|
||
export const euiSearchBar__searchHolder = (euiThemeContext: UseEuiTheme) => { | ||
const { maxWidth } = euiFormVariables(euiThemeContext); | ||
return css` | ||
${logicalCSS( | ||
JasonStoltz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'min-width', | ||
mathWithUnits(maxWidth, (x) => x / 2) | ||
)} | ||
`; | ||
}; | ||
|
||
export const euiSearchBar__filtersHolder = (euiThemeContext: UseEuiTheme) => { | ||
const { euiTheme } = euiThemeContext; | ||
return css` | ||
${euiBreakpoint(euiThemeContext, ['m', 'l', 'xl'])} { | ||
/* Helps with flex-wrapping */ | ||
${logicalCSS('max-width', `calc(100% - ${euiTheme.size.base})`)} | ||
} | ||
`; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
import React, { Component, ReactElement } from 'react'; | ||
|
||
import { htmlIdGenerator } from '../../services/accessibility'; | ||
import { RenderWithEuiTheme, htmlIdGenerator } from '../../services'; | ||
import { isString } from '../../services/predicate'; | ||
import { EuiFlexGroup, EuiFlexItem } from '../flex'; | ||
import { EuiSearchBox } from './search_box'; | ||
|
@@ -18,6 +18,10 @@ import { CommonProps } from '../common'; | |
import { EuiFieldSearchProps } from '../form/field_search'; | ||
import { EuiInputPopoverProps } from '../popover'; | ||
|
||
import { | ||
euiSearchBar__searchHolder, | ||
euiSearchBar__filtersHolder, | ||
} from './search_bar.styles'; | ||
export { Query, AST as Ast } from './query'; | ||
|
||
export type QueryType = Query | string; | ||
|
@@ -259,24 +263,20 @@ export class EuiSearchBar extends Component<EuiSearchBarProps, State> { | |
|
||
const toolsLeftEl = this.renderTools(toolsLeft); | ||
|
||
const filtersBar = !filters ? undefined : ( | ||
<EuiFlexItem className="euiSearchBar__filtersHolder" grow={false}> | ||
<EuiSearchBarFilters | ||
filters={filters} | ||
query={query} | ||
onChange={this.onFiltersChange} | ||
/> | ||
</EuiFlexItem> | ||
); | ||
|
||
const toolsRightEl = this.renderTools(toolsRight); | ||
|
||
const isHintVisible = hint?.popoverProps?.isOpen ?? isHintVisibleState; | ||
|
||
return ( | ||
<RenderWithEuiTheme> | ||
{(euiTheme) => ( | ||
<EuiFlexGroup gutterSize="m" alignItems="center" wrap> | ||
{toolsLeftEl} | ||
<EuiFlexItem className="euiSearchBar__searchHolder" grow={true}> | ||
<EuiFlexItem | ||
className="euiSearchBar__searchHolder" | ||
css={euiSearchBar__searchHolder(euiTheme)} | ||
grow={true} | ||
> | ||
<EuiSearchBox | ||
{...box} | ||
query={queryText} | ||
|
@@ -298,9 +298,23 @@ export class EuiSearchBar extends Component<EuiSearchBarProps, State> { | |
} | ||
/> | ||
</EuiFlexItem> | ||
{filtersBar} | ||
{filters && ( | ||
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. DELETED 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.
That's wild that this has a performance implication, I had no idea. I assume this is what you're referring to. I'm going to link to this change specifically as a reference on #7499 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. Kevin chatted about me with this in relation to #7374, but iirc the issue is that React creates the conditional node |
||
<EuiFlexItem | ||
className="euiSearchBar__filtersHolder" | ||
css={euiSearchBar__filtersHolder(euiTheme)} | ||
grow={false} | ||
> | ||
<EuiSearchBarFilters | ||
filters={filters} | ||
query={query} | ||
onChange={this.onFiltersChange} | ||
/> | ||
</EuiFlexItem> | ||
)} | ||
{toolsRightEl} | ||
</EuiFlexGroup> | ||
)} | ||
</RenderWithEuiTheme> | ||
); | ||
} | ||
} |
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.
This very likely has performance implications as well (see #7486) and we likely need to memoize
euiFormVariables
(and other CSS-in-JS component style vars) going forward. I'll address that in a separate PR from this one