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

Beta badges on panels #888

Merged
merged 5 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added the ability for `EuiBetaBadge` to appear on `EuiPanel` similar to `EuiCard` ([#885](https://github.com/elastic/eui/pull/888))

**Bug fixes**
- Removed `.nvmrc` file from published npm package ([#892](https://github.com/elastic/eui/pull/892))
- `EuiComboBox` no longer shows the _clear_ icon when it's a no-op ([#890](https://github.com/elastic/eui/pull/890))
Expand Down
29 changes: 29 additions & 0 deletions src-docs/src/views/panel/panel_badge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';

import {
EuiPanel,
EuiFlexGroup,
EuiFlexItem,
} from '../../../../src/components';

const badges = [null, 'Beta', 'Lab'];

const panelNodes = badges.map(function (item, index) {
return (
<EuiFlexItem key={index}>
<EuiPanel
betaBadgeLabel={badges[index]}
betaBadgeTooltipContent={badges[index] ? "This module is not GA. Please help us by reporting any bugs." : undefined}
onClick={() => window.alert('Card clicked')}
>
I am some panel content
</EuiPanel>
</EuiFlexItem>
);
});

export default () => (
<EuiFlexGroup gutterSize="l">
{panelNodes}
</EuiFlexGroup>
);
20 changes: 20 additions & 0 deletions src-docs/src/views/panel/panel_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import PanelHover from './panel_hover';
const panelHoverSource = require('!!raw-loader!./panel_hover');
const panelHoverHtml = renderToHtml(PanelHover);

import PanelBadge from './panel_badge';
const panelBadgeSource = require('!!raw-loader!./panel_badge');
const panelBadgeHtml = renderToHtml(PanelBadge);

export const PanelExample = {
title: 'Panel',
sections: [{
Expand Down Expand Up @@ -56,5 +60,21 @@ export const PanelExample = {
</p>
),
demo: <PanelHover />,
}, {
title: 'Panel beta badges',
source: [{
type: GuideSectionTypes.JS,
code: panelBadgeSource,
}, {
type: GuideSectionTypes.HTML,
code: panelBadgeHtml,
}],
text: (
<p>
Similar to <Link to="/display/card">EuiCard</Link>, panels can also accept
an <Link to="/display/badge">EuiBetaBadge</Link>.
</p>
),
demo: <PanelBadge />,
}],
};
1 change: 1 addition & 0 deletions src/components/badge/beta_badge/_index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import 'mixins';
@import 'beta_badge';
30 changes: 30 additions & 0 deletions src/components/badge/beta_badge/_mixins.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

/**
* 1. Extend beta badges to at least 40% of the container's width
*/

@mixin hasBetaBadge($selector, $spacing: $euiSize) {
&.#{$selector}--hasBetaBadge {
position: relative;

.#{$selector}__betaBadgeWrapper {
position: absolute;
top: $euiSizeL/-2;
left: 50%;
transform: translateX(-50%);
z-index: 3; // get above abs positioned image
min-width: 40%; /* 1 */
max-width: calc(100% - #{$spacing*2});

.euiToolTipAnchor,
.#{$selector}__betaBadge {
width: 100%; /* 1 */
}

.#{$selector}__betaBadge {
overflow: hidden;
text-overflow: ellipsis;
}
}
}
}
40 changes: 9 additions & 31 deletions src/components/card/_card.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "../panel/variables";
@import "../panel/mixins";
@import '../badge/beta_badge/mixins';

$euiCardSpacing: map-get($euiPanelPaddingModifiers, "paddingMedium");
$euiCardTitleSize: 18px; // Hardcoded pixel value for theme parity.
Expand All @@ -9,43 +10,20 @@ $euiCardTitleSize: 18px; // Hardcoded pixel value for theme parity.

/**
* 1. Footer is always at the bottom.
* 2. Extend beta badges to at least 40% of the card's width
* 3. Fix for IE to ensure badges are visible outside of a <button> tag
* 4. Fix for IE where the image correctly resizes in width but doesn't collapse it's height
* 2. Fix for IE to ensure badges are visible outside of a <button> tag
* 3. Fix for IE where the image correctly resizes in width but doesn't collapse it's height
(https://github.com/philipwalton/flexbugs/issues/75#issuecomment-134702421)
* 5. Horizontal layouts should always top left align no matter the textAlign prop
* 4. Horizontal layouts should always top left align no matter the textAlign prop
*/

// EuiCard specific
.euiCard {
display: flex;
flex-direction: column;
padding: $euiCardSpacing;
overflow: visible; /* 3 */
overflow: visible; /* 2 */

&.euiCard--hasBetaBadge {
position: relative;

.euiCard__betaBadgeWrapper {
position: absolute;
top: $euiSizeL/-2;
left: 50%;
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;
}
}
}
@include hasBetaBadge($selector: 'euiCard', $spacing: $euiCardSpacing);

.euiCard__top,
.euiCard__content,
Expand Down Expand Up @@ -87,7 +65,7 @@ $euiCardTitleSize: 18px; // Hardcoded pixel value for theme parity.
.euiCard__top {
flex-grow: 0; /* 1 */
position: relative;
min-height: 1px; /* 4 */
min-height: 1px; /* 3 */

.euiCard__icon {
margin-top: $euiCardSpacing/2;
Expand Down Expand Up @@ -143,15 +121,15 @@ $euiCardTitleSize: 18px; // Hardcoded pixel value for theme parity.
.euiCard.euiCard--horizontal {
.euiCard__content {
padding-top: $euiSizeS; // Aligns title and text a bit better and adds spacing in case of beta badge
text-align: left; /* 5 */
text-align: left; /* 4 */
}
}

// Only change the flex direction if the card has an icon
// otherwise the button tag won't properly align contents to top
.euiCard.euiCard--horizontal.euiCard--hasIcon {
flex-direction: row;
align-items: flex-start !important; /* 5 */
align-items: flex-start !important; /* 4 */

.euiCard__top,
.euiCard__content {
Expand Down
11 changes: 11 additions & 0 deletions src/components/panel/_panel.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
@import '../badge/beta_badge/mixins';

// Export basic class & modifiers
@include euiPanel($selector: 'euiPanel');

.euiPanel {
@include hasBetaBadge($selector: 'euiPanel');
}

// Specific
@each $modifier, $amount in $euiPanelPaddingModifiers {
.euiPanel.euiPanel--#{$modifier} {
padding: $amount;

// Overwrite @hasBetaBadge max-width depending upon padding
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 just make all the width stuff it's own mixin? I can possibly see instances where we may not even want it to have a min-width, so it might be nice to leave it as an option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm gonna leave this as is for the moment. It's the only usage so making another mixin feels like overkill (for now). If we start using it more we probably should, but for now the @each was there anyway, so it's pretty simple.

.euiPanel__betaBadgeWrapper {
max-width: calc(100% - #{$amount*2});
}
}
}
39 changes: 39 additions & 0 deletions src/components/panel/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import { EuiBetaBadge } from '../badge/beta_badge';

const paddingSizeToClassNameMap = {
none: null,
s: 'euiPanel--paddingSmall',
Expand All @@ -19,6 +21,9 @@ export const EuiPanel = ({
grow,
panelRef,
onClick,
betaBadgeLabel,
betaBadgeTooltipContent,
betaBadgeTitle,
...rest
}) => {

Expand All @@ -29,6 +34,7 @@ export const EuiPanel = ({
'euiPanel--shadow': hasShadow,
'euiPanel--flexGrowZero': !grow,
'euiPanel--isClickable': onClick,
'euiPanel--hasBetaBadge': betaBadgeLabel,
},
className
);
Expand All @@ -46,8 +52,18 @@ export const EuiPanel = ({
props.onClick = onClick;
}

let optionalBetaBadge;
if (betaBadgeLabel) {
optionalBetaBadge = (
<span className="euiPanel__betaBadgeWrapper">
<EuiBetaBadge label={betaBadgeLabel} title={betaBadgeTitle} tooltipContent={betaBadgeTooltipContent} className="euiPanel__betaBadge" />
</span>
)
}

return (
<PanelTag {...props} {...rest}>
{optionalBetaBadge}
{children}
</PanelTag>
);
Expand All @@ -57,11 +73,34 @@ export const EuiPanel = ({
EuiPanel.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
/**
* If active, adds a deeper shadow to the panel
*/
hasShadow: PropTypes.bool,
/**
* Padding applied to the panel
*/
paddingSize: PropTypes.oneOf(SIZES),
/**
* When true the panel will grow to match `EuiFlexItem`
*/
grow: PropTypes.bool,
panelRef: PropTypes.func,
onClick: PropTypes.func,
/**
* Add a badge to the panel to label it as "Beta" or other non-GA state
*/
betaBadgeLabel: PropTypes.string,

/**
* Add a description to the beta badge (will appear in a tooltip)
*/
betaBadgeTooltipContent: PropTypes.node,

/**
* Optional title will be supplied as tooltip title or title attribute otherwise the label will be used
*/
betaBadgeTitle: PropTypes.string,
};

EuiPanel.defaultProps = {
Expand Down