1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4 |
|
5 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.default = exports.styles = void 0;
|
11 |
|
12 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13 |
|
14 | var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
15 |
|
16 | var React = _interopRequireWildcard(require("react"));
|
17 |
|
18 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
19 |
|
20 | var _clsx = _interopRequireDefault(require("clsx"));
|
21 |
|
22 | var _utils = require("@material-ui/utils");
|
23 |
|
24 | var _withStyles = _interopRequireDefault(require("../styles/withStyles"));
|
25 |
|
26 | var _colorManipulator = require("../styles/colorManipulator");
|
27 |
|
28 | var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
|
29 |
|
30 | var _SwitchBase = _interopRequireDefault(require("../internal/SwitchBase"));
|
31 |
|
32 |
|
33 | var styles = function styles(theme) {
|
34 | return {
|
35 |
|
36 | root: {
|
37 | display: 'inline-flex',
|
38 | width: 34 + 12 * 2,
|
39 | height: 14 + 12 * 2,
|
40 | overflow: 'hidden',
|
41 | padding: 12,
|
42 | boxSizing: 'border-box',
|
43 | position: 'relative',
|
44 | flexShrink: 0,
|
45 | zIndex: 0,
|
46 |
|
47 | verticalAlign: 'middle',
|
48 |
|
49 | '@media print': {
|
50 | colorAdjust: 'exact'
|
51 | }
|
52 | },
|
53 |
|
54 |
|
55 | edgeStart: {
|
56 | marginLeft: -8
|
57 | },
|
58 |
|
59 |
|
60 | edgeEnd: {
|
61 | marginRight: -8
|
62 | },
|
63 |
|
64 |
|
65 | switchBase: {
|
66 | position: 'absolute',
|
67 | top: 0,
|
68 | left: 0,
|
69 | zIndex: 1,
|
70 |
|
71 | color: theme.palette.type === 'light' ? theme.palette.grey[50] : theme.palette.grey[400],
|
72 | transition: theme.transitions.create(['left', 'transform'], {
|
73 | duration: theme.transitions.duration.shortest
|
74 | }),
|
75 | '&$checked': {
|
76 | transform: 'translateX(20px)'
|
77 | },
|
78 | '&$disabled': {
|
79 | color: theme.palette.type === 'light' ? theme.palette.grey[400] : theme.palette.grey[800]
|
80 | },
|
81 | '&$checked + $track': {
|
82 | opacity: 0.5
|
83 | },
|
84 | '&$disabled + $track': {
|
85 | opacity: theme.palette.type === 'light' ? 0.12 : 0.1
|
86 | }
|
87 | },
|
88 |
|
89 |
|
90 | colorPrimary: {
|
91 | '&$checked': {
|
92 | color: theme.palette.primary.main,
|
93 | '&:hover': {
|
94 | backgroundColor: (0, _colorManipulator.alpha)(theme.palette.primary.main, theme.palette.action.hoverOpacity),
|
95 | '@media (hover: none)': {
|
96 | backgroundColor: 'transparent'
|
97 | }
|
98 | }
|
99 | },
|
100 | '&$disabled': {
|
101 | color: theme.palette.type === 'light' ? theme.palette.grey[400] : theme.palette.grey[800]
|
102 | },
|
103 | '&$checked + $track': {
|
104 | backgroundColor: theme.palette.primary.main
|
105 | },
|
106 | '&$disabled + $track': {
|
107 | backgroundColor: theme.palette.type === 'light' ? theme.palette.common.black : theme.palette.common.white
|
108 | }
|
109 | },
|
110 |
|
111 |
|
112 | colorSecondary: {
|
113 | '&$checked': {
|
114 | color: theme.palette.secondary.main,
|
115 | '&:hover': {
|
116 | backgroundColor: (0, _colorManipulator.alpha)(theme.palette.secondary.main, theme.palette.action.hoverOpacity),
|
117 | '@media (hover: none)': {
|
118 | backgroundColor: 'transparent'
|
119 | }
|
120 | }
|
121 | },
|
122 | '&$disabled': {
|
123 | color: theme.palette.type === 'light' ? theme.palette.grey[400] : theme.palette.grey[800]
|
124 | },
|
125 | '&$checked + $track': {
|
126 | backgroundColor: theme.palette.secondary.main
|
127 | },
|
128 | '&$disabled + $track': {
|
129 | backgroundColor: theme.palette.type === 'light' ? theme.palette.common.black : theme.palette.common.white
|
130 | }
|
131 | },
|
132 |
|
133 |
|
134 | sizeSmall: {
|
135 | width: 40,
|
136 | height: 24,
|
137 | padding: 7,
|
138 | '& $thumb': {
|
139 | width: 16,
|
140 | height: 16
|
141 | },
|
142 | '& $switchBase': {
|
143 | padding: 4,
|
144 | '&$checked': {
|
145 | transform: 'translateX(16px)'
|
146 | }
|
147 | }
|
148 | },
|
149 |
|
150 |
|
151 | checked: {},
|
152 |
|
153 |
|
154 | disabled: {},
|
155 |
|
156 |
|
157 | input: {
|
158 | left: '-100%',
|
159 | width: '300%'
|
160 | },
|
161 |
|
162 |
|
163 | thumb: {
|
164 | boxShadow: theme.shadows[1],
|
165 | backgroundColor: 'currentColor',
|
166 | width: 20,
|
167 | height: 20,
|
168 | borderRadius: '50%'
|
169 | },
|
170 |
|
171 |
|
172 | track: {
|
173 | height: '100%',
|
174 | width: '100%',
|
175 | borderRadius: 14 / 2,
|
176 | zIndex: -1,
|
177 | transition: theme.transitions.create(['opacity', 'background-color'], {
|
178 | duration: theme.transitions.duration.shortest
|
179 | }),
|
180 | backgroundColor: theme.palette.type === 'light' ? theme.palette.common.black : theme.palette.common.white,
|
181 | opacity: theme.palette.type === 'light' ? 0.38 : 0.3
|
182 | }
|
183 | };
|
184 | };
|
185 |
|
186 | exports.styles = styles;
|
187 | var Switch = React.forwardRef(function Switch(props, ref) {
|
188 | var classes = props.classes,
|
189 | className = props.className,
|
190 | _props$color = props.color,
|
191 | color = _props$color === void 0 ? 'secondary' : _props$color,
|
192 | _props$edge = props.edge,
|
193 | edge = _props$edge === void 0 ? false : _props$edge,
|
194 | _props$size = props.size,
|
195 | size = _props$size === void 0 ? 'medium' : _props$size,
|
196 | other = (0, _objectWithoutProperties2.default)(props, ["classes", "className", "color", "edge", "size"]);
|
197 | var icon = React.createElement("span", {
|
198 | className: classes.thumb
|
199 | });
|
200 | return React.createElement("span", {
|
201 | className: (0, _clsx.default)(classes.root, className, {
|
202 | 'start': classes.edgeStart,
|
203 | 'end': classes.edgeEnd
|
204 | }[edge], size === "small" && classes["size".concat((0, _capitalize.default)(size))])
|
205 | }, React.createElement(_SwitchBase.default, (0, _extends2.default)({
|
206 | type: "checkbox",
|
207 | icon: icon,
|
208 | checkedIcon: icon,
|
209 | classes: {
|
210 | root: (0, _clsx.default)(classes.switchBase, classes["color".concat((0, _capitalize.default)(color))]),
|
211 | input: classes.input,
|
212 | checked: classes.checked,
|
213 | disabled: classes.disabled
|
214 | },
|
215 | ref: ref
|
216 | }, other)), React.createElement("span", {
|
217 | className: classes.track
|
218 | }));
|
219 | });
|
220 | process.env.NODE_ENV !== "production" ? Switch.propTypes = {
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | |
227 |
|
228 |
|
229 | checked: _propTypes.default.bool,
|
230 |
|
231 | |
232 |
|
233 |
|
234 | checkedIcon: _propTypes.default.node,
|
235 |
|
236 | |
237 |
|
238 |
|
239 |
|
240 | classes: _propTypes.default.object,
|
241 |
|
242 | |
243 |
|
244 |
|
245 | className: _propTypes.default.string,
|
246 |
|
247 | |
248 |
|
249 |
|
250 | color: _propTypes.default.oneOf(['default', 'primary', 'secondary']),
|
251 |
|
252 | |
253 |
|
254 |
|
255 | defaultChecked: _propTypes.default.bool,
|
256 |
|
257 | |
258 |
|
259 |
|
260 | disabled: _propTypes.default.bool,
|
261 |
|
262 | |
263 |
|
264 |
|
265 | disableRipple: _propTypes.default.bool,
|
266 |
|
267 | |
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 | edge: _propTypes.default.oneOf(['end', 'start', false]),
|
274 |
|
275 | |
276 |
|
277 |
|
278 | icon: _propTypes.default.node,
|
279 |
|
280 | |
281 |
|
282 |
|
283 | id: _propTypes.default.string,
|
284 |
|
285 | |
286 |
|
287 |
|
288 | inputProps: _propTypes.default.object,
|
289 |
|
290 | |
291 |
|
292 |
|
293 | inputRef: _utils.refType,
|
294 |
|
295 | |
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 | onChange: _propTypes.default.func,
|
303 |
|
304 | |
305 |
|
306 |
|
307 | required: _propTypes.default.bool,
|
308 |
|
309 | |
310 |
|
311 |
|
312 |
|
313 | size: _propTypes.default.oneOf(['medium', 'small']),
|
314 |
|
315 | |
316 |
|
317 |
|
318 |
|
319 | value: _propTypes.default.any
|
320 | } : void 0;
|
321 |
|
322 | var _default = (0, _withStyles.default)(styles, {
|
323 | name: 'MuiSwitch'
|
324 | })(Switch);
|
325 |
|
326 | exports.default = _default; |
\ | No newline at end of file |