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 _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
13 |
|
14 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
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 _styles = require("@material-ui/core/styles");
|
23 |
|
24 | var _ButtonBase = _interopRequireDefault(require("@material-ui/core/ButtonBase"));
|
25 |
|
26 | var _utils = require("@material-ui/core/utils");
|
27 |
|
28 |
|
29 | var styles = function styles(theme) {
|
30 | return {
|
31 |
|
32 | root: (0, _extends2.default)({}, theme.typography.button, {
|
33 | boxSizing: 'border-box',
|
34 | borderRadius: theme.shape.borderRadius,
|
35 | padding: 11,
|
36 | border: "1px solid ".concat((0, _styles.alpha)(theme.palette.action.active, 0.12)),
|
37 | color: (0, _styles.alpha)(theme.palette.action.active, 0.38),
|
38 | '&$selected': {
|
39 | color: theme.palette.action.active,
|
40 | backgroundColor: (0, _styles.alpha)(theme.palette.action.active, 0.12),
|
41 | '&:hover': {
|
42 | backgroundColor: (0, _styles.alpha)(theme.palette.action.active, 0.15)
|
43 | },
|
44 | '& + &': {
|
45 | borderLeft: 0,
|
46 | marginLeft: 0
|
47 | }
|
48 | },
|
49 | '&$disabled': {
|
50 | color: (0, _styles.alpha)(theme.palette.action.disabled, 0.12)
|
51 | },
|
52 | '&:hover': {
|
53 | textDecoration: 'none',
|
54 |
|
55 | backgroundColor: (0, _styles.alpha)(theme.palette.text.primary, 0.05),
|
56 | '@media (hover: none)': {
|
57 | backgroundColor: 'transparent'
|
58 | },
|
59 | '&$disabled': {
|
60 | backgroundColor: 'transparent'
|
61 | }
|
62 | }
|
63 | }),
|
64 |
|
65 |
|
66 | disabled: {},
|
67 |
|
68 |
|
69 | selected: {},
|
70 |
|
71 |
|
72 | label: {
|
73 | width: '100%',
|
74 |
|
75 | display: 'inherit',
|
76 | alignItems: 'inherit',
|
77 | justifyContent: 'inherit'
|
78 | },
|
79 |
|
80 |
|
81 | sizeSmall: {
|
82 | padding: 7,
|
83 | fontSize: theme.typography.pxToRem(13)
|
84 | },
|
85 |
|
86 |
|
87 | sizeLarge: {
|
88 | padding: 15,
|
89 | fontSize: theme.typography.pxToRem(15)
|
90 | }
|
91 | };
|
92 | };
|
93 |
|
94 | exports.styles = styles;
|
95 | var ToggleButton = React.forwardRef(function ToggleButton(props, ref) {
|
96 | var children = props.children,
|
97 | classes = props.classes,
|
98 | className = props.className,
|
99 | _props$disabled = props.disabled,
|
100 | disabled = _props$disabled === void 0 ? false : _props$disabled,
|
101 | _props$disableFocusRi = props.disableFocusRipple,
|
102 | disableFocusRipple = _props$disableFocusRi === void 0 ? false : _props$disableFocusRi,
|
103 | onChange = props.onChange,
|
104 | onClick = props.onClick,
|
105 | selected = props.selected,
|
106 | _props$size = props.size,
|
107 | size = _props$size === void 0 ? 'medium' : _props$size,
|
108 | value = props.value,
|
109 | other = (0, _objectWithoutProperties2.default)(props, ["children", "classes", "className", "disabled", "disableFocusRipple", "onChange", "onClick", "selected", "size", "value"]);
|
110 |
|
111 | var handleChange = function handleChange(event) {
|
112 | if (onClick) {
|
113 | onClick(event, value);
|
114 |
|
115 | if (event.isDefaultPrevented()) {
|
116 | return;
|
117 | }
|
118 | }
|
119 |
|
120 | if (onChange) {
|
121 | onChange(event, value);
|
122 | }
|
123 | };
|
124 |
|
125 | return React.createElement(_ButtonBase.default, (0, _extends2.default)({
|
126 | className: (0, _clsx.default)(classes.root, className, disabled && classes.disabled, selected && classes.selected, size !== 'medium' && classes["size".concat((0, _utils.capitalize)(size))]),
|
127 | disabled: disabled,
|
128 | focusRipple: !disableFocusRipple,
|
129 | ref: ref,
|
130 | onClick: handleChange,
|
131 | onChange: onChange,
|
132 | value: value,
|
133 | "aria-pressed": selected
|
134 | }, other), React.createElement("span", {
|
135 | className: classes.label
|
136 | }, children));
|
137 | });
|
138 | process.env.NODE_ENV !== "production" ? ToggleButton.propTypes = {
|
139 | |
140 |
|
141 |
|
142 | children: _propTypes.default.node.isRequired,
|
143 |
|
144 | |
145 |
|
146 |
|
147 |
|
148 | classes: _propTypes.default.object.isRequired,
|
149 |
|
150 | |
151 |
|
152 |
|
153 | className: _propTypes.default.string,
|
154 |
|
155 | |
156 |
|
157 |
|
158 | disabled: _propTypes.default.bool,
|
159 |
|
160 | |
161 |
|
162 |
|
163 | disableFocusRipple: _propTypes.default.bool,
|
164 |
|
165 | |
166 |
|
167 |
|
168 | disableRipple: _propTypes.default.bool,
|
169 |
|
170 | |
171 |
|
172 |
|
173 | onChange: _propTypes.default.func,
|
174 |
|
175 | |
176 |
|
177 |
|
178 | onClick: _propTypes.default.func,
|
179 |
|
180 | |
181 |
|
182 |
|
183 | selected: _propTypes.default.bool,
|
184 |
|
185 | |
186 |
|
187 |
|
188 | size: _propTypes.default.oneOf(['small', 'medium', 'large']),
|
189 |
|
190 | |
191 |
|
192 |
|
193 |
|
194 | value: _propTypes.default.any.isRequired
|
195 | } : void 0;
|
196 |
|
197 | var _default = (0, _styles.withStyles)(styles, {
|
198 | name: 'MuiToggleButton'
|
199 | })(ToggleButton);
|
200 |
|
201 | exports.default = _default; |
\ | No newline at end of file |