UNPKG

4.39 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _react = _interopRequireDefault(require("react"));
9
10var _propTypes = _interopRequireDefault(require("prop-types"));
11
12var _Label = _interopRequireDefault(require("./Label"));
13
14var _CheckboxOnly = _interopRequireDefault(require("./CheckboxOnly"));
15
16var _Text = _interopRequireDefault(require("./Text"));
17
18var _withStyles = require("../helpers/withStyles");
19
20var _reactWithStyles = require("react-with-styles");
21
22function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
24function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
25
26function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
28var propTypes = _objectSpread({}, _reactWithStyles.withStylesPropTypes, {
29 checked: _propTypes.default.bool,
30 disabled: _propTypes.default.bool,
31 id: _propTypes.default.string,
32 invalid: _propTypes.default.bool,
33 label: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]),
34 name: _propTypes.default.string,
35 onBlur: _propTypes.default.func,
36 onChange: _propTypes.default.func,
37 onFocus: _propTypes.default.func,
38 pullRight: _propTypes.default.bool,
39 refForFocus: _propTypes.default.func,
40 subtitle: _propTypes.default.string
41});
42
43var defaultProps = {
44 label: '',
45 radioButton: false
46};
47
48var Checkbox = function Checkbox(_ref) {
49 var checked = _ref.checked,
50 css = _ref.css,
51 disabled = _ref.disabled,
52 id = _ref.id,
53 invalid = _ref.invalid,
54 label = _ref.label,
55 name = _ref.name,
56 onBlur = _ref.onBlur,
57 onChange = _ref.onChange,
58 onFocus = _ref.onFocus,
59 pullRight = _ref.pullRight,
60 refForFocus = _ref.refForFocus,
61 styles = _ref.styles,
62 subtitle = _ref.subtitle;
63 return _react.default.createElement(_Label.default, {
64 htmlFor: id
65 }, _react.default.createElement("div", css(styles.column, pullRight && styles.pullRight), _react.default.createElement(_CheckboxOnly.default, {
66 id: id,
67 checked: checked,
68 disabled: disabled,
69 invalid: invalid,
70 name: name,
71 onBlur: onBlur,
72 onChange: onChange,
73 onFocus: onFocus
74 })), _react.default.createElement("div", css(styles.column, pullRight ? styles.marginRight : styles.spacing), _react.default.createElement("div", css(styles.checkbox__label), typeof label === 'string' ? _react.default.createElement(_Text.default, {
75 disabled: disabled
76 }, label) : label), subtitle && checked && _react.default.createElement("div", css(styles.subtitle), _react.default.createElement(_Text.default, {
77 small: true
78 }, subtitle))));
79};
80
81Checkbox.propTypes = propTypes;
82Checkbox.defaultProps = defaultProps;
83var CheckboxWithStyles = (0, _withStyles.withStyles)(function (_ref2) {
84 var units = _ref2.units,
85 color = _ref2.color,
86 font = _ref2.font,
87 fontSize = _ref2.fontSize,
88 weight = _ref2.weight,
89 lineHeight = _ref2.lineHeight,
90 breakpoint = _ref2.breakpoint;
91 return {
92 checkbox: {},
93 column: {
94 display: 'table-cell',
95 verticalAlign: 'top',
96 whiteSpace: 'normal'
97 },
98 checkbox__label: _defineProperty({
99 color: color.grayDarker,
100 cursor: 'pointer',
101 display: 'inline-block',
102 wordWrap: 'break-word',
103 letterSpacing: 'normal',
104 fontFamily: font.default,
105 fontWeight: weight.normal,
106 fontSize: fontSize.small.regular,
107 lineHeight: lineHeight.regular
108 }, breakpoint.large, {
109 fontSize: fontSize.large.regular
110 }),
111 spacing: {
112 paddingLeft: 12
113 },
114 marginRight: {
115 marginRight: 32
116 },
117 pullRight: {
118 float: 'right'
119 },
120 subtitle: {
121 paddingTop: 2
122 }
123 };
124})(Checkbox);
125var _default = CheckboxWithStyles;
126exports.default = _default;
\No newline at end of file