typescript-overlay-essentials 2.1.1 → 2.1.2

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.
@@ -56,6 +56,8 @@ export function TutorialOverlay({ state, setState }) {
56
56
  const [highlightElementRect, setHighlightElementRect] = useState(null);
57
57
  // Wird verwendet um zu tracken bei welchem Schritt des Tutorials der Nutzer ist
58
58
  const [tutorialStep, setTutorialStep] = useState(0);
59
+ // Wird verwendet um ggf. die TutorialBox wenn sie oben aus dem Bildschirm ragt nach unten zu verschieben
60
+ const tutorialBoxRef = useRef(null);
59
61
  const proceedButtonRef = useRef(null);
60
62
  // Sobald der State von außen aktualisiert wird triggert diese Funktion
61
63
  // Die setzt showTutorial auf true
@@ -88,6 +90,27 @@ export function TutorialOverlay({ state, setState }) {
88
90
  document.body.style.overflow = "";
89
91
  };
90
92
  }, [showTutorial]);
93
+ useEffect(() => {
94
+ var _a, _b, _c;
95
+ if (!tutorialPos || !tutorialBoxRef.current || tutorialPos.position !== Positions.TOP)
96
+ return;
97
+ const tutorialBoxRect = tutorialBoxRef.current.getBoundingClientRect();
98
+ if (tutorialBoxRect.top < 0) {
99
+ const attachElement = (typeof ((_a = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _a === void 0 ? void 0 : _a.attachToObject) === "string"
100
+ ? document.getElementById((_b = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _b === void 0 ? void 0 : _b.attachToObject)
101
+ : (_c = state === null || state === void 0 ? void 0 : state.steps[tutorialStep]) === null || _c === void 0 ? void 0 : _c.attachToObject);
102
+ if (attachElement instanceof HTMLElement) {
103
+ var rect = attachElement.getBoundingClientRect();
104
+ // 25 rem
105
+ const _1rem = parseFloat(getComputedStyle(document.documentElement).fontSize);
106
+ setTutorialPos({
107
+ position: Positions.BOTTOM,
108
+ px_left: null,
109
+ px_top: rect.bottom + _1rem
110
+ });
111
+ }
112
+ }
113
+ }, [tutorialPos, tutorialStep]);
91
114
  const showTutorialAtElement = (e, dontHighlightElement) => {
92
115
  var rect = e.getBoundingClientRect();
93
116
  const viewportHeight = window.innerHeight;
@@ -103,17 +126,15 @@ export function TutorialOverlay({ state, setState }) {
103
126
  // 25 rem
104
127
  const _1rem = parseFloat(getComputedStyle(document.documentElement).fontSize);
105
128
  const tooltipWidth = 32 * _1rem;
106
- const tooltipHeight = tooltipWidth;
107
129
  const position = rect.right + tooltipWidth <= window.innerWidth ? Positions.RIGHT
108
130
  : (rect.left - tooltipWidth >= 0 ? Positions.LEFT
109
- : (rect.top - tooltipHeight >= 0 ? Positions.TOP
110
- : Positions.BOTTOM));
131
+ : Positions.TOP); // Immer Top nehmen und nur wenn tatsächlich rausragt => Nach rendern auf Bottom ändern
111
132
  setTutorialPos({
112
133
  position,
113
134
  px_left: position === Positions.LEFT ? rect.left - tooltipWidth
114
135
  : (position === Positions.RIGHT ? rect.right + _1rem
115
136
  : null),
116
- px_top: position === Positions.TOP ? (rect.top - tooltipHeight) : (position !== Positions.BOTTOM ? rect.top : (rect.bottom + _1rem))
137
+ px_top: position === Positions.TOP ? (rect.top - _1rem) : rect.top
117
138
  });
118
139
  if (!dontHighlightElement) {
119
140
  setHighlightElementRect({
@@ -143,11 +164,11 @@ export function TutorialOverlay({ state, setState }) {
143
164
  position: "fixed",
144
165
  left: (_e = tutorialPos.px_left) !== null && _e !== void 0 ? _e : '',
145
166
  top: tutorialPos.px_top,
146
- transform: 'none'
167
+ transform: tutorialPos.position === Positions.TOP ? "translateY(-100%)" : 'none'
147
168
  }
148
169
  : {}),
149
170
  ...((state === null || state === void 0 ? void 0 : state.style) != null ? state.style : {})
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) => {
171
+ }, ref: tutorialBoxRef, 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) => {
151
172
  var _a;
152
173
  if (event.key === "Escape") {
153
174
  const nextCommand = (_a = state.cancelCommand) !== null && _a !== void 0 ? _a : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-overlay-essentials",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
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",