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

[EuiDataGrid] Redesigns feature branch #7382

Merged
merged 9 commits into from
Nov 23, 2023
6 changes: 6 additions & 0 deletions changelogs/upcoming/7343.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Updated `EuiDataGrid` cell actions to display above cells instead of within them, to avoid content clipping issues
- Updated `EuiDataGrid` cell expansion popovers to sit on top of cells instead of below/next to them

**Bug fixes**

- Fixed incorrect `EuiPopover` positioning calculations when `hasArrow` was set to false
3 changes: 3 additions & 0 deletions changelogs/upcoming/7369.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Added a new `EuiDataGridToolbarControl` subcomponent, which is useful for rendering your own custom `EuiDataGrid` toolbar buttons while matching the look of the default controls
- Updated `EuiDataGrid`'s toolbar controls to show active/current counts in badges, and updated the Columns button icon
- Updated `EuiButtonEmpty` to allow passing `false` to `textProps`, which allows rendering custom button content without an extra text wrapper
6 changes: 6 additions & 0 deletions changelogs/upcoming/7371.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Updated `EuiDataGrid` column header cells to show the sort arrow after the heading text, instead of before
- Updated `EuiDataGrid`'s column header actions icon from a chevron to `boxesVertical`

**Bug fixes**

- Fixed `EuiDataGrid`'s numeric and currency column heading cells to be correctly right-aligned
1 change: 1 addition & 0 deletions cypress/support/component-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="css-styles">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap">
<title>Components App</title>
</head>

Expand Down
6 changes: 3 additions & 3 deletions src-docs/src/views/datagrid/toolbar/additional_controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { faker } from '@faker-js/faker';

