@pie-lib/correct-answer-toggle 4.0.2-next.2 → 4.0.3-next.0
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/expander.d.ts +19 -0
- package/dist/expander.js +68 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +146 -0
- package/package.json +29 -26
- package/CHANGELOG.json +0 -1
- package/CHANGELOG.md +0 -971
- package/LICENSE.md +0 -5
- package/lib/expander.js +0 -80
- package/lib/expander.js.map +0 -1
- package/lib/index.js +0 -211
- package/lib/index.js.map +0 -1
- package/src/__tests__/index.test.jsx +0 -85
- package/src/expander.jsx +0 -75
- package/src/index.jsx +0 -177
package/LICENSE.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
Copyright 2019 CoreSpring Inc
|
|
2
|
-
|
|
3
|
-
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
|
-
|
|
5
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/lib/expander.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
var _styles = require("@mui/material/styles");
|
|
12
|
-
var _reactTransitionGroup = require("react-transition-group");
|
|
13
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
14
|
-
var transition = 'height ease-in 300ms, opacity ease-in 300ms';
|
|
15
|
-
var StyledExpander = (0, _styles.styled)('div')(function () {
|
|
16
|
-
return {
|
|
17
|
-
position: 'relative',
|
|
18
|
-
height: 0,
|
|
19
|
-
overflow: 'hidden',
|
|
20
|
-
display: 'flex',
|
|
21
|
-
visibility: 'hidden',
|
|
22
|
-
width: 0,
|
|
23
|
-
'&.enter': {
|
|
24
|
-
transition: transition,
|
|
25
|
-
opacity: 1,
|
|
26
|
-
height: 'auto',
|
|
27
|
-
width: 'auto',
|
|
28
|
-
visibility: 'visible',
|
|
29
|
-
minHeight: '25px'
|
|
30
|
-
},
|
|
31
|
-
'&.enter-done': {
|
|
32
|
-
height: 'auto',
|
|
33
|
-
visibility: 'visible',
|
|
34
|
-
width: 'auto',
|
|
35
|
-
minHeight: '25px'
|
|
36
|
-
},
|
|
37
|
-
'&.exit': {
|
|
38
|
-
transition: transition,
|
|
39
|
-
opacity: 0,
|
|
40
|
-
height: 0,
|
|
41
|
-
visibility: 'visible',
|
|
42
|
-
width: 0
|
|
43
|
-
},
|
|
44
|
-
'&.exit-done': {
|
|
45
|
-
opacity: 0,
|
|
46
|
-
visibility: 'hidden',
|
|
47
|
-
height: 0,
|
|
48
|
-
width: 0
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
var Expander = function Expander(props) {
|
|
53
|
-
var show = props.show,
|
|
54
|
-
children = props.children,
|
|
55
|
-
className = props.className;
|
|
56
|
-
var nodeRef = (0, _react.useRef)(null);
|
|
57
|
-
return /*#__PURE__*/_react["default"].createElement(_reactTransitionGroup.CSSTransition, {
|
|
58
|
-
nodeRef: nodeRef,
|
|
59
|
-
"in": show,
|
|
60
|
-
appear: true,
|
|
61
|
-
mountOnEnter: false,
|
|
62
|
-
timeout: 300,
|
|
63
|
-
classNames: {
|
|
64
|
-
enter: 'enter',
|
|
65
|
-
enterDone: 'enter-done',
|
|
66
|
-
exit: 'exit',
|
|
67
|
-
exitDone: 'exit-done'
|
|
68
|
-
}
|
|
69
|
-
}, /*#__PURE__*/_react["default"].createElement(StyledExpander, {
|
|
70
|
-
ref: nodeRef,
|
|
71
|
-
className: className
|
|
72
|
-
}, children));
|
|
73
|
-
};
|
|
74
|
-
Expander.propTypes = {
|
|
75
|
-
show: _propTypes["default"].bool.isRequired,
|
|
76
|
-
className: _propTypes["default"].string,
|
|
77
|
-
children: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].node), _propTypes["default"].node]).isRequired
|
|
78
|
-
};
|
|
79
|
-
var _default = exports["default"] = Expander;
|
|
80
|
-
//# sourceMappingURL=expander.js.map
|
package/lib/expander.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expander.js","names":["_react","_interopRequireWildcard","require","_propTypes","_interopRequireDefault","_styles","_reactTransitionGroup","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","transition","StyledExpander","styled","position","height","overflow","display","visibility","width","opacity","minHeight","Expander","props","show","children","className","nodeRef","useRef","createElement","CSSTransition","appear","mountOnEnter","timeout","classNames","enter","enterDone","exit","exitDone","ref","propTypes","PropTypes","bool","isRequired","string","oneOfType","arrayOf","node","_default","exports"],"sources":["../src/expander.jsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport PropTypes from 'prop-types';\nimport { styled } from '@mui/material/styles';\nimport { CSSTransition } from 'react-transition-group';\n\nconst transition = 'height ease-in 300ms, opacity ease-in 300ms';\n\nconst StyledExpander = styled('div')(() => ({\n position: 'relative',\n height: 0,\n overflow: 'hidden',\n display: 'flex',\n visibility: 'hidden',\n width: 0,\n '&.enter': {\n transition,\n opacity: 1,\n height: 'auto',\n width: 'auto',\n visibility: 'visible',\n minHeight: '25px',\n },\n '&.enter-done': {\n height: 'auto',\n visibility: 'visible',\n width: 'auto',\n minHeight: '25px',\n },\n '&.exit': {\n transition,\n opacity: 0,\n height: 0,\n visibility: 'visible',\n width: 0,\n },\n '&.exit-done': {\n opacity: 0,\n visibility: 'hidden',\n height: 0,\n width: 0,\n },\n}));\n\nconst Expander = (props) => {\n const { show, children, className } = props;\n const nodeRef = useRef(null);\n\n return (\n <CSSTransition\n nodeRef={nodeRef}\n in={show}\n appear={true}\n mountOnEnter={false}\n timeout={300}\n classNames={{\n enter: 'enter',\n enterDone: 'enter-done',\n exit: 'exit',\n exitDone: 'exit-done',\n }}\n >\n <StyledExpander ref={nodeRef} className={className}>\n {children}\n </StyledExpander>\n </CSSTransition>\n );\n};\n\nExpander.propTypes = {\n show: PropTypes.bool.isRequired,\n className: PropTypes.string,\n children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,\n};\n\nexport default Expander;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OA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AAEZ,OAAQ;IAACD,SAAS,EAAEA;EAAU,GAChDD,QACa,CACH,CAAC;AAEpB,CAAC;AAEDH,QAAQ,CAACkB,SAAS,GAAG;EACnBhB,IAAI,EAAEiB,qBAAS,CAACC,IAAI,CAACC,UAAU;EAC/BjB,SAAS,EAAEe,qBAAS,CAACG,MAAM;EAC3BnB,QAAQ,EAAEgB,qBAAS,CAACI,SAAS,CAAC,CAACJ,qBAAS,CAACK,OAAO,CAACL,qBAAS,CAACM,IAAI,CAAC,EAAEN,qBAAS,CAACM,IAAI,CAAC,CAAC,CAACJ;AACrF,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,cAEa3B,QAAQ","ignoreList":[]}
|
package/lib/index.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports["default"] = exports.CorrectAnswerToggle = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
11
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
12
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
var _styles = require("@mui/material/styles");
|
|
15
|
-
var _reactTransitionGroup = require("react-transition-group");
|
|
16
|
-
var _icons = require("@pie-lib/icons");
|
|
17
|
-
var _renderUi = require("@pie-lib/render-ui");
|
|
18
|
-
var _expander = _interopRequireDefault(require("./expander"));
|
|
19
|
-
var _react = _interopRequireDefault(require("react"));
|
|
20
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
21
|
-
var _translator = _interopRequireDefault(require("@pie-lib/translator"));
|
|
22
|
-
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
23
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
24
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
26
|
-
var translator = _translator["default"].translator;
|
|
27
|
-
var noTouch = {
|
|
28
|
-
'-webkit-touchCcallout': 'none',
|
|
29
|
-
'-webkit-user-select': 'none',
|
|
30
|
-
'-khtml-user-select': 'none',
|
|
31
|
-
'-moz-user-select': 'none',
|
|
32
|
-
'-ms-user-select': 'none',
|
|
33
|
-
'user-select': 'none'
|
|
34
|
-
};
|
|
35
|
-
var StyledRoot = (0, _styles.styled)('div')(function () {
|
|
36
|
-
return {
|
|
37
|
-
width: '100%',
|
|
38
|
-
cursor: 'pointer'
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
var StyledContent = (0, _styles.styled)('div')(function () {
|
|
42
|
-
return {
|
|
43
|
-
margin: '0 auto',
|
|
44
|
-
textAlign: 'center',
|
|
45
|
-
display: 'flex'
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
var StyledLabel = (0, _styles.styled)('div')(function () {
|
|
49
|
-
return _objectSpread({
|
|
50
|
-
width: 'fit-content',
|
|
51
|
-
minWidth: '140px',
|
|
52
|
-
alignSelf: 'center',
|
|
53
|
-
verticalAlign: 'middle',
|
|
54
|
-
color: "var(--correct-answer-toggle-label-color, ".concat(_renderUi.color.text(), ")"),
|
|
55
|
-
fontWeight: 'normal'
|
|
56
|
-
}, noTouch);
|
|
57
|
-
});
|
|
58
|
-
var StyledIcon = (0, _styles.styled)('div')(function () {
|
|
59
|
-
return {
|
|
60
|
-
position: 'absolute',
|
|
61
|
-
width: '25px',
|
|
62
|
-
'&.enter': {
|
|
63
|
-
opacity: '0'
|
|
64
|
-
},
|
|
65
|
-
'&.enter-active': {
|
|
66
|
-
opacity: '1',
|
|
67
|
-
transition: 'opacity 0.3s ease-in'
|
|
68
|
-
},
|
|
69
|
-
'&.exit': {
|
|
70
|
-
opacity: '1'
|
|
71
|
-
},
|
|
72
|
-
'&.exit-active': {
|
|
73
|
-
opacity: '0',
|
|
74
|
-
transition: 'opacity 0.3s ease-in'
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
var StyledIconHolder = (0, _styles.styled)('div')(function () {
|
|
79
|
-
return {
|
|
80
|
-
width: '25px',
|
|
81
|
-
marginRight: '5px',
|
|
82
|
-
display: 'flex',
|
|
83
|
-
alignItems: 'center'
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* We export the raw unstyled class for testability. For public use please use the default export.
|
|
89
|
-
*/
|
|
90
|
-
var CorrectAnswerToggle = exports.CorrectAnswerToggle = /*#__PURE__*/function (_React$Component) {
|
|
91
|
-
function CorrectAnswerToggle(props) {
|
|
92
|
-
var _this;
|
|
93
|
-
(0, _classCallCheck2["default"])(this, CorrectAnswerToggle);
|
|
94
|
-
_this = _callSuper(this, CorrectAnswerToggle, [props]);
|
|
95
|
-
_this.state = {
|
|
96
|
-
show: props.show
|
|
97
|
-
};
|
|
98
|
-
_this.openIconRef = /*#__PURE__*/_react["default"].createRef();
|
|
99
|
-
_this.closedIconRef = /*#__PURE__*/_react["default"].createRef();
|
|
100
|
-
CorrectAnswerToggle.defaultProps = _objectSpread(_objectSpread({}, CorrectAnswerToggle.defaultProps), {}, {
|
|
101
|
-
showMessage: translator.t('common:showCorrectAnswer', {
|
|
102
|
-
lng: props.language
|
|
103
|
-
}),
|
|
104
|
-
hideMessage: translator.t('common:hideCorrectAnswer', {
|
|
105
|
-
lng: props.language
|
|
106
|
-
})
|
|
107
|
-
});
|
|
108
|
-
return _this;
|
|
109
|
-
}
|
|
110
|
-
(0, _inherits2["default"])(CorrectAnswerToggle, _React$Component);
|
|
111
|
-
return (0, _createClass2["default"])(CorrectAnswerToggle, [{
|
|
112
|
-
key: "onClick",
|
|
113
|
-
value: function onClick() {
|
|
114
|
-
this.props.onToggle(!this.props.toggled);
|
|
115
|
-
}
|
|
116
|
-
}, {
|
|
117
|
-
key: "onTouch",
|
|
118
|
-
value: function onTouch(event) {
|
|
119
|
-
event.preventDefault(); // Prevents the default action (click event)
|
|
120
|
-
this.props.onToggle(!this.props.toggled);
|
|
121
|
-
}
|
|
122
|
-
}, {
|
|
123
|
-
key: "UNSAFE_componentWillReceiveProps",
|
|
124
|
-
value: function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
125
|
-
var _this$props;
|
|
126
|
-
this.setState({
|
|
127
|
-
show: nextProps.show
|
|
128
|
-
});
|
|
129
|
-
if (nextProps.language !== ((_this$props = this.props) === null || _this$props === void 0 ? void 0 : _this$props.language)) {
|
|
130
|
-
CorrectAnswerToggle.defaultProps = _objectSpread(_objectSpread({}, CorrectAnswerToggle.defaultProps), {}, {
|
|
131
|
-
showMessage: translator.t('common:showCorrectAnswer', {
|
|
132
|
-
lng: nextProps.language
|
|
133
|
-
}),
|
|
134
|
-
hideMessage: translator.t('common:hideCorrectAnswer', {
|
|
135
|
-
lng: nextProps.language
|
|
136
|
-
})
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}, {
|
|
141
|
-
key: "render",
|
|
142
|
-
value: function render() {
|
|
143
|
-
var _this$props2 = this.props,
|
|
144
|
-
className = _this$props2.className,
|
|
145
|
-
toggled = _this$props2.toggled,
|
|
146
|
-
hideMessage = _this$props2.hideMessage,
|
|
147
|
-
showMessage = _this$props2.showMessage;
|
|
148
|
-
return /*#__PURE__*/_react["default"].createElement(StyledRoot, {
|
|
149
|
-
className: className
|
|
150
|
-
}, /*#__PURE__*/_react["default"].createElement(_expander["default"], {
|
|
151
|
-
show: this.state.show
|
|
152
|
-
}, /*#__PURE__*/_react["default"].createElement(StyledContent, {
|
|
153
|
-
onClick: this.onClick.bind(this),
|
|
154
|
-
onTouchEnd: this.onTouch.bind(this)
|
|
155
|
-
}, /*#__PURE__*/_react["default"].createElement(StyledIconHolder, null, /*#__PURE__*/_react["default"].createElement(_reactTransitionGroup.CSSTransition, {
|
|
156
|
-
nodeRef: this.openIconRef,
|
|
157
|
-
timeout: 400,
|
|
158
|
-
"in": toggled,
|
|
159
|
-
exit: !toggled,
|
|
160
|
-
classNames: {
|
|
161
|
-
enter: 'enter',
|
|
162
|
-
enterActive: 'enter-active',
|
|
163
|
-
exit: 'exit',
|
|
164
|
-
exitActive: 'exit-active'
|
|
165
|
-
}
|
|
166
|
-
}, /*#__PURE__*/_react["default"].createElement(StyledIcon, {
|
|
167
|
-
ref: this.openIconRef
|
|
168
|
-
}, /*#__PURE__*/_react["default"].createElement(_icons.CorrectResponse, {
|
|
169
|
-
open: toggled,
|
|
170
|
-
key: "correct-open"
|
|
171
|
-
}))), /*#__PURE__*/_react["default"].createElement(_reactTransitionGroup.CSSTransition, {
|
|
172
|
-
nodeRef: this.closedIconRef,
|
|
173
|
-
timeout: 5000,
|
|
174
|
-
"in": !toggled,
|
|
175
|
-
exit: toggled,
|
|
176
|
-
classNames: {
|
|
177
|
-
enter: 'enter',
|
|
178
|
-
enterActive: 'enter-active',
|
|
179
|
-
exit: 'exit',
|
|
180
|
-
exitActive: 'exit-active'
|
|
181
|
-
}
|
|
182
|
-
}, /*#__PURE__*/_react["default"].createElement(StyledIcon, {
|
|
183
|
-
ref: this.closedIconRef
|
|
184
|
-
}, /*#__PURE__*/_react["default"].createElement(_icons.CorrectResponse, {
|
|
185
|
-
open: toggled,
|
|
186
|
-
key: "correct-closed"
|
|
187
|
-
})))), /*#__PURE__*/_react["default"].createElement(_renderUi.Readable, {
|
|
188
|
-
"false": true
|
|
189
|
-
}, /*#__PURE__*/_react["default"].createElement(StyledLabel, {
|
|
190
|
-
"aria-hidden": !this.state.show
|
|
191
|
-
}, toggled ? hideMessage : showMessage)))));
|
|
192
|
-
}
|
|
193
|
-
}]);
|
|
194
|
-
}(_react["default"].Component);
|
|
195
|
-
(0, _defineProperty2["default"])(CorrectAnswerToggle, "propTypes", {
|
|
196
|
-
onToggle: _propTypes["default"].func,
|
|
197
|
-
toggled: _propTypes["default"].bool,
|
|
198
|
-
show: _propTypes["default"].bool,
|
|
199
|
-
hideMessage: _propTypes["default"].string,
|
|
200
|
-
showMessage: _propTypes["default"].string,
|
|
201
|
-
className: _propTypes["default"].string,
|
|
202
|
-
language: _propTypes["default"].string
|
|
203
|
-
});
|
|
204
|
-
(0, _defineProperty2["default"])(CorrectAnswerToggle, "defaultProps", {
|
|
205
|
-
showMessage: 'Show correct answer',
|
|
206
|
-
hideMessage: 'Hide correct answer',
|
|
207
|
-
show: false,
|
|
208
|
-
toggled: false
|
|
209
|
-
});
|
|
210
|
-
var _default = exports["default"] = CorrectAnswerToggle;
|
|
211
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_styles","require","_reactTransitionGroup","_icons","_renderUi","_expander","_interopRequireDefault","_react","_propTypes","_translator","_callSuper","t","o","e","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","ownKeys","r","Object","keys","getOwnPropertySymbols","filter","getOwnPropertyDescriptor","enumerable","push","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","translator","Translator","noTouch","StyledRoot","styled","width","cursor","StyledContent","margin","textAlign","display","StyledLabel","minWidth","alignSelf","verticalAlign","color","concat","text","fontWeight","StyledIcon","position","opacity","transition","StyledIconHolder","marginRight","alignItems","CorrectAnswerToggle","exports","_React$Component","props","_this","_classCallCheck2","state","show","openIconRef","React","createRef","closedIconRef","defaultProps","showMessage","lng","language","hideMessage","_inherits2","_createClass2","key","value","onClick","onToggle","toggled","onTouch","event","preventDefault","UNSAFE_componentWillReceiveProps","nextProps","_this$props","setState","render","_this$props2","className","createElement","bind","onTouchEnd","CSSTransition","nodeRef","timeout","exit","classNames","enter","enterActive","exitActive","ref","CorrectResponse","open","Readable","Component","PropTypes","func","bool","string","_default"],"sources":["../src/index.jsx"],"sourcesContent":["import { styled } from '@mui/material/styles';\nimport { CSSTransition } from 'react-transition-group';\nimport { CorrectResponse } from '@pie-lib/icons';\nimport { color, Readable } from '@pie-lib/render-ui';\nimport Expander from './expander';\nimport React from 'react';\nimport PropTypes from 'prop-types';\nimport Translator from '@pie-lib/translator';\n\nconst { translator } = Translator;\n\nconst noTouch = {\n '-webkit-touchCcallout': 'none',\n '-webkit-user-select': 'none',\n '-khtml-user-select': 'none',\n '-moz-user-select': 'none',\n '-ms-user-select': 'none',\n 'user-select': 'none',\n};\n\nconst StyledRoot = styled('div')(() => ({\n width: '100%',\n cursor: 'pointer',\n}));\n\nconst StyledContent = styled('div')(() => ({\n margin: '0 auto',\n textAlign: 'center',\n display: 'flex',\n}));\n\nconst StyledLabel = styled('div')(() => ({\n width: 'fit-content',\n minWidth: '140px',\n alignSelf: 'center',\n verticalAlign: 'middle',\n color: `var(--correct-answer-toggle-label-color, ${color.text()})`,\n fontWeight: 'normal',\n ...noTouch,\n}));\n\nconst StyledIcon = styled('div')(() => ({\n position: 'absolute',\n width: '25px',\n '&.enter': {\n opacity: '0',\n },\n '&.enter-active': {\n opacity: '1',\n transition: 'opacity 0.3s ease-in',\n },\n '&.exit': {\n opacity: '1',\n },\n '&.exit-active': {\n opacity: '0',\n transition: 'opacity 0.3s ease-in',\n },\n}));\n\nconst StyledIconHolder = styled('div')(() => ({\n width: '25px',\n marginRight: '5px',\n display: 'flex',\n alignItems: 'center',\n}));\n\n/**\n * We export the raw unstyled class for testability. For public use please use the default export.\n */\nexport class CorrectAnswerToggle extends React.Component {\n static propTypes = {\n onToggle: PropTypes.func,\n toggled: PropTypes.bool,\n show: PropTypes.bool,\n hideMessage: PropTypes.string,\n showMessage: PropTypes.string,\n className: PropTypes.string,\n language: PropTypes.string,\n };\n\n static defaultProps = {\n showMessage: 'Show correct answer',\n hideMessage: 'Hide correct answer',\n show: false,\n toggled: false,\n };\n\n constructor(props) {\n super(props);\n this.state = {\n show: props.show,\n };\n this.openIconRef = React.createRef();\n this.closedIconRef = React.createRef();\n\n CorrectAnswerToggle.defaultProps = {\n ...CorrectAnswerToggle.defaultProps,\n showMessage: translator.t('common:showCorrectAnswer', { lng: props.language }),\n hideMessage: translator.t('common:hideCorrectAnswer', { lng: props.language }),\n };\n }\n\n onClick() {\n this.props.onToggle(!this.props.toggled);\n }\n onTouch(event) {\n event.preventDefault(); // Prevents the default action (click event)\n this.props.onToggle(!this.props.toggled);\n }\n\n UNSAFE_componentWillReceiveProps(nextProps) {\n this.setState({\n show: nextProps.show,\n });\n\n if (nextProps.language !== this.props?.language) {\n CorrectAnswerToggle.defaultProps = {\n ...CorrectAnswerToggle.defaultProps,\n showMessage: translator.t('common:showCorrectAnswer', { lng: nextProps.language }),\n hideMessage: translator.t('common:hideCorrectAnswer', { lng: nextProps.language }),\n };\n }\n }\n\n render() {\n const { className, toggled, hideMessage, showMessage } = this.props;\n\n return (\n <StyledRoot className={className}>\n <Expander show={this.state.show}>\n <StyledContent onClick={this.onClick.bind(this)} onTouchEnd={this.onTouch.bind(this)}>\n <StyledIconHolder>\n <CSSTransition\n nodeRef={this.openIconRef}\n timeout={400}\n in={toggled}\n exit={!toggled}\n classNames={{\n enter: 'enter',\n enterActive: 'enter-active',\n exit: 'exit',\n exitActive: 'exit-active',\n }}\n >\n <StyledIcon ref={this.openIconRef}>\n <CorrectResponse open={toggled} key=\"correct-open\" />\n </StyledIcon>\n </CSSTransition>\n <CSSTransition\n nodeRef={this.closedIconRef}\n timeout={5000}\n in={!toggled}\n exit={toggled}\n classNames={{\n enter: 'enter',\n enterActive: 'enter-active',\n exit: 'exit',\n exitActive: 'exit-active',\n }}\n >\n <StyledIcon ref={this.closedIconRef}>\n <CorrectResponse open={toggled} key=\"correct-closed\" />\n </StyledIcon>\n </CSSTransition>\n </StyledIconHolder>\n <Readable false>\n <StyledLabel aria-hidden={!this.state.show}>{toggled ? hideMessage : showMessage}</StyledLabel>\n </Readable>\n </StyledContent>\n </Expander>\n </StyledRoot>\n );\n }\n}\n\nexport default CorrectAnswerToggle;\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,MAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,UAAA,GAAAF,sBAAA,CAAAL,OAAA;AACA,IAAAQ,WAAA,GAAAH,sBAAA,CAAAL,OAAA;AAA6C,SAAAS,WAAAC,CAAA,EAAAC,CAAA,EAAAC,CA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@testing-library/react';
|
|
2
|
-
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { CorrectAnswerToggle } from '../index';
|
|
5
|
-
|
|
6
|
-
describe('CorrectAnswerToggle', () => {
|
|
7
|
-
let onToggle;
|
|
8
|
-
|
|
9
|
-
const renderComponent = (toggled = true, msgs = {}) => {
|
|
10
|
-
return render(
|
|
11
|
-
<CorrectAnswerToggle
|
|
12
|
-
show={true}
|
|
13
|
-
toggled={toggled}
|
|
14
|
-
onToggle={onToggle}
|
|
15
|
-
hideMessage={msgs.hide}
|
|
16
|
-
showMessage={msgs.show}
|
|
17
|
-
/>,
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
onToggle = jest.fn();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe('rendering', () => {
|
|
26
|
-
it('shows hide message when toggled is true', () => {
|
|
27
|
-
renderComponent(true);
|
|
28
|
-
expect(screen.getByText('Hide correct answer')).toBeInTheDocument();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('shows show message when toggled is false', () => {
|
|
32
|
-
renderComponent(false);
|
|
33
|
-
expect(screen.getByText('Show correct answer')).toBeInTheDocument();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('displays custom hide message', () => {
|
|
37
|
-
renderComponent(true, { hide: 'hide!' });
|
|
38
|
-
expect(screen.getByText('hide!')).toBeInTheDocument();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('displays custom show message', () => {
|
|
42
|
-
renderComponent(false, { show: 'show!' });
|
|
43
|
-
expect(screen.getByText('show!')).toBeInTheDocument();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('user interactions', () => {
|
|
48
|
-
it('calls onToggle with false when clicked while toggled', async () => {
|
|
49
|
-
const user = userEvent.setup();
|
|
50
|
-
renderComponent(true);
|
|
51
|
-
|
|
52
|
-
const button = screen.getByText('Hide correct answer');
|
|
53
|
-
await user.click(button);
|
|
54
|
-
|
|
55
|
-
expect(onToggle).toHaveBeenCalledWith(false);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('calls onToggle with true when clicked while not toggled', async () => {
|
|
59
|
-
const user = userEvent.setup();
|
|
60
|
-
renderComponent(false);
|
|
61
|
-
|
|
62
|
-
const button = screen.getByText('Show correct answer');
|
|
63
|
-
await user.click(button);
|
|
64
|
-
|
|
65
|
-
expect(onToggle).toHaveBeenCalledWith(true);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('toggles correctly after prop update', async () => {
|
|
69
|
-
const user = userEvent.setup();
|
|
70
|
-
const { rerender } = renderComponent(true);
|
|
71
|
-
|
|
72
|
-
// First click - toggled is true, should call with false
|
|
73
|
-
await user.click(screen.getByText('Hide correct answer'));
|
|
74
|
-
expect(onToggle).toHaveBeenCalledWith(false);
|
|
75
|
-
|
|
76
|
-
// Simulate prop update to toggled=false
|
|
77
|
-
onToggle.mockClear();
|
|
78
|
-
rerender(<CorrectAnswerToggle show={true} toggled={false} onToggle={onToggle} />);
|
|
79
|
-
|
|
80
|
-
// Second click - toggled is false, should call with true
|
|
81
|
-
await user.click(screen.getByText('Show correct answer'));
|
|
82
|
-
expect(onToggle).toHaveBeenCalledWith(true);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
package/src/expander.jsx
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import React, { useRef } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { styled } from '@mui/material/styles';
|
|
4
|
-
import { CSSTransition } from 'react-transition-group';
|
|
5
|
-
|
|
6
|
-
const transition = 'height ease-in 300ms, opacity ease-in 300ms';
|
|
7
|
-
|
|
8
|
-
const StyledExpander = styled('div')(() => ({
|
|
9
|
-
position: 'relative',
|
|
10
|
-
height: 0,
|
|
11
|
-
overflow: 'hidden',
|
|
12
|
-
display: 'flex',
|
|
13
|
-
visibility: 'hidden',
|
|
14
|
-
width: 0,
|
|
15
|
-
'&.enter': {
|
|
16
|
-
transition,
|
|
17
|
-
opacity: 1,
|
|
18
|
-
height: 'auto',
|
|
19
|
-
width: 'auto',
|
|
20
|
-
visibility: 'visible',
|
|
21
|
-
minHeight: '25px',
|
|
22
|
-
},
|
|
23
|
-
'&.enter-done': {
|
|
24
|
-
height: 'auto',
|
|
25
|
-
visibility: 'visible',
|
|
26
|
-
width: 'auto',
|
|
27
|
-
minHeight: '25px',
|
|
28
|
-
},
|
|
29
|
-
'&.exit': {
|
|
30
|
-
transition,
|
|
31
|
-
opacity: 0,
|
|
32
|
-
height: 0,
|
|
33
|
-
visibility: 'visible',
|
|
34
|
-
width: 0,
|
|
35
|
-
},
|
|
36
|
-
'&.exit-done': {
|
|
37
|
-
opacity: 0,
|
|
38
|
-
visibility: 'hidden',
|
|
39
|
-
height: 0,
|
|
40
|
-
width: 0,
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
|
|
44
|
-
const Expander = (props) => {
|
|
45
|
-
const { show, children, className } = props;
|
|
46
|
-
const nodeRef = useRef(null);
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<CSSTransition
|
|
50
|
-
nodeRef={nodeRef}
|
|
51
|
-
in={show}
|
|
52
|
-
appear={true}
|
|
53
|
-
mountOnEnter={false}
|
|
54
|
-
timeout={300}
|
|
55
|
-
classNames={{
|
|
56
|
-
enter: 'enter',
|
|
57
|
-
enterDone: 'enter-done',
|
|
58
|
-
exit: 'exit',
|
|
59
|
-
exitDone: 'exit-done',
|
|
60
|
-
}}
|
|
61
|
-
>
|
|
62
|
-
<StyledExpander ref={nodeRef} className={className}>
|
|
63
|
-
{children}
|
|
64
|
-
</StyledExpander>
|
|
65
|
-
</CSSTransition>
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
Expander.propTypes = {
|
|
70
|
-
show: PropTypes.bool.isRequired,
|
|
71
|
-
className: PropTypes.string,
|
|
72
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export default Expander;
|