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,11 +1,13 @@
## [`main`](https://github.com/elastic/eui/tree/main)

- Added `compressed` prop to `EuiFilterGroup` and reduced the size of the `EuiFilterButton` notification badge ([#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))
- Added `editorChecklist` glyph to `EuiIcon` ([#5705](https://github.com/elastic/eui/pull/5705))

**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 @@ -119,7 +140,7 @@ exports[`EuiFilterButton props numActiveFilters and hasActiveFilters is rendered
/>
<span
aria-label="5 active filters"
class="euiNotificationBadge euiNotificationBadge--medium euiFilterButton__notification"
class="euiNotificationBadge euiFilterButton__notification"
>
5
</span>
Expand All @@ -144,7 +165,7 @@ exports[`EuiFilterButton props numFilters is rendered 1`] = `
/>
<span
aria-label="5 available filters"
class="euiNotificationBadge euiNotificationBadge--medium euiNotificationBadge--subdued euiFilterButton__notification"
class="euiNotificationBadge euiNotificationBadge--subdued euiFilterButton__notification"
>
5
</span>
Expand Down Expand Up @@ -209,32 +230,11 @@ exports[`EuiFilterButton renders zero properly 1`] = `
/>
<span
aria-label="0 available filters"
class="euiNotificationBadge euiNotificationBadge--medium euiNotificationBadge--subdued euiFilterButton__notification"
class="euiNotificationBadge euiNotificationBadge--subdued euiFilterButton__notification"
>
0
</span>
</span>
</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
11 changes: 7 additions & 4 deletions src/components/filter_group/filter_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ 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';
import { DistributiveOmit } from '../common';

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

export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
children,
Expand Down Expand Up @@ -107,7 +111,6 @@ export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
const badgeContent = showBadge && (
<EuiNotificationBadge
className="euiFilterButton__notification"
size="m"
aria-label={hasActiveFilters ? activeBadgeLabel : availableBadgeLabel}
color={isDisabled || !hasActiveFilters ? 'subdued' : 'accent'}
>
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
8 changes: 8 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,14 @@
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
.euiFilterButton {
border-radius: 0;
border: none;
Expand Down