This repository was archived by the owner on Aug 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathreact.js
68 lines (58 loc) · 2.24 KB
/
react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*! [replace-name] v[replace-version] */
/***************************************************************************************************************************************************************
*
* cta-link function
*
* Provide a see more/all link when there are too many items to show in the current context.
*
**************************************************************************************************************************************************************/
import React from 'react';
import PropTypes from 'prop-types';
import { isValidElementType } from "react-is";
// The following line will be replaced automatically with generic imports for the ES5 pipeline.
// You can safely ignore this bit if you use this module with pancake
//
// [replace-imports]
/**
* DEFAULT
* The cta link component
*
* @param {string} linkComponent - The component used for the link
* @param {boolean} dark - Add the dark variation class, optional
* @param {string} link - The link target, if not supplied this will render as a button, optional
* @param {string} text - The text of the CTA link
* @param {string} className - An additional class, optional
* @param {object} attributeOptions - Any other attribute options
*/
const AUctaLink = ({ linkComponent, dark, link, text, className = '', ...attributeOptions }) => {
const LinkComponent = linkComponent;
if( link ) {
// If we are using a normal link
if( LinkComponent === 'a' ) {
attributeOptions.href = link;
}
// If we are using a link component
else if( isValidElementType(LinkComponent) ) {
attributeOptions.to = link;
}
return (
<LinkComponent className={ `au-cta-link ${ className }${ dark ? ` au-cta-link--dark` : '' }` } { ...attributeOptions }>{ text }</LinkComponent>
);
}
else {
return (
<button className={ `au-cta-link${ dark ? ` au-cta-link--dark` : '' }` } { ...attributeOptions }>{ text }</button>
);
}
}
AUctaLink.propTypes = {
dark: PropTypes.bool,
link: PropTypes.string,
text: PropTypes.string.isRequired,
className: PropTypes.string,
linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.elementType ])
};
AUctaLink.defaultProps = {
linkComponent: 'a',
};
export default AUctaLink;