typescript-overlay-essentials 2.0.4 → 2.1.1
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/README.md +47 -0
- package/dist/TutorialOverlay.js +31 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
# typescript-overlay-essentials
|
|
2
|
+
## EN:
|
|
3
|
+
A small collection of useful tools, which can be used out of the box. All included overlays can be opened as reaction on something by calling the appropriate setState hooks, after interaction they close automatically.
|
|
4
|
+
- [ConfirmationBox]: An Overlay with a ConfirmationBox (Proceed / Cancel),
|
|
5
|
+
- [InfoOverlay]: A simpel Overlay with an Informationbox, which can be confirmed,
|
|
6
|
+
- [InfoOverlayWithInput]: An Overlay with an input field that the user can put information into,
|
|
7
|
+
- [LoadingOverlay]: A simple Overlay with a loading-animation and optional loading text,
|
|
8
|
+
- [MultipleChoiceOverlay]: A simple Overlay with multiple-choice options for the user to choose from,
|
|
9
|
+
- [MultipleRadioOverlay]: A simple Overlay with radio buttons for the user to choose exactly one,
|
|
10
|
+
- [TutorialOverlay]: A simple Overlay for step by step tutorials or guided tours in which for each step a highlighted element and commands can be defined which are executed when entering the step (e.g. for switching between views),
|
|
11
|
+
- [Toast]: A simple Toast that appears on the screen in green on the top right,
|
|
12
|
+
- [ToggleSwitch]: A choice between two options in the appearence (Option 1 | Option 2),
|
|
13
|
+
- [Dropdown]: A simplified Dropdown-menu (on the basis of react-select), a little simpler to configure and has some default-configurations,
|
|
14
|
+
- [InputFilter]: A Tool which can be used to apply a Regex-Filter on an Inputfield to only allow specific user inputs.
|
|
15
|
+
|
|
16
|
+
## DE:
|
|
2
17
|
Eine kleine Ansammlung an praktischen Tools, die out of the Box genutzt werden können. Alle enthaltenen Overlays können als Reaktion auf etwas geöffnet werden und schließen sich danach automatisch. Es beinhaltet:
|
|
3
18
|
- [ConfirmationBox]: Ein Overlay mit einer ConfirmationBox (Fortfahren / Abbrechen),
|
|
4
19
|
- [InfoOverlay]: ein simples Overlay mit einer Informationsbox die man bestätigen kann,
|
|
@@ -6,7 +21,39 @@ Eine kleine Ansammlung an praktischen Tools, die out of the Box genutzt werden k
|
|
|
6
21
|
- [LoadingOverlay]: Ein simples Overlay mit einer Lade-animation und optionalem Ladetext,
|
|
7
22
|
- [MultipleChoiceOverlay]: Ein simples Overlay bei dem ein Nutzer aus mehreren gegebenen Aktionen auswählen kann,
|
|
8
23
|
- [MultipleRadioOverlay]: Ein simples Overlay bei dem ein Nutzer genau eine aus mehreren gegebenen Aktionen auswählen kann,
|
|
24
|
+
- [TutorialOverlay]: Ein simples Overlay für step-by-step Tutorials oder Guided Tours bei denen in jedem Schritt ein Element hervorgehoben werden kann und Commands übergeben werden können, die beim betreten des Schritts ausgeführt werden (z.B. um zwischen Sichten zu wechseln),
|
|
9
25
|
- [Toast]: Ein simpler Toast der für kurze Zeit grün hinterlegt in der oberen rechten Ecke des Bildschirms angezeigt wird,
|
|
10
26
|
- [ToggleSwitch]: Eine Auswahl aus zwei Optionen aus denen ein Nutzer wählen kann in der Darstellung (Option 1 | Option 2),
|
|
11
27
|
- [Dropdown]: Ein simples Dropdown-Menü (auf Basis von react-select), welches einfacherer zu Konfigurieren ist und einige default-Einstellungen hat,
|
|
12
28
|
- [InputFilter]: Ein Tool was genutzt werden kann um auf einem Inputfeld einen Regex-Filter anzuwenden und dem User so nur Eingaben erlaubt die dem Filter entsprechen.
|
|
29
|
+
|
|
30
|
+
## Examples:
|
|
31
|
+
{
|
|
32
|
+
import { useState } from "react";
|
|
33
|
+
import { ConfirmationBox, ConfirmationBoxState, defaultConfirmationState } from 'typescript-overlay-essentials';
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function App() {
|
|
37
|
+
|
|
38
|
+
const [stateConfirmationBox, setStateConfirmationBox] = useState<ConfirmationBoxState>(defaultConfirmationState);
|
|
39
|
+
|
|
40
|
+
function handleLicenseAgreement() {
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return <div id="root">
|
|
45
|
+
<ConfirmationBox state={stateConfirmationBox} setState={setStateConfirmationBox} />
|
|
46
|
+
<button onClick={() => {
|
|
47
|
+
setStateConfirmationBox({
|
|
48
|
+
headline: "Are you sure?",
|
|
49
|
+
message: "Do you want to accept the License agreement?",
|
|
50
|
+
proceedButtonText: "Agree",
|
|
51
|
+
cancelButtonText: "Decline",
|
|
52
|
+
handlerOk: handleLicenseAgreement
|
|
53
|
+
})
|
|
54
|
+
}}>
|
|
55
|
+
Confirm License
|
|
56
|
+
</button>
|
|
57
|
+
</div>;
|
|
58
|
+
}
|
|
59
|
+
}
|
package/dist/TutorialOverlay.js
CHANGED
|
@@ -21,6 +21,14 @@ const defaultTutorialState = {
|
|
|
21
21
|
cancelCommand: undefined,
|
|
22
22
|
style: undefined,
|
|
23
23
|
};
|
|
24
|
+
var Positions;
|
|
25
|
+
(function (Positions) {
|
|
26
|
+
Positions[Positions["TOP"] = 0] = "TOP";
|
|
27
|
+
Positions[Positions["RIGHT"] = 1] = "RIGHT";
|
|
28
|
+
Positions[Positions["BOTTOM"] = 2] = "BOTTOM";
|
|
29
|
+
Positions[Positions["LEFT"] = 3] = "LEFT";
|
|
30
|
+
})(Positions || (Positions = {}));
|
|
31
|
+
;
|
|
24
32
|
const TIMEOUT_OVERLAY_WAIT_FOR_COMMAND_EXECUTION_MS = 100;
|
|
25
33
|
// Wobei alle Attribute grundsätzlich optional sind:
|
|
26
34
|
// - steps: Ist ein Array, welches alle Schritte des Tutorials im Format {message: string, attachToObject: JSX.Element, dontHighlightObject: boolean} angibt.
|
|
@@ -40,7 +48,7 @@ const TIMEOUT_OVERLAY_WAIT_FOR_COMMAND_EXECUTION_MS = 100;
|
|
|
40
48
|
// - cancelButtonText: ist der Text der auf dem Abbrechen Button stehen soll (ohne Angabe wird "Überspringen" verwendet)
|
|
41
49
|
// - style: ist der Style des Tutorial-Overlays (Standardmäßig unverändert)
|
|
42
50
|
export function TutorialOverlay({ state, setState }) {
|
|
43
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
44
52
|
// Wird verwendet um das Tutorial-Overlay ein- und auszublenden
|
|
45
53
|
const [showTutorial, setShowTutorial] = useState(false);
|
|
46
54
|
// Wird verwendet um die Position des Textes zu bestimmen
|
|
@@ -92,16 +100,20 @@ export function TutorialOverlay({ state, setState }) {
|
|
|
92
100
|
else {
|
|
93
101
|
e.scrollIntoView({ behavior: "instant", block: "center" });
|
|
94
102
|
}
|
|
95
|
-
rect = e.getBoundingClientRect();
|
|
96
103
|
// 25 rem
|
|
97
|
-
const
|
|
98
|
-
const
|
|
104
|
+
const _1rem = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
105
|
+
const tooltipWidth = 32 * _1rem;
|
|
106
|
+
const tooltipHeight = tooltipWidth;
|
|
107
|
+
const position = rect.right + tooltipWidth <= window.innerWidth ? Positions.RIGHT
|
|
108
|
+
: (rect.left - tooltipWidth >= 0 ? Positions.LEFT
|
|
109
|
+
: (rect.top - tooltipHeight >= 0 ? Positions.TOP
|
|
110
|
+
: Positions.BOTTOM));
|
|
99
111
|
setTutorialPos({
|
|
100
|
-
|
|
101
|
-
px_left:
|
|
102
|
-
? rect.
|
|
103
|
-
|
|
104
|
-
px_top: rect.top
|
|
112
|
+
position,
|
|
113
|
+
px_left: position === Positions.LEFT ? rect.left - tooltipWidth
|
|
114
|
+
: (position === Positions.RIGHT ? rect.right + _1rem
|
|
115
|
+
: null),
|
|
116
|
+
px_top: position === Positions.TOP ? (rect.top - tooltipHeight) : (position !== Positions.BOTTOM ? rect.top : (rect.bottom + _1rem))
|
|
105
117
|
});
|
|
106
118
|
if (!dontHighlightElement) {
|
|
107
119
|
setHighlightElementRect({
|
|
@@ -125,29 +137,29 @@ export function TutorialOverlay({ state, setState }) {
|
|
|
125
137
|
top: `${(_b = highlightElementRect === null || highlightElementRect === void 0 ? void 0 : highlightElementRect.top) !== null && _b !== void 0 ? _b : 0}px`,
|
|
126
138
|
width: `${(_c = highlightElementRect === null || highlightElementRect === void 0 ? void 0 : highlightElementRect.width) !== null && _c !== void 0 ? _c : 0}px`,
|
|
127
139
|
height: `${(_d = highlightElementRect === null || highlightElementRect === void 0 ? void 0 : highlightElementRect.height) !== null && _d !== void 0 ? _d : 0}px`,
|
|
128
|
-
} }), _jsxs("div", { className: "overlay-essentials-tutorial-box", style: {
|
|
140
|
+
} }), _jsxs("div", { className: "overlay-essentials-tutorial-box", id: "overlay-essentials-tutorial-box", style: {
|
|
129
141
|
...(tutorialPos
|
|
130
142
|
? {
|
|
131
143
|
position: "fixed",
|
|
132
|
-
left: tutorialPos.px_left,
|
|
144
|
+
left: (_e = tutorialPos.px_left) !== null && _e !== void 0 ? _e : '',
|
|
133
145
|
top: tutorialPos.px_top,
|
|
134
146
|
transform: 'none'
|
|
135
147
|
}
|
|
136
148
|
: {}),
|
|
137
149
|
...((state === null || state === void 0 ? void 0 : state.style) != null ? state.style : {})
|
|
138
|
-
}, role: "dialog", "aria-modal": "true", "aria-labelledby": ((
|
|
150
|
+
}, role: "dialog", "aria-modal": "true", "aria-labelledby": ((_f = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _f === void 0 ? void 0 : _f.headline) != null ? "tutorial-headline" : undefined, "aria-label": ((_g = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _g === void 0 ? void 0 : _g.headline) != null ? undefined : "Tutorial", "aria-describedby": "tutorial-message", onKeyDown: (event) => {
|
|
139
151
|
var _a;
|
|
140
152
|
if (event.key === "Escape") {
|
|
141
153
|
const nextCommand = (_a = state.cancelCommand) !== null && _a !== void 0 ? _a : null;
|
|
142
154
|
setState((prev) => ({ ...prev, currentCommand: nextCommand !== null && nextCommand !== void 0 ? nextCommand : undefined }));
|
|
143
155
|
}
|
|
144
|
-
}, children: [_jsx("div", { id: "overlay-essentials-tutorial-headline", className: "overlay-essentials-tutorial-headline", children: _jsxs("strong", { children: [(
|
|
156
|
+
}, children: [_jsx("div", { id: "overlay-essentials-tutorial-headline", className: "overlay-essentials-tutorial-headline", children: _jsxs("strong", { children: [(_j = (_h = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _h === void 0 ? void 0 : _h.headline) !== null && _j !== void 0 ? _j : "", " ", tutorialStep + 1, "/", state.steps.length] }) }), _jsx("div", { id: "overlay-essentials-tutorial-message", className: "overlay-essentials-tutorial-message", children: (_l = (_k = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _k === void 0 ? void 0 : _k.message) !== null && _l !== void 0 ? _l : "" }), _jsxs("div", { className: "overlay-essentials-tutorial-buttons", children: [_jsx("button", { onClick: () => {
|
|
145
157
|
var _a, _b, _c, _d;
|
|
146
158
|
if (tutorialStep > 0) {
|
|
147
159
|
const nextCommand = (_b = (_a = state.steps[tutorialStep]) === null || _a === void 0 ? void 0 : _a.backCommand) !== null && _b !== void 0 ? _b : null;
|
|
148
160
|
setState((prev) => ({ ...prev, currentCommand: nextCommand !== null && nextCommand !== void 0 ? nextCommand : undefined }));
|
|
149
161
|
setTimeout(() => {
|
|
150
|
-
var _a, _b, _c;
|
|
162
|
+
var _a, _b, _c, _d;
|
|
151
163
|
const attachTo = (_a = state === null || state === void 0 ? void 0 : state.steps[tutorialStep - 1]) === null || _a === void 0 ? void 0 : _a.attachToObject;
|
|
152
164
|
const attachElement = typeof attachTo === "string"
|
|
153
165
|
? document.getElementById(attachTo)
|
|
@@ -160,19 +172,20 @@ export function TutorialOverlay({ state, setState }) {
|
|
|
160
172
|
setHighlightElementRect(null);
|
|
161
173
|
}
|
|
162
174
|
setTutorialStep(prev => prev - 1);
|
|
175
|
+
(_d = document.getElementById("overlay-essentials-tutorial-box")) === null || _d === void 0 ? void 0 : _d.scrollIntoView();
|
|
163
176
|
}, nextCommand != null ? ((_c = state === null || state === void 0 ? void 0 : state.steps[tutorialStep - 1].waitFor) !== null && _c !== void 0 ? _c : TIMEOUT_OVERLAY_WAIT_FOR_COMMAND_EXECUTION_MS) : 0);
|
|
164
177
|
}
|
|
165
178
|
else {
|
|
166
179
|
const nextCommand = (_d = state.cancelCommand) !== null && _d !== void 0 ? _d : null;
|
|
167
180
|
setState((prev) => ({ ...prev, currentCommand: nextCommand !== null && nextCommand !== void 0 ? nextCommand : undefined, steps: [] }));
|
|
168
181
|
}
|
|
169
|
-
}, type: "button", className: "px-4 py-2 bg-gray-300 rounded " + (tutorialStep > 0 ? "overlay-essentials-back-button" : "overlay-essentials-cancel-button"), children: tutorialStep > 0 ? ((
|
|
182
|
+
}, type: "button", className: "px-4 py-2 bg-gray-300 rounded " + (tutorialStep > 0 ? "overlay-essentials-back-button" : "overlay-essentials-cancel-button"), children: tutorialStep > 0 ? ((_m = state === null || state === void 0 ? void 0 : state.backButtonText) !== null && _m !== void 0 ? _m : "Zurück") : ((_o = state === null || state === void 0 ? void 0 : state.cancelButtonText) !== null && _o !== void 0 ? _o : "Überspringen") }), _jsx("button", { onClick: () => {
|
|
170
183
|
var _a, _b, _c, _d;
|
|
171
184
|
if (tutorialStep + 1 < state.steps.length) {
|
|
172
185
|
const nextCommand = (_b = (_a = state.steps[tutorialStep + 1]) === null || _a === void 0 ? void 0 : _a.command) !== null && _b !== void 0 ? _b : null;
|
|
173
186
|
setState((prev) => ({ ...prev, currentCommand: nextCommand !== null && nextCommand !== void 0 ? nextCommand : undefined }));
|
|
174
187
|
setTimeout(() => {
|
|
175
|
-
var _a, _b, _c;
|
|
188
|
+
var _a, _b, _c, _d;
|
|
176
189
|
const attachTo = (_a = state === null || state === void 0 ? void 0 : state.steps[tutorialStep + 1]) === null || _a === void 0 ? void 0 : _a.attachToObject;
|
|
177
190
|
const attachElement = typeof attachTo === "string"
|
|
178
191
|
? document.getElementById(attachTo)
|
|
@@ -185,11 +198,12 @@ export function TutorialOverlay({ state, setState }) {
|
|
|
185
198
|
setHighlightElementRect(null);
|
|
186
199
|
}
|
|
187
200
|
setTutorialStep(prev => prev + 1);
|
|
201
|
+
(_d = document.getElementById("overlay-essentials-tutorial-box")) === null || _d === void 0 ? void 0 : _d.scrollIntoView();
|
|
188
202
|
}, nextCommand != null ? (_c = state === null || state === void 0 ? void 0 : state.steps[tutorialStep + 1].waitFor) !== null && _c !== void 0 ? _c : TIMEOUT_OVERLAY_WAIT_FOR_COMMAND_EXECUTION_MS : 0);
|
|
189
203
|
}
|
|
190
204
|
else {
|
|
191
205
|
const nextCommand = (_d = state.completeCommand) !== null && _d !== void 0 ? _d : null;
|
|
192
206
|
setState((prev) => ({ ...prev, currentCommand: nextCommand !== null && nextCommand !== void 0 ? nextCommand : undefined, steps: [] }));
|
|
193
207
|
}
|
|
194
|
-
}, ref: proceedButtonRef, type: "button", className: "px-4 py-2 bg-blue-600 text-white rounded " + (tutorialStep > 0 ? "overlay-essentials-proceed-button" : "overlay-essentials-complete-button"), children: tutorialStep < state.steps.length - 1 ? ((
|
|
208
|
+
}, ref: proceedButtonRef, type: "button", className: "px-4 py-2 bg-blue-600 text-white rounded " + (tutorialStep > 0 ? "overlay-essentials-proceed-button" : "overlay-essentials-complete-button"), children: tutorialStep < state.steps.length - 1 ? ((_p = state === null || state === void 0 ? void 0 : state.proceedButtonText) !== null && _p !== void 0 ? _p : "Weiter") : ((_q = state === null || state === void 0 ? void 0 : state.completeButtonText) !== null && _q !== void 0 ? _q : "Abschließen") })] })] })] }) : _jsx(_Fragment, {});
|
|
195
209
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-overlay-essentials",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Eine kleine Ansammlung an praktischen Tools, die out of the Box genutzt werden können. Alle enthaltenen Overlays können als Reaktion auf etwas geöffnet werden und schließen sich danach automatisch. Es beinhaltet: \\n - [ConfirmationBox]: Ein Overlay mit einer ConfirmationBox (Fortfahren / Abbrechen), \\n - [InfoOverlay]: ein simples Overlay mit einer Informationsbox die man bestätigen kann, \\n - [InfoOverlayWithInput]: Ein Overlay bei dem ein User zusätzlich ein Freitext-Feld zur Eingabe hat, \\n - [LoadingOverlay]: Ein simples Overlay mit einer Lade-animation und optionalem Ladetext, \\n - [MultipleChoiceOverlay]: Ein simples Overlay bei dem ein Nutzer aus mehreren gegebenen Aktionen auswählen kann, \\n - [MultipleRadioOverlay]: Ein simples Overlay bei dem ein Nutzer genau eine aus mehreren gegebenen Aktionen auswählen kann, \\n - [Toast]: Ein simpler Toast der für kurze Zeit grün hinterlegt in der oberen rechten Ecke des Bildschirms angezeigt wird, \\n - [ToggleSwitch]: Eine Auswahl aus zwei Optionen aus denen ein Nutzer wählen kann in der Darstellung (Option 1 | Option 2), \\n - [Dropdown]: Ein simples Dropdown-Menü (auf Basis von react-select), welches einfacherer zu Konfigurieren ist und einige default-Einstellungen hat, \\n - [InputFilter]: Ein Tool was genutzt werden kann um auf einem Inputfeld einen Regex-Filter anzuwenden und dem User so nur Eingaben erlaubt die dem Filter entsprechen.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|