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

[EuiFilterGroup] Add compressed prop #5717

Merged
merged 11 commits into from
Mar 15, 2022
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
## [`main`](https://github.com/elastic/eui/tree/main)

- Added `compressed` prop to `EuiFilterGroup` ([#5717](https://github.com/elastic/eui/pull/5717))
- Updated `testenv` mock for `EuiIcon` to render `aria-label` as text ([#5709](https://github.com/elastic/eui/pull/5709))

**Breaking changes**

- Removed Legacy theme including compiled CSS ([#5688](https://github.com/elastic/eui/pull/5688))
- Removed `flush` and `size` props in `EuiFilterButtonProps` ([#5717](https://github.com/elastic/eui/pull/5717))

## [`51.1.0`](https://github.com/elastic/eui/tree/v51.1.0)

Expand Down
45 changes: 27 additions & 18 deletions src-docs/src/views/filter_group/filter_group_simple.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';

import { EuiFilterGroup, EuiFilterButton } from '../../../../src/components';
import { DisplayToggles } from '../form_controls/display_toggles';

export default () => {
const [isFilterOn, setIsFilterOn] = useState(false);
Expand All @@ -22,23 +23,31 @@ export default () => {
};

return (
<EuiFilterGroup>
<EuiFilterButton hasActiveFilters={isFilterOn} onClick={toggleFilter}>
Single filter
</EuiFilterButton>
<EuiFilterButton
withNext
hasActiveFilters={isOnFilterOn}
onClick={toggleOnFilter}
>
On
</EuiFilterButton>
<EuiFilterButton
hasActiveFilters={isOffFilterOn}
onClick={toggleOffFilter}
>
Off
</EuiFilterButton>
</EuiFilterGroup>
<DisplayToggles
canDisabled={false}
canReadOnly={false}
canLoading={false}
canInvalid={false}
canFullWidth
>
<EuiFilterGroup>
<EuiFilterButton hasActiveFilters={isFilterOn} onClick={toggleFilter}>
Single filter
</EuiFilterButton>
<EuiFilterButton
withNext
hasActiveFilters={isOnFilterOn}
onClick={toggleOnFilter}
>
On
</EuiFilterButton>
<EuiFilterButton
hasActiveFilters={isOffFilterOn}
onClick={toggleOffFilter}
>
Off
</EuiFilterButton>
</EuiFilterGroup>
</DisplayToggles>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiFilterButton does not render a badge or count if numFilters is not passed 1`] = `
<button
aria-label="aria-label"
class="euiButtonEmpty euiButtonEmpty--text euiFilterButton testClass1 testClass2"
data-test-subj="test subject string"
type="button"
>
<span
class="euiButtonContent euiButtonContent--iconRight euiButtonEmpty__content"
>
<span
class="euiButtonEmpty__text"
>
<span
class="euiFilterButton__textShift"
/>
</span>
</span>
</button>
`;

exports[`EuiFilterButton is rendered 1`] = `
<button
aria-label="aria-label"
Expand Down Expand Up @@ -217,24 +238,3 @@ exports[`EuiFilterButton renders zero properly 1`] = `
</span>
</button>
`;

exports[`EuiFilterButton does not render a badge or count if numFilters is not passed 1`] = `
<button
aria-label="aria-label"
class="euiButtonEmpty euiButtonEmpty--text euiFilterButton testClass1 testClass2"
data-test-subj="test subject string"
type="button"
>
<span
class="euiButtonContent euiButtonContent--iconRight euiButtonEmpty__content"
>
<span
class="euiButtonEmpty__text"
>
<span
class="euiFilterButton__textShift"
/>
</span>
</span>
</button>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ exports[`EuiFilterGroup is rendered 1`] = `
/>
`;

exports[`EuiFilterGroup props compressed is rendered 1`] = `
<div
class="euiFilterGroup euiFilterGroup--compressed"
/>
`;

exports[`EuiFilterGroup props fullWidth is rendered 1`] = `
<div
class="euiFilterGroup euiFilterGroup--fullWidth"
Expand Down
10 changes: 7 additions & 3 deletions src/components/filter_group/filter_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import classNames from 'classnames';

import { useEuiI18n } from '../i18n';
import { EuiNotificationBadge } from '../badge/notification_badge';
import { EuiButtonEmpty, EuiButtonEmptyProps } from '../button/button_empty';
import {
EuiButtonEmpty,
EuiButtonEmptyProps,
} from '../button/button_empty/button_empty';
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved

import { useInnerText } from '../inner_text';

export type EuiFilterButtonProps = EuiButtonEmptyProps & {
export type EuiFilterButtonProps = {
/**
* Bolds the button if true
*/
Expand Down Expand Up @@ -47,7 +50,7 @@ export type EuiFilterButtonProps = EuiButtonEmptyProps & {
* Remove border after button, good for opposite filters
*/
noDivider?: boolean;
};
} & Omit<EuiButtonEmptyProps, 'flush' | 'size'>;

export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
children,
Expand Down Expand Up @@ -137,6 +140,7 @@ export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
);

return (
// @ts-ignore type error
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
<EuiButtonEmpty
className={classes}
color={color}
Expand Down
6 changes: 6 additions & 0 deletions src/components/filter_group/filter_group.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ describe('EuiFilterGroup', () => {

expect(component).toMatchSnapshot();
});

test('compressed is rendered', () => {
const component = render(<EuiFilterGroup compressed />);

expect(component).toMatchSnapshot();
});
});
});
6 changes: 6 additions & 0 deletions src/components/filter_group/filter_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ export type EuiFilterGroupProps = HTMLAttributes<HTMLDivElement> &
* Expand the whole bar to fill its parent's width
*/
fullWidth?: boolean;
/**
* When `true` creates a shorter height filter group matching that of `compressed` form controls
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved
*/
compressed?: boolean;
};

export const EuiFilterGroup: FunctionComponent<EuiFilterGroupProps> = ({
children,
className,
fullWidth = false,
compressed,
...rest
}) => {
const classes = classNames(
'euiFilterGroup',
{
'euiFilterGroup--fullWidth': fullWidth,
'euiFilterGroup--compressed': compressed,
},
className
);
Expand Down
15 changes: 15 additions & 0 deletions src/themes/amsterdam/overrides/_filter_group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
box-shadow: inset 0 0 0 1px $euiFormBorderColor;
}

.euiFilterGroup--compressed {
border-radius: $euiFormControlCompressedBorderRadius;

& .euiFilterButton {
height: $euiFormControlCompressedHeight;
}

elizabetdev marked this conversation as resolved.
Show resolved Hide resolved
// Override the size to match the default `.euiNotificationBadge` size
.euiFilterButton__notification {
line-height: $euiSize;
height: $euiSize;
min-width: $euiSize;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right, because you're not applying a size to the filter button itself, there's no way to set size="s" directly on the notification badge.... 🤔

This is kind of a scary override/customization to maintain.

What if it's just always size="s"? And remove any current overrides to the style. It feels a bit large to begin with.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One thing that I did first was to remove the size="m" and when the .euiFilterGroup:not(.euiFilterGroup--compressed) I was extending the .euiNotificationBadge--medium. But I noticed that we don't use Sass extends regularly so I decided to override. 😬

But just leave the default size="s" looks good to me.

}

.euiFilterButton {
border-radius: 0;
border: none;
Expand Down