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

Add paddingSize prop to EuiCard and display example to docs #3638

Merged
merged 15 commits into from
Jul 2, 2020
Merged
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 `26.0.1`.
- Added `paddingSize` prop to `EuiCard` ([#3638](https://github.com/elastic/eui/pull/3638))

## [`26.0.1`](https://github.com/elastic/eui/tree/v26.0.1)

Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/card/card_beta.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ const cardNodes = icons.map(function(item, index) {
);
});

export default () => <EuiFlexGroup gutterSize="l">{cardNodes}</EuiFlexGroup>;
export default () => <EuiFlexGroup gutterSize="l">{cardNodes} </EuiFlexGroup>;
15 changes: 15 additions & 0 deletions src-docs/src/views/card/card_display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

import { EuiCard, EuiIcon } from '../../../../src/components';

export default () => (
<div style={{ maxWidth: 350 }}>
<EuiCard
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
layout="horizontal"
icon={<EuiIcon size="xl" type="logoLogging" />}
title="Logs"
display="plain"
description="The Elastic Stack is the most popular open source logging platform."
/>
</div>
);
31 changes: 31 additions & 0 deletions src-docs/src/views/card/card_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ import CardCheckable from './card_checkable';
const cardCheckableSource = require('!!raw-loader!./card_checkable');
const cardCheckableHtml = renderToHtml(CardCheckable);

import CardDisplay from './card_display';
const cardDisplaySource = require('!!raw-loader!./card_display');
const cardDisplayHtml = renderToHtml(CardDisplay);

export const CardExample = {
title: 'Card',
sections: [
Expand Down Expand Up @@ -367,5 +371,32 @@ export const CardExample = {
</EuiText>
</EuiCard>`,
},
{
title: 'Plain cards',
source: [
{
type: GuideSectionTypes.JS,
code: cardDisplaySource,
},
{
type: GuideSectionTypes.HTML,
code: cardDisplayHtml,
},
],
text: (
<Fragment>
<p>
If you need a card with no borders or shadows pass{' '}
<EuiCode language="ts">{'display="plain"'}</EuiCode>.
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
</p>
</Fragment>
),
props: { EuiCard },
demo: <CardDisplay />,
snippet: `<EuiCard
title="title"
display="plain"
description="description" />`,
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
},
],
};
24 changes: 12 additions & 12 deletions src/components/card/__snapshots__/card.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`EuiCard is rendered 1`] = `
<div
aria-label="aria-label"
class="euiCard euiCard--centerAligned testClass1 testClass2"
class="euiCard euiCard--paddingMedium euiCard--centerAligned testClass1 testClass2"
data-test-subj="test subject string"
>
<div
Expand All @@ -29,7 +29,7 @@ exports[`EuiCard is rendered 1`] = `

exports[`EuiCard props a null icon 1`] = `
<div
class="euiCard euiCard--centerAligned"
class="euiCard euiCard--paddingMedium euiCard--centerAligned"
>
<div
class="euiCard__content"
Expand All @@ -54,7 +54,7 @@ exports[`EuiCard props a null icon 1`] = `

exports[`EuiCard props children 1`] = `
<div
class="euiCard euiCard--centerAligned euiCard--hasChildren"
class="euiCard euiCard--paddingMedium euiCard--centerAligned euiCard--hasChildren"
>
<div
class="euiCard__content"
Expand All @@ -80,7 +80,7 @@ exports[`EuiCard props children 1`] = `

exports[`EuiCard props display 1`] = `
<div
class="euiCard euiCard--plain euiCard--centerAligned"
class="euiCard euiCard--paddingMedium euiCard--plain euiCard--centerAligned"
>
<div
class="euiCard__content"
Expand All @@ -105,7 +105,7 @@ exports[`EuiCard props display 1`] = `

exports[`EuiCard props footer 1`] = `
<div
class="euiCard euiCard--centerAligned"
class="euiCard euiCard--paddingMedium euiCard--centerAligned"
>
<div
class="euiCard__content"
Expand Down Expand Up @@ -137,7 +137,7 @@ exports[`EuiCard props footer 1`] = `

exports[`EuiCard props horizontal 1`] = `
<div
class="euiCard euiCard--centerAligned euiCard--horizontal"
class="euiCard euiCard--paddingMedium euiCard--centerAligned euiCard--horizontal"
>
<div
class="euiCard__content"
Expand Down Expand Up @@ -167,7 +167,7 @@ exports[`EuiCard props href supports href as a link 1`] = `
title="Hoi"
>
<div
className="euiCard euiCard--centerAligned euiCard--isClickable"
className="euiCard euiCard--paddingMedium euiCard--centerAligned euiCard--isClickable"
onClick={[Function]}
>
<div
Expand Down Expand Up @@ -213,7 +213,7 @@ exports[`EuiCard props href supports href as a link 1`] = `

exports[`EuiCard props icon 1`] = `
<div
class="euiCard euiCard--centerAligned euiCard--hasIcon"
class="euiCard euiCard--paddingMedium euiCard--centerAligned euiCard--hasIcon"
>
<div
class="euiCard__top"
Expand Down Expand Up @@ -246,7 +246,7 @@ exports[`EuiCard props icon 1`] = `

exports[`EuiCard props selectable 1`] = `
<div
class="euiCard euiCard--centerAligned euiCard--isClickable euiCard--isSelectable euiCard--isSelectable--text"
class="euiCard euiCard--paddingMedium euiCard--centerAligned euiCard--isClickable euiCard--isSelectable euiCard--isSelectable--text"
>
<div
class="euiCard__content"
Expand Down Expand Up @@ -288,7 +288,7 @@ exports[`EuiCard props selectable 1`] = `

exports[`EuiCard props textAlign 1`] = `
<div
class="euiCard euiCard--rightAligned"
class="euiCard euiCard--paddingMedium euiCard--rightAligned"
>
<div
class="euiCard__content"
Expand All @@ -313,7 +313,7 @@ exports[`EuiCard props textAlign 1`] = `

exports[`EuiCard props titleElement 1`] = `
<div
class="euiCard euiCard--centerAligned"
class="euiCard euiCard--paddingMedium euiCard--centerAligned"
>
<div
class="euiCard__content"
Expand All @@ -338,7 +338,7 @@ exports[`EuiCard props titleElement 1`] = `

exports[`EuiCard props titleSize 1`] = `
<div
class="euiCard euiCard--centerAligned"
class="euiCard euiCard--paddingMedium euiCard--centerAligned"
>
<div
class="euiCard__content"
Expand Down
108 changes: 58 additions & 50 deletions src/components/card/_card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
.euiCard {
display: flex;
flex-direction: column;
padding: $euiCardSpacing;
cchaos marked this conversation as resolved.
Show resolved Hide resolved
min-height: 1px; /* 2 */// sass-lint:disable-line mixins-before-declarations

&.euiCard-isDisabled {
Expand Down Expand Up @@ -99,11 +98,6 @@
}
}

&.euiCard--isSelectable {
position: relative;
padding-bottom: $euiCardSpacing + $euiCardBottomNodeHeight;
}

&.euiCard-isSelected {
transition: all $euiAnimSpeedFast $euiAnimSlightResistance;
}
Expand All @@ -112,6 +106,64 @@
// This creates a bunch of sub selectors for the beta badge
@include euiHasBetaBadge($selector: '.euiCard', $spacing: $euiCardSpacing);

@each $modifier, $amount in $euiPanelPaddingModifiers {
&.euiCard--#{$modifier} {
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
padding: $amount;

&.euiCard--isSelectable {
position: relative;
padding-bottom: $amount + $euiCardBottomNodeHeight;
}

.euiCard__top {
flex-grow: 0; /* 1 */
position: relative;
min-height: 1px; /* 2 */
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved

.euiCard__icon {
margin-top: $amount / 2;
}

.euiCard__image {
position: relative;
width: calc(100% + (#{$amount} * 2));
left: $amount * -1;
top: $amount * -1;
margin-bottom: $amount * -1; // ensure the parent is only as tall as the image

// match border radius, minus 1px because it's inside a border
border-top-left-radius: $euiBorderRadius - 1px;
border-top-right-radius: $euiBorderRadius - 1px;
overflow: hidden;

img {
width: 100%;
}

// IF both exist, position the icon centered on top of image
+ .euiCard__icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -75%); // Fallback for IE as it doesn't accept calcs in translates
transform: translate(-50%, calc(-50% + #{$amount * -1})); // sass-lint:disable-line no-duplicate-properties
}
}
}

.euiCard__content {
.euiCard__description {
margin-top: $amount / 2;
}
}

.euiCard__footer:not(:empty) {
flex-grow: 0; /* 1 */
margin-top: $amount;
}
}
}

// Selectable cards don't work well without a border
.euiCard--plain:not(.euiCard--isSelectable) {
border: none;
Expand All @@ -129,42 +181,6 @@
}
}

.euiCard__top {
flex-grow: 0; /* 1 */
position: relative;
min-height: 1px; /* 2 */

.euiCard__icon {
margin-top: $euiCardSpacing / 2;
}

.euiCard__image {
position: relative;
width: calc(100% + (#{$euiCardSpacing} * 2));
left: $euiCardSpacing * -1;
top: $euiCardSpacing * -1;
margin-bottom: $euiCardSpacing * -1; // ensure the parent is only as tall as the image

// match border radius, minus 1px because it's inside a border
border-top-left-radius: $euiBorderRadius - 1px;
border-top-right-radius: $euiBorderRadius - 1px;
overflow: hidden;

img {
width: 100%;
}

// IF both exist, position the icon centered on top of image
+ .euiCard__icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -75%); // Fallback for IE as it doesn't accept calcs in translates
transform: translate(-50%, calc(-50% + #{$euiCardSpacing * -1})); // sass-lint:disable-line no-duplicate-properties
}
}
}

// If an icon or image exists, add some space
.euiCard__top + .euiCard__content {
margin-top: $euiCardSpacing;
Expand All @@ -184,14 +200,6 @@
}
}

.euiCard__description {
margin-top: $euiCardSpacing / 2;
}
}

.euiCard__footer:not(:empty) {
flex-grow: 0; /* 1 */
margin-top: $euiCardSpacing;
}

.euiCard.euiCard--horizontal {
Expand Down
16 changes: 16 additions & 0 deletions src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const displayToClassNameMap: { [display in CardDisplay]: string } = {

export const DISPLAYS = keysOf(displayToClassNameMap);

export type CardPaddingSize = 's' | 'm' | 'l';
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved

type EuiCardProps = Omit<CommonProps, 'aria-label'> & {
/**
* Card's are required to have at least a title and description
Expand Down Expand Up @@ -154,8 +156,20 @@ type EuiCardProps = Omit<CommonProps, 'aria-label'> & {
* Selectable cards will always display as 'panel'.
*/
display?: CardDisplay;
/**
* Padding applied to the card
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
*/
paddingSize?: CardPaddingSize;
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
};

const paddingSizeToClassNameMap = {
s: 'euiCard--paddingSmall',
m: 'euiCard--paddingMedium',
l: 'euiCard--paddingLarge',
};

export const SIZES = Object.keys(paddingSizeToClassNameMap);

export const EuiCard: FunctionComponent<EuiCardProps> = ({
className,
description,
Expand All @@ -178,6 +192,7 @@ export const EuiCard: FunctionComponent<EuiCardProps> = ({
layout = 'vertical',
selectable,
display = 'panel',
paddingSize = 'm',
...rest
}) => {
/**
Expand Down Expand Up @@ -209,6 +224,7 @@ export const EuiCard: FunctionComponent<EuiCardProps> = ({

const classes = classNames(
'euiCard',
paddingSize ? paddingSizeToClassNameMap[paddingSize] : null,
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
displayToClassNameMap[display],
textAlignToClassNameMap[textAlign],
layoutToClassNameMap[layout],
Expand Down