@pie-lib/correct-answer-toggle 0.1.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.d.ts.map +1 -0
- package/dist/expander.js +68 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +146 -0
- package/package.json +37 -0
- package/src/expander.tsx +85 -0
- package/src/index.tsx +215 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/correct-answer-toggle/src/expander.jsx
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
import PropTypes from 'prop-types';
|
|
10
|
+
declare const Expander: {
|
|
11
|
+
(props: any): JSX.Element;
|
|
12
|
+
propTypes: {
|
|
13
|
+
show: PropTypes.Validator<boolean>;
|
|
14
|
+
className: PropTypes.Requireable<string>;
|
|
15
|
+
children: PropTypes.Validator<NonNullable<NonNullable<PropTypes.ReactNodeLike>>>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export default Expander;
|
|
19
|
+
//# sourceMappingURL=expander.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expander.d.ts","sourceRoot":"","sources":["../src/expander.tsx"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAGH,OAAO,SAAS,MAAM,YAAY,CAAC;AA0CnC,QAAA,MAAM,QAAQ;;;;;;;CAuBb,CAAC;AAQF,eAAe,QAAQ,CAAC"}
|
package/dist/expander.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { styled as e } from "@mui/material/styles";
|
|
2
|
+
import { CSSTransition as t } from "react-transition-group";
|
|
3
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
4
|
+
import { useRef as r } from "react";
|
|
5
|
+
import i from "prop-types";
|
|
6
|
+
//#region src/expander.tsx
|
|
7
|
+
var a = "height ease-in 300ms, opacity ease-in 300ms", o = e("div")(() => ({
|
|
8
|
+
position: "relative",
|
|
9
|
+
height: 0,
|
|
10
|
+
overflow: "hidden",
|
|
11
|
+
display: "flex",
|
|
12
|
+
visibility: "hidden",
|
|
13
|
+
width: 0,
|
|
14
|
+
"&.enter": {
|
|
15
|
+
transition: a,
|
|
16
|
+
opacity: 1,
|
|
17
|
+
height: "auto",
|
|
18
|
+
width: "auto",
|
|
19
|
+
visibility: "visible",
|
|
20
|
+
minHeight: "25px"
|
|
21
|
+
},
|
|
22
|
+
"&.enter-done": {
|
|
23
|
+
height: "auto",
|
|
24
|
+
visibility: "visible",
|
|
25
|
+
width: "auto",
|
|
26
|
+
minHeight: "25px"
|
|
27
|
+
},
|
|
28
|
+
"&.exit": {
|
|
29
|
+
transition: a,
|
|
30
|
+
opacity: 0,
|
|
31
|
+
height: 0,
|
|
32
|
+
visibility: "visible",
|
|
33
|
+
width: 0
|
|
34
|
+
},
|
|
35
|
+
"&.exit-done": {
|
|
36
|
+
opacity: 0,
|
|
37
|
+
visibility: "hidden",
|
|
38
|
+
height: 0,
|
|
39
|
+
width: 0
|
|
40
|
+
}
|
|
41
|
+
})), s = (e) => {
|
|
42
|
+
let { show: i, children: a, className: s } = e, c = r(null);
|
|
43
|
+
return /* @__PURE__ */ n(t, {
|
|
44
|
+
nodeRef: c,
|
|
45
|
+
in: i,
|
|
46
|
+
appear: !0,
|
|
47
|
+
mountOnEnter: !1,
|
|
48
|
+
timeout: 300,
|
|
49
|
+
classNames: {
|
|
50
|
+
enter: "enter",
|
|
51
|
+
enterDone: "enter-done",
|
|
52
|
+
exit: "exit",
|
|
53
|
+
exitDone: "exit-done"
|
|
54
|
+
},
|
|
55
|
+
children: /* @__PURE__ */ n(o, {
|
|
56
|
+
ref: c,
|
|
57
|
+
className: s,
|
|
58
|
+
children: a
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
s.propTypes = {
|
|
63
|
+
show: i.bool.isRequired,
|
|
64
|
+
className: i.string,
|
|
65
|
+
children: i.oneOfType([i.arrayOf(i.node), i.node]).isRequired
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { s as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/correct-answer-toggle/src/index.jsx
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
/**
|
|
12
|
+
* We export the raw unstyled class for testability. For public use please use the default export.
|
|
13
|
+
*/
|
|
14
|
+
export declare class CorrectAnswerToggle extends React.Component {
|
|
15
|
+
static propTypes: {
|
|
16
|
+
onToggle: PropTypes.Requireable<(...args: any[]) => any>;
|
|
17
|
+
toggled: PropTypes.Requireable<boolean>;
|
|
18
|
+
show: PropTypes.Requireable<boolean>;
|
|
19
|
+
hideMessage: PropTypes.Requireable<string>;
|
|
20
|
+
showMessage: PropTypes.Requireable<string>;
|
|
21
|
+
className: PropTypes.Requireable<string>;
|
|
22
|
+
language: PropTypes.Requireable<string>;
|
|
23
|
+
};
|
|
24
|
+
static defaultProps: {
|
|
25
|
+
showMessage: string;
|
|
26
|
+
hideMessage: string;
|
|
27
|
+
show: boolean;
|
|
28
|
+
toggled: boolean;
|
|
29
|
+
};
|
|
30
|
+
constructor(props: any);
|
|
31
|
+
onClick(): void;
|
|
32
|
+
onTouch(event: any): void;
|
|
33
|
+
UNSAFE_componentWillReceiveProps(nextProps: any): void;
|
|
34
|
+
render(): JSX.Element;
|
|
35
|
+
}
|
|
36
|
+
export default CorrectAnswerToggle;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAmCH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,SAAS,MAAM,YAAY,CAAC;AA6DnC;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK,CAAC,SAAS;IACtD,MAAM,CAAC,SAAS;;;;;;;;MAQd;IAEF,MAAM,CAAC,YAAY;;;;;MAKjB;gBAEU,KAAK,KAAA;IAejB,OAAO;IAGP,OAAO,CAAC,KAAK,KAAA;IAKb,gCAAgC,CAAC,SAAS,KAAA;IAc1C,MAAM;CAiDP;AAED,eAAe,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import e from "./expander.js";
|
|
2
|
+
import { styled as t } from "@mui/material/styles";
|
|
3
|
+
import { CSSTransition as n } from "react-transition-group";
|
|
4
|
+
import { CorrectResponse as r } from "@pie-lib/icons";
|
|
5
|
+
import * as i from "@pie-lib/render-ui";
|
|
6
|
+
import { Readable as a, color as o } from "@pie-lib/render-ui";
|
|
7
|
+
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
8
|
+
import l from "react";
|
|
9
|
+
import u from "prop-types";
|
|
10
|
+
import d from "@pie-lib/translator";
|
|
11
|
+
//#region src/index.tsx
|
|
12
|
+
function f(e) {
|
|
13
|
+
return typeof e == "function" || typeof e == "object" && !!e && typeof e.$$typeof == "symbol";
|
|
14
|
+
}
|
|
15
|
+
function p(e, t) {
|
|
16
|
+
return !e || f(e) ? e : f(e.default) ? e.default : t && f(e[t]) ? e[t] : t && f(e[t]?.default) ? e[t].default : e;
|
|
17
|
+
}
|
|
18
|
+
var m = p(a, "Readable") || p(_.Readable, "Readable"), h = i, g = h.default, _ = g && typeof g == "object" ? g : h, { translator: v } = d, y = {
|
|
19
|
+
WebkitTouchCallout: "none",
|
|
20
|
+
WebkitUserSelect: "none",
|
|
21
|
+
KhtmlUserSelect: "none",
|
|
22
|
+
MozUserSelect: "none",
|
|
23
|
+
msUserSelect: "none",
|
|
24
|
+
userSelect: "none"
|
|
25
|
+
}, b = t("div")(() => ({
|
|
26
|
+
width: "100%",
|
|
27
|
+
cursor: "pointer"
|
|
28
|
+
})), x = t("div")(() => ({
|
|
29
|
+
margin: "0 auto",
|
|
30
|
+
textAlign: "center",
|
|
31
|
+
display: "flex"
|
|
32
|
+
})), S = t("div")(() => ({
|
|
33
|
+
width: "fit-content",
|
|
34
|
+
minWidth: "140px",
|
|
35
|
+
alignSelf: "center",
|
|
36
|
+
verticalAlign: "middle",
|
|
37
|
+
color: `var(--correct-answer-toggle-label-color, ${o.text()})`,
|
|
38
|
+
fontWeight: "normal",
|
|
39
|
+
...y
|
|
40
|
+
})), C = t("div")(() => ({
|
|
41
|
+
position: "absolute",
|
|
42
|
+
width: "25px",
|
|
43
|
+
"&.enter": { opacity: "0" },
|
|
44
|
+
"&.enter-active": {
|
|
45
|
+
opacity: "1",
|
|
46
|
+
transition: "opacity 0.3s ease-in"
|
|
47
|
+
},
|
|
48
|
+
"&.exit": { opacity: "1" },
|
|
49
|
+
"&.exit-active": {
|
|
50
|
+
opacity: "0",
|
|
51
|
+
transition: "opacity 0.3s ease-in"
|
|
52
|
+
}
|
|
53
|
+
})), w = t("div")(() => ({
|
|
54
|
+
width: "25px",
|
|
55
|
+
marginRight: "5px",
|
|
56
|
+
display: "flex",
|
|
57
|
+
alignItems: "center"
|
|
58
|
+
})), T = class t extends l.Component {
|
|
59
|
+
static propTypes = {
|
|
60
|
+
onToggle: u.func,
|
|
61
|
+
toggled: u.bool,
|
|
62
|
+
show: u.bool,
|
|
63
|
+
hideMessage: u.string,
|
|
64
|
+
showMessage: u.string,
|
|
65
|
+
className: u.string,
|
|
66
|
+
language: u.string
|
|
67
|
+
};
|
|
68
|
+
static defaultProps = {
|
|
69
|
+
showMessage: "Show correct answer",
|
|
70
|
+
hideMessage: "Hide correct answer",
|
|
71
|
+
show: !1,
|
|
72
|
+
toggled: !1
|
|
73
|
+
};
|
|
74
|
+
constructor(e) {
|
|
75
|
+
super(e), this.state = { show: e.show }, this.openIconRef = l.createRef(), this.closedIconRef = l.createRef(), t.defaultProps = {
|
|
76
|
+
...t.defaultProps,
|
|
77
|
+
showMessage: v.t("common:showCorrectAnswer", { lng: e.language }),
|
|
78
|
+
hideMessage: v.t("common:hideCorrectAnswer", { lng: e.language })
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
onClick() {
|
|
82
|
+
this.props.onToggle(!this.props.toggled);
|
|
83
|
+
}
|
|
84
|
+
onTouch(e) {
|
|
85
|
+
e.preventDefault(), this.props.onToggle(!this.props.toggled);
|
|
86
|
+
}
|
|
87
|
+
UNSAFE_componentWillReceiveProps(e) {
|
|
88
|
+
this.setState({ show: e.show }), e.language !== this.props?.language && (t.defaultProps = {
|
|
89
|
+
...t.defaultProps,
|
|
90
|
+
showMessage: v.t("common:showCorrectAnswer", { lng: e.language }),
|
|
91
|
+
hideMessage: v.t("common:hideCorrectAnswer", { lng: e.language })
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
render() {
|
|
95
|
+
let { className: t, toggled: i, hideMessage: a, showMessage: o } = this.props;
|
|
96
|
+
return /* @__PURE__ */ s(b, {
|
|
97
|
+
className: t,
|
|
98
|
+
children: /* @__PURE__ */ s(e, {
|
|
99
|
+
show: this.state.show,
|
|
100
|
+
children: /* @__PURE__ */ c(x, {
|
|
101
|
+
onClick: this.onClick.bind(this),
|
|
102
|
+
onTouchEnd: this.onTouch.bind(this),
|
|
103
|
+
children: [/* @__PURE__ */ c(w, { children: [/* @__PURE__ */ s(n, {
|
|
104
|
+
nodeRef: this.openIconRef,
|
|
105
|
+
timeout: 400,
|
|
106
|
+
in: i,
|
|
107
|
+
exit: !i,
|
|
108
|
+
classNames: {
|
|
109
|
+
enter: "enter",
|
|
110
|
+
enterActive: "enter-active",
|
|
111
|
+
exit: "exit",
|
|
112
|
+
exitActive: "exit-active"
|
|
113
|
+
},
|
|
114
|
+
children: /* @__PURE__ */ s(C, {
|
|
115
|
+
ref: this.openIconRef,
|
|
116
|
+
children: /* @__PURE__ */ s(r, { open: i }, "correct-open")
|
|
117
|
+
})
|
|
118
|
+
}), /* @__PURE__ */ s(n, {
|
|
119
|
+
nodeRef: this.closedIconRef,
|
|
120
|
+
timeout: 5e3,
|
|
121
|
+
in: !i,
|
|
122
|
+
exit: i,
|
|
123
|
+
classNames: {
|
|
124
|
+
enter: "enter",
|
|
125
|
+
enterActive: "enter-active",
|
|
126
|
+
exit: "exit",
|
|
127
|
+
exitActive: "exit-active"
|
|
128
|
+
},
|
|
129
|
+
children: /* @__PURE__ */ s(C, {
|
|
130
|
+
ref: this.closedIconRef,
|
|
131
|
+
children: /* @__PURE__ */ s(r, { open: i }, "correct-closed")
|
|
132
|
+
})
|
|
133
|
+
})] }), /* @__PURE__ */ s(m, {
|
|
134
|
+
false: !0,
|
|
135
|
+
children: /* @__PURE__ */ s(S, {
|
|
136
|
+
"aria-hidden": !this.state.show,
|
|
137
|
+
children: i ? a : o
|
|
138
|
+
})
|
|
139
|
+
})]
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
//#endregion
|
|
146
|
+
export { T as CorrectAnswerToggle, T as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pie-lib/correct-answer-toggle",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A react based toggle component",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@emotion/react": "^11.14.0",
|
|
7
|
+
"@emotion/style": "^0.8.0",
|
|
8
|
+
"@mui/icons-material": "^7.3.4",
|
|
9
|
+
"@mui/material": "^7.3.4",
|
|
10
|
+
"@pie-lib/icons": "0.1.0",
|
|
11
|
+
"@pie-lib/render-ui": "0.1.0",
|
|
12
|
+
"@pie-lib/translator": "0.1.0",
|
|
13
|
+
"lodash-es": "^4.17.23",
|
|
14
|
+
"prop-types": "^15.6.2",
|
|
15
|
+
"react-transition-group": "^4.4.5",
|
|
16
|
+
"react": "^18.2.0"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"src"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "bun x vite build && bun x tsc --emitDeclarationOnly",
|
|
34
|
+
"dev": "bun x vite",
|
|
35
|
+
"test": "bun x vitest run"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/expander.tsx
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/correct-answer-toggle/src/expander.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React, { useRef } from 'react';
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import { styled } from '@mui/material/styles';
|
|
14
|
+
import { CSSTransition } from 'react-transition-group';
|
|
15
|
+
|
|
16
|
+
const transition = 'height ease-in 300ms, opacity ease-in 300ms';
|
|
17
|
+
|
|
18
|
+
const StyledExpander: any = styled('div')(() => ({
|
|
19
|
+
position: 'relative',
|
|
20
|
+
height: 0,
|
|
21
|
+
overflow: 'hidden',
|
|
22
|
+
display: 'flex',
|
|
23
|
+
visibility: 'hidden',
|
|
24
|
+
width: 0,
|
|
25
|
+
'&.enter': {
|
|
26
|
+
transition,
|
|
27
|
+
opacity: 1,
|
|
28
|
+
height: 'auto',
|
|
29
|
+
width: 'auto',
|
|
30
|
+
visibility: 'visible',
|
|
31
|
+
minHeight: '25px',
|
|
32
|
+
},
|
|
33
|
+
'&.enter-done': {
|
|
34
|
+
height: 'auto',
|
|
35
|
+
visibility: 'visible',
|
|
36
|
+
width: 'auto',
|
|
37
|
+
minHeight: '25px',
|
|
38
|
+
},
|
|
39
|
+
'&.exit': {
|
|
40
|
+
transition,
|
|
41
|
+
opacity: 0,
|
|
42
|
+
height: 0,
|
|
43
|
+
visibility: 'visible',
|
|
44
|
+
width: 0,
|
|
45
|
+
},
|
|
46
|
+
'&.exit-done': {
|
|
47
|
+
opacity: 0,
|
|
48
|
+
visibility: 'hidden',
|
|
49
|
+
height: 0,
|
|
50
|
+
width: 0,
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
const Expander = (props) => {
|
|
55
|
+
const { show, children, className } = props;
|
|
56
|
+
const nodeRef = useRef(null);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<CSSTransition
|
|
60
|
+
nodeRef={nodeRef}
|
|
61
|
+
in={show}
|
|
62
|
+
appear={true}
|
|
63
|
+
mountOnEnter={false}
|
|
64
|
+
timeout={300}
|
|
65
|
+
classNames={{
|
|
66
|
+
enter: 'enter',
|
|
67
|
+
enterDone: 'enter-done',
|
|
68
|
+
exit: 'exit',
|
|
69
|
+
exitDone: 'exit-done',
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
<StyledExpander ref={nodeRef} className={className}>
|
|
73
|
+
{children}
|
|
74
|
+
</StyledExpander>
|
|
75
|
+
</CSSTransition>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
Expander.propTypes = {
|
|
80
|
+
show: PropTypes.bool.isRequired,
|
|
81
|
+
className: PropTypes.string,
|
|
82
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export default Expander;
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/correct-answer-toggle/src/index.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { styled } from '@mui/material/styles';
|
|
12
|
+
import { CSSTransition } from 'react-transition-group';
|
|
13
|
+
import { CorrectResponse } from '@pie-lib/icons';
|
|
14
|
+
import { color, Readable as ReadableImport } from '@pie-lib/render-ui';
|
|
15
|
+
|
|
16
|
+
function isRenderableReactInteropType(value: any) {
|
|
17
|
+
return (
|
|
18
|
+
typeof value === 'function' ||
|
|
19
|
+
(typeof value === 'object' && value !== null && typeof value.$$typeof === 'symbol')
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function unwrapReactInteropSymbol(maybeSymbol: any, namedExport?: string) {
|
|
24
|
+
if (!maybeSymbol) return maybeSymbol;
|
|
25
|
+
if (isRenderableReactInteropType(maybeSymbol)) return maybeSymbol;
|
|
26
|
+
if (isRenderableReactInteropType(maybeSymbol.default)) return maybeSymbol.default;
|
|
27
|
+
if (namedExport && isRenderableReactInteropType(maybeSymbol[namedExport])) {
|
|
28
|
+
return maybeSymbol[namedExport];
|
|
29
|
+
}
|
|
30
|
+
if (namedExport && isRenderableReactInteropType(maybeSymbol[namedExport]?.default)) {
|
|
31
|
+
return maybeSymbol[namedExport].default;
|
|
32
|
+
}
|
|
33
|
+
return maybeSymbol;
|
|
34
|
+
}
|
|
35
|
+
const Readable = unwrapReactInteropSymbol(ReadableImport, 'Readable') || unwrapReactInteropSymbol(renderUi.Readable, 'Readable');
|
|
36
|
+
import * as RenderUiNamespace from '@pie-lib/render-ui';
|
|
37
|
+
const renderUiNamespaceAny = RenderUiNamespace as any;
|
|
38
|
+
const renderUiDefaultMaybe = renderUiNamespaceAny['default'];
|
|
39
|
+
const renderUi =
|
|
40
|
+
renderUiDefaultMaybe && typeof renderUiDefaultMaybe === 'object'
|
|
41
|
+
? renderUiDefaultMaybe
|
|
42
|
+
: renderUiNamespaceAny;
|
|
43
|
+
import Expander from './expander.js';
|
|
44
|
+
import React from 'react';
|
|
45
|
+
import PropTypes from 'prop-types';
|
|
46
|
+
import Translator from '@pie-lib/translator';
|
|
47
|
+
|
|
48
|
+
const { translator } = Translator;
|
|
49
|
+
|
|
50
|
+
const noTouch = {
|
|
51
|
+
WebkitTouchCallout: 'none',
|
|
52
|
+
WebkitUserSelect: 'none',
|
|
53
|
+
KhtmlUserSelect: 'none',
|
|
54
|
+
MozUserSelect: 'none',
|
|
55
|
+
msUserSelect: 'none',
|
|
56
|
+
userSelect: 'none',
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const StyledRoot: any = styled('div')(() => ({
|
|
60
|
+
width: '100%',
|
|
61
|
+
cursor: 'pointer',
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
const StyledContent: any = styled('div')(() => ({
|
|
65
|
+
margin: '0 auto',
|
|
66
|
+
textAlign: 'center',
|
|
67
|
+
display: 'flex',
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
const StyledLabel: any = styled('div')(() => ({
|
|
71
|
+
width: 'fit-content',
|
|
72
|
+
minWidth: '140px',
|
|
73
|
+
alignSelf: 'center',
|
|
74
|
+
verticalAlign: 'middle',
|
|
75
|
+
color: `var(--correct-answer-toggle-label-color, ${color.text()})`,
|
|
76
|
+
fontWeight: 'normal',
|
|
77
|
+
...noTouch,
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
const StyledIcon: any = styled('div')(() => ({
|
|
81
|
+
position: 'absolute',
|
|
82
|
+
width: '25px',
|
|
83
|
+
'&.enter': {
|
|
84
|
+
opacity: '0',
|
|
85
|
+
},
|
|
86
|
+
'&.enter-active': {
|
|
87
|
+
opacity: '1',
|
|
88
|
+
transition: 'opacity 0.3s ease-in',
|
|
89
|
+
},
|
|
90
|
+
'&.exit': {
|
|
91
|
+
opacity: '1',
|
|
92
|
+
},
|
|
93
|
+
'&.exit-active': {
|
|
94
|
+
opacity: '0',
|
|
95
|
+
transition: 'opacity 0.3s ease-in',
|
|
96
|
+
},
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
const StyledIconHolder: any = styled('div')(() => ({
|
|
100
|
+
width: '25px',
|
|
101
|
+
marginRight: '5px',
|
|
102
|
+
display: 'flex',
|
|
103
|
+
alignItems: 'center',
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* We export the raw unstyled class for testability. For public use please use the default export.
|
|
108
|
+
*/
|
|
109
|
+
export class CorrectAnswerToggle extends React.Component {
|
|
110
|
+
static propTypes = {
|
|
111
|
+
onToggle: PropTypes.func,
|
|
112
|
+
toggled: PropTypes.bool,
|
|
113
|
+
show: PropTypes.bool,
|
|
114
|
+
hideMessage: PropTypes.string,
|
|
115
|
+
showMessage: PropTypes.string,
|
|
116
|
+
className: PropTypes.string,
|
|
117
|
+
language: PropTypes.string,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
static defaultProps = {
|
|
121
|
+
showMessage: 'Show correct answer',
|
|
122
|
+
hideMessage: 'Hide correct answer',
|
|
123
|
+
show: false,
|
|
124
|
+
toggled: false,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
constructor(props) {
|
|
128
|
+
super(props);
|
|
129
|
+
this.state = {
|
|
130
|
+
show: props.show,
|
|
131
|
+
};
|
|
132
|
+
this.openIconRef = React.createRef();
|
|
133
|
+
this.closedIconRef = React.createRef();
|
|
134
|
+
|
|
135
|
+
CorrectAnswerToggle.defaultProps = {
|
|
136
|
+
...CorrectAnswerToggle.defaultProps,
|
|
137
|
+
showMessage: translator.t('common:showCorrectAnswer', { lng: props.language }),
|
|
138
|
+
hideMessage: translator.t('common:hideCorrectAnswer', { lng: props.language }),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
onClick() {
|
|
143
|
+
this.props.onToggle(!this.props.toggled);
|
|
144
|
+
}
|
|
145
|
+
onTouch(event) {
|
|
146
|
+
event.preventDefault(); // Prevents the default action (click event)
|
|
147
|
+
this.props.onToggle(!this.props.toggled);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
151
|
+
this.setState({
|
|
152
|
+
show: nextProps.show,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
if (nextProps.language !== this.props?.language) {
|
|
156
|
+
CorrectAnswerToggle.defaultProps = {
|
|
157
|
+
...CorrectAnswerToggle.defaultProps,
|
|
158
|
+
showMessage: translator.t('common:showCorrectAnswer', { lng: nextProps.language }),
|
|
159
|
+
hideMessage: translator.t('common:hideCorrectAnswer', { lng: nextProps.language }),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
render() {
|
|
165
|
+
const { className, toggled, hideMessage, showMessage } = this.props;
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<StyledRoot className={className}>
|
|
169
|
+
<Expander show={this.state.show}>
|
|
170
|
+
<StyledContent onClick={this.onClick.bind(this)} onTouchEnd={this.onTouch.bind(this)}>
|
|
171
|
+
<StyledIconHolder>
|
|
172
|
+
<CSSTransition
|
|
173
|
+
nodeRef={this.openIconRef}
|
|
174
|
+
timeout={400}
|
|
175
|
+
in={toggled}
|
|
176
|
+
exit={!toggled}
|
|
177
|
+
classNames={{
|
|
178
|
+
enter: 'enter',
|
|
179
|
+
enterActive: 'enter-active',
|
|
180
|
+
exit: 'exit',
|
|
181
|
+
exitActive: 'exit-active',
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
184
|
+
<StyledIcon ref={this.openIconRef}>
|
|
185
|
+
<CorrectResponse open={toggled} key="correct-open" />
|
|
186
|
+
</StyledIcon>
|
|
187
|
+
</CSSTransition>
|
|
188
|
+
<CSSTransition
|
|
189
|
+
nodeRef={this.closedIconRef}
|
|
190
|
+
timeout={5000}
|
|
191
|
+
in={!toggled}
|
|
192
|
+
exit={toggled}
|
|
193
|
+
classNames={{
|
|
194
|
+
enter: 'enter',
|
|
195
|
+
enterActive: 'enter-active',
|
|
196
|
+
exit: 'exit',
|
|
197
|
+
exitActive: 'exit-active',
|
|
198
|
+
}}
|
|
199
|
+
>
|
|
200
|
+
<StyledIcon ref={this.closedIconRef}>
|
|
201
|
+
<CorrectResponse open={toggled} key="correct-closed" />
|
|
202
|
+
</StyledIcon>
|
|
203
|
+
</CSSTransition>
|
|
204
|
+
</StyledIconHolder>
|
|
205
|
+
<Readable false>
|
|
206
|
+
<StyledLabel aria-hidden={!this.state.show}>{toggled ? hideMessage : showMessage}</StyledLabel>
|
|
207
|
+
</Readable>
|
|
208
|
+
</StyledContent>
|
|
209
|
+
</Expander>
|
|
210
|
+
</StyledRoot>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export default CorrectAnswerToggle;
|