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

[EuiNotificationBadge] Add success color #6864

Merged
merged 9 commits into from
Jun 23, 2023
17 changes: 15 additions & 2 deletions src-docs/src/views/badge/notification_badge.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import React from 'react';

import { EuiNotificationBadge } from '../../../../src/components/badge/notification_badge';
import {
EuiFlexGroup,
EuiFlexItem,
EuiNotificationBadge,
} from '../../../../src/components';

export default () => <EuiNotificationBadge>3</EuiNotificationBadge>;
export default () => (
<EuiFlexGroup responsive={false} gutterSize="s">
<EuiFlexItem grow={false}>
<EuiNotificationBadge>3</EuiNotificationBadge>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiNotificationBadge color="success">3</EuiNotificationBadge>
</EuiFlexItem>
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
</EuiFlexGroup>
);
1 change: 1 addition & 0 deletions src-docs/src/views/filter_group/filter_group_multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default () => {
const button = (
<EuiFilterButton
iconType="arrowDown"
badgeColor="success"
onClick={onButtonClick}
isSelected={isPopoverOpen}
numFilters={items.filter((item) => item.checked !== 'off').length}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ exports[`EuiNotificationBadge props color subdued is rendered 1`] = `
</span>
`;

exports[`EuiNotificationBadge props color success is rendered 1`] = `
<span
class="euiNotificationBadge emotion-euiNotificationBadge-s-success"
>
5
</span>
`;

exports[`EuiNotificationBadge props size m is rendered 1`] = `
<span
class="euiNotificationBadge emotion-euiNotificationBadge-m-accent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
mathWithUnits,
} from '../../../global_styling';
import { UseEuiTheme, tint } from '../../../services';

import { euiButtonFillColor } from '../../../themes/amsterdam/global_styling/mixins';
import { getBadgeColors } from '../beta_badge/beta_badge.styles';

export const euiNotificationBadgeStyles = (euiThemeContext: UseEuiTheme) => {
Expand Down Expand Up @@ -57,6 +57,11 @@ export const euiNotificationBadgeStyles = (euiThemeContext: UseEuiTheme) => {
accent: css`
${getBadgeColors(euiTheme.colors.accentText, euiThemeContext)}
`,
success: css`
background-color: ${euiButtonFillColor(euiThemeContext, 'success')
.backgroundColor};
color: ${euiTheme.colors.ink};
`,
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
subdued: css`
${getBadgeColors(tint(euiTheme.colors.lightShade, 0.3), euiThemeContext)}
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useEuiTheme } from '../../../services';

import { euiNotificationBadgeStyles } from './badge_notification.styles';

export const COLORS = ['accent', 'subdued'] as const;
export const COLORS = ['accent', 'subdued', 'success'] as const;
export type BadgeNotificationColor = (typeof COLORS)[number];

export const SIZES = ['s', 'm'] as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ exports[`EuiFilterButton is rendered 1`] = `
</button>
`;

exports[`EuiFilterButton props badgeColor is rendered 1`] = `
<button
class="euiButtonEmpty euiFilterButton css-wvaqcf-empty-text"
type="button"
>
<span
class="euiButtonContent euiButtonContent--iconRight euiButtonEmpty__content"
>
<span
class="euiButtonEmpty__text"
>
<span
class="euiFilterButton__textShift"
/>
</span>
</span>
</button>
`;

exports[`EuiFilterButton props grow can be turned off 1`] = `
<button
class="euiButtonEmpty euiFilterButton euiFilterButton--noGrow css-wvaqcf-empty-text"
Expand Down
8 changes: 8 additions & 0 deletions src/components/filter_group/filter_button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,13 @@ describe('EuiFilterButton', () => {
expect(component).toMatchSnapshot();
});
});

describe('badgeColor', () => {
it('is rendered', () => {
const component = render(<EuiFilterButton badgeColor="success" />);

expect(component).toMatchSnapshot();
});
});
});
});
10 changes: 9 additions & 1 deletion src/components/filter_group/filter_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { EuiButtonEmpty, EuiButtonEmptyProps } from '../button/button_empty';
import { useInnerText } from '../inner_text';
import { DistributiveOmit } from '../common';

export const COLORS = ['accent', 'success'] as const;
export type BadgeNotificationColor = (typeof COLORS)[number];
cee-chen marked this conversation as resolved.
Show resolved Hide resolved

export type EuiFilterButtonProps = {
/**
* Bolds the button if true
Expand Down Expand Up @@ -43,6 +46,10 @@ export type EuiFilterButtonProps = {
* Remove border after button, good for opposite filters
*/
withNext?: boolean;
/**
* Change color of the counter badge
*/
badgeColor?: BadgeNotificationColor;
} & DistributiveOmit<EuiButtonEmptyProps, 'flush' | 'size'>;

export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
Expand All @@ -51,6 +58,7 @@ export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
iconType,
iconSide = 'right',
color = 'text',
badgeColor = 'accent',
hasActiveFilters,
numFilters,
numActiveFilters,
Expand Down Expand Up @@ -103,7 +111,7 @@ export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
<EuiNotificationBadge
className="euiFilterButton__notification"
aria-label={hasActiveFilters ? activeBadgeLabel : availableBadgeLabel}
color={isDisabled || !hasActiveFilters ? 'subdued' : 'accent'}
color={isDisabled || !hasActiveFilters ? 'subdued' : badgeColor}
role="marquee" // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/marquee_role
>
{badgeCount}
Expand Down
2 changes: 2 additions & 0 deletions upcoming_changelogs/6864.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added success color `EuiNotificationBadge`
- Added `badgeColor` prop to `EuiFilterButton`