import {
EuiDataGrid,
EuiDataGridToolbarControl,
EuiButtonEmpty,
EuiButtonIcon,
EuiLink,
Expand Down Expand Up @@ -149,13 +150,12 @@ export default () => {
<EuiPopover
id={popoverId}
button={
<EuiButtonEmpty
size="xs"
<EuiDataGridToolbarControl
iconType="download"
onClick={() => setPopover((open) => !open)}
>
Download
</EuiButtonEmpty>
</EuiDataGridToolbarControl>
}
isOpen={isPopoverOpen}
closePopover={() => setPopover(false)}
Expand Down
30 changes: 22 additions & 8 deletions src-docs/src/views/datagrid/toolbar/datagrid_toolbar_example.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React, { Fragment } from 'react';

import { GuideSectionTypes } from '../../../components';
import { EuiCode } from '../../../../../src';
import {
EuiDataGridToolbarControl,
EuiCode,
EuiCallOut,
} from '../../../../../src';

import DataGridToolbarVisibility from './visibility';
const dataGridToolbarVisibilitySource = require('!!raw-loader!./_grid');
Expand Down Expand Up @@ -174,7 +178,7 @@ export const DataGridToolbarExample = {
</ul>
<p>
Although any node is allowed, the recommendation is to use{' '}
<EuiCode>{'<EuiButtonEmpty size="xs" />'}</EuiCode> for the
<EuiCode>{'<EuiDataGridToolbarControl />'}</EuiCode> for the
left-side of the toolbar and{' '}
<EuiCode>{'<EuiButtonIcon size="xs" />'}</EuiCode> for the
right-side of the toolbar.
Expand All @@ -186,6 +190,7 @@ export const DataGridToolbarExample = {
EuiDataGridToolBarVisibilityOptions,
EuiDataGridToolBarAdditionalControlsOptions,
EuiDataGridToolBarAdditionalControlsLeftOptions,
EuiDataGridToolbarControl,
},
demo: <DataGridControls />,
},
Expand All @@ -211,18 +216,27 @@ export const DataGridToolbarExample = {
<EuiCode>renderCustomToolbar</EuiCode> should only be used when a
very custom layout (e.g. moving default buttons between sides,
interspering custom controls between default controls, custom
responsive behavior, etc.) is required. We would caution you to keep
consistency in mind also when customizing the toolbar: if using
multiple datagrid instances across your app, users will typically
want to reach for the same controls for each grid. Changing the
available controls inconsistently across your app may result in user
frustration.
responsive behavior, etc.) is required. For consistent visuals, we
recommend using the{' '}
<EuiCode>{'<EuiDataGridToolbarControl />'}</EuiCode> subcomponent
when rendering custom controls.
</p>
<EuiCallOut
color="warning"
iconType="alert"
title="Keep consistency in mind when customizing the toolbar"
>
If using multiple datagrid instances across your app, users will
typically want to reach for the same controls for each grid.
Changing the available controls inconsistently across your app may
result in user frustration.
</EuiCallOut>
</>
),
demo: <DataGridCustomToolbar />,
props: {
EuiDataGridCustomToolbarProps,
EuiDataGridToolbarControl,
},
snippet: `<EuiDataGrid
aria-label="Data grid with a custom toolbar and additional content in the display settings popover "
Expand Down
12 changes: 8 additions & 4 deletions src-docs/src/views/datagrid/toolbar/render_custom_toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
EuiDataGridSorting,
EuiDataGridColumnSortingConfig,
EuiDataGridToolbarProps,
EuiButtonEmpty,
EuiDataGridToolbarControl,
EuiFormRow,
EuiRange,
EuiFlexGroup,
Expand Down Expand Up @@ -45,7 +45,7 @@ const renderCustomToolbar: EuiDataGridToolbarProps['renderCustomToolbar'] = ({
const mobileStyles =
!hasRoomForGridControls &&
css`
.euiDataGrid__controlBtn .euiButtonEmpty__text {
.euiDataGridToolbarControl__text {
${euiScreenReaderOnly()}
}
`;
Expand All @@ -59,9 +59,13 @@ const renderCustomToolbar: EuiDataGridToolbarProps['renderCustomToolbar'] = ({
>
<EuiFlexItem grow={false}>
{hasRoomForGridControls && (
<EuiButtonEmpty size="xs" color="primary">
<EuiDataGridToolbarControl
iconType="brush"
badgeContent={10}
onClick={() => {}}
>
Custom left side
</EuiButtonEmpty>
</EuiDataGridToolbarControl>
)}
</EuiFlexItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ describe('EuiButtonDisplayContent', () => {
expect(container.querySelector('.eui-textTruncate')).toBeTruthy();
});

it('does not render a text span wrapper if textProps is explicitly set to false', () => {
const { container } = render(
<EuiButtonDisplayContent textProps={false}>
Text
</EuiButtonDisplayContent>
);

expect(container.querySelector('.eui-textTruncate')).toBeFalsy();
});

it('does not render a text span wrapper if custom child with no textProps are passed', () => {
const { getByTestSubject, container } = render(
<EuiButtonDisplayContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ export interface EuiButtonDisplayContentProps extends CommonProps {
iconSide?: ButtonContentIconSide;
isLoading?: boolean;
/**
* Object of props passed to the <span/> wrapping the content's text/children only (not icon)
* Object of props passed to the `<span>` wrapping the content's text/children only (not icon)
*
* This span wrapper can be removed by passing `textProps={false}`.
*/
textProps?: HTMLAttributes<HTMLSpanElement> &
CommonProps & {
ref?: Ref<HTMLSpanElement>;
'data-text'?: string;
};
textProps?:
| (HTMLAttributes<HTMLSpanElement> &
CommonProps & {
ref?: Ref<HTMLSpanElement>;
'data-text'?: string;
})
| false;
iconSize?: ButtonContentIconSize;
isDisabled?: boolean;
}
Expand Down Expand Up @@ -90,11 +94,13 @@ export const EuiButtonDisplayContent: FunctionComponent<
}

const isText = typeof children === 'string';
const doNotRenderTextWrapper = textProps === false;
const renderTextWrapper = (isText || textProps) && !doNotRenderTextWrapper;

return (
<span css={cssStyles} {...contentProps}>
{iconSide === 'left' && icon}
{isText || textProps ? (
{renderTextWrapper ? (
<span
{...textProps}
className={classNames('eui-textTruncate', textProps?.className)}
Expand Down
10 changes: 10 additions & 0 deletions src/components/button/button_empty/button_empty.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,15 @@ describe('EuiButtonEmpty', () => {

expect(container.firstChild).toMatchSnapshot();
});

it('does not render the text wrapper when textProps is set to false', () => {
const { container } = render(
<EuiButtonEmpty textProps={false}>Content</EuiButtonEmpty>
);

expect(
container.querySelector('.euiButtonEmpty__text')
).not.toBeInTheDocument();
});
});
});
10 changes: 7 additions & 3 deletions src/components/button/button_empty/button_empty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface CommonEuiButtonEmptyProps
type?: 'button' | 'submit';
buttonRef?: Ref<HTMLButtonElement | HTMLAnchorElement>;
/**
* Object of props passed to the <span/> wrapping the button's content
* Object of props passed to the `<span>` wrapping the button's content
*/
contentProps?: CommonProps & EuiButtonDisplayContentType;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ export const EuiButtonEmpty: FunctionComponent<EuiButtonEmptyProps> = ({

const textClassNames = classNames(
'euiButtonEmpty__text',
textProps?.className
textProps && textProps.className
);

const innerNode = (
Expand All @@ -149,7 +149,11 @@ export const EuiButtonEmpty: FunctionComponent<EuiButtonEmptyProps> = ({
iconType={iconType}
iconSide={iconSide}
iconSize={size === 'xs' ? 's' : iconSize}
textProps={{ ...textProps, className: textClassNames }}
textProps={
textProps === false
? false
: { ...textProps, className: textClassNames }
}
{...{ ...contentProps, className: contentClassNames }}
>
{children}
Expand Down
13 changes: 0 additions & 13 deletions src/components/combo_box/combo_box.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ import {
type EuiComboBoxOptionOption,
} from './index';

// CI doesn't have access to the Inter font, so we need to manually include it
// for truncation font calculations to work correctly
before(() => {
const linkElem = document.createElement('link');
linkElem.setAttribute('rel', 'stylesheet');
linkElem.setAttribute(
'href',
'https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap'
);
document.head.appendChild(linkElem);
cy.wait(1000); // Wait a second to give the font time to load/swap in
});

describe('EuiComboBox', () => {
describe('focus management', () => {
it('keeps focus on the input box when clicking a disabled item', () => {
Expand Down
Loading
Loading