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

[EuiBetaBadge] Add color and size props and support for click event #4798

Merged
merged 17 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `34.1.0`.
- Added `color` and `size` props and added support for click event to `EuiBetaBadge` ([#4798](https://github.com/elastic/eui/pull/4798))

## [`34.1.0`](https://github.com/elastic/eui/tree/v34.1.0)

Expand Down
2 changes: 2 additions & 0 deletions src-docs/src/views/badge/badge_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ export const BadgeExample = {
If you pass in an <EuiCode>iconType</EuiCode>, only the icon will be
used in the badge itself and the label will be applied as the title.
Only use an icon when attaching the beta badge to small components.
Beta badges can also be made clickable by passing{' '}
<EuiCode>href</EuiCode> or <EuiCode>onClick</EuiCode> as needed.
</p>
<p>
They can also be used in conjunction with{' '}
Expand Down
58 changes: 43 additions & 15 deletions src-docs/src/views/badge/beta_badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@ import React from 'react';

import { EuiBetaBadge, EuiSpacer, EuiTitle } from '../../../../src/components';

const colors = ['hollow', 'accent', 'subdued'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we support all the badge colors and also allow to use custom color examples?

Screenshot 2021-05-14 at 14 39 44

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I wonder if the beta badge's use cases are better suited for a limited set of colors. Likely @cchaos can weigh in as I think she's the one who proposed adding two more colors only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could sway either way, keeping it limited may help users notice it more since they tend to mark product features. If we were to change the set to accept the same as regular badges, are they then any different really? I would then consider if there's any real necessity to keep separate components. But I'd suggest starting a more targeted discussion for that and keep this PR scoped to the current changeset.


export default () => (
<div>
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
<EuiBetaBadge
label="Beta"
tooltipContent="This module is not GA. Please help us by reporting any bugs."
/>
&emsp;
<EuiBetaBadge
label="Lab"
title="Laboratory"
tooltipContent="This module is not GA. Please help us by reporting any bugs."
/>
&emsp;
<EuiBetaBadge label="Lab" iconType="beaker" />
&emsp;
<EuiBetaBadge label="Lens" iconType="lensApp" />
<EuiSpacer />
{colors.map((item, index) => (
<div key={index}>
<EuiBetaBadge
label="Beta"
color={item}
tooltipContent="This module is not GA. Please help us by reporting any bugs."
/>
&emsp;
<EuiBetaBadge
label="Beta"
color={item}
size="s"
tooltipContent="This module is not GA. Please help us by reporting any bugs."
/>
&emsp;
<EuiBetaBadge label="B" color={item} />
&emsp;
<EuiBetaBadge size="s" label="B" color={item} />
&emsp;
<EuiBetaBadge label="Lab" color={item} iconType="beaker" />
&emsp;
<EuiBetaBadge label="Lab" size="s" color={item} iconType="beaker" />
<EuiSpacer size="s" />
</div>
))}
<EuiSpacer size="s" />
<EuiTitle size="s">
<h3>
Beta badges will also line up nicely with titles &nbsp;
Expand All @@ -28,5 +41,20 @@ export default () => (
/>
</h3>
</EuiTitle>
<EuiTitle size="xxs">
<h4>Clickable beta badges</h4>
</EuiTitle>
<EuiSpacer size="s" />
<EuiBetaBadge
label="Lens"
iconType="lensApp"
onClick={() => alert('Goes to Lens')}
/>
&emsp;
<EuiBetaBadge
label="Basic"
href="http://www.elastic.co/subscriptions"
target="_blank"
/>
</div>
);
25 changes: 22 additions & 3 deletions src-docs/src/views/card/card_beta.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
EuiFlexItem,
} from '../../../../src/components';

const icons = ['dashboard', 'monitoring', 'watches'];
const badges = [null, 'Beta', 'Lab'];
const icons = ['dashboard', 'monitoring'];
const badges = [null, 'Beta'];

const cardNodes = icons.map(function (item, index) {
return (
Expand All @@ -29,4 +29,23 @@ const cardNodes = icons.map(function (item, index) {
);
});

export default () => <EuiFlexGroup gutterSize="l">{cardNodes} </EuiFlexGroup>;
export default () => (
<EuiFlexGroup gutterSize="l">
{cardNodes}
<EuiFlexItem>
<EuiCard
icon={<EuiIcon size="xxl" type="lensApp" />}
title="Lens"
isDisabled
description="Disabled cards can have active links using EuiBetaBadge."
betaBadgeProps={{
href: 'http://www.elastic.co/subscriptions',
target: '_blank',
}}
betaBadgeLabel="Basic"
betaBadgeTooltipContent="This feature requires a Basic License"
onClick={() => {}}
/>
</EuiFlexItem>
</EuiFlexGroup>
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,55 @@
exports[`EuiBetaBadge is rendered 1`] = `
<span
aria-label="aria-label"
class="euiBetaBadge testClass1 testClass2"
class="euiBetaBadge euiBetaBadge--hollow testClass1 testClass2"
data-test-subj="test subject string"
title="Beta"
>
Beta
</span>
`;

exports[`EuiBetaBadge props color accent is rendered 1`] = `
<span
class="euiBetaBadge euiBetaBadge--accent"
title="Beta"
>
Beta
</span>
`;

exports[`EuiBetaBadge props color hollow is rendered 1`] = `
<span
class="euiBetaBadge euiBetaBadge--hollow"
title="Beta"
>
Beta
</span>
`;

exports[`EuiBetaBadge props color subdued is rendered 1`] = `
<span
class="euiBetaBadge euiBetaBadge--subdued"
title="Beta"
>
Beta
</span>
`;

exports[`EuiBetaBadge props size m is rendered 1`] = `
<span
class="euiBetaBadge euiBetaBadge--hollow"
title="Beta"
>
Beta
</span>
`;

exports[`EuiBetaBadge props size s is rendered 1`] = `
<span
class="euiBetaBadge euiBetaBadge--hollow euiBetaBadge--small"
title="Beta"
>
Beta
</span>
`;
53 changes: 53 additions & 0 deletions src/components/badge/beta_badge/_beta_badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
&:focus {
@include euiFocusRing;
}

&:not(.euiBetaBadge--hollow) {
box-shadow: none;
}

&.euiBetaBadge--small {
@include fontSize($euiFontSize * .625);
line-height: $euiSize + $euiSizeXS;
padding: 0 $euiSizeM;
}

}

// When it's just an icon, make it a circle
Expand All @@ -28,4 +39,46 @@
position: relative;
margin-top: -1px;
}

&.euiBetaBadge--small {
width: $euiSize + $euiSizeXS;
padding: 0;
}
}

.euiBetaBadge--singleLetter {
padding: 0 0 0 1px;
width: $euiSizeL;

&.euiBetaBadge--small {
width: $euiSize + $euiSizeXS;
padding: 0 0 0 1px;
}
}

.euiBetaBadge--subdued {
$backgroundColor: tint($euiColorLightShade, 30%);
background: $backgroundColor;
color: chooseLightOrDarkText($backgroundColor, $euiColorGhost, $euiColorInk);

&.euiBetaBadge-isClickable {
color: chooseLightOrDarkText($backgroundColor, $euiColorGhost, $euiColorInk);
}
}

.euiBetaBadge--hollow {
&.euiBetaBadge-isClickable {
$backgroundColor: tint($euiColorLightShade, 30%);
color: chooseLightOrDarkText($backgroundColor, $euiColorGhost, $euiColorInk);
}
}

.euiBetaBadge--accent {
$backgroundColor: $euiColorAccentText;
background: $backgroundColor;
color: chooseLightOrDarkText($backgroundColor, $euiColorGhost, $euiColorInk);

&.euiBetaBadge-isClickable {
color: chooseLightOrDarkText($backgroundColor, $euiColorGhost, $euiColorInk);
}
}
24 changes: 23 additions & 1 deletion src/components/badge/beta_badge/beta_badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,34 @@ import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../../test';

import { EuiBetaBadge } from './beta_badge';
import { EuiBetaBadge, COLORS, SIZES } from './beta_badge';

describe('EuiBetaBadge', () => {
test('is rendered', () => {
const component = render(<EuiBetaBadge label="Beta" {...requiredProps} />);

expect(component).toMatchSnapshot();
});

describe('props', () => {
describe('color', () => {
COLORS.forEach((color) => {
test(`${color} is rendered`, () => {
const component = render(<EuiBetaBadge label="Beta" color={color} />);

expect(component).toMatchSnapshot();
});
});
});

describe('size', () => {
SIZES.forEach((size) => {
test(`${size} is rendered`, () => {
const component = render(<EuiBetaBadge label="Beta" size={size} />);

expect(component).toMatchSnapshot();
});
});
});
});
});
Loading