-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from alisonjoseph/feature-card
feat(FeatureCard): add feature card component
- Loading branch information
Showing
11 changed files
with
278 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
title: FeatureCard | ||
--- | ||
|
||
import { Row, Column, FeatureCard, PageDescription } from 'gatsby-theme-carbon'; | ||
|
||
<PageDescription> | ||
|
||
The `<FeatureCard>` component takes the same props as the `<ResourceCard>` component (except for `aspectRatio`, this is fixed at `1:2` for the card), this component should not be used within `<Row>` or `<Column>` components as the grid is built in to the component already. | ||
|
||
</PageDescription> | ||
|
||
## Example | ||
|
||
<FeatureCard | ||
subTitle="With subtitle" | ||
title="Title" | ||
actionIcon="arrowRight" | ||
href="/" | ||
color="dark" | ||
> | ||
|
||
![demo image](/images/large-image.png) | ||
|
||
</FeatureCard> | ||
|
||
## Code | ||
|
||
``` | ||
<FeatureCard | ||
subTitle="With subtitle" | ||
title="Title" | ||
actionIcon="arrowRight" | ||
href="/" | ||
disabled | ||
color="dark" | ||
> | ||
![demo image](/images/large-image.png) | ||
</FeatureCard> | ||
``` | ||
|
||
## Props | ||
|
||
| property | propType | required | default | description | | ||
| ---------- | -------- | -------- | -------- | --------------------------------------------------------------------------------------- | | ||
| children | node | | | Use large image as child, will display above the card | | ||
| href | string | | | Set url for card | | ||
| subTitle | string | | | Smaller title | | ||
| title | string | | | Large title | | ||
| actionIcon | string | | `launch` | Action icon, default is launch, options are `Launch`, `ArrowRight`, `Download`, `Error` | | ||
| color | string | | light | Set to `dark` for dark background | | ||
| disabled | bool | | false | Set for disabled card | | ||
| className | string | | | Add custom class name | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
packages/gatsby-theme-carbon/src/components/FeatureCard/FeatureCard.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
import { Link } from 'gatsby'; | ||
import { Row, Column } from '../Grid'; | ||
import ResourceCard from '../ResourceCard'; | ||
import { settings } from 'carbon-components'; | ||
|
||
const { prefix } = settings; | ||
|
||
export default class FeatureCard extends React.Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
|
||
/** | ||
* Set url for card | ||
*/ | ||
href: PropTypes.string, | ||
|
||
/** | ||
* Smaller heading | ||
*/ | ||
subTitle: PropTypes.string, | ||
|
||
/** | ||
* Large heading | ||
*/ | ||
title: PropTypes.string, | ||
|
||
/** | ||
* Action icon, default is launch, options are Launch, ArrowRight, Download, Error | ||
*/ | ||
actionIcon: PropTypes.string, | ||
|
||
/** | ||
* set to "dark" for dark background card | ||
*/ | ||
color: PropTypes.string, | ||
|
||
/** | ||
* Use for disabled card | ||
*/ | ||
disabled: PropTypes.bool, | ||
|
||
/** | ||
* Specify a custom class | ||
*/ | ||
className: PropTypes.string, | ||
}; | ||
|
||
static defaultProps = { | ||
dark: false, | ||
disabled: false, | ||
aspectRatio: '2:1', | ||
actionIcon: 'launch', | ||
}; | ||
|
||
render() { | ||
const { | ||
children, | ||
href, | ||
subTitle, | ||
title, | ||
color, | ||
disabled, | ||
actionIcon, | ||
className, | ||
} = this.props; | ||
|
||
let isLink; | ||
if (href !== undefined) { | ||
isLink = href.charAt(0) === '/'; | ||
} | ||
|
||
const FeatureCardClassNames = classnames([`${prefix}--feature-card`], { | ||
[className]: className, | ||
}); | ||
|
||
const cardContent = ( | ||
<> | ||
<Row> | ||
<Column noGutterSm> | ||
<div | ||
className={`${prefix}--feature-card__img ${prefix}--aspect-ratio--1x1`} | ||
> | ||
<div className={`${prefix}--aspect-ratio--object`}> | ||
{children} | ||
</div> | ||
</div> | ||
</Column> | ||
|
||
<Column | ||
className={`${prefix}--feature-card__row`} | ||
colMd={4} | ||
colLg={4} | ||
offsetLg={8} | ||
offsetMd={4} | ||
noGutterSm | ||
> | ||
<ResourceCard | ||
title={title} | ||
subTitle={subTitle} | ||
aspectRatio="2:1" | ||
href={href} | ||
actionIcon={actionIcon} | ||
color={color} | ||
disabled={disabled} | ||
/> | ||
</Column> | ||
</Row> | ||
</> | ||
); | ||
|
||
let cardContainer; | ||
if (disabled === true) { | ||
cardContainer = <div>{cardContent}</div>; | ||
} else if (isLink === true && !disabled) { | ||
cardContainer = ( | ||
<Link className={`${prefix}--feature-card__link`} to={href}> | ||
{cardContent} | ||
</Link> | ||
); | ||
} else { | ||
cardContainer = ( | ||
<a | ||
className={`${prefix}--feature-card__link`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
href={href} | ||
> | ||
{cardContent} | ||
</a> | ||
); | ||
} | ||
|
||
return <div className={FeatureCardClassNames}>{cardContainer}</div>; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
packages/gatsby-theme-carbon/src/components/FeatureCard/feature-card.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
.#{$prefix}--feature-card { | ||
position: relative; | ||
} | ||
|
||
.#{$prefix}--feature-card__row { | ||
@include carbon--breakpoint('md') { | ||
position: absolute; | ||
bottom: 0; | ||
right: 0; | ||
} | ||
} | ||
|
||
.#{$prefix}--feature-card__img { | ||
position: relative; | ||
} | ||
|
||
.#{$prefix}--feature-card .gatsby-resp-image-wrapper { | ||
margin-bottom: 0; | ||
} | ||
|
||
.#{$prefix}--feature-card:hover | ||
.#{$prefix}--feature-card__link | ||
.#{$prefix}--tile { | ||
background: $hover-ui; | ||
} | ||
|
||
.#{$prefix}--feature-card:hover | ||
.#{$prefix}--feature-card__link | ||
.#{$prefix}--resource-card--dark | ||
.#{$prefix}--tile { | ||
background: $carbon--gray-80; //$hover-ui for gray 90 theme | ||
} | ||
|
||
// Display image at square aspect ratio only on mobile | ||
.#{$prefix}--feature-card__img.#{$prefix}--aspect-ratio--1x1 { | ||
@include carbon--breakpoint('md') { | ||
padding-bottom: 0; | ||
} | ||
} | ||
|
||
.#{$prefix}--feature-card__img .#{$prefix}--aspect-ratio--object { | ||
@include carbon--breakpoint('md') { | ||
position: static; | ||
} | ||
} | ||
|
||
@include carbon--breakpoint('sm') { | ||
.#{$prefix}--feature-card .gatsby-resp-image-wrapper { | ||
position: relative; | ||
display: block; | ||
margin-left: -1rem; | ||
margin-right: -1rem; | ||
max-width: 100%; | ||
overflow: hidden; | ||
height: 100%; | ||
} | ||
|
||
.#{$prefix}--feature-card .gatsby-resp-image-background-image { | ||
padding-bottom: 100%; | ||
} | ||
|
||
.#{$prefix}--feature-card .gatsby-resp-image-image { | ||
width: auto !important; | ||
left: auto !important; | ||
right: 0; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/gatsby-theme-carbon/src/components/FeatureCard/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import FeatureCard from './FeatureCard'; | ||
|
||
export default FeatureCard; |
5 changes: 5 additions & 0 deletions
5
packages/gatsby-theme-carbon/src/components/ResourceCard/resource-card.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters