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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`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**
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
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: 9 additions & 2 deletions src/components/filter_group/filter_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ 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 = Omit<
EuiButtonEmptyProps,
'flush' | 'size'
> & {
Copy link
Contributor

Choose a reason for hiding this comment

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

On thing that I've noticed with our Props tables in the docs is that it spits out the props in the order that we supply them here. So in this case, the custom filter button props will display after all the EuiButtonEmptyProps. Can I make a suggestion and put this after the filter button props?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also removing these props may be considered a breaking change in case users are in fact using this props?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this is technically a breaking change

/**
* Bolds the button if true
*/
Expand Down Expand Up @@ -137,6 +143,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
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
9 changes: 9 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,15 @@
box-shadow: inset 0 0 0 1px $euiFormBorderColor;
}

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

& .euiFilterButton {
height: $euiButtonHeightSmall;
elizabetdev marked this conversation as resolved.
Show resolved Hide resolved
}
}

elizabetdev marked this conversation as resolved.
Show resolved Hide resolved

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