1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import { refType } from '@material-ui/utils';
|
7 | import SwitchBase from '../internal/SwitchBase';
|
8 | import CheckBoxOutlineBlankIcon from '../internal/svg-icons/CheckBoxOutlineBlank';
|
9 | import CheckBoxIcon from '../internal/svg-icons/CheckBox';
|
10 | import { alpha } from '../styles/colorManipulator';
|
11 | import IndeterminateCheckBoxIcon from '../internal/svg-icons/IndeterminateCheckBox';
|
12 | import capitalize from '../utils/capitalize';
|
13 | import withStyles from '../styles/withStyles';
|
14 | export const styles = theme => ({
|
15 |
|
16 | root: {
|
17 | color: theme.palette.text.secondary
|
18 | },
|
19 |
|
20 |
|
21 | checked: {},
|
22 |
|
23 |
|
24 | disabled: {},
|
25 |
|
26 |
|
27 | indeterminate: {},
|
28 |
|
29 |
|
30 | colorPrimary: {
|
31 | '&$checked': {
|
32 | color: theme.palette.primary.main,
|
33 | '&:hover': {
|
34 | backgroundColor: alpha(theme.palette.primary.main, theme.palette.action.hoverOpacity),
|
35 |
|
36 | '@media (hover: none)': {
|
37 | backgroundColor: 'transparent'
|
38 | }
|
39 | }
|
40 | },
|
41 | '&$disabled': {
|
42 | color: theme.palette.action.disabled
|
43 | }
|
44 | },
|
45 |
|
46 |
|
47 | colorSecondary: {
|
48 | '&$checked': {
|
49 | color: theme.palette.secondary.main,
|
50 | '&:hover': {
|
51 | backgroundColor: alpha(theme.palette.secondary.main, theme.palette.action.hoverOpacity),
|
52 |
|
53 | '@media (hover: none)': {
|
54 | backgroundColor: 'transparent'
|
55 | }
|
56 | }
|
57 | },
|
58 | '&$disabled': {
|
59 | color: theme.palette.action.disabled
|
60 | }
|
61 | }
|
62 | });
|
63 | const defaultCheckedIcon = React.createElement(CheckBoxIcon, null);
|
64 | const defaultIcon = React.createElement(CheckBoxOutlineBlankIcon, null);
|
65 | const defaultIndeterminateIcon = React.createElement(IndeterminateCheckBoxIcon, null);
|
66 | const Checkbox = React.forwardRef(function Checkbox(props, ref) {
|
67 | const {
|
68 | checkedIcon = defaultCheckedIcon,
|
69 | classes,
|
70 | color = 'secondary',
|
71 | icon: iconProp = defaultIcon,
|
72 | indeterminate = false,
|
73 | indeterminateIcon: indeterminateIconProp = defaultIndeterminateIcon,
|
74 | inputProps,
|
75 | size = 'medium'
|
76 | } = props,
|
77 | other = _objectWithoutPropertiesLoose(props, ["checkedIcon", "classes", "color", "icon", "indeterminate", "indeterminateIcon", "inputProps", "size"]);
|
78 |
|
79 | const icon = indeterminate ? indeterminateIconProp : iconProp;
|
80 | const indeterminateIcon = indeterminate ? indeterminateIconProp : checkedIcon;
|
81 | return React.createElement(SwitchBase, _extends({
|
82 | type: "checkbox",
|
83 | classes: {
|
84 | root: clsx(classes.root, classes[`color${capitalize(color)}`], indeterminate && classes.indeterminate),
|
85 | checked: classes.checked,
|
86 | disabled: classes.disabled
|
87 | },
|
88 | color: color,
|
89 | inputProps: _extends({
|
90 | 'data-indeterminate': indeterminate
|
91 | }, inputProps),
|
92 | icon: React.cloneElement(icon, {
|
93 | fontSize: icon.props.fontSize === undefined && size === "small" ? size : icon.props.fontSize
|
94 | }),
|
95 | checkedIcon: React.cloneElement(indeterminateIcon, {
|
96 | fontSize: indeterminateIcon.props.fontSize === undefined && size === "small" ? size : indeterminateIcon.props.fontSize
|
97 | }),
|
98 | ref: ref
|
99 | }, other));
|
100 | });
|
101 | process.env.NODE_ENV !== "production" ? Checkbox.propTypes = {
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | |
108 |
|
109 |
|
110 | checked: PropTypes.bool,
|
111 |
|
112 | |
113 |
|
114 |
|
115 | checkedIcon: PropTypes.node,
|
116 |
|
117 | |
118 |
|
119 |
|
120 |
|
121 | classes: PropTypes.object,
|
122 |
|
123 | |
124 |
|
125 |
|
126 | color: PropTypes.oneOf(['default', 'primary', 'secondary']),
|
127 |
|
128 | |
129 |
|
130 |
|
131 | disabled: PropTypes.bool,
|
132 |
|
133 | |
134 |
|
135 |
|
136 | disableRipple: PropTypes.bool,
|
137 |
|
138 | |
139 |
|
140 |
|
141 | icon: PropTypes.node,
|
142 |
|
143 | |
144 |
|
145 |
|
146 | id: PropTypes.string,
|
147 |
|
148 | |
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | indeterminate: PropTypes.bool,
|
155 |
|
156 | |
157 |
|
158 |
|
159 | indeterminateIcon: PropTypes.node,
|
160 |
|
161 | |
162 |
|
163 |
|
164 | inputProps: PropTypes.object,
|
165 |
|
166 | |
167 |
|
168 |
|
169 | inputRef: refType,
|
170 |
|
171 | |
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | onChange: PropTypes.func,
|
178 |
|
179 | |
180 |
|
181 |
|
182 | required: PropTypes.bool,
|
183 |
|
184 | |
185 |
|
186 |
|
187 |
|
188 | size: PropTypes.oneOf(['medium', 'small']),
|
189 |
|
190 | |
191 |
|
192 |
|
193 |
|
194 | value: PropTypes.any
|
195 | } : void 0;
|
196 | export default withStyles(styles, {
|
197 | name: 'MuiCheckbox'
|
198 | })(Checkbox); |
\ | No newline at end of file |