-
Notifications
You must be signed in to change notification settings - Fork 843
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
Changing the way EuiCard inherits EuiPanel #415
Changes from 6 commits
efe2fde
d980560
bf602bf
9c9cffc
ab03ad0
11e4690
ecdcfd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ import React from 'react'; | |
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
import { EuiPanel } from '../panel'; | ||
import { EuiText } from '../text'; | ||
import { EuiTitle } from '../title'; | ||
|
||
|
@@ -30,7 +29,6 @@ export const EuiCard = ({ | |
textAlignToClassNameMap[textAlign], | ||
{ | ||
'euiCard--isClickable': onClick, | ||
'euiCard--textAlign': textAlign, | ||
}, | ||
className, | ||
); | ||
|
@@ -50,41 +48,60 @@ export const EuiCard = ({ | |
); | ||
} | ||
|
||
const OuterElement = onClick ? 'button' : 'div'; | ||
const InnerElement = onClick ? 'span' : 'div'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just leave this a span in all cases? |
||
|
||
return ( | ||
<EuiPanel | ||
<OuterElement | ||
onClick={onClick} | ||
className={classes} | ||
{...rest} | ||
> | ||
<div className="euiCard__top"> | ||
<InnerElement className="euiCard__top"> | ||
{imageNode} | ||
{iconNode} | ||
</div> | ||
</InnerElement> | ||
|
||
<div className="euiCard__content"> | ||
<InnerElement className="euiCard__content"> | ||
<EuiTitle size="s" className="euiCard__title"> | ||
<span>{title}</span> | ||
</EuiTitle> | ||
|
||
<EuiText size="s" className="euiCard__description"> | ||
<p>{description}</p> | ||
</EuiText> | ||
</div> | ||
</InnerElement> | ||
|
||
<div className="euiCard__footer"> | ||
<InnerElement className="euiCard__footer"> | ||
{footer} | ||
</div> | ||
</EuiPanel> | ||
</InnerElement> | ||
</OuterElement> | ||
); | ||
}; | ||
|
||
EuiCard.propTypes = { | ||
className: PropTypes.string, | ||
description: PropTypes.string.isRequired, | ||
title: PropTypes.string.isRequired, | ||
description: PropTypes.string.isRequired, | ||
|
||
/** | ||
* Requires a <EuiIcon> node | ||
*/ | ||
icon: PropTypes.node, | ||
|
||
/** | ||
* Accepts a url in string form | ||
*/ | ||
image: PropTypes.string, | ||
|
||
/** | ||
* Accepts any combination of elements | ||
*/ | ||
footer: PropTypes.node, | ||
|
||
/** | ||
* Use only if you want to forego a button in the footer and make the whole card clickable | ||
*/ | ||
onClick: PropTypes.func, | ||
textAlign: PropTypes.oneOf(ALIGNMENTS), | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import 'variables'; | ||
@import 'panel'; | ||
@import 'mixins'; | ||
@import 'panel'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Mixin for use in: | ||
* - EuiCard | ||
*/ | ||
@mixin euiPanel($selector){ | ||
@if variable-exists(selector) == false { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really neat, I've never seen this sort of mixin before in Sass. TIL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I'm trying to get better at writing error messages for Sass |
||
@error "A $selector must be provided to @mixin euiPanel()."; | ||
} | ||
@else { | ||
.#{$selector} { | ||
|
||
@include euiBottomShadowSmall; | ||
background-color: $euiColorEmptyShade; | ||
border: $euiBorderThin; | ||
border-radius: $euiBorderRadius; | ||
flex-grow: 1; | ||
&.#{$selector}--flexGrowZero { | ||
flex-grow: 0; | ||
} | ||
|
||
&.#{$selector}--isClickable { | ||
// in case of button wrapper which inherently is inline-block and no width | ||
display: block; | ||
width: 100%; | ||
text-align: left; | ||
|
||
// transition the shadow | ||
@include euiSlightShadow; | ||
transition: all $euiAnimSpeedFast $euiAnimSlightResistance; | ||
|
||
&:hover, | ||
&:focus { | ||
@include euiSlightShadowHover; | ||
transform: translateY(-2px); | ||
cursor: pointer; | ||
} | ||
} | ||
|
||
&.#{$selector}--shadow { | ||
&, | ||
&:hover, | ||
&:focus { | ||
@include euiBottomShadow; | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,9 @@ | ||
.euiPanel { | ||
@include euiBottomShadowSmall; | ||
background-color: $euiColorEmptyShade; | ||
border: $euiBorderThin; | ||
border-radius: $euiBorderRadius; | ||
flex-grow: 1; | ||
// Export basic class & modifiers | ||
@include euiPanel($selector: 'euiPanel'); | ||
|
||
@each $modifier, $amount in $euiPanelPaddingModifiers { | ||
&.euiPanel--#{$modifier} { | ||
padding: $amount; | ||
} | ||
} | ||
|
||
&.euiPanel--shadow { | ||
@include euiBottomShadow; | ||
} | ||
|
||
&.euiPanel--flexGrowZero { | ||
flex-grow: 0; | ||
} | ||
|
||
&.euiPanel--isClickable { | ||
// in case of button wrapper which inherently is inline-block and no width | ||
display: block; | ||
width: 100%; | ||
text-align: left; | ||
|
||
// transition the shadow | ||
@include euiSlightShadow; | ||
transition: all $euiAnimSpeedFast $euiAnimSlightResistance; | ||
|
||
&:hover, | ||
&:focus { | ||
@include euiSlightShadowHover; | ||
transform: translateY(-2px); | ||
cursor: pointer; | ||
} | ||
// Specific | ||
@each $modifier, $amount in $euiPanelPaddingModifiers { | ||
.euiPanel.euiPanel--#{$modifier} { | ||
padding: $amount; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid this by putting these styles on the descendent classes themselves, e.g.
euiCard__top
,euiCard__content
andeuiCard__footer
? I used to love doing stuff like this but I have always ended up regretting it.