-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
688b779
commit 34a454e
Showing
7 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> | ||
<EuiBadgeGroup wrap responsive={false} gutterSize="xs"> | ||
{badges.map(badge => ( | ||
<EuiFlexItem grow={false} key={badge}> | ||
<EuiBadge color={badge}>{badge}</EuiBadge> | ||
</EuiFlexItem> | ||
))} | ||
</EuiBadgeGroup> | ||
<EuiSpacer /> | ||
</Fragment> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
$gutterTypes: ( | ||
gutterExtraSmall: $euiSizeXS, | ||
gutterSmall: $euiSizeS, | ||
gutterMedium: $euiSize, | ||
gutterLarge: $euiSizeL, | ||
gutterExtraLarge: $euiSizeXXL, | ||
); | ||
|
||
.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 */ | ||
} | ||
} | ||
|
||
// 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
export interface EuiBadgeGroupProps { | ||
gutterSize?: BadgeGroupGutterSize; | ||
responsive?: boolean; | ||
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 | ||
>( | ||
( | ||
{ | ||
children, | ||
className, | ||
gutterSize = 'l', | ||
responsive = true, | ||
wrap = false, | ||
...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>}> | ||
{children} | ||
</div> | ||
); | ||
} | ||
); | ||
EuiBadgeGroup.displayName = 'EuiBadgeGroup'; | ||
|
||
export { EuiBadgeGroup }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters