typescript-overlay-essentials 2.0.3 → 2.0.5

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 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,37 @@ 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
+ import { useState } from "react";
32
+ import { ConfirmationBox, ConfirmationBoxState, defaultConfirmationState } from 'typescript-overlay-essentials';
33
+
34
+
35
+ function App() {
36
+
37
+ const [stateConfirmationBox, setStateConfirmationBox] = useState<ConfirmationBoxState>(defaultConfirmationState);
38
+
39
+ function handleLicenseAgreement() {
40
+
41
+ }
42
+
43
+ return <div id="root">
44
+ <ConfirmationBox state={stateConfirmationBox} setState={setStateConfirmationBox} />
45
+ <button onClick={() => {
46
+ setStateConfirmationBox({
47
+ headline: "Are you sure?",
48
+ message: "Do you want to accept the License agreement?",
49
+ proceedButtonText: "Agree",
50
+ cancelButtonText: "Decline",
51
+ handlerOk: handleLicenseAgreement
52
+ })
53
+ }}>
54
+ Confirm License
55
+ </button>
56
+ </div>;
57
+ }
package/dist/Toast.css CHANGED
@@ -1,7 +1,7 @@
1
1
  .overlay-essentials-toast-notification {
2
2
  font-size: 80%;
3
3
  position: fixed;
4
- top: 14rem;
4
+ top: 4rem;
5
5
  right: 1rem;
6
6
  background-color: var(--DunkleresGruen, #1a7f37);
7
7
  color: white;
@@ -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,18 @@ 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 tooltipWidth = 31 * parseFloat(getComputedStyle(document.documentElement).fontSize);
98
- const showLeft = rect.right + tooltipWidth > window.innerWidth;
104
+ const _1rem = parseFloat(getComputedStyle(document.documentElement).fontSize);
105
+ const tooltipWidth = 32 * _1rem;
106
+ const position = rect.right + tooltipWidth <= window.innerWidth ? Positions.RIGHT
107
+ : (rect.left - tooltipWidth >= 0 ? Positions.LEFT
108
+ : Positions.BOTTOM);
99
109
  setTutorialPos({
100
- showLeft,
101
- px_left: showLeft
102
- ? rect.left - tooltipWidth - parseFloat(getComputedStyle(document.documentElement).fontSize)
103
- : rect.right + parseFloat(getComputedStyle(document.documentElement).fontSize),
104
- px_top: rect.top
110
+ position,
111
+ px_left: position === Positions.LEFT ? rect.left - tooltipWidth
112
+ : (position === Positions.RIGHT ? rect.right + _1rem
113
+ : null),
114
+ px_top: position !== Positions.BOTTOM ? rect.top : (rect.bottom + _1rem)
105
115
  });
106
116
  if (!dontHighlightElement) {
107
117
  setHighlightElementRect({
@@ -125,23 +135,23 @@ export function TutorialOverlay({ state, setState }) {
125
135
  top: `${(_b = highlightElementRect === null || highlightElementRect === void 0 ? void 0 : highlightElementRect.top) !== null && _b !== void 0 ? _b : 0}px`,
126
136
  width: `${(_c = highlightElementRect === null || highlightElementRect === void 0 ? void 0 : highlightElementRect.width) !== null && _c !== void 0 ? _c : 0}px`,
127
137
  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: {
138
+ } }), _jsxs("div", { className: "overlay-essentials-tutorial-box", id: "overlay-essentials-tutorial-box", style: {
129
139
  ...(tutorialPos
130
140
  ? {
131
141
  position: "fixed",
132
- left: tutorialPos.px_left,
142
+ left: (_e = tutorialPos.px_left) !== null && _e !== void 0 ? _e : ';',
133
143
  top: tutorialPos.px_top,
134
144
  transform: 'none'
135
145
  }
136
146
  : {}),
137
147
  ...((state === null || state === void 0 ? void 0 : state.style) != null ? state.style : {})
138
- }, role: "dialog", "aria-modal": "true", "aria-labelledby": ((_e = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _e === void 0 ? void 0 : _e.headline) != null ? "tutorial-headline" : undefined, "aria-label": ((_f = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _f === void 0 ? void 0 : _f.headline) != null ? undefined : "Tutorial", "aria-describedby": "tutorial-message", onKeyDown: (event) => {
148
+ }, 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
149
  var _a;
140
150
  if (event.key === "Escape") {
141
151
  const nextCommand = (_a = state.cancelCommand) !== null && _a !== void 0 ? _a : null;
142
152
  setState((prev) => ({ ...prev, currentCommand: nextCommand !== null && nextCommand !== void 0 ? nextCommand : undefined }));
143
153
  }
144
- }, children: [_jsx("div", { id: "overlay-essentials-tutorial-headline", className: "overlay-essentials-tutorial-headline", children: _jsxs("strong", { children: [(_h = (_g = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _g === void 0 ? void 0 : _g.headline) !== null && _h !== void 0 ? _h : "", " ", tutorialStep + 1, "/", state.steps.length] }) }), _jsx("div", { id: "overlay-essentials-tutorial-message", className: "overlay-essentials-tutorial-message", children: (_k = (_j = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _j === void 0 ? void 0 : _j.message) !== null && _k !== void 0 ? _k : "" }), _jsxs("div", { className: "overlay-essentials-tutorial-buttons", children: [_jsx("button", { onClick: () => {
154
+ }, 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
155
  var _a, _b, _c, _d;
146
156
  if (tutorialStep > 0) {
147
157
  const nextCommand = (_b = (_a = state.steps[tutorialStep]) === null || _a === void 0 ? void 0 : _a.backCommand) !== null && _b !== void 0 ? _b : null;
@@ -160,13 +170,17 @@ export function TutorialOverlay({ state, setState }) {
160
170
  setHighlightElementRect(null);
161
171
  }
162
172
  setTutorialStep(prev => prev - 1);
173
+ setTimeout(() => {
174
+ var _a;
175
+ (_a = document.getElementById("overlay-essentials-tutorial-box")) === null || _a === void 0 ? void 0 : _a.scrollIntoView();
176
+ }, 10);
163
177
  }, 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
178
  }
165
179
  else {
166
180
  const nextCommand = (_d = state.cancelCommand) !== null && _d !== void 0 ? _d : null;
167
181
  setState((prev) => ({ ...prev, currentCommand: nextCommand !== null && nextCommand !== void 0 ? nextCommand : undefined, steps: [] }));
168
182
  }
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 ? ((_l = state === null || state === void 0 ? void 0 : state.backButtonText) !== null && _l !== void 0 ? _l : "Zurück") : ((_m = state === null || state === void 0 ? void 0 : state.cancelButtonText) !== null && _m !== void 0 ? _m : "Überspringen") }), _jsx("button", { onClick: () => {
183
+ }, 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
184
  var _a, _b, _c, _d;
171
185
  if (tutorialStep + 1 < state.steps.length) {
172
186
  const nextCommand = (_b = (_a = state.steps[tutorialStep + 1]) === null || _a === void 0 ? void 0 : _a.command) !== null && _b !== void 0 ? _b : null;
@@ -185,11 +199,15 @@ export function TutorialOverlay({ state, setState }) {
185
199
  setHighlightElementRect(null);
186
200
  }
187
201
  setTutorialStep(prev => prev + 1);
202
+ setTimeout(() => {
203
+ var _a;
204
+ (_a = document.getElementById("overlay-essentials-tutorial-box")) === null || _a === void 0 ? void 0 : _a.scrollIntoView();
205
+ }, 10);
188
206
  }, 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
207
  }
190
208
  else {
191
209
  const nextCommand = (_d = state.completeCommand) !== null && _d !== void 0 ? _d : null;
192
210
  setState((prev) => ({ ...prev, currentCommand: nextCommand !== null && nextCommand !== void 0 ? nextCommand : undefined, steps: [] }));
193
211
  }
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 ? ((_o = state === null || state === void 0 ? void 0 : state.proceedButtonText) !== null && _o !== void 0 ? _o : "Weiter") : ((_p = state === null || state === void 0 ? void 0 : state.completeButtonText) !== null && _p !== void 0 ? _p : "Abschließen") })] })] })] }) : _jsx(_Fragment, {});
212
+ }, 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
213
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-overlay-essentials",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
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",