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

[Emotion] Convert EuiTextArea, EuiSelect, and EuiSuperSelect #7812

Merged
merged 16 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ exports[`EuiSuperSelect renders 1`] = `
>
<button
aria-selected="false"
class="euiContextMenuItem euiSuperSelect__item emotion-euiContextMenuItem-m-center"
class="euiContextMenuItem euiSuperSelect__item emotion-euiContextMenuItem-m-center-euiSuperSelect__item"
id="1"
role="option"
type="button"
Expand All @@ -222,7 +222,7 @@ exports[`EuiSuperSelect renders 1`] = `
</button>
<button
aria-selected="false"
class="euiContextMenuItem euiSuperSelect__item emotion-euiContextMenuItem-m-center"
class="euiContextMenuItem euiSuperSelect__item emotion-euiContextMenuItem-m-center-euiSuperSelect__item"
id="2"
role="option"
type="button"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
.euiSuperSelect__item {
@include euiFontSizeS;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it's intended, but I think this mixin is missing in the emotion version?
I'm seeing differences due to that in the option content height (line-height specifically is different now)

super_select_emotion_conversion.mov

Copy link
Member Author

Choose a reason for hiding this comment

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

Shoot, I did totally miss this! 🤦 Thank you so much for catching it!

Copy link
Member Author

@cee-chen cee-chen Jun 6, 2024

Choose a reason for hiding this comment

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

Actually, it looks like the new Emotion CSS-in-JS euiFontSize(euiThemeContext, 's') changes the line height to be smaller anyway (Caroline intentionally changed this as part of Emotion work) so I think the reduced height would have been an intentional change in any case. (and IMO, it looks pretty good!)

I'm going to go ahead and explicitly add it in any case because it's better to be clear than not clear 🤷 c2f14e3

Copy link
Member Author

Choose a reason for hiding this comment

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

Also just mentioning for my own memory - @include euiInteractiveStates didn't appear to do anything / was already handled by EuiContextMenuItem, and can be safely removed

@include euiInteractiveStates;
padding: $euiSizeS;
}

.euiSuperSelect__item--hasDividers:not(:last-of-type) {
border-bottom: $euiBorderThin;
}
7 changes: 3 additions & 4 deletions packages/eui/src/components/form/super_select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

export type { EuiSuperSelectProps } from './super_select';
export { EuiSuperSelect } from './super_select';
export type {
EuiSuperSelectControlProps,
EuiSuperSelectOption,
} from './super_select_control';
export type { EuiSuperSelectOption } from './super_select_item';

export type { EuiSuperSelectControlProps } from './super_select_control';
export { EuiSuperSelectControl } from './super_select_control';
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { css } from '@emotion/react';

import { UseEuiTheme } from '../../../services';
import { logicalCSS, logicalCSSWithFallback } from '../../../global_styling';

export const euiSuperSelectStyles = {
Expand All @@ -17,3 +18,14 @@ export const euiSuperSelectStyles = {
${logicalCSSWithFallback('overflow-x', 'hidden')}
`,
};

export const euiSuperSelectItemStyles = ({ euiTheme }: UseEuiTheme) => ({
euiSuperSelect__item: css`
padding: ${euiTheme.size.s};
`,
hasDividers: css`
&:not(:last-of-type) {
${logicalCSS('border-bottom', euiTheme.border.thin)}
}
`,
});
27 changes: 11 additions & 16 deletions packages/eui/src/components/form/super_select/super_select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import { CommonProps } from '../../common';
import { EuiI18n } from '../../i18n';
import { EuiScreenReaderOnly } from '../../accessibility';
import { EuiInputPopover, type EuiInputPopoverProps } from '../../popover';
import { EuiContextMenuItem, type EuiContextMenuItemLayoutAlignment } from '../../context_menu';
import { type EuiContextMenuItemLayoutAlignment } from '../../context_menu';

import {
EuiSuperSelectControl,
type EuiSuperSelectControlProps,
type EuiSuperSelectOption,
} from './super_select_control';
import {
EuiSuperSelectItem,
type EuiSuperSelectOption,
} from './super_select_item';
import { euiSuperSelectStyles as styles } from './super_select.styles';

enum ShiftDirection {
Expand Down Expand Up @@ -287,14 +290,6 @@ export class EuiSuperSelect<T = string> extends Component<
className
);

const itemClasses = classNames(
'euiSuperSelect__item',
{
'euiSuperSelect__item--hasDividers': hasDividers,
},
itemClassName
);

const button = (
<EuiSuperSelectControl
options={options}
Expand All @@ -318,21 +313,21 @@ export class EuiSuperSelect<T = string> extends Component<
if (value == null) return;

return (
<EuiContextMenuItem
<EuiSuperSelectItem
key={index}
className={itemClasses}
id={String(value)}
className={itemClassName}
hasDividers={hasDividers}
layoutAlign={itemLayoutAlign}
icon={valueOfSelected === value ? 'check' : 'empty'}
onClick={() => this.itemClicked(value)}
onKeyDown={this.onItemKeyDown}
layoutAlign={itemLayoutAlign}
buttonRef={(node) => this.setItemNode(node, index)}
role="option"
id={String(value)}
aria-selected={valueOfSelected === value}
{...optionRest}
>
{dropdownDisplay || inputDisplay}
</EuiContextMenuItem>
</EuiSuperSelectItem>
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ import {
import { getFormControlClassNameForIconCount } from '../form_control_layout/_num_icons';
import { useFormContext } from '../eui_form_context';

export interface EuiSuperSelectOption<T> {
value: NonNullable<T>;
inputDisplay?: ReactNode;
dropdownDisplay?: ReactNode;
disabled?: boolean;
'data-test-subj'?: string;
}
import { EuiSuperSelectOption } from './super_select_item';
cee-chen marked this conversation as resolved.
Show resolved Hide resolved

export interface EuiSuperSelectControlProps<T>
extends CommonProps,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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, ComponentProps, ReactNode } from 'react';
import classNames from 'classnames';

import { useEuiMemoizedStyles } from '../../../services';
import { EuiContextMenuItem } from '../../context_menu';
import { euiSuperSelectItemStyles } from './super_select.styles';

// Type exposed to consumers via API
export interface EuiSuperSelectOption<T> {
value: NonNullable<T>;
inputDisplay?: ReactNode;
dropdownDisplay?: ReactNode;
disabled?: boolean;
'data-test-subj'?: string;
}

// Actual props used by below component, transmogged by parent EuiSuperSelect
// from consumer props to internal EUI props
type EuiSuperSelectItemProps = ComponentProps<typeof EuiContextMenuItem> & {
hasDividers?: boolean;
};

// Internal subcomponent util, primarily for easier usage of hooks
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
export const EuiSuperSelectItem: FunctionComponent<EuiSuperSelectItemProps> = ({
children,
className,
hasDividers,
...rest
}) => {
const classes = classNames('euiSuperSelect__item', className);
const styles = useEuiMemoizedStyles(euiSuperSelectItemStyles);
const cssStyles = [
styles.euiSuperSelect__item,
hasDividers && styles.hasDividers,
];

return (
<EuiContextMenuItem
css={cssStyles}
className={classes}
role="option"
{...rest}
>
{children}
</EuiContextMenuItem>
);
};