forked from coreui/coreui-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCButton.js
87 lines (77 loc) · 1.78 KB
/
CButton.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
import React from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import { tagPropType } from '../utils/helper.js'
import CLink from '../link/CLink'
//component - CoreUI / CButton
const CButton = props => {
let {
tag: Tag,
className,
//
innerRef,
onClick,
disabled,
active,
block,
color,
size,
pressed,
shape,
variant,
...attributes
} = props
const click = e => !disabled && onClick && onClick(e)
const isLink = attributes.to || attributes.href
//render
const classes = classNames(
className,
'btn',
variant || color ? `btn${variant ? '-' + variant : ''}-${color}` : false,
size ? `btn-${size}` : false,
block ? 'btn-block' : false,
shape ? `btn-${shape}` : false,
pressed ? 'btn-pressed' : false,
{ 'active': active && !isLink,
'disabled': disabled && !isLink }
)
if (isLink) {
return <CLink
{...attributes}
active={active}
disabled={disabled}
className={classes}
onClick={click}
innerRef={innerRef}
/>
} else {
return <Tag
className={classes}
type="button"
disabled={disabled}
{...attributes}
onClick={click}
ref={innerRef}
/>
}
}
CButton.propTypes = {
tag: tagPropType,
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
//
innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
active: PropTypes.bool,
block: PropTypes.bool,
shape: PropTypes.string,
variant: PropTypes.oneOf(['', 'ghost', 'outline']),
color: PropTypes.string,
disabled: PropTypes.bool,
onClick: PropTypes.func,
size: PropTypes.string,
pressed: PropTypes.bool,
}
CButton.defaultProps = {
tag: 'button'
}
//export
export default CButton