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