typescript-overlay-essentials 1.0.0 → 1.2.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/Dropdown.tsx CHANGED
@@ -5,7 +5,7 @@ import type { CSSObject } from '@emotion/react';
5
5
  import './Dropdown.css';
6
6
 
7
7
  // Um das Dropdown Menü zu nutzen, müssen die Optionen das folgende Interface nutzen:
8
- export interface Option<T = string> {
8
+ export interface DropdownOption<T = string> {
9
9
  value: T;
10
10
  label: string;
11
11
  disabled?: boolean;
@@ -37,14 +37,14 @@ export interface Option<T = string> {
37
37
 
38
38
  export function Dropdown<T = string>({ selections, value, onChange, maxMenuHeight, menuPlacement, width, placeHolder, defaultValue, isMulti = false, cardColorVariant = false, ignoreDarkMode = false, ...rest} :
39
39
  {
40
- selections: Option<T>[],
40
+ selections: DropdownOption<T>[],
41
41
  value: T | T[],
42
42
  onChange: (value: T | T[] | undefined) => void,
43
43
  maxMenuHeight?: number,
44
44
  menuPlacement?: "top" | "bottom",
45
45
  width?: React.CSSProperties["width"],
46
46
  placeHolder?: string,
47
- defaultValue?: Option<T> | Option<T>[],
47
+ defaultValue?: DropdownOption<T> | DropdownOption<T>[],
48
48
  isMulti?: boolean,
49
49
  cardColorVariant?: boolean,
50
50
  ignoreDarkMode?: boolean,
@@ -55,7 +55,7 @@ export function Dropdown<T = string>({ selections, value, onChange, maxMenuHeigh
55
55
  const options = selections.map(({value, label, disabled, indent}) => ({value: value, label: label, isDisabled: disabled ?? false, indent}));
56
56
 
57
57
  if(!initializedRef.current && Array.isArray(value) && value.length === 0 && Array.isArray(defaultValue) && defaultValue.length > 0) {
58
- value = options.filter(opt => (defaultValue as Option<T>[]).map(({value}) => (value)).includes(opt.value)).map(opt => opt.value);
58
+ value = options.filter(opt => (defaultValue as DropdownOption<T>[]).map(({value}) => (value)).includes(opt.value)).map(opt => opt.value);
59
59
  }
60
60
 
61
61
  function usePrefersDarkMode() : boolean {
@@ -84,7 +84,7 @@ export function Dropdown<T = string>({ selections, value, onChange, maxMenuHeigh
84
84
  }
85
85
 
86
86
  return isMulti || Array.isArray(defaultValue) ? (
87
- <Select<Option<T>, true>
87
+ <Select<DropdownOption<T>, true>
88
88
  className = "custom-select"
89
89
  isMulti={true}
90
90
  placeholder = {placeHolder ?? ""}
@@ -93,12 +93,12 @@ export function Dropdown<T = string>({ selections, value, onChange, maxMenuHeigh
93
93
  options.filter(opt => (hasId(opt.value) && (value as T[]).find(val => hasId(val) && hasId(opt.value) && val.id === opt.value.id))) // Dann alle Optionen, die in den values per id vorkommen
94
94
  : options.filter(opt => ((value as T[]).includes(opt.value))) // Ansonsten einfach alle Optionen, die in den values vorkommen
95
95
  }
96
- onChange={(selectedOption: MultiValue<Option<T>>) => {initializedRef.current = true; onChange(selectedOption.map((opt: Option<T>) => opt.value))}}
96
+ onChange={(selectedOption: MultiValue<DropdownOption<T>>) => {initializedRef.current = true; onChange(selectedOption.map((opt: DropdownOption<T>) => opt.value))}}
97
97
  maxMenuHeight={maxMenuHeight ?? 280}
98
98
  menuPlacement={menuPlacement ?? "auto"}
99
99
  menuPosition="fixed"
100
100
  classNamePrefix="dropdown"
101
- defaultValue={options.filter(opt => (defaultValue as Option<T>[]).map(({value}) => (value)).includes(opt.value))}
101
+ defaultValue={options.filter(opt => (defaultValue as DropdownOption<T>[]).map(({value}) => (value)).includes(opt.value))}
102
102
  formatOptionLabel={({ label, indent }: { label: string; indent?: number },{ context } : { context: string }) => {
103
103
  if (context === 'menu') {
104
104
  // Alle mit indent angegebenen Werte im Dropdown-Menü einrücken
@@ -146,7 +146,7 @@ export function Dropdown<T = string>({ selections, value, onChange, maxMenuHeigh
146
146
  {...rest}
147
147
  />
148
148
  ) : (
149
- <Select<Option<T>, false>
149
+ <Select<DropdownOption<T>, false>
150
150
  className = "custom-select"
151
151
  isMulti={false}
152
152
  placeholder = {placeHolder ?? ""}
@@ -155,7 +155,7 @@ export function Dropdown<T = string>({ selections, value, onChange, maxMenuHeigh
155
155
  options.find(opt => hasId(opt.value) && hasId(value) && opt.value.id === value.id) // Die eine Option mit der passenden id finden
156
156
  : options.find(opt => opt.value === value)} // Ohne Multi oder id nur die eine Option finden
157
157
 
158
- onChange={(selectedOption: SingleValue<Option<T>>) => onChange(selectedOption?.value ?? undefined)}
158
+ onChange={(selectedOption: SingleValue<DropdownOption<T>>) => onChange(selectedOption?.value ?? undefined)}
159
159
  maxMenuHeight={maxMenuHeight ?? 280}
160
160
  menuPlacement={menuPlacement ?? "auto"}
161
161
  menuPosition="fixed"
@@ -18,7 +18,7 @@ export interface InfoOverlayWithInputState {
18
18
  }
19
19
 
20
20
  // Um das InfoOverlayWithInput zu nutzen, muss der State die folgende Struktur haben:
21
- export const defaultInformationState : InfoOverlayWithInputState = {
21
+ export const defaultInfoOverlayWithInputState : InfoOverlayWithInputState = {
22
22
  headline: undefined,
23
23
  message: undefined,
24
24
  preInput: undefined,
@@ -87,7 +87,7 @@ export function InfoOverlayWithInput({ state, setState }: { state: InfoOverlayWi
87
87
  handler: handler,
88
88
  handlerArgs: state.handlerArgs
89
89
  };
90
- setState(defaultInformationState);
90
+ setState(defaultInfoOverlayWithInputState);
91
91
  if (typeof tempState.handler === 'function' && useInput)
92
92
  (tempState.handler as ((userInput: string, args?: unknown) => void))(input, tempState.handlerArgs);
93
93
  else if (typeof tempState.handler === 'function')
package/Toast.tsx CHANGED
@@ -1,9 +1,8 @@
1
- import { useEffect, useState } from 'react';
2
- import * as React from 'react';
1
+ import { useEffect, useState, ReactElement } from 'react';
3
2
  import './Toast.css'
4
3
 
5
4
  // Zeigt einen kleinen Toast in der oberen rechten Ecke an, der nach 2,5 Sekunden wieder verschwindet
6
- function Toast({ state, setState }: { state: string, setState: (value: string) => void }) : React.ReactElement {
5
+ export function Toast({ state, setState }: { state: string, setState: (value: string) => void }) : ReactElement {
7
6
  // Wird verwendet um die Toast-Notification ein-/auszublenden
8
7
  const [showToast, setShowToast] = useState(false);
9
8
  // Wird verwendet um den Inhalt der Toast-Notification zu bestimmen
@@ -29,6 +28,4 @@ function Toast({ state, setState }: { state: string, setState: (value: string) =
29
28
  {toastContent}
30
29
  </div>)}
31
30
  </>
32
- }
33
-
34
- export default Toast;
31
+ }
package/ToggleSwitch.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import React, { useRef, useEffect, useState } from "react";
2
2
  import "./ToggleSwitch.css";
3
3
 
4
- export interface Option<T> {
4
+ export interface ToggleSwitchOption<T> {
5
5
  value: T;
6
6
  label: string;
7
7
  }
@@ -13,7 +13,7 @@ export interface Option<T> {
13
13
  // - onChange: Die Funktion die bei Änderung ausgeführt werden soll.
14
14
  // Standardmäßig könnte z.B. {(value) => {value === valueLeft ? setValue(valueLeft) : setValue(valueRight)}} genutzt werden
15
15
 
16
- export function ToggleSwitch<T>({ optionLeft, optionRight, value, onChange } : { optionLeft: Option<T>, optionRight: Option<T>, value: T, onChange: (value: T) => void }) {
16
+ export function ToggleSwitch<T>({ optionLeft, optionRight, value, onChange } : { optionLeft: ToggleSwitchOption<T>, optionRight: ToggleSwitchOption<T>, value: T, onChange: (value: T) => void }) {
17
17
  const containerRef = useRef<HTMLDivElement>(null);
18
18
  const optionLeftRef = useRef<HTMLDivElement>(null);
19
19
  const optionRightRef = useRef<HTMLDivElement>(null);
package/index.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  export { ConfirmationBox, ConfirmationBoxState, defaultConfirmationState } from './ConfirmationBox.tsx';
2
- export { Dropdown, Option } from './Dropdown.tsx';
2
+ export { Dropdown, DropdownOption } from './Dropdown.tsx';
3
3
  export { InfoOverlay, InfoOverlayState, defaultInfoOverlayState } from './InfoOverlay.tsx';
4
- export { InfoOverlayWithInput, InfoOverlayWithInputState, defaultInformationState } from './InfoOverlayWithInput.tsx';
4
+ export { InfoOverlayWithInput, InfoOverlayWithInputState, defaultInfoOverlayWithInputState } from './InfoOverlayWithInput.tsx';
5
5
  export { setInputFilter } from './InputFilter.tsx';
6
6
  export { LoadingOverlay, LoadingOverlayState, defaultLoadingOverlayState } from './LoadingOverlay.tsx';
7
7
  export { MultipleChoiceOverlay, MultipleChoiceOverlayState, defaultMultipleChoiceState } from './MultipleChoiceOverlay.tsx';
8
- export { MultipleRadioOverlay, MultipleRadioOverlayState, defaultMultipleRadioState } from './MultipleRadioOverlay.tsx';
8
+ export { MultipleRadioOverlay, MultipleRadioOverlayState, defaultMultipleRadioState } from './MultipleRadioOverlay.tsx';
9
+ export { Toast } from './Toast.tsx';
10
+ export { ToggleSwitch, ToggleSwitchOption } from './ToggleSwitch.tsx'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-overlay-essentials",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
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",
@@ -35,5 +35,8 @@
35
35
  "main": "index.ts",
36
36
  "scripts": {
37
37
  "test": "echo \"No test needed\""
38
+ },
39
+ "dependencies": {
40
+ "react-select": "^5.10.2"
38
41
  }
39
42
  }