This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
button.js
75 lines (67 loc) · 1.84 KB
/
button.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
import React from 'react';
import PropTypes from 'prop-types';
import { ButtonSizes, ButtonColors } from '../enums';
import { GeneralPropTypes, FlexboxPropTypes, createClassName, generalClassNames, removeProps, objectKeys, objectValues } from '../utils';
/**
* Button property types.
*
* @type {Object}
*/
const ButtonPropTypes = {
...GeneralPropTypes,
...FlexboxPropTypes,
color: PropTypes.oneOf(objectValues(ButtonColors)),
size: PropTypes.oneOf(objectValues(ButtonSizes)),
isHollow: PropTypes.bool,
isClear: PropTypes.bool,
isExpanded: PropTypes.bool,
isDisabled: PropTypes.bool,
isDropdown: PropTypes.bool
};
/**
* Button component.
* http://foundation.zurb.com/sites/docs/button.html
*
* @param {Object} props
* @returns {Object}
*/
export const Button = (props) => {
const passProps = removeProps(props, objectKeys(Button.propTypes));
return <button {...passProps} className={createButtonClassName(props)}/>;
};
Button.propTypes = ButtonPropTypes;
/**
* Link button component.
* http://foundation.zurb.com/sites/docs/button.html#basics
*
* @param {Object} props
* @returns {Object}
*/
export const Link = (props) => {
const passProps = removeProps(props, objectKeys(Button.propTypes));
return <a {...passProps} className={createButtonClassName(props)}/>;
};
Link.propTypes = ButtonPropTypes;
/**
* Creates button class name from the given properties.
*
* @param {Object} props
* @returns {string}
*/
function createButtonClassName(props) {
return createClassName(
props.noDefaultClassName ? null : 'button',
props.className,
props.size,
props.color,
{
'hollow': props.isHollow,
'clear': props.isClear,
'expanded': props.isExpanded,
'disabled': props.isDisabled,
'dropdown': props.isDropdown,
'arrow-only': props.isArrowOnly
},
generalClassNames(props)
);
}