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

[EuiSuperDatePicker] Convert quick select styles to Emotion #7909

Merged
merged 11 commits into from
Jul 29, 2024
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
.euiQuickSelectPopover__panel {
&:not(:first-child) {
border-top: $euiBorderThin;
padding-top: $euiSizeM;
margin-top: $euiSizeM;
}

.euiQuickSelectPopover__panelTitle {
float: left;
margin-bottom: $euiSizeM;
}
}

.euiQuickSelectPopover__section {
@include euiScrollBar;
max-height: $euiSizeM * 11;
overflow: hidden;
overflow-y: auto;
margin: $euiSizeS 0 0;
clear: both;
}

.euiQuickSelectPopover__sectionItem {
font-size: $euiFontSizeS;
line-height: $euiFontSizeS;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 {
euiScrollBarStyles,
logicalCSS,
logicalCSSWithFallback,
mathWithUnits,
} from '../../../../global_styling';

export const euiQuickSelectPanelStyles = (euiThemeContext: UseEuiTheme) => {
const { euiTheme } = euiThemeContext;

return {
euiQuickSelectPanel: css`
&:not(:first-child) {
${logicalCSS('border-top', euiTheme.border.thin)}
${logicalCSS('padding-top', euiTheme.size.m)}
${logicalCSS('margin-top', euiTheme.size.m)}
}
`,
euiQuickSelectPanel__title: css`
float: left; /* Required for fieldset/legend elements */
Copy link
Contributor

Choose a reason for hiding this comment

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

This float is now added to span as well as legend and I see this causes some differences in spacing:

Screen.Recording.2024-07-26.at.09.06.51.mov

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 new version is actually more correct - we want the <span> to render more like a display block, which float automatically does. It looks like production was missing that

${logicalCSS('margin-bottom', euiTheme.size.m)}
`,
euiQuickSelectPanel__section: css`
clear: both; /* Required for fieldset/legend elements */
${logicalCSS('margin-top', euiTheme.size.s)}
${logicalCSS(
'max-height',
mathWithUnits(euiTheme.size.m, (x) => x * 12)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just wanted to highlight * 12 as an intentional change from the previous * 11 in Sass. This extra ~12px of height allows us to remove a custom CSS override in Kibana: https://github.com/elastic/kibana/blob/1a6ab7e85ad36ec17a0333568c0393b279f22fff/src/plugins/unified_search/public/query_string_input/query_bar.scss#L6-L9

)}
overflow: hidden;
${logicalCSSWithFallback('overflow-y', 'auto')}
${euiScrollBarStyles(euiThemeContext)}
`,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 React, { FunctionComponent, ReactNode } from 'react';

import { useEuiMemoizedStyles } from '../../../../services';
import { EuiTitle } from '../../../title';
import type { CommonProps } from '../../../common';

import { euiQuickSelectPanelStyles } from './quick_select_panel.styles';

type EuiQuickSelectPanelProps = CommonProps & {
component?: 'div' | 'fieldset';
title?: ReactNode;
titleId?: string;
children?: ReactNode;
};

export const EuiQuickSelectPanel: FunctionComponent<
EuiQuickSelectPanelProps
> = ({ component: Component = 'div', title, titleId, children, ...rest }) => {
const isFieldset = Component === 'fieldset';
const TitleComponent = isFieldset ? 'legend' : 'span';

const styles = useEuiMemoizedStyles(euiQuickSelectPanelStyles);

return (
<Component css={styles.euiQuickSelectPanel} {...rest}>
{title ? (
<>
<EuiTitle size="xxxs">
<TitleComponent
id={titleId}
css={styles.euiQuickSelectPanel__title}
>
{title}
</TitleComponent>
</EuiTitle>
<div css={styles.euiQuickSelectPanel__section}>{children}</div>
</>
) : (
children
)}
</Component>
);
};