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 25 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
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
72 changes: 52 additions & 20 deletions src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ exports[`EuiDataGrid rendering renders additional toolbar controls 1`] = `
data-test-subj="dataGridColumnSelectorPopover"
>
<button
class="euiButtonEmpty euiDataGrid__controlBtn emotion-euiButtonDisplay-euiButtonEmpty-xs-empty-text"
class="euiButtonEmpty euiDataGridToolbarControl emotion-euiButtonDisplay-euiButtonEmpty-xs-empty-text-EuiDataGridToolbarControl"
data-test-subj="dataGridColumnSelectorButton"
type="button"
>
Expand All @@ -485,13 +485,20 @@ exports[`EuiDataGrid rendering renders additional toolbar controls 1`] = `
>
<span
color="inherit"
data-euiicon-type="listAdd"
data-euiicon-type="tableDensityNormal"
/>
<span
class="eui-textTruncate euiButtonEmpty__text"
class="euiDataGridToolbarControl__text eui-textTruncate"
>
Columns
</span>
<span
aria-label="- Active: 2"
class="euiNotificationBadge euiDataGridToolbarControl__badge emotion-euiNotificationBadge-s-subdued-EuiDataGridToolbarControl"
role="marquee"
>
2
</span>
</span>
</button>
</div>
Expand Down Expand Up @@ -533,7 +540,7 @@ exports[`EuiDataGrid rendering renders additional toolbar controls 1`] = `
>
<button
aria-label="Display options"
class="euiButtonIcon euiDataGrid__controlBtn emotion-euiButtonIcon-xs-empty-text"
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text"
data-test-subj="dataGridDisplaySelectorButton"
type="button"
>
Expand All @@ -551,7 +558,8 @@ exports[`EuiDataGrid rendering renders additional toolbar controls 1`] = `
>
<button
aria-label="Enter fullscreen"
class="euiButtonIcon euiDataGrid__controlBtn emotion-euiButtonIcon-xs-empty-text"
aria-pressed="false"
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text"
data-test-subj="dataGridFullScreenButton"
type="button"
>
Expand Down Expand Up @@ -895,7 +903,7 @@ exports[`EuiDataGrid rendering renders control columns 1`] = `
data-test-subj="dataGridColumnSelectorPopover"
>
<button
class="euiButtonEmpty euiDataGrid__controlBtn emotion-euiButtonDisplay-euiButtonEmpty-xs-empty-text"
class="euiButtonEmpty euiDataGridToolbarControl emotion-euiButtonDisplay-euiButtonEmpty-xs-empty-text-EuiDataGridToolbarControl"
data-test-subj="dataGridColumnSelectorButton"
type="button"
>
Expand All @@ -904,13 +912,20 @@ exports[`EuiDataGrid rendering renders control columns 1`] = `
>
<span
color="inherit"
data-euiicon-type="listAdd"
data-euiicon-type="tableDensityNormal"
/>
<span
class="eui-textTruncate euiButtonEmpty__text"
class="euiDataGridToolbarControl__text eui-textTruncate"
>
Columns
</span>
<span
aria-label="- Active: 2"
class="euiNotificationBadge euiDataGridToolbarControl__badge emotion-euiNotificationBadge-s-subdued-EuiDataGridToolbarControl"
role="marquee"
>
2
</span>
</span>
</button>
</div>
Expand Down Expand Up @@ -952,7 +967,7 @@ exports[`EuiDataGrid rendering renders control columns 1`] = `
>
<button
aria-label="Display options"
class="euiButtonIcon euiDataGrid__controlBtn emotion-euiButtonIcon-xs-empty-text"
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text"
data-test-subj="dataGridDisplaySelectorButton"
type="button"
>
Expand All @@ -970,7 +985,8 @@ exports[`EuiDataGrid rendering renders control columns 1`] = `
>
<button
aria-label="Enter fullscreen"
class="euiButtonIcon euiDataGrid__controlBtn emotion-euiButtonIcon-xs-empty-text"
aria-pressed="false"
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text"
data-test-subj="dataGridFullScreenButton"
type="button"
>
Expand Down Expand Up @@ -1592,7 +1608,7 @@ exports[`EuiDataGrid rendering renders custom column headers 1`] = `
data-test-subj="dataGridColumnSelectorPopover"
>
<button
class="euiButtonEmpty euiDataGrid__controlBtn emotion-euiButtonDisplay-euiButtonEmpty-xs-empty-text"
class="euiButtonEmpty euiDataGridToolbarControl emotion-euiButtonDisplay-euiButtonEmpty-xs-empty-text-EuiDataGridToolbarControl"
data-test-subj="dataGridColumnSelectorButton"
type="button"
>
Expand All @@ -1601,13 +1617,20 @@ exports[`EuiDataGrid rendering renders custom column headers 1`] = `
>
<span
color="inherit"
data-euiicon-type="listAdd"
data-euiicon-type="tableDensityNormal"
/>
<span
class="eui-textTruncate euiButtonEmpty__text"
class="euiDataGridToolbarControl__text eui-textTruncate"
>
Columns
</span>
<span
aria-label="- Active: 2"
class="euiNotificationBadge euiDataGridToolbarControl__badge emotion-euiNotificationBadge-s-subdued-EuiDataGridToolbarControl"
role="marquee"
>
2
</span>
</span>
</button>
</div>
Expand Down Expand Up @@ -1646,7 +1669,7 @@ exports[`EuiDataGrid rendering renders custom column headers 1`] = `
>
<button
aria-label="Display options"
class="euiButtonIcon euiDataGrid__controlBtn emotion-euiButtonIcon-xs-empty-text"
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text"
data-test-subj="dataGridDisplaySelectorButton"
type="button"
>
Expand All @@ -1664,7 +1687,8 @@ exports[`EuiDataGrid rendering renders custom column headers 1`] = `
>
<button
aria-label="Enter fullscreen"
class="euiButtonIcon euiDataGrid__controlBtn emotion-euiButtonIcon-xs-empty-text"
aria-pressed="false"
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text"
data-test-subj="dataGridFullScreenButton"
type="button"
>
Expand Down Expand Up @@ -2010,7 +2034,7 @@ exports[`EuiDataGrid rendering renders with common and div attributes 1`] = `
data-test-subj="dataGridColumnSelectorPopover"
>
<button
class="euiButtonEmpty euiDataGrid__controlBtn emotion-euiButtonDisplay-euiButtonEmpty-xs-empty-text"
class="euiButtonEmpty euiDataGridToolbarControl emotion-euiButtonDisplay-euiButtonEmpty-xs-empty-text-EuiDataGridToolbarControl"
data-test-subj="dataGridColumnSelectorButton"
type="button"
>
Expand All @@ -2019,13 +2043,20 @@ exports[`EuiDataGrid rendering renders with common and div attributes 1`] = `
>
<span
color="inherit"
data-euiicon-type="listAdd"
data-euiicon-type="tableDensityNormal"
/>
<span
class="eui-textTruncate euiButtonEmpty__text"
class="euiDataGridToolbarControl__text eui-textTruncate"
>
Columns
</span>
<span
aria-label="- Active: 2"
class="euiNotificationBadge euiDataGridToolbarControl__badge emotion-euiNotificationBadge-s-subdued-EuiDataGridToolbarControl"
role="marquee"
>
2
</span>
</span>
</button>
</div>
Expand Down Expand Up @@ -2064,7 +2095,7 @@ exports[`EuiDataGrid rendering renders with common and div attributes 1`] = `
>
<button
aria-label="Display options"
class="euiButtonIcon euiDataGrid__controlBtn emotion-euiButtonIcon-xs-empty-text"
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text"
data-test-subj="dataGridDisplaySelectorButton"
type="button"
>
Expand All @@ -2082,7 +2113,8 @@ exports[`EuiDataGrid rendering renders with common and div attributes 1`] = `
>
<button
aria-label="Enter fullscreen"
class="euiButtonIcon euiDataGrid__controlBtn emotion-euiButtonIcon-xs-empty-text"
aria-pressed="false"
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text"
data-test-subj="dataGridFullScreenButton"
type="button"
>
Expand Down
Loading