orc-shared 5.8.0-dev.15 → 5.8.0-dev.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/MaterialUI/Inputs/DatePicker.js +9 -10
- package/dist/components/MaterialUI/Inputs/Select.js +14 -1
- package/dist/components/MaterialUI/Inputs/SelectProps.js +2 -1
- package/dist/components/MaterialUI/Inputs/Switch.js +28 -16
- package/package.json +1 -1
- package/src/components/MaterialUI/Inputs/DatePicker.js +16 -4
- package/src/components/MaterialUI/Inputs/DatePicker.test.js +35 -1
- package/src/components/MaterialUI/Inputs/Select.js +13 -1
- package/src/components/MaterialUI/Inputs/Select.test.js +37 -0
- package/src/components/MaterialUI/Inputs/SelectProps.js +1 -0
- package/src/components/MaterialUI/Inputs/Switch.js +28 -6
- package/src/components/MaterialUI/Inputs/Switch.test.js +39 -0
|
@@ -43,17 +43,11 @@ var useStyles = (0, _styles.makeStyles)(function (theme) {
|
|
|
43
43
|
datePickerWrapper: {
|
|
44
44
|
display: "flex",
|
|
45
45
|
width: "auto",
|
|
46
|
-
padding:
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
border: function border(props) {
|
|
50
|
-
return props.readOnly ? "none" : "1px solid ".concat(theme.palette.grey.borders);
|
|
51
|
-
},
|
|
46
|
+
padding: theme.spacing(0.3, 0.5),
|
|
47
|
+
border: "1px solid ".concat(theme.palette.grey.borders),
|
|
52
48
|
borderRadius: theme.shape.borderRadius,
|
|
53
49
|
alignItems: "center",
|
|
54
|
-
backgroundColor:
|
|
55
|
-
return props.readOnly ? "inherit" : theme.palette.background.default;
|
|
56
|
-
},
|
|
50
|
+
backgroundColor: theme.palette.background.default,
|
|
57
51
|
"&:focus, &:focus-within": {
|
|
58
52
|
borderRadius: theme.shape.borderRadius,
|
|
59
53
|
borderColor: theme.palette.focus,
|
|
@@ -110,6 +104,11 @@ var useStyles = (0, _styles.makeStyles)(function (theme) {
|
|
|
110
104
|
opacity: 0.4
|
|
111
105
|
}
|
|
112
106
|
},
|
|
107
|
+
datePickerWrapperReadOnly: {
|
|
108
|
+
padding: "0",
|
|
109
|
+
border: "none",
|
|
110
|
+
backgroundColor: "inherit"
|
|
111
|
+
},
|
|
113
112
|
disabled: {
|
|
114
113
|
border: "1px solid ".concat(theme.palette.grey.light, " !important"),
|
|
115
114
|
backgroundColor: "".concat(theme.palette.grey.light, " !important")
|
|
@@ -182,7 +181,7 @@ var WrappedDatePicker = function WrappedDatePicker(_ref) {
|
|
|
182
181
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
183
182
|
className: classes.container
|
|
184
183
|
}, /*#__PURE__*/_react.default.createElement("label", {
|
|
185
|
-
className: (0, _classnames.default)(classes.datePickerWrapper, disabledCls, error ? classes.errorInput : null)
|
|
184
|
+
className: (0, _classnames.default)(classes.datePickerWrapper, readOnly ? classes.datePickerWrapperReadOnly : null, disabledCls, error ? classes.errorInput : null)
|
|
186
185
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
187
186
|
className: classes.datePickerContainer
|
|
188
187
|
}, /*#__PURE__*/_react.default.createElement(_reactDatepicker.default, _extends({}, props, {
|
|
@@ -185,6 +185,7 @@ __signature__(SelectIconButton, "useStyles{classes}", function () {
|
|
|
185
185
|
__signature__(SelectIconButton, "useStyles{classes}", function () {
|
|
186
186
|
return [useStyles];
|
|
187
187
|
});
|
|
188
|
+
var selectEmptyValue = "~~#~~";
|
|
188
189
|
var Select = function Select(_ref) {
|
|
189
190
|
var _selectProps$get;
|
|
190
191
|
var options = _ref.options,
|
|
@@ -222,6 +223,16 @@ var Select = function Select(_ref) {
|
|
|
222
223
|
options.sort(function (a, b) {
|
|
223
224
|
return a.sortOrder > b.sortOrder ? 1 : -1;
|
|
224
225
|
});
|
|
226
|
+
} else if (sortType === _SelectProps.sortTypeEnum.alphabetical) {
|
|
227
|
+
options.sort(function (a, b) {
|
|
228
|
+
if (a.value === selectEmptyValue) {
|
|
229
|
+
return -1;
|
|
230
|
+
}
|
|
231
|
+
if (b.value === selectEmptyValue) {
|
|
232
|
+
return 1;
|
|
233
|
+
}
|
|
234
|
+
return a.label.localeCompare(b.label);
|
|
235
|
+
});
|
|
225
236
|
}
|
|
226
237
|
if (showAllValue && showAllLabel) {
|
|
227
238
|
options.unshift({
|
|
@@ -245,7 +256,7 @@ var Select = function Select(_ref) {
|
|
|
245
256
|
var items = options == null ? void 0 : options.map(function (option) {
|
|
246
257
|
var clss = option != null && option.level ? classes["level" + option.level] : "";
|
|
247
258
|
var appliedClasses = (0, _classnames.default)(classes.baseItem, clss);
|
|
248
|
-
var labelClss = (0, _classnames.default)(_defineProperty(_defineProperty({}, classes.label, true), classes.emptyLabel, option.value === "" || option.value ===
|
|
259
|
+
var labelClss = (0, _classnames.default)(_defineProperty(_defineProperty({}, classes.label, true), classes.emptyLabel, option.value === "" || option.value === selectEmptyValue));
|
|
249
260
|
var disabled = !!option.disabled;
|
|
250
261
|
var groupHeader = !!option.isGroupHeader;
|
|
251
262
|
if (groupHeader) {
|
|
@@ -332,6 +343,7 @@ var _default3 = exports.default = _default2;
|
|
|
332
343
|
reactHotLoader.register(getIconButtonMenuProps, "getIconButtonMenuProps", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
333
344
|
reactHotLoader.register(SelectIcon, "SelectIcon", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
334
345
|
reactHotLoader.register(SelectIconButton, "SelectIconButton", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
346
|
+
reactHotLoader.register(selectEmptyValue, "selectEmptyValue", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
335
347
|
reactHotLoader.register(Select, "Select", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
336
348
|
reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
337
349
|
})();
|
|
@@ -351,6 +363,7 @@ var _default3 = exports.default = _default2;
|
|
|
351
363
|
reactHotLoader.register(getIconButtonMenuProps, "getIconButtonMenuProps", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
352
364
|
reactHotLoader.register(SelectIcon, "SelectIcon", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
353
365
|
reactHotLoader.register(SelectIconButton, "SelectIconButton", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
366
|
+
reactHotLoader.register(selectEmptyValue, "selectEmptyValue", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
354
367
|
reactHotLoader.register(Select, "Select", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
355
368
|
reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
356
369
|
})();
|
|
@@ -26,7 +26,8 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
|
|
|
26
26
|
var sortTypeEnum = exports.sortTypeEnum = {
|
|
27
27
|
none: 0,
|
|
28
28
|
default: 1,
|
|
29
|
-
numeric: 2
|
|
29
|
+
numeric: 2,
|
|
30
|
+
alphabetical: 3
|
|
30
31
|
};
|
|
31
32
|
var SelectProps = /*#__PURE__*/function (_ComponentProps) {
|
|
32
33
|
function SelectProps() {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.useStyles = exports.default = void 0;
|
|
5
5
|
var _react = _interopRequireDefault(require("react"));
|
|
6
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
6
7
|
var _Switch = _interopRequireDefault(require("@material-ui/core/Switch"));
|
|
7
8
|
var _styles = require("@material-ui/core/styles");
|
|
8
9
|
var _SwitchProps = _interopRequireWildcard(require("./SwitchProps"));
|
|
@@ -47,17 +48,19 @@ var useStyles = exports.useStyles = (0, _styles.makeStyles)(function (theme) {
|
|
|
47
48
|
input: {
|
|
48
49
|
left: "-250%",
|
|
49
50
|
width: "600%",
|
|
50
|
-
cursor:
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
cursor: "inherit"
|
|
52
|
+
},
|
|
53
|
+
inputReadOnly: {
|
|
54
|
+
cursor: "default"
|
|
53
55
|
},
|
|
54
56
|
thumb: {
|
|
55
57
|
width: theme.spacing(1.3),
|
|
56
58
|
height: theme.spacing(1.3),
|
|
57
59
|
backgroundColor: theme.palette.background.default,
|
|
58
|
-
display:
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
display: "inherit"
|
|
61
|
+
},
|
|
62
|
+
thumbReadOnly: {
|
|
63
|
+
display: "none"
|
|
61
64
|
},
|
|
62
65
|
track: {
|
|
63
66
|
backgroundColor: theme.palette.grey.borders,
|
|
@@ -77,19 +80,21 @@ var useStyles = exports.useStyles = (0, _styles.makeStyles)(function (theme) {
|
|
|
77
80
|
return "\"".concat(props.formattedOnCaption, "\"");
|
|
78
81
|
},
|
|
79
82
|
left: theme.spacing(0.9),
|
|
80
|
-
right: function right(props) {
|
|
81
|
-
return props.readOnly && theme.spacing(0.9);
|
|
82
|
-
},
|
|
83
83
|
opacity: 0
|
|
84
84
|
},
|
|
85
85
|
"&:after": {
|
|
86
86
|
content: function content(props) {
|
|
87
87
|
return "\"".concat(props.formattedOffCaption, "\"");
|
|
88
88
|
},
|
|
89
|
-
right: theme.spacing(0.9)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
right: theme.spacing(0.9)
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
trackReadOnly: {
|
|
93
|
+
"&:before": {
|
|
94
|
+
right: theme.spacing(0.9)
|
|
95
|
+
},
|
|
96
|
+
"&:after": {
|
|
97
|
+
left: theme.spacing(0.9)
|
|
93
98
|
}
|
|
94
99
|
},
|
|
95
100
|
checked: {
|
|
@@ -133,10 +138,17 @@ var Switch = function Switch(_ref) {
|
|
|
133
138
|
var formattedOffCaption = offCaption != null ? formatMessage(offCaption) : "";
|
|
134
139
|
var classes = useStyles({
|
|
135
140
|
formattedOnCaption: formattedOnCaption,
|
|
136
|
-
formattedOffCaption: formattedOffCaption
|
|
137
|
-
readOnly: readOnly
|
|
141
|
+
formattedOffCaption: formattedOffCaption
|
|
138
142
|
});
|
|
139
|
-
var switchClasses = _objectSpread(
|
|
143
|
+
var switchClasses = _objectSpread({
|
|
144
|
+
root: classes.root,
|
|
145
|
+
switchBase: classes.switchBase,
|
|
146
|
+
input: (0, _classnames.default)(classes.input, _defineProperty({}, classes.inputReadOnly, readOnly)),
|
|
147
|
+
thumb: (0, _classnames.default)(classes.thumb, _defineProperty({}, classes.thumbReadOnly, readOnly)),
|
|
148
|
+
track: (0, _classnames.default)(classes.track, _defineProperty({}, classes.trackReadOnly, readOnly)),
|
|
149
|
+
checked: classes.checked,
|
|
150
|
+
disabled: classes.disabled
|
|
151
|
+
}, className);
|
|
140
152
|
return /*#__PURE__*/_react.default.createElement(_Switch.default, {
|
|
141
153
|
disabled: disabled,
|
|
142
154
|
classes: switchClasses,
|
package/package.json
CHANGED
|
@@ -21,11 +21,11 @@ const useStyles = makeStyles(theme => ({
|
|
|
21
21
|
datePickerWrapper: {
|
|
22
22
|
display: "flex",
|
|
23
23
|
width: "auto",
|
|
24
|
-
padding:
|
|
25
|
-
border:
|
|
24
|
+
padding: theme.spacing(0.3, 0.5),
|
|
25
|
+
border: `1px solid ${theme.palette.grey.borders}`,
|
|
26
26
|
borderRadius: theme.shape.borderRadius,
|
|
27
27
|
alignItems: "center",
|
|
28
|
-
backgroundColor:
|
|
28
|
+
backgroundColor: theme.palette.background.default,
|
|
29
29
|
"&:focus, &:focus-within": {
|
|
30
30
|
borderRadius: theme.shape.borderRadius,
|
|
31
31
|
borderColor: theme.palette.focus,
|
|
@@ -82,6 +82,11 @@ const useStyles = makeStyles(theme => ({
|
|
|
82
82
|
opacity: 0.4,
|
|
83
83
|
},
|
|
84
84
|
},
|
|
85
|
+
datePickerWrapperReadOnly: {
|
|
86
|
+
padding: "0",
|
|
87
|
+
border: "none",
|
|
88
|
+
backgroundColor: "inherit",
|
|
89
|
+
},
|
|
85
90
|
disabled: {
|
|
86
91
|
border: `1px solid ${theme.palette.grey.light} !important`,
|
|
87
92
|
backgroundColor: `${theme.palette.grey.light} !important`,
|
|
@@ -157,7 +162,14 @@ const WrappedDatePicker = ({
|
|
|
157
162
|
|
|
158
163
|
return (
|
|
159
164
|
<div className={classes.container}>
|
|
160
|
-
<label
|
|
165
|
+
<label
|
|
166
|
+
className={classNames(
|
|
167
|
+
classes.datePickerWrapper,
|
|
168
|
+
readOnly ? classes.datePickerWrapperReadOnly : null,
|
|
169
|
+
disabledCls,
|
|
170
|
+
error ? classes.errorInput : null,
|
|
171
|
+
)}
|
|
172
|
+
>
|
|
161
173
|
<div className={classes.datePickerContainer}>
|
|
162
174
|
<DatePicker
|
|
163
175
|
{...props}
|
|
@@ -3,8 +3,10 @@ import DatePicker, { createFormat } from "./DatePicker";
|
|
|
3
3
|
import { mount } from "enzyme";
|
|
4
4
|
import sinon from "sinon";
|
|
5
5
|
import Icon from "../DataDisplay/Icon";
|
|
6
|
-
import { TestWrapper, createMuiTheme } from "./../../../utils/testUtils";
|
|
6
|
+
import { TestWrapper, createMuiTheme, generateClassName } from "./../../../utils/testUtils";
|
|
7
7
|
import Immutable from "immutable";
|
|
8
|
+
import { StylesProvider } from "@material-ui/core/styles";
|
|
9
|
+
import { MuiThemeProvider } from "@material-ui/core";
|
|
8
10
|
|
|
9
11
|
describe("DatePicker", () => {
|
|
10
12
|
let updater, state, store;
|
|
@@ -426,6 +428,38 @@ describe("DatePicker", () => {
|
|
|
426
428
|
input.at(0).simulate("change", event);
|
|
427
429
|
});
|
|
428
430
|
|
|
431
|
+
it("should have readonly styles when readonly", () => {
|
|
432
|
+
const date = new Date("2020-06-30T00:00:00");
|
|
433
|
+
|
|
434
|
+
const component = (
|
|
435
|
+
<TestWrapper provider={{ store }} intlProvider>
|
|
436
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
437
|
+
<MuiThemeProvider theme={createMuiTheme()}>
|
|
438
|
+
<DatePicker useTime={true} readOnly={true} onChange={updater} value={date} />
|
|
439
|
+
</MuiThemeProvider>
|
|
440
|
+
</StylesProvider>
|
|
441
|
+
</TestWrapper>
|
|
442
|
+
);
|
|
443
|
+
const mountedComponent = mount(component);
|
|
444
|
+
expect(mountedComponent.exists(".makeStyles-datePickerWrapperReadOnly"), "to be true");
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it("should have updatable styles when updatable", () => {
|
|
448
|
+
const date = new Date("2020-06-30T00:00:00");
|
|
449
|
+
|
|
450
|
+
const component = (
|
|
451
|
+
<TestWrapper provider={{ store }} intlProvider>
|
|
452
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
453
|
+
<MuiThemeProvider theme={createMuiTheme()}>
|
|
454
|
+
<DatePicker useTime={true} readOnly={false} onChange={updater} value={date} />
|
|
455
|
+
</MuiThemeProvider>
|
|
456
|
+
</StylesProvider>
|
|
457
|
+
</TestWrapper>
|
|
458
|
+
);
|
|
459
|
+
const mountedComponent = mount(component);
|
|
460
|
+
expect(mountedComponent.exists(".makeStyles-datePickerWrapperReadOnly"), "to be false");
|
|
461
|
+
});
|
|
462
|
+
|
|
429
463
|
it("should call onChange prop with useTimeZone", () => {
|
|
430
464
|
const onChangeMock = jest.fn();
|
|
431
465
|
const date = new Date("2020-06-30T00:00:00");
|
|
@@ -145,6 +145,8 @@ export const SelectIconButton = props => {
|
|
|
145
145
|
);
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
+
const selectEmptyValue = "~~#~~";
|
|
149
|
+
|
|
148
150
|
const Select = ({ options, selectProps, children }) => {
|
|
149
151
|
if (isSelectProps(selectProps) === false) {
|
|
150
152
|
throw new TypeError("selectProps property is not of type SelectProps");
|
|
@@ -177,6 +179,16 @@ const Select = ({ options, selectProps, children }) => {
|
|
|
177
179
|
);
|
|
178
180
|
} else if (sortType === sortTypeEnum.default) {
|
|
179
181
|
options.sort((a, b) => (a.sortOrder > b.sortOrder ? 1 : -1));
|
|
182
|
+
} else if (sortType === sortTypeEnum.alphabetical) {
|
|
183
|
+
options.sort((a, b) => {
|
|
184
|
+
if (a.value === selectEmptyValue) {
|
|
185
|
+
return -1;
|
|
186
|
+
}
|
|
187
|
+
if (b.value === selectEmptyValue) {
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
return a.label.localeCompare(b.label);
|
|
191
|
+
});
|
|
180
192
|
}
|
|
181
193
|
|
|
182
194
|
if (showAllValue && showAllLabel) {
|
|
@@ -207,7 +219,7 @@ const Select = ({ options, selectProps, children }) => {
|
|
|
207
219
|
const appliedClasses = classNames(classes.baseItem, clss);
|
|
208
220
|
const labelClss = classNames({
|
|
209
221
|
[classes.label]: true,
|
|
210
|
-
[classes.emptyLabel]: option.value === "" || option.value ===
|
|
222
|
+
[classes.emptyLabel]: option.value === "" || option.value === selectEmptyValue,
|
|
211
223
|
});
|
|
212
224
|
|
|
213
225
|
const disabled = !!option.disabled;
|
|
@@ -496,6 +496,43 @@ describe("Select Component", () => {
|
|
|
496
496
|
expect(optionsKeys, "to equal", ["#All#", "a", "b", "c"]);
|
|
497
497
|
});
|
|
498
498
|
|
|
499
|
+
it("Sorts select options correctly with alphabetical sorting", () => {
|
|
500
|
+
const emptyValue = "~~#~~";
|
|
501
|
+
|
|
502
|
+
const options = [
|
|
503
|
+
{ value: "c", label: "c" },
|
|
504
|
+
{ value: "a", label: "a" },
|
|
505
|
+
{ value: "b", label: "b" },
|
|
506
|
+
{ value: "f", label: "f" },
|
|
507
|
+
{ value: emptyValue, label: "empty" },
|
|
508
|
+
{ value: "h", label: "h" },
|
|
509
|
+
{ value: "g", label: "g" },
|
|
510
|
+
{ value: "e", label: "e" },
|
|
511
|
+
{ value: "d", label: "[d]" },
|
|
512
|
+
];
|
|
513
|
+
|
|
514
|
+
const selectProps = new SelectProps();
|
|
515
|
+
|
|
516
|
+
selectProps.set(SelectProps.propNames.sortType, sortTypeEnum.alphabetical);
|
|
517
|
+
selectProps.set(SelectProps.propNames.value, "b");
|
|
518
|
+
|
|
519
|
+
const component = (
|
|
520
|
+
<TestWrapper stylesProvider muiThemeProvider={{ theme }}>
|
|
521
|
+
<Select options={options} selectProps={selectProps} />
|
|
522
|
+
</TestWrapper>
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
const mountedComponent = mount(component);
|
|
526
|
+
|
|
527
|
+
const test = mountedComponent.find(SelectMUI);
|
|
528
|
+
|
|
529
|
+
const mountedOptions = test.props().children;
|
|
530
|
+
|
|
531
|
+
const optionsKeys = mountedOptions.map(option => option.key);
|
|
532
|
+
|
|
533
|
+
expect(optionsKeys, "to equal", [emptyValue, "d", "a", "b", "c", "e", "f", "g", "h"]);
|
|
534
|
+
});
|
|
535
|
+
|
|
499
536
|
it("Sorts select options correctly with numeric sorting", () => {
|
|
500
537
|
const options = [
|
|
501
538
|
{ value: "BRC-409 - BRC-PROMENADES", label: "BRC-409 - BRC-PROMENADES", sortOrder: "BRC-409 - BRC-PROMENADES" },
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import classNames from "classnames";
|
|
2
3
|
import SwitchMui from "@material-ui/core/Switch";
|
|
3
4
|
import { makeStyles } from "@material-ui/core/styles";
|
|
4
5
|
import SwitchProps, { isSwitchProps } from "./SwitchProps";
|
|
@@ -21,13 +22,19 @@ export const useStyles = makeStyles(theme => ({
|
|
|
21
22
|
input: {
|
|
22
23
|
left: "-250%",
|
|
23
24
|
width: "600%",
|
|
24
|
-
cursor:
|
|
25
|
+
cursor: "inherit",
|
|
26
|
+
},
|
|
27
|
+
inputReadOnly: {
|
|
28
|
+
cursor: "default",
|
|
25
29
|
},
|
|
26
30
|
thumb: {
|
|
27
31
|
width: theme.spacing(1.3),
|
|
28
32
|
height: theme.spacing(1.3),
|
|
29
33
|
backgroundColor: theme.palette.background.default,
|
|
30
|
-
display:
|
|
34
|
+
display: "inherit",
|
|
35
|
+
},
|
|
36
|
+
thumbReadOnly: {
|
|
37
|
+
display: "none",
|
|
31
38
|
},
|
|
32
39
|
track: {
|
|
33
40
|
backgroundColor: theme.palette.grey.borders,
|
|
@@ -45,13 +52,19 @@ export const useStyles = makeStyles(theme => ({
|
|
|
45
52
|
"&:before": {
|
|
46
53
|
content: props => `"${props.formattedOnCaption}"`,
|
|
47
54
|
left: theme.spacing(0.9),
|
|
48
|
-
right: props => props.readOnly && theme.spacing(0.9),
|
|
49
55
|
opacity: 0,
|
|
50
56
|
},
|
|
51
57
|
"&:after": {
|
|
52
58
|
content: props => `"${props.formattedOffCaption}"`,
|
|
53
59
|
right: theme.spacing(0.9),
|
|
54
|
-
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
trackReadOnly: {
|
|
63
|
+
"&:before": {
|
|
64
|
+
right: theme.spacing(0.9),
|
|
65
|
+
},
|
|
66
|
+
"&:after": {
|
|
67
|
+
left: theme.spacing(0.9),
|
|
55
68
|
},
|
|
56
69
|
},
|
|
57
70
|
checked: {
|
|
@@ -95,8 +108,17 @@ const Switch = ({ switchProps }) => {
|
|
|
95
108
|
const formattedOnCaption = onCaption != null ? formatMessage(onCaption) : "";
|
|
96
109
|
const formattedOffCaption = offCaption != null ? formatMessage(offCaption) : "";
|
|
97
110
|
|
|
98
|
-
const classes = useStyles({ formattedOnCaption, formattedOffCaption
|
|
99
|
-
const switchClasses = {
|
|
111
|
+
const classes = useStyles({ formattedOnCaption, formattedOffCaption });
|
|
112
|
+
const switchClasses = {
|
|
113
|
+
root: classes.root,
|
|
114
|
+
switchBase: classes.switchBase,
|
|
115
|
+
input: classNames(classes.input, { [classes.inputReadOnly]: readOnly }),
|
|
116
|
+
thumb: classNames(classes.thumb, { [classes.thumbReadOnly]: readOnly }),
|
|
117
|
+
track: classNames(classes.track, { [classes.trackReadOnly]: readOnly }),
|
|
118
|
+
checked: classes.checked,
|
|
119
|
+
disabled: classes.disabled,
|
|
120
|
+
...className,
|
|
121
|
+
};
|
|
100
122
|
|
|
101
123
|
return (
|
|
102
124
|
<SwitchMui
|
|
@@ -6,6 +6,9 @@ import { ignoreConsoleError } from "../../../utils/testUtils";
|
|
|
6
6
|
import SwitchProps from "./SwitchProps";
|
|
7
7
|
import Switch from "./Switch";
|
|
8
8
|
import { IntlProvider } from "react-intl";
|
|
9
|
+
import { StylesProvider } from "@material-ui/core/styles";
|
|
10
|
+
import { MuiThemeProvider } from "@material-ui/core";
|
|
11
|
+
import { generateClassName, createMuiTheme } from "~/utils/testUtils";
|
|
9
12
|
|
|
10
13
|
const messages = {
|
|
11
14
|
captionOn: "is On",
|
|
@@ -77,6 +80,42 @@ describe("Switch Component", () => {
|
|
|
77
80
|
expect(update, "to have calls satisfying", [{ args: [true, {}] }]);
|
|
78
81
|
});
|
|
79
82
|
|
|
83
|
+
it("Renders readonly switch with readonly styles", () => {
|
|
84
|
+
const switchProps = new SwitchProps();
|
|
85
|
+
switchProps.set(SwitchProps.propNames.readOnly, true);
|
|
86
|
+
const component = (
|
|
87
|
+
<IntlProvider locale="en-US">
|
|
88
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
89
|
+
<MuiThemeProvider theme={createMuiTheme()}>
|
|
90
|
+
<Switch switchProps={switchProps} />
|
|
91
|
+
</MuiThemeProvider>
|
|
92
|
+
</StylesProvider>
|
|
93
|
+
</IntlProvider>
|
|
94
|
+
);
|
|
95
|
+
const mountedComponent = mount(component);
|
|
96
|
+
expect(mountedComponent.exists(".makeStyles-inputReadOnly"), "to be true");
|
|
97
|
+
expect(mountedComponent.exists(".makeStyles-thumbReadOnly"), "to be true");
|
|
98
|
+
expect(mountedComponent.exists(".makeStyles-trackReadOnly"), "to be true");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("Renders updatable switch with updatable styles", () => {
|
|
102
|
+
const switchProps = new SwitchProps();
|
|
103
|
+
switchProps.set(SwitchProps.propNames.readOnly, false);
|
|
104
|
+
const component = (
|
|
105
|
+
<IntlProvider locale="en-US">
|
|
106
|
+
<StylesProvider generateClassName={generateClassName}>
|
|
107
|
+
<MuiThemeProvider theme={createMuiTheme()}>
|
|
108
|
+
<Switch switchProps={switchProps} />
|
|
109
|
+
</MuiThemeProvider>
|
|
110
|
+
</StylesProvider>
|
|
111
|
+
</IntlProvider>
|
|
112
|
+
);
|
|
113
|
+
const mountedComponent = mount(component);
|
|
114
|
+
expect(mountedComponent.exists(".makeStyles-inputReadOnly"), "to be false");
|
|
115
|
+
expect(mountedComponent.exists(".makeStyles-thumbReadOnly"), "to be false");
|
|
116
|
+
expect(mountedComponent.exists(".makeStyles-trackReadOnly"), "to be false");
|
|
117
|
+
});
|
|
118
|
+
|
|
80
119
|
it("Checkbox component handles uncheck", () => {
|
|
81
120
|
const switchProps = new SwitchProps();
|
|
82
121
|
|