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] Badges in grid toolbar #7369

Merged
merged 27 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1cfe8c0
Show badges in grid toolbar
jughosta Nov 14, 2023
4423ca3
Add tests
jughosta Nov 15, 2023
c358a37
Merge remote-tracking branch 'upstream/main' into 7283-grid-toolbar-b…
jughosta Nov 15, 2023
30aa39c
Update tests
jughosta Nov 15, 2023
f643745
Add changelog
jughosta Nov 15, 2023
562a8ea
Export EuiDataGridToolbarControl component and update its props
jughosta Nov 15, 2023
a6f0b7d
Export EuiDataGridToolbarControl component and update its props
jughosta Nov 15, 2023
7e2fa6e
Update snapshots for previous react versions
jughosta Nov 15, 2023
0d47cd7
Rename changelog to PR id
jughosta Nov 15, 2023
8eb7277
Don't highlight active controls and update label for hidden columns
jughosta Nov 15, 2023
21e2d8e
Merge branch 'main' into 7283-grid-toolbar-badges
jughosta Nov 15, 2023
bafd011
Update src/components/datagrid/controls/data_grid_toolbar_control.tsx
jughosta Nov 21, 2023
eb63b18
Update snapshots
jughosta Nov 21, 2023
a987085
Merge branch 'datagrid-redesigns' into 7283-grid-toolbar-badges
cee-chen Nov 21, 2023
bb8cca0
[EuiButtonEmpty] Allow disabling the text wrapper
cee-chen Nov 21, 2023
3408cfb
[EuiFilterButton] Clean up DOM/CSS by disabling text wrapper
cee-chen Nov 21, 2023
5e3b8c9
Update datagrid button to use new `textProps={false}`
cee-chen Nov 21, 2023
472161e
[misc cleanup] Move new component props to file
cee-chen Nov 21, 2023
184f1b7
CSS fixes/className cleanups
cee-chen Nov 21, 2023
f467443
[cleanup] Remove `.euiDataGrid__controlBtn` className
cee-chen Nov 21, 2023
41aac63
[cleanup] EuiDataGridToolbarControl tests
cee-chen Nov 21, 2023
4c3c8e5
[cleanup] Badge text assertions
cee-chen Nov 21, 2023
f4d0c88
[a11y] Screen reader UX improvements for columns badge
cee-chen Nov 21, 2023
9a67614
changelog
cee-chen Nov 21, 2023
545e6de
Revert "[EuiFilterButton] Clean up DOM/CSS by disabling text wrapper"
cee-chen Nov 21, 2023
44cb0f4
[docs] Add more documentation for new `EuiDataGridToolbarControl`
cee-chen Nov 21, 2023
43e5426
React 16/17 snapshots
cee-chen Nov 21, 2023
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
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: 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
20 changes: 13 additions & 7 deletions src/components/button/button_display/_button_display_content.tsx
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
Loading