This repository has been archived by the owner on Aug 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
/
react.js
99 lines (87 loc) 路 2.97 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*! [replace-name] v[replace-version] */
/***************************************************************************************************************************************************************
*
* buttons function
*
* Buttons signal action. Use them to move the user through the service.
*
**************************************************************************************************************************************************************/
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]
/**
* All different kind of button options
*
* @type {Object}
*/
const options = {
'primary': '',
'secondary': 'au-btn--secondary',
'tertiary': 'au-btn--tertiary',
};
/**
* DEFAULT
* The primary button
*
* @param {string} linkComponent - The component used for the link
* @param {string} link - If this is a link the location it goes
* @param {string} children - Anything inside
* @param {string} as - The kind of button, can be either 'primary', 'secondary', 'tertiary', default: 'primary'
* @param {boolean} dark - Add the dark variation class, optional
* @param {string} type - The type attribute, default: 'button', optional
* @param {boolean} block - The block option, optional
* @param {string} className - An additional class, optional
* @param {object} attributeOptions - Any other attribute options
*/
const AUbutton = ({ linkComponent, link, children, as, dark, type, block, className = '', ...attributeOptions }) => {
if( link ) {
const LinkComponent = linkComponent;
// 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-btn ${ className } ${ options[ as ] }${ block ? ' au-btn--block' : '' }${ dark ? ' au-btn--dark' : '' }` }
{ ...attributeOptions }
>
{ children }
</LinkComponent>
);
}
else {
return (
<button
type={ type }
className={ `au-btn ${ className } ${ options[ as ] }${ block ? ' au-btn--block' : '' }${ dark ? ' au-btn--dark' : '' }` }
{ ...attributeOptions }
>
{ children }
</button>
);
}
};
AUbutton.propTypes = {
link: PropTypes.string,
children: PropTypes.node.isRequired,
as: PropTypes.oneOf([ 'primary', 'secondary', 'tertiary' ]).isRequired,
dark: PropTypes.bool,
type: PropTypes.string,
block: PropTypes.bool,
className: PropTypes.string,
linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.elementType ]),
};
AUbutton.defaultProps = {
type: 'button',
as: 'primary',
linkComponent: 'a',
};
export default AUbutton;