UNPKG

8 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
5var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
7Object.defineProperty(exports, "__esModule", {
8 value: true
9});
10exports.default = exports.styles = void 0;
11
12var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
14var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
15
16var React = _interopRequireWildcard(require("react"));
17
18var _propTypes = _interopRequireDefault(require("prop-types"));
19
20var _clsx = _interopRequireDefault(require("clsx"));
21
22var _utils = require("@material-ui/utils");
23
24var _SwitchBase = _interopRequireDefault(require("../internal/SwitchBase"));
25
26var _CheckBoxOutlineBlank = _interopRequireDefault(require("../internal/svg-icons/CheckBoxOutlineBlank"));
27
28var _CheckBox = _interopRequireDefault(require("../internal/svg-icons/CheckBox"));
29
30var _colorManipulator = require("../styles/colorManipulator");
31
32var _IndeterminateCheckBox = _interopRequireDefault(require("../internal/svg-icons/IndeterminateCheckBox"));
33
34var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
35
36var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
37
38var styles = function styles(theme) {
39 return {
40 /* Styles applied to the root element. */
41 root: {
42 color: theme.palette.text.secondary
43 },
44
45 /* Pseudo-class applied to the root element if `checked={true}`. */
46 checked: {},
47
48 /* Pseudo-class applied to the root element if `disabled={true}`. */
49 disabled: {},
50
51 /* Pseudo-class applied to the root element if `indeterminate={true}`. */
52 indeterminate: {},
53
54 /* Styles applied to the root element if `color="primary"`. */
55 colorPrimary: {
56 '&$checked': {
57 color: theme.palette.primary.main,
58 '&:hover': {
59 backgroundColor: (0, _colorManipulator.alpha)(theme.palette.primary.main, theme.palette.action.hoverOpacity),
60 // Reset on touch devices, it doesn't add specificity
61 '@media (hover: none)': {
62 backgroundColor: 'transparent'
63 }
64 }
65 },
66 '&$disabled': {
67 color: theme.palette.action.disabled
68 }
69 },
70
71 /* Styles applied to the root element if `color="secondary"`. */
72 colorSecondary: {
73 '&$checked': {
74 color: theme.palette.secondary.main,
75 '&:hover': {
76 backgroundColor: (0, _colorManipulator.alpha)(theme.palette.secondary.main, theme.palette.action.hoverOpacity),
77 // Reset on touch devices, it doesn't add specificity
78 '@media (hover: none)': {
79 backgroundColor: 'transparent'
80 }
81 }
82 },
83 '&$disabled': {
84 color: theme.palette.action.disabled
85 }
86 }
87 };
88};
89
90exports.styles = styles;
91var defaultCheckedIcon = /*#__PURE__*/React.createElement(_CheckBox.default, null);
92var defaultIcon = /*#__PURE__*/React.createElement(_CheckBoxOutlineBlank.default, null);
93var defaultIndeterminateIcon = /*#__PURE__*/React.createElement(_IndeterminateCheckBox.default, null);
94var Checkbox = /*#__PURE__*/React.forwardRef(function Checkbox(props, ref) {
95 var _props$checkedIcon = props.checkedIcon,
96 checkedIcon = _props$checkedIcon === void 0 ? defaultCheckedIcon : _props$checkedIcon,
97 classes = props.classes,
98 _props$color = props.color,
99 color = _props$color === void 0 ? 'secondary' : _props$color,
100 _props$icon = props.icon,
101 iconProp = _props$icon === void 0 ? defaultIcon : _props$icon,
102 _props$indeterminate = props.indeterminate,
103 indeterminate = _props$indeterminate === void 0 ? false : _props$indeterminate,
104 _props$indeterminateI = props.indeterminateIcon,
105 indeterminateIconProp = _props$indeterminateI === void 0 ? defaultIndeterminateIcon : _props$indeterminateI,
106 inputProps = props.inputProps,
107 _props$size = props.size,
108 size = _props$size === void 0 ? 'medium' : _props$size,
109 other = (0, _objectWithoutProperties2.default)(props, ["checkedIcon", "classes", "color", "icon", "indeterminate", "indeterminateIcon", "inputProps", "size"]);
110 var icon = indeterminate ? indeterminateIconProp : iconProp;
111 var indeterminateIcon = indeterminate ? indeterminateIconProp : checkedIcon;
112 return /*#__PURE__*/React.createElement(_SwitchBase.default, (0, _extends2.default)({
113 type: "checkbox",
114 classes: {
115 root: (0, _clsx.default)(classes.root, classes["color".concat((0, _capitalize.default)(color))], indeterminate && classes.indeterminate),
116 checked: classes.checked,
117 disabled: classes.disabled
118 },
119 color: color,
120 inputProps: (0, _extends2.default)({
121 'data-indeterminate': indeterminate
122 }, inputProps),
123 icon: /*#__PURE__*/React.cloneElement(icon, {
124 fontSize: icon.props.fontSize === undefined && size === "small" ? size : icon.props.fontSize
125 }),
126 checkedIcon: /*#__PURE__*/React.cloneElement(indeterminateIcon, {
127 fontSize: indeterminateIcon.props.fontSize === undefined && size === "small" ? size : indeterminateIcon.props.fontSize
128 }),
129 ref: ref
130 }, other));
131});
132process.env.NODE_ENV !== "production" ? Checkbox.propTypes = {
133 // ----------------------------- Warning --------------------------------
134 // | These PropTypes are generated from the TypeScript type definitions |
135 // | To update them edit the d.ts file and run "yarn proptypes" |
136 // ----------------------------------------------------------------------
137
138 /**
139 * If `true`, the component is checked.
140 */
141 checked: _propTypes.default.bool,
142
143 /**
144 * The icon to display when the component is checked.
145 */
146 checkedIcon: _propTypes.default.node,
147
148 /**
149 * Override or extend the styles applied to the component.
150 * See [CSS API](#css) below for more details.
151 */
152 classes: _propTypes.default.object,
153
154 /**
155 * The color of the component. It supports those theme colors that make sense for this component.
156 */
157 color: _propTypes.default.oneOf(['default', 'primary', 'secondary']),
158
159 /**
160 * If `true`, the checkbox will be disabled.
161 */
162 disabled: _propTypes.default.bool,
163
164 /**
165 * If `true`, the ripple effect will be disabled.
166 */
167 disableRipple: _propTypes.default.bool,
168
169 /**
170 * The icon to display when the component is unchecked.
171 */
172 icon: _propTypes.default.node,
173
174 /**
175 * The id of the `input` element.
176 */
177 id: _propTypes.default.string,
178
179 /**
180 * If `true`, the component appears indeterminate.
181 * This does not set the native input element to indeterminate due
182 * to inconsistent behavior across browsers.
183 * However, we set a `data-indeterminate` attribute on the input.
184 */
185 indeterminate: _propTypes.default.bool,
186
187 /**
188 * The icon to display when the component is indeterminate.
189 */
190 indeterminateIcon: _propTypes.default.node,
191
192 /**
193 * [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes) applied to the `input` element.
194 */
195 inputProps: _propTypes.default.object,
196
197 /**
198 * Pass a ref to the `input` element.
199 */
200 inputRef: _utils.refType,
201
202 /**
203 * Callback fired when the state is changed.
204 *
205 * @param {object} event The event source of the callback.
206 * You can pull out the new checked state by accessing `event.target.checked` (boolean).
207 */
208 onChange: _propTypes.default.func,
209
210 /**
211 * If `true`, the `input` element will be required.
212 */
213 required: _propTypes.default.bool,
214
215 /**
216 * The size of the checkbox.
217 * `small` is equivalent to the dense checkbox styling.
218 */
219 size: _propTypes.default.oneOf(['medium', 'small']),
220
221 /**
222 * The value of the component. The DOM API casts this to a string.
223 * The browser uses "on" as the default value.
224 */
225 value: _propTypes.default.any
226} : void 0;
227
228var _default = (0, _withStyles.default)(styles, {
229 name: 'MuiCheckbox'
230})(Checkbox);
231
232exports.default = _default;
\No newline at end of file