orc-shared 5.8.0-dev.14 → 5.8.0-dev.16
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/Switch.js +28 -16
- package/dist/components/MaterialUI/hocs/withDeferredPopper.js +1 -7
- 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/Switch.js +28 -6
- package/src/components/MaterialUI/Inputs/Switch.test.js +39 -0
- package/src/components/MaterialUI/hocs/withDeferredPopper.js +1 -4
- package/src/components/MaterialUI/hocs/withDeferredPopper.test.js +2 -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, {
|
|
@@ -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,
|
|
@@ -114,19 +114,13 @@ var withDeferredPopper = function withDeferredPopper(Comp) {
|
|
|
114
114
|
}
|
|
115
115
|
}, props));
|
|
116
116
|
var togglePopper = function togglePopper(event) {
|
|
117
|
-
var _event$_dispatchInsta;
|
|
118
|
-
var linkParent = event == null || (_event$_dispatchInsta = event._dispatchInstances) == null ? void 0 : _event$_dispatchInsta.filter(function (item) {
|
|
119
|
-
return item.elementType === "a";
|
|
120
|
-
});
|
|
121
|
-
if (linkParent) {
|
|
122
|
-
event.preventDefault();
|
|
123
|
-
}
|
|
124
117
|
var isDisplayed = !popperState.isDisplayed;
|
|
125
118
|
var anchorElement = event.currentTarget;
|
|
126
119
|
setPopperState({
|
|
127
120
|
isDisplayed: isDisplayed,
|
|
128
121
|
anchorElement: anchorElement
|
|
129
122
|
});
|
|
123
|
+
event.preventDefault();
|
|
130
124
|
event.bubbles = false;
|
|
131
125
|
event.stopPropagation();
|
|
132
126
|
};
|
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");
|
|
@@ -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
|
|
|
@@ -78,16 +78,13 @@ const withDeferredPopper =
|
|
|
78
78
|
const defaultComponent = <Comp onClick={event => togglePopper(event)} {...props} />;
|
|
79
79
|
|
|
80
80
|
const togglePopper = function (event) {
|
|
81
|
-
const linkParent = event?._dispatchInstances?.filter(item => item.elementType === "a");
|
|
82
|
-
if (linkParent) {
|
|
83
|
-
event.preventDefault();
|
|
84
|
-
}
|
|
85
81
|
const isDisplayed = !popperState.isDisplayed;
|
|
86
82
|
const anchorElement = event.currentTarget;
|
|
87
83
|
setPopperState({
|
|
88
84
|
isDisplayed: isDisplayed,
|
|
89
85
|
anchorElement: anchorElement,
|
|
90
86
|
});
|
|
87
|
+
event.preventDefault();
|
|
91
88
|
event.bubbles = false;
|
|
92
89
|
event.stopPropagation();
|
|
93
90
|
};
|
|
@@ -265,6 +265,7 @@ describe("withDeferredPopper", () => {
|
|
|
265
265
|
ignoreConsoleError(() => {
|
|
266
266
|
const event = {
|
|
267
267
|
currentTarget: wrapper,
|
|
268
|
+
preventDefault: jest.fn(),
|
|
268
269
|
stopPropagation: jest.fn(),
|
|
269
270
|
};
|
|
270
271
|
|
|
@@ -296,6 +297,7 @@ describe("withDeferredPopper", () => {
|
|
|
296
297
|
ignoreConsoleError(() => {
|
|
297
298
|
const event = {
|
|
298
299
|
currentTarget: null,
|
|
300
|
+
preventDefault: jest.fn(),
|
|
299
301
|
stopPropagation: jest.fn(),
|
|
300
302
|
};
|
|
301
303
|
|