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

added badge group component #2921

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -22,6 +22,7 @@

**Breaking changes**

- Created `EuiBadgeGroup` component ([#2921](https://github.com/elastic/eui/pull/2921))
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
- Removed `visControls` and `visHeatmap` duplicate icons from docs ([#2908](https://github.com/elastic/eui/pull/2908))

## [`19.0.0`](https://github.com/elastic/eui/tree/v19.0.0)
Expand Down
40 changes: 40 additions & 0 deletions src-docs/src/views/badge/badge_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ import {
EuiCode,
EuiBetaBadge,
EuiNotificationBadge,
EuiBadgeGroup,
EuiFlexItem,
EuiCallOut,
} from '../../../../src/components';

const badges = [
'default',
'hollow',
'primary',
'secondary',
'accent',
'warning',
'danger',
];
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved

import Badge from './badge';
const badgeSource = require('!!raw-loader!./badge');
const badgeHtml = renderToHtml(Badge);
Expand Down Expand Up @@ -91,6 +103,10 @@ const notificationBadgeHtml = renderToHtml(NotificationBadge);
const notificationBadgeSnippet = `<EuiNotificationBadge>3</EuiNotificationBadge>
`;

import BadgeGroup from './badge_group';
const badgeGroupSource = require('!!raw-loader!./badge_group');
const badgeGroupHtml = renderToHtml(BadgeGroup);

export const BadgeExample = {
title: 'Badge',
sections: [
Expand Down Expand Up @@ -261,5 +277,29 @@ export const BadgeExample = {
snippet: notificationBadgeSnippet,
demo: <NotificationBadge />,
},
{
title: 'Badge Group',
source: [
{
type: GuideSectionTypes.JS,
code: badgeGroupSource,
},
{
type: GuideSectionTypes.HTML,
code: badgeGroupHtml,
},
],
text: <p>Used to group Badges together </p>,
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
props: { EuiBadgeGroup },
demo: (
<EuiBadgeGroup wrap responsive={false} gutterSize="xs">
{badges.map(badge => (
<EuiFlexItem grow={false} key={badge}>
<EuiBadge color={badge}>{badge}</EuiBadge>
</EuiFlexItem>
))}
</EuiBadgeGroup>
),
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
},
],
};
38 changes: 38 additions & 0 deletions src-docs/src/views/badge/badge_group.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { Fragment } from 'react';

import {
EuiBadge,
EuiFlexItem,
EuiSpacer,
EuiBadgeGroup,
EuiTitle,
} from '../../../../src/components';

const badges = [
'default',
'hollow',
'primary',
'secondary',
'accent',
'warning',
'danger',
];

export default () => {
return (
<Fragment>
<EuiTitle size="xs">
<h3>Badge Group</h3>
</EuiTitle>
<EuiSpacer size="m" />
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
<EuiBadgeGroup wrap responsive={false} gutterSize="xs">
{badges.map(badge => (
<EuiFlexItem grow={false} key={badge}>
<EuiBadge color={badge}>{badge}</EuiBadge>
</EuiFlexItem>
))}
</EuiBadgeGroup>
<EuiSpacer />
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
</Fragment>
);
};
49 changes: 49 additions & 0 deletions src/components/badge/_badge_group.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
$gutterTypes: (
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
gutterExtraSmall: $euiSizeXS,
gutterSmall: $euiSizeS,
gutterMedium: $euiSize,
gutterLarge: $euiSizeL,
gutterExtraLarge: $euiSizeXXL,
);

.euiBadgeGroup {
display: flex;
align-items: center;
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
flex-flow: row;
flex-grow: 1; /* 1 */
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved

.euiBadgeItem {
@include internetExplorerOnly {
min-width: 1px;
}

flex-grow: 1;
flex-basis: 0%; /* 2 */
}
}

// Gutter Sizes
@each $gutterName, $gutterSize in $gutterTypes {
$halfGutterSize: $gutterSize * .5;

.euiBadgeGroup--#{$gutterName} {
margin: -$halfGutterSize;

& > .euiBadgeItem {
margin: $halfGutterSize;
}
}
}

// Wrap
.euiBadgeGroup--wrap {
flex-wrap: wrap;
}

@include euiBreakpoint('xs', 's') {
.euiBadgeGroup--responsive {
flex-wrap: wrap;
margin-left: 0;
margin-right: 0;
}
}
64 changes: 64 additions & 0 deletions src/components/badge/badge_group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, { HTMLAttributes, Ref } from 'react';
import classNames from 'classnames';
import { CommonProps, keysOf } from '../common';

export type BadgeGroupGutterSize = keyof typeof gutterSizeToClassNameMap;
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved

export interface EuiBadgeGroupProps {
gutterSize?: BadgeGroupGutterSize;
responsive?: boolean;
wrap?: boolean;
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
}

const gutterSizeToClassNameMap = {
none: null,
xs: 'euiBadgeGroup--gutterExtraSmall',
s: 'euiBadgeGroup--gutterSmall',
m: 'euiBadgeGroup--gutterMedium',
l: 'euiBadgeGroup--gutterLarge',
xl: 'euiBadgeGroup--gutterExtraLarge',
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
};

export const GUTTER_SIZES = keysOf(gutterSizeToClassNameMap);
export type EuiBadgeGroupGutterSize = keyof typeof gutterSizeToClassNameMap;
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved

const EuiBadgeGroup = React.forwardRef<
cchaos marked this conversation as resolved.
Show resolved Hide resolved
HTMLDivElement | HTMLSpanElement,
CommonProps &
HTMLAttributes<HTMLDivElement | HTMLSpanElement> &
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
EuiBadgeGroupProps
>(
(
{
children,
className,
gutterSize = 'l',
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
responsive = true,
wrap = false,
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
...rest
},
ref: Ref<HTMLDivElement> | Ref<HTMLSpanElement>
) => {
const classes = classNames(
'euiBadgeGroup',
gutterSizeToClassNameMap[gutterSize as BadgeGroupGutterSize],
{
'euiBadgeGroup--responsive': responsive,
'euiBadgeGroup--wrap': wrap,
},
className
);

return (
<div
className={classes}
ref={ref as Ref<HTMLDivElement>}
{...rest as HTMLAttributes<HTMLDivElement>}>
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
{children}
</div>
);
}
);
EuiBadgeGroup.displayName = 'EuiBadgeGroup';

export { EuiBadgeGroup };
anishagg17 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/components/badge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export { EuiBadge, EuiBadgeProps } from './badge';
export { EuiBetaBadge } from './beta_badge';

export { EuiNotificationBadge } from './notification_badge';

export { EuiBadgeGroup } from './badge_group';
7 changes: 6 additions & 1 deletion src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ export { EuiAvatar } from './avatar';

export { EuiKeyboardAccessible, EuiScreenReaderOnly } from './accessibility';

export { EuiBadge, EuiBetaBadge, EuiNotificationBadge } from './badge';
export {
EuiBadge,
EuiBetaBadge,
EuiNotificationBadge,
EuiBadgeGroup,
} from './badge';

export { EuiBottomBar } from './bottom_bar';

Expand Down