Skip to content

Commit bfae7e0

Browse files
authored
feat(cardlink): adds cardlink (#2506)
feat(cardlink): adds cardlink component
1 parent 7a8d749 commit bfae7e0

File tree

14 files changed

+2664
-1683
lines changed

14 files changed

+2664
-1683
lines changed

packages/react/src/__tests__/__snapshots__/storyshots.test.js.snap

+2,293-1,608
Large diffs are not rendered by default.

packages/react/src/components/CTA/CardCTA.js

+23-26
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7-
import { Card } from '../Card';
7+
8+
import { CardLink } from '../CardLink';
89
import CTALogic from './CTALogic';
910
import PropTypes from 'prop-types';
1011
import React from 'react';
11-
import settings from 'carbon-components/es/globals/js/settings';
12-
13-
const { prefix } = settings;
1412

1513
/**
1614
* Card subcomponent for CTA.
@@ -23,37 +21,36 @@ const CardCTA = ({
2321
...otherProps
2422
}) => {
2523
return type === 'video' ? (
26-
<div>
24+
<>
2725
{CTALogic.launchLightBox(renderLightBox, openLightBox, otherProps.media)}
2826
{!renderLightBox && (
29-
<Card
30-
customClassName={`${prefix}--card__CTA`}
31-
cta={{
32-
href: '#',
33-
icon: {
34-
src: CTALogic.iconSelector(type),
27+
<CardLink
28+
card={{
29+
cta: {
30+
href: '#',
31+
icon: {
32+
src: CTALogic.iconSelector(type),
33+
},
3534
},
35+
copy: videoTitle[0].title,
36+
handleClick: e => CTALogic.setLightBox(e, openLightBox),
3637
}}
37-
copy={videoTitle[0].title}
38-
type="link"
39-
handleClick={e => CTALogic.setLightBox(e, openLightBox)}
4038
/>
4139
)}
42-
</div>
40+
</>
4341
) : (
44-
<Card
45-
customClassName={`${prefix}--card__CTA`}
46-
cta={{
47-
type,
48-
href: otherProps.cta.href,
49-
icon: {
50-
src: CTALogic.iconSelector(type),
42+
<CardLink
43+
card={{
44+
cta: {
45+
type,
46+
href: otherProps.cta.href,
47+
icon: {
48+
src: CTALogic.iconSelector(type),
49+
},
5150
},
51+
copy: otherProps.copy,
52+
target: CTALogic.external(type),
5253
}}
53-
copy={otherProps.copy}
54-
type="link"
55-
target={CTALogic.external(type)}
56-
role="region"
5754
/>
5855
);
5956
};

packages/react/src/components/CTA/FeatureCTA.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const FeatureCTA = ({
1919
videoTitle,
2020
...otherProps
2121
}) => {
22+
console.log(otherProps);
2223
return type === 'video' ? (
2324
<div>
2425
{CTALogic.launchLightBox(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright IBM Corp. 2016, 2020
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { Card } from '../Card';
9+
import PropTypes from 'prop-types';
10+
import React from 'react';
11+
import settings from 'carbon-components/es/globals/js/settings';
12+
13+
const { prefix } = settings;
14+
15+
/**
16+
* CardLink component
17+
*/
18+
const CardLink = ({ card }) => {
19+
return (
20+
<Card
21+
customClassName={`${prefix}--card__CTA`}
22+
{...card}
23+
role="region"
24+
type="link"
25+
/>
26+
);
27+
};
28+
29+
CardLink.propTypes = {
30+
/**
31+
* Card options.
32+
* See [`<Card>`'s README](http://ibmdotcom-react.mybluemix.net/?path=/docs/components-card--link-clickable#props) for full usage details.
33+
*/
34+
card: PropTypes.shape(Card.propTypes).isRequired,
35+
};
36+
37+
export default CardLink;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Props } from '@storybook/addon-docs/blocks';
2+
import { Card } from '../Card';
3+
4+
# CardLink
5+
6+
> The cardlink component uses
7+
> [Carbon's Clickable Tile component](https://www.carbondesignsystem.com/components/tile/code#clickable-tile)
8+
> while presenting content in a concise and readable style.
9+
10+
## Getting started
11+
12+
Here's a quick example to get you started.
13+
14+
##### CSS
15+
16+
```css
17+
// yourapplication.scss
18+
@import '@carbon/type/scss/font-face/mono';
19+
@import '@carbon/type/scss/font-face/sans';
20+
@include carbon--font-face-mono();
21+
@include carbon--font-face-sans();
22+
@import '@carbon/ibmdotcom-styles/scss/patterns/sub-patterns/card/index.scss';
23+
```
24+
25+
> 💡 Only import fonts once per usage. Don't forget to import the Card styles
26+
> from
27+
> [@carbon/ibmdotcom-styles](https://github.com/carbon-design-system/ibm-dotcom-library/blob/master/packages/styles).
28+
29+
##### JS
30+
31+
```javascript
32+
import React from 'react';
33+
import ReactDOM from 'react-dom';
34+
import { CardLink } from '@carbon/ibmdotcom-react';
35+
import 'yourapplication.scss';
36+
37+
function App() {
38+
return (
39+
<CardLink
40+
card={{
41+
heading: 'Heading',
42+
copy: 'Lorem ipsum dolor sit amet',
43+
cta: {
44+
href: 'http://www.example.com',
45+
icon: {
46+
src: ArrowRight20,
47+
},
48+
},
49+
}}
50+
/>
51+
);
52+
}
53+
54+
ReactDOM.render(<App />, document.querySelector('#app'));
55+
```
56+
57+
Add the following line in your `.env` file at the root of your project.
58+
[See more details](https://github.com/carbon-design-system/ibm-dotcom-library/tree/master/packages/styles#usage).
59+
60+
```
61+
SASS_PATH=node_modules:src
62+
```
63+
64+
> 💡 Don't forget to import the card styles from
65+
> [@carbon/ibmdotcom-styles](https://github.com/carbon-design-system/ibm-dotcom-library/blob/master/packages/styles).
66+
67+
## Props
68+
69+
<Props of={Card} />
70+
71+
## 🙌 Contributing
72+
73+
We're always looking for contributors to help us fix bugs, build new features,
74+
or help us improve the project documentation. If you're interested, definitely
75+
check out our
76+
[Contributing Guide](https://github.com/carbon-design-system/ibm-dotcom-library/blob/master/.github/CONTRIBUTING.md)!
77+
👀
78+
79+
## 📝 License
80+
81+
Licensed under the
82+
[Apache 2.0 License](https://github.com/carbon-design-system/ibm-dotcom-library/blob/master/LICENSE).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright IBM Corp. 2016, 2020
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { text, withKnobs } from '@storybook/addon-knobs';
9+
import ArrowRight20 from '@carbon/icons-react/es/arrow--right/20';
10+
import CardLink from '../CardLink';
11+
import React from 'react';
12+
import readme from '../README.stories.mdx';
13+
14+
export default {
15+
title: 'Components|CardLink',
16+
decorators: [withKnobs],
17+
18+
parameters: {
19+
...readme.parameters,
20+
},
21+
};
22+
23+
export const Default = () => {
24+
const cardheading = text(
25+
'Card Heading:',
26+
'Explore AI use cases in all industries'
27+
);
28+
const cardhref = text('Card href:', 'https://www.example.com');
29+
30+
return (
31+
<div className="bx--grid">
32+
<div className="bx--row">
33+
<div className="bx--col-sm-4 bx--col-lg-8 bx--offset-lg-4">
34+
<CardLink
35+
card={{
36+
copy: cardheading,
37+
cta: {
38+
href: cardhref,
39+
icon: {
40+
src: ArrowRight20,
41+
},
42+
},
43+
}}
44+
/>
45+
</div>
46+
</div>
47+
</div>
48+
);
49+
};
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
2-
* Copyright IBM Corp. 2020
2+
* Copyright IBM Corp. 2016, 2020
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
@import '../../../../../../styles/scss/patterns/sections/ctasection/index';
8+
export { default as CardLink } from './CardLink';

0 commit comments

Comments
 (0)