@@ -11,7 +11,7 @@ import { FeaturedLink } from '../../patterns/blocks/FeaturedLink';
11
11
import { LinkWithIcon } from '../LinkWithIcon' ;
12
12
import PropTypes from 'prop-types' ;
13
13
import React from 'react' ;
14
- import { smoothScrolling } from '@carbon/ibmdotcom-utilities' ;
14
+ import { smoothScroll } from '@carbon/ibmdotcom-utilities' ;
15
15
/**
16
16
* CTA component
17
17
*
@@ -28,14 +28,16 @@ const CTA = ({ style, type, ...cta }) => {
28
28
< CardLink
29
29
{ ...cta }
30
30
icon = { iconSelector ( type ) }
31
- onClick = { type === 'jump' ? smoothScrolling : null }
31
+ target = { external ( type ) }
32
+ onClick = { e => jump ( e , type ) }
32
33
/>
33
34
) ;
34
35
case 'button' :
35
36
return (
36
37
< ButtonGroup
37
38
buttons = { renderButtons ( cta ) }
38
- onClick = { type === 'jump' ? smoothScrolling : null }
39
+ target = { external ( type ) }
40
+ onClick = { e => jump ( e , type ) }
39
41
/>
40
42
) ;
41
43
case 'feature' :
@@ -44,22 +46,39 @@ const CTA = ({ style, type, ...cta }) => {
44
46
return (
45
47
< LinkWithIcon
46
48
href = { cta . href }
47
- target = { type === ' external' ? '_blank' : null }
48
- onClick = { type === ' jump' ? smoothScrolling : null } >
49
+ target = { external ( type ) }
50
+ onClick = { e => jump ( e , type ) } >
49
51
{ cta . copy }
50
52
{ iconSelector ( type ) }
51
53
</ LinkWithIcon >
52
54
) ;
53
55
}
54
56
} ;
57
+
58
+ /**
59
+ * jump to target element onClick
60
+ * @param {* } e event object
61
+ * @param {* } type cta type ( external | jump | local)
62
+ * * @returns {* } behaviour object
63
+ */
64
+ const jump = ( e , type ) => ( type === 'jump' ? smoothScroll ( e ) : null ) ;
65
+
66
+ /**
67
+ * sets target
68
+ * @param {string } type cta type ( external | jump | local)
69
+ * @returns {string } target value
70
+ */
71
+ const external = type => ( type === 'external' ? '_blank' : null ) ;
72
+
55
73
/**
56
74
* TEMPORARY sets icon based on link type
57
75
*
58
76
* @param {string } type cta type ( external | jump | local)
59
- * @returns {* } cta type component
77
+ * @returns {* } type of icon component
60
78
*/
61
79
const TEMP_iconSelector = type =>
62
80
type === 'external' ? Launch20 : type === 'jump' ? ArrowDown20 : ArrowRight20 ;
81
+
63
82
/**
64
83
* sets icon based on link type
65
84
*
@@ -74,6 +93,7 @@ const iconSelector = type =>
74
93
) : (
75
94
< ArrowRight20 />
76
95
) ;
96
+
77
97
/**
78
98
* sets button
79
99
*
@@ -85,8 +105,8 @@ const renderButtons = ({ buttons }) =>
85
105
button . renderIcon = TEMP_iconSelector ( button . type ) ;
86
106
return button ;
87
107
} ) ;
108
+
88
109
CTA . propTypes = {
89
- cta : PropTypes . object ,
90
110
style : PropTypes . string ,
91
111
type : PropTypes . string ,
92
112
} ;
0 commit comments