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

[EUI] Improve EuiFilterButton badge i18n #5061

Merged
merged 7 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Fixed rerender state issues in `PaginationButton` inside `EuiPagination` ([#5048](https://github.com/elastic/eui/pull/5048))
- Fixed bug in `euiHeaderAffordForFixed` mixin that was not accounting for situations where `EuiDataGrid` was in full screen mode ([#5054](https://github.com/elastic/eui/pull/5054))
- Fixed `z-index` styles that were causing `EuiModal` and `EuiFlyout` components to appear behind `EuiDataGrid` when in full screen mode ([#5054](https://github.com/elastic/eui/pull/5054))
- Fixed untranslated i18n strings for `EuiFilterButton` - adds 2 new tokens and removes old `euiFilterButton.filterBadge` token ([#4750](https://github.com/elastic/eui/pull/5061))

**Theme: Amsterdam**

Expand Down
56 changes: 26 additions & 30 deletions src/components/filter_group/filter_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import React, { Fragment, FunctionComponent } from 'react';
import classNames from 'classnames';

import { EuiI18n } from '../i18n';
import { useEuiI18n } from '../i18n';
import { EuiNotificationBadge } from '../badge/notification_badge';
import { EuiButtonEmpty, EuiButtonEmptyProps } from '../button/button_empty';

Expand Down Expand Up @@ -67,8 +67,8 @@ export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
textProps,
...rest
}) => {
// != instead of !== to allow for null and undefined
const numFiltersDefined = numFilters != null;
const numFiltersDefined = numFilters != null; // != instead of !== to allow for null and undefined
const numActiveFiltersDefined = numActiveFilters && numActiveFilters > 0;

const classes = classNames(
'euiFilterButton',
Expand All @@ -91,10 +91,28 @@ export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
textProps && textProps.className
);

let activeFilters;
if (numActiveFilters && numActiveFilters > 0) {
activeFilters = true;
}
const showBadge = numFiltersDefined || numActiveFiltersDefined;
const badgeCount = numActiveFilters || numFilters;
const activeBadgeLabel = useEuiI18n(
'euiFilterButton.filterBadgeActiveAriaLabel',
'{count} active filters',
{ count: badgeCount }
);
const availableBadgeLabel = useEuiI18n(
'euiFilterButton.filterBadgeAvailableAriaLabel',
'{count} available filters',
{ count: badgeCount }
);
const badgeContent = showBadge && (
<EuiNotificationBadge
className="euiFilterButton__notification"
size="m"
aria-label={hasActiveFilters ? activeBadgeLabel : availableBadgeLabel}
color={isDisabled || !hasActiveFilters ? 'subdued' : 'accent'}
>
{badgeCount}
</EuiNotificationBadge>
);

let dataText;
if (typeof children === 'string') {
Expand All @@ -113,29 +131,7 @@ export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
{children}
</span>

{(numFiltersDefined || activeFilters) && (
<EuiI18n
token="euiFilterButton.filterBadge"
values={{
count: numActiveFilters || numFilters,
hasActiveFilters: hasActiveFilters ? 'active' : 'available',
}}
default="{count} {hasActiveFilters} filters"
>
{(filterBadge: string) => {
return (
<EuiNotificationBadge
className="euiFilterButton__notification"
size="m"
aria-label={filterBadge}
color={isDisabled || !hasActiveFilters ? 'subdued' : 'accent'}
>
{numActiveFilters || numFilters}
</EuiNotificationBadge>
);
}}
</EuiI18n>
)}
{badgeContent}
</Fragment>
);

Expand Down