Date: Thu, 26 Apr 2018 14:42:23 -0400
Subject: [PATCH 4/4] Addressing PR comments
- Fixing use of font-size variables
- Adding example of badge inline with title
- Max-widthed the card version
- Now always using the label as the tooltip title or title attr if title is not supplied
- Fixing naming conventions to better suit imported components
- Allowing icon only badges
---
src-docs/src/views/badge/badge_example.js | 9 +++-
src-docs/src/views/badge/beta_badge.js | 13 ++++-
src-docs/src/views/card/card_beta.js | 4 +-
src-docs/src/views/card/card_example.js | 5 +-
.../src/views/key_pad_menu/key_pad_beta.js | 9 ++--
.../key_pad_menu/key_pad_menu_example.js | 17 +++++--
src/components/badge/_badge.scss | 2 +-
.../__snapshots__/beta_badge.test.js.snap | 1 +
.../badge/beta_badge/_beta_badge.scss | 17 +++++--
src/components/badge/beta_badge/beta_badge.js | 48 ++++++++++++++-----
src/components/card/_card.scss | 6 +++
src/components/card/card.js | 22 +++++----
.../key_pad_menu/_key_pad_menu.scss | 4 +-
.../key_pad_menu/key_pad_menu_item.js | 38 ++++++++++-----
14 files changed, 142 insertions(+), 53 deletions(-)
diff --git a/src-docs/src/views/badge/badge_example.js b/src-docs/src/views/badge/badge_example.js
index 8fee1ae6cce..c8358ed3ab0 100644
--- a/src-docs/src/views/badge/badge_example.js
+++ b/src-docs/src/views/badge/badge_example.js
@@ -96,7 +96,14 @@ export const BadgeExample = {
The EuiBetaBadge was created specifically to call out
modules that are not in GA. Generally the labels used are "Beta" or "Lab".
- They require an extra description that will be presented in a tooltip.
+ They require an extra tooltipContent to describe the purpose of the badge.
+ You can pass an optional title prop to populate the tooltip title or html title
+ attribute but by default it will use the label.
+
+
+ If you pass in an iconType, 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 like the EuiKeyPadMenuItem.
They can also be used in conjunction
diff --git a/src-docs/src/views/badge/beta_badge.js b/src-docs/src/views/badge/beta_badge.js
index d3180d2f4a6..04a5a2c8456 100644
--- a/src-docs/src/views/badge/beta_badge.js
+++ b/src-docs/src/views/badge/beta_badge.js
@@ -2,12 +2,21 @@ import React from 'react';
import {
EuiBetaBadge,
+ EuiSpacer,
+ EuiTitle,
} from '../../../../src/components';
export default () => (
-
+
-
+
+
+
+
+
+
+ Beta badges will also line up nicely with titles
+
);
diff --git a/src-docs/src/views/card/card_beta.js b/src-docs/src/views/card/card_beta.js
index d5796aaf130..15f4f8f78f9 100644
--- a/src-docs/src/views/card/card_beta.js
+++ b/src-docs/src/views/card/card_beta.js
@@ -17,8 +17,8 @@ const cardNodes = icons.map(function (item, index) {
icon={}
title={`Kibana ${item}`}
description="Example of a card's description. Stick to one or two sentences."
- betaLabel={badges[index]}
- betaDescription={badges[index] ? "This module is not GA. Please help us by reporting any bugs." : undefined}
+ betaBadgeLabel={badges[index]}
+ betaBadgeTooltipContent={badges[index] ? "This module is not GA. Please help us by reporting any bugs." : undefined}
onClick={() => window.alert('Card clicked')}
/>
diff --git a/src-docs/src/views/card/card_example.js b/src-docs/src/views/card/card_example.js
index 7ea2670d2eb..d8baa7dee52 100644
--- a/src-docs/src/views/card/card_example.js
+++ b/src-docs/src/views/card/card_example.js
@@ -108,8 +108,9 @@ export const CardExample = {
text: (
If the card links to or references a module that is not GA (beta, lab, etc),
- you can add a betaLabel and betaDescription to
- the card and it will properly create and position an EuiBetaBadge.
+ you can add a betaBadgeLabel and betaBadgeTooltipContent to
+ the card and it will properly create and position an EuiBetaBadge. If you want to
+ change the title of the tooltip, supply a betaBadgeTitle prop.
),
components: { EuiCard },
diff --git a/src-docs/src/views/key_pad_menu/key_pad_beta.js b/src-docs/src/views/key_pad_menu/key_pad_beta.js
index 8571eac6584..fcfec82f735 100644
--- a/src-docs/src/views/key_pad_menu/key_pad_beta.js
+++ b/src-docs/src/views/key_pad_menu/key_pad_beta.js
@@ -18,8 +18,8 @@ export default () => (
@@ -27,8 +27,9 @@ export default () => (
diff --git a/src-docs/src/views/key_pad_menu/key_pad_menu_example.js b/src-docs/src/views/key_pad_menu/key_pad_menu_example.js
index 06a85de2bd1..4a0962d2364 100644
--- a/src-docs/src/views/key_pad_menu/key_pad_menu_example.js
+++ b/src-docs/src/views/key_pad_menu/key_pad_menu_example.js
@@ -68,11 +68,18 @@ export const KeyPadMenuExample = {
code: keyPadBetaHtml,
}],
text: (
-
- If the item links to a module that is not GA (beta, lab, etc),
- you can add a betaLabel and betaDescription to
- the card and it will properly create and position an EuiBetaBadge.
-
+
+
+ If the item links to a module that is not GA (beta, lab, etc),
+ you can add a betaBadgeLabel and betaBadgeTooltipContent to
+ the card and it will properly create and position an EuiBetaBadge.
+
+
+ Supplying just a label will only show the first letter in the badge and supply the full label
+ to the tooltip. You can also pass an iconType to replace the letter only badge
+ and the label will still become the title.
+
+
),
demo: ,
}],
diff --git a/src/components/badge/_badge.scss b/src/components/badge/_badge.scss
index b635706cb6f..b7d75c04dd8 100644
--- a/src/components/badge/_badge.scss
+++ b/src/components/badge/_badge.scss
@@ -2,7 +2,7 @@
* 1. Accounts for the border
*/
.euiBadge {
- font-size: $euiSizeM;
+ font-size: $euiFontSizeXS;
font-weight: $euiFontWeightMedium;
line-height: $euiSize + 2px; /* 1 */
display: inline-block;
diff --git a/src/components/badge/beta_badge/__snapshots__/beta_badge.test.js.snap b/src/components/badge/beta_badge/__snapshots__/beta_badge.test.js.snap
index 5bdebee34c8..fbf03346008 100644
--- a/src/components/badge/beta_badge/__snapshots__/beta_badge.test.js.snap
+++ b/src/components/badge/beta_badge/__snapshots__/beta_badge.test.js.snap
@@ -5,6 +5,7 @@ exports[`EuiBetaBadge is rendered 1`] = `
aria-label="aria-label"
class="euiBetaBadge testClass1 testClass2"
data-test-subj="test subject string"
+ title="Beta"
>
Beta
diff --git a/src/components/badge/beta_badge/_beta_badge.scss b/src/components/badge/beta_badge/_beta_badge.scss
index f4a6eaa0626..8a7494d7441 100644
--- a/src/components/badge/beta_badge/_beta_badge.scss
+++ b/src/components/badge/beta_badge/_beta_badge.scss
@@ -3,17 +3,28 @@
padding: 0 $euiSizeL;
border-radius: $euiSizeL;
background-color: $euiColorAccent;
- vertical-align: text-bottom; // if displayed inline with text
+ vertical-align: super; // if displayed inline with text
@include euiSlightShadowHover($euiColorAccent);
- font-size: $euiSizeM;
+ font-size: $euiFontSizeXS;
font-weight: $euiFontWeightBold;
+ text-transform: uppercase;
letter-spacing: .05em;
color: chooseLightOrDarkText($euiColorAccent, $euiColorEmptyShade, $euiColorFullShade);
- text-transform: uppercase;
line-height: $euiSizeL;
text-align: center;
white-space: nowrap;
cursor: default;
+
+ // When it's just an icon, make it a circle
+ &.euiBetaBadge--iconOnly {
+ padding: 0;
+ width: $euiSizeL;
+
+ .euiBetaBadge__icon {
+ position: relative;
+ margin-top: -1px;
+ }
+ }
}
diff --git a/src/components/badge/beta_badge/beta_badge.js b/src/components/badge/beta_badge/beta_badge.js
index 98d43e20f05..53840de3d46 100644
--- a/src/components/badge/beta_badge/beta_badge.js
+++ b/src/components/badge/beta_badge/beta_badge.js
@@ -4,32 +4,53 @@ import classNames from 'classnames';
import { EuiToolTip } from '../../tool_tip';
+import {
+ ICON_TYPES,
+ EuiIcon,
+} from '../../icon';
+
export const EuiBetaBadge = ({
className,
label,
- description,
+ tooltipContent,
tooltipPosition,
title,
+ iconType,
...rest,
}) => {
const classes = classNames(
'euiBetaBadge',
+ {
+ 'euiBetaBadge--iconOnly': iconType,
+ },
className
);
- if (description) {
+ let icon;
+ if (iconType) {
+ icon = (
+
+ );
+ }
+
+ if (tooltipContent) {
return (
- {label}
+ {icon || label}
);
@@ -37,10 +58,10 @@ export const EuiBetaBadge = ({
return (
- {label}
+ {icon || label}
)
}
@@ -52,12 +73,17 @@ EuiBetaBadge.propTypes = {
/**
* One word label like "Beta" or "Lab"
*/
- label: PropTypes.string.isRequired,
+ label: PropTypes.node.isRequired,
+
+ /**
+ * Supply an icon type if the badge should just be an icon
+ */
+ iconType: PropTypes.oneOf(ICON_TYPES),
/**
- * Description for the tooltip
+ * Content for the tooltip
*/
- description: PropTypes.node,
+ tooltipContent: PropTypes.node,
/**
* Custom position of the tooltip
@@ -65,7 +91,7 @@ EuiBetaBadge.propTypes = {
tooltipPosition: PropTypes.string,
/**
- * Optional title will be supplied as tooltip title or title attribute
+ * Optional title will be supplied as tooltip title or title attribute otherwise the label will be used
*/
title: PropTypes.string,
}
diff --git a/src/components/card/_card.scss b/src/components/card/_card.scss
index cc3c2c37c6b..9ac04f65ba3 100644
--- a/src/components/card/_card.scss
+++ b/src/components/card/_card.scss
@@ -28,11 +28,17 @@ $euiCardTitleSize: 18px; // Hardcoded pixel value for theme parity.
transform: translateX(-50%);
z-index: 3; // get above abs positioned image
min-width: 40%; /* 2 */
+ max-width: calc(100% - #{$euiCardSpacing*2});
.euiToolTipAnchor,
.euiCard__betaBadge {
width: 100%; /* 2 */
}
+
+ .euiCard__betaBadge {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
}
}
diff --git a/src/components/card/card.js b/src/components/card/card.js
index a81fb7bdb33..80687543b50 100644
--- a/src/components/card/card.js
+++ b/src/components/card/card.js
@@ -25,8 +25,9 @@ export const EuiCard = ({
href,
textAlign,
isClickable,
- betaLabel,
- betaDescription,
+ betaBadgeLabel,
+ betaBadgeTooltipContent,
+ betaBadgeTitle,
...rest,
}) => {
const classes = classNames(
@@ -34,7 +35,7 @@ export const EuiCard = ({
textAlignToClassNameMap[textAlign],
{
'euiCard--isClickable': onClick || href || isClickable,
- 'euiCard--hasBetaBadge': betaLabel,
+ 'euiCard--hasBetaBadge': betaBadgeLabel,
},
className,
);
@@ -72,10 +73,10 @@ export const EuiCard = ({
}
let optionalBetaBadge;
- if (betaLabel) {
+ if (betaBadgeLabel) {
optionalBetaBadge = (
-
+
)
}
@@ -138,12 +139,17 @@ EuiCard.propTypes = {
/**
* Add a badge to the card to label it as "Beta" or other non-GA state
*/
- betaLabel: PropTypes.string,
+ betaBadgeLabel: PropTypes.string,
/**
- * Add a description to the beta label (will appear in a tooltip)
+ * Add a description to the beta badge (will appear in a tooltip)
*/
- betaDescription: PropTypes.node,
+ betaBadgeTooltipContent: PropTypes.node,
+
+ /**
+ * Optional title will be supplied as tooltip title or title attribute otherwise the label will be used
+ */
+ betaBadgeTitle: PropTypes.string,
};
EuiCard.defaultProps = {
diff --git a/src/components/key_pad_menu/_key_pad_menu.scss b/src/components/key_pad_menu/_key_pad_menu.scss
index c26af1176a3..3692a9bfafb 100644
--- a/src/components/key_pad_menu/_key_pad_menu.scss
+++ b/src/components/key_pad_menu/_key_pad_menu.scss
@@ -62,9 +62,9 @@
right: $euiSizeM * -.5;
z-index: 3;
- .euiKeyPadMenuItem__betaBadge {
+ .euiKeyPadMenuItem__betaBadge:not(.euiBetaBadge--iconOnly) {
width: $euiSizeL;
- padding: 0 8px; /* 2 */
+ padding: 0 ($euiSizeL - $euiFontSizeXS)/1.5; /* 2 */
overflow: hidden; /* 2 */
letter-spacing: 3rem; /* 2 */
}
diff --git a/src/components/key_pad_menu/key_pad_menu_item.js b/src/components/key_pad_menu/key_pad_menu_item.js
index de2e22cb764..ea8e2d4cbc9 100644
--- a/src/components/key_pad_menu/key_pad_menu_item.js
+++ b/src/components/key_pad_menu/key_pad_menu_item.js
@@ -4,11 +4,20 @@ import classNames from 'classnames';
import { EuiBetaBadge } from '../../components/badge/beta_badge';
-const renderContent = (children, label, betaLabel, betaDescription) => (
+import {
+ ICON_TYPES,
+} from '../icon';
+
+const renderContent = (children, label, betaBadgeLabel, betaBadgeTooltipContent, betaBadgeIconType) => (
- {betaLabel &&
+ {betaBadgeLabel &&
-
+
}
@@ -29,19 +38,24 @@ const commonPropTypes = {
/**
* Add a badge to the card to label it as "Beta" or other non-GA state
*/
- betaLabel: PropTypes.string,
+ betaBadgeLabel: PropTypes.string,
+
+ /**
+ * Supply an icon type if the badge should just be an icon
+ */
+ betaBadgeIconType: PropTypes.oneOf(ICON_TYPES),
/**
- * Add a description to the beta label (will appear in a tooltip)
+ * Add a description to the beta badge (will appear in a tooltip)
*/
- betaDescription: PropTypes.node,
+ betaBadgeTooltipContent: PropTypes.node,
};
-export const EuiKeyPadMenuItem = ({ href, label, children, className, betaLabel, betaDescription, ...rest }) => {
+export const EuiKeyPadMenuItem = ({ href, label, children, className, betaBadgeLabel, betaBadgeTooltipContent, betaBadgeIconType, ...rest }) => {
const classes = classNames(
'euiKeyPadMenuItem',
{
- 'euiKeyPadMenuItem--hasBetaBadge': betaLabel,
+ 'euiKeyPadMenuItem--hasBetaBadge': betaBadgeLabel,
},
className
);
@@ -52,7 +66,7 @@ export const EuiKeyPadMenuItem = ({ href, label, children, className, betaLabel,
className={classes}
{...rest}
>
- {renderContent(children, label, betaLabel, betaDescription)}
+ {renderContent(children, label, betaBadgeLabel, betaBadgeTooltipContent, betaBadgeIconType)}
);
};
@@ -61,11 +75,11 @@ EuiKeyPadMenuItem.propTypes = ({ ...{
href: PropTypes.string,
}, ...commonPropTypes });
-export const EuiKeyPadMenuItemButton = ({ onClick, label, children, className, betaLabel, betaDescription, ...rest }) => {
+export const EuiKeyPadMenuItemButton = ({ onClick, label, children, className, betaBadgeLabel, betaBadgeTooltipContent, betaBadgeIconType, ...rest }) => {
const classes = classNames(
'euiKeyPadMenuItem',
{
- 'euiKeyPadMenuItem--hasBetaBadge': betaLabel,
+ 'euiKeyPadMenuItem--hasBetaBadge': betaBadgeLabel,
},
className
);
@@ -77,7 +91,7 @@ export const EuiKeyPadMenuItemButton = ({ onClick, label, children, className, b
className={classes}
{...rest}
>
- {renderContent(children, label, betaLabel, betaDescription)}
+ {renderContent(children, label, betaBadgeLabel, betaBadgeTooltipContent, betaBadgeIconType)}
);
};