Skip to content

Commit

Permalink
added comments to props, refactored some code
Browse files Browse the repository at this point in the history
  • Loading branch information
anishagg17 committed Feb 26, 2020
1 parent df3a194 commit 9780db7
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 71 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Created `EuiBadgeGroup` component ([#2921](https://github.com/elastic/eui/pull/2921))
- Converted `EuiComboBox`, `EuiComboBoxInput`, `EuiComboBoxPill`, `EuiComboBoxOptionsList`, `EuiComboBoxOption`, and `EuiComboBoxTitle` to TypeScript ([#2838](https://github.com/elastic/eui/pull/2838))
- Converted `EuiCodeEditor` to TypeScript ([#2836](https://github.com/elastic/eui/pull/2836))
- Converted `EuiCode` and `EuiCodeBlock` and to TypeScript ([#2835](https://github.com/elastic/eui/pull/2835))
Expand All @@ -22,7 +23,6 @@

**Breaking changes**

- Created `EuiBadgeGroup` component ([#2921](https://github.com/elastic/eui/pull/2921))
- 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
29 changes: 8 additions & 21 deletions src-docs/src/views/badge/badge_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,11 @@ import {
EuiBetaBadge,
EuiNotificationBadge,
EuiBadgeGroup,
EuiFlexItem,
EuiCallOut,
} from '../../../../src/components';

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

import Badge from './badge';

const badgeSource = require('!!raw-loader!./badge');
const badgeHtml = renderToHtml(Badge);
const badgeSnippet = [
Expand Down Expand Up @@ -289,17 +279,14 @@ export const BadgeExample = {
code: badgeGroupHtml,
},
],
text: <p>Used to group Badges together </p>,
props: { EuiBadgeGroup },
demo: (
<EuiBadgeGroup wrap responsive={false} gutterSize="xs">
{badges.map(badge => (
<EuiFlexItem grow={false} key={badge}>
<EuiBadge color={badge}>{badge}</EuiBadge>
</EuiFlexItem>
))}
</EuiBadgeGroup>
text: (
<p>
Grouping badges with EuiBadgeGroup, ensures they wrap and truncate
properly.
</p>
),
props: { EuiBadgeGroup },
demo: <BadgeGroup />,
},
],
};
7 changes: 0 additions & 7 deletions src-docs/src/views/badge/badge_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import React, { Fragment } from 'react';
import {
EuiBadge,
EuiFlexItem,
EuiSpacer,
EuiBadgeGroup,
EuiTitle,
} from '../../../../src/components';

const badges = [
Expand All @@ -21,18 +19,13 @@ const badges = [
export default () => {
return (
<Fragment>
<EuiTitle size="xs">
<h3>Badge Group</h3>
</EuiTitle>
<EuiSpacer size="m" />
<EuiBadgeGroup wrap responsive={false} gutterSize="xs">
{badges.map(badge => (
<EuiFlexItem grow={false} key={badge}>
<EuiBadge color={badge}>{badge}</EuiBadge>
</EuiFlexItem>
))}
</EuiBadgeGroup>
<EuiSpacer />
</Fragment>
);
};
26 changes: 26 additions & 0 deletions src/components/badge/__snapshots__/badge_group.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiBadgeGroup is rendered 1`] = `
<div
aria-label="aria-label"
class="euiBadgeGroup euiBadgeGroup--gutterExtraSmall euiBadgeGroup--responsive euiBadgeGroup--wrap testClass1 testClass2"
data-test-subj="test subject string"
>
<span
aria-label="aria-label"
class="euiBadge euiBadge-isDisabled euiBadge--iconLeft testClass1 testClass2"
data-test-subj="test subject string"
style="background-color:#d3dae6;color:#000"
>
<span
class="euiBadge__content"
>
<span
class="euiBadge__text"
>
Content
</span>
</span>
</span>
</div>
`;
50 changes: 25 additions & 25 deletions src/components/badge/_badge_group.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$euiGutterTypes: (
$gutterTypes: (
gutterExtraSmall: $euiSizeXS,
gutterSmall: $euiSizeS,
gutterMedium: $euiSize,
Expand All @@ -7,43 +7,43 @@ $euiGutterTypes: (
);

.euiBadgeGroup {
display: flex;
align-items: center;
flex-flow: row;
flex-grow: 1; /* 1 */

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

flex-grow: 1;
flex-basis: 0%; /* 2 */
display: flex;
align-items: center;
flex-flow: row;
flex-grow: 1;

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

flex-grow: 1;
flex-basis: 0%;
}
}

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

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

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

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

@include euiBreakpoint('xs', 's') {
.euiBadgeGroup--responsive {
flex-wrap: wrap;
margin-left: 0;
margin-right: 0;
}
.euiBadgeGroup--responsive {
flex-wrap: wrap;
margin-left: 0;
margin-right: 0;
}
}
1 change: 1 addition & 0 deletions src/components/badge/_index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import 'badge';
@import 'badge_group';
@import 'beta_badge/index';
@import 'notification_badge/index';
20 changes: 20 additions & 0 deletions src/components/badge/badge_group.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';

import { EuiBadge } from './badge';
import { EuiBadgeGroup } from './badge_group';

describe('EuiBadgeGroup', () => {
test('is rendered', () => {
const component = render(
<EuiBadgeGroup {...requiredProps}>
<EuiBadge isDisabled {...requiredProps}>
Content
</EuiBadge>
</EuiBadgeGroup>
);

expect(component).toMatchSnapshot();
});
});
32 changes: 15 additions & 17 deletions src/components/badge/badge_group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,42 @@ import { CommonProps, keysOf } from '../common';
type BadgeGroupGutterSize = keyof typeof gutterSizeToClassNameMap;

export interface EuiBadgeGroupProps {
/**
* Space between badges
*/
gutterSize?: BadgeGroupGutterSize;
/**
* Force each badges to be display block on smaller screens
*/
responsive?: boolean;
/**
* Force each badge to wrap if necessary
*/
wrap?: boolean;
}

const gutterSizeToClassNameMap = {
none: null,
xs: 'euiBadgeGroup--gutterExtraSmall',
s: 'euiBadgeGroup--gutterSmall',
m: 'euiBadgeGroup--gutterMedium',
l: 'euiBadgeGroup--gutterLarge',
xl: 'euiBadgeGroup--gutterExtraLarge',
};

export const GUTTER_SIZES = keysOf(gutterSizeToClassNameMap);
export type EuiBadgeGroupGutterSize = keyof typeof gutterSizeToClassNameMap;

const EuiBadgeGroup = React.forwardRef<
HTMLDivElement | HTMLSpanElement,
CommonProps &
HTMLAttributes<HTMLDivElement | HTMLSpanElement> &
EuiBadgeGroupProps
export const EuiBadgeGroup = React.forwardRef<
HTMLDivElement,
CommonProps & HTMLAttributes<HTMLDivElement> & EuiBadgeGroupProps
>(
(
{
children,
className,
gutterSize = 'xs',
responsive = true,
wrap = false,
wrap = true,
...rest
},
ref: Ref<HTMLDivElement> | Ref<HTMLSpanElement>
ref: Ref<HTMLDivElement>
) => {
const classes = classNames(
'euiBadgeGroup',
Expand All @@ -50,15 +53,10 @@ const EuiBadgeGroup = React.forwardRef<
);

return (
<div
className={classes}
ref={ref as Ref<HTMLDivElement>}
{...rest as HTMLAttributes<HTMLDivElement>}>
<div className={classes} ref={ref} {...rest}>
{children}
</div>
);
}
);
EuiBadgeGroup.displayName = 'EuiBadgeGroup';

export { EuiBadgeGroup };

0 comments on commit 9780db7

Please sign in to comment.