@rivtn/noseur 1.0.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.
Files changed (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/esm/Template.d.ts +7 -0
  4. package/dist/esm/Template.js +13 -0
  5. package/dist/esm/compose/Composed.css +437 -0
  6. package/dist/esm/compose/exotic/ColorPicker.d.ts +41 -0
  7. package/dist/esm/compose/exotic/ColorPicker.js +85 -0
  8. package/dist/esm/compose/exotic/ColorSlider.d.ts +30 -0
  9. package/dist/esm/compose/exotic/ColorSlider.js +99 -0
  10. package/dist/esm/compose/form/ComposedPassword.d.ts +25 -0
  11. package/dist/esm/compose/form/ComposedPassword.js +103 -0
  12. package/dist/esm/compose/form/DateTimeInput.d.ts +28 -0
  13. package/dist/esm/compose/form/DateTimeInput.js +154 -0
  14. package/dist/esm/compose/form/DateTimePicker.d.ts +341 -0
  15. package/dist/esm/compose/form/DateTimePicker.js +1265 -0
  16. package/dist/esm/compose/form/FormControl.d.ts +33 -0
  17. package/dist/esm/compose/form/FormControl.js +163 -0
  18. package/dist/esm/compose/form/FormGroup.d.ts +14 -0
  19. package/dist/esm/compose/form/FormGroup.js +58 -0
  20. package/dist/esm/compose/overlay/Alert.d.ts +56 -0
  21. package/dist/esm/compose/overlay/Alert.js +267 -0
  22. package/dist/esm/constants/Alignment.d.ts +17 -0
  23. package/dist/esm/constants/Alignment.js +18 -0
  24. package/dist/esm/constants/Direction.d.ts +26 -0
  25. package/dist/esm/constants/Direction.js +22 -0
  26. package/dist/esm/constants/Orientation.d.ts +8 -0
  27. package/dist/esm/constants/Orientation.js +9 -0
  28. package/dist/esm/constants/Scheme.d.ts +39 -0
  29. package/dist/esm/constants/Scheme.js +43 -0
  30. package/dist/esm/constants/Transition.d.ts +81 -0
  31. package/dist/esm/constants/Transition.js +85 -0
  32. package/dist/esm/constants/Types.d.ts +74 -0
  33. package/dist/esm/constants/Types.js +14 -0
  34. package/dist/esm/core/ComponentBaseProps.d.ts +53 -0
  35. package/dist/esm/core/ComponentBaseProps.js +33 -0
  36. package/dist/esm/core/noseur.css +2390 -0
  37. package/dist/esm/data/Column.d.ts +235 -0
  38. package/dist/esm/data/Column.js +98 -0
  39. package/dist/esm/data/Data.css +213 -0
  40. package/dist/esm/data/Data.d.ts +98 -0
  41. package/dist/esm/data/Data.js +142 -0
  42. package/dist/esm/data/List.d.ts +14 -0
  43. package/dist/esm/data/List.js +117 -0
  44. package/dist/esm/data/Table.d.ts +22 -0
  45. package/dist/esm/data/Table.js +236 -0
  46. package/dist/esm/form/Button.d.ts +35 -0
  47. package/dist/esm/form/Button.js +131 -0
  48. package/dist/esm/form/Calendar.d.ts +20 -0
  49. package/dist/esm/form/Calendar.js +46 -0
  50. package/dist/esm/form/Checkbox.d.ts +20 -0
  51. package/dist/esm/form/Checkbox.js +155 -0
  52. package/dist/esm/form/ColorMap.d.ts +22 -0
  53. package/dist/esm/form/ColorMap.js +43 -0
  54. package/dist/esm/form/ColorPalette.d.ts +28 -0
  55. package/dist/esm/form/ColorPalette.js +87 -0
  56. package/dist/esm/form/Dropdown.d.ts +78 -0
  57. package/dist/esm/form/Dropdown.js +360 -0
  58. package/dist/esm/form/FileInput.d.ts +134 -0
  59. package/dist/esm/form/FileInput.js +523 -0
  60. package/dist/esm/form/Form.css +467 -0
  61. package/dist/esm/form/Input.d.ts +45 -0
  62. package/dist/esm/form/Input.js +186 -0
  63. package/dist/esm/form/RadioButton.d.ts +21 -0
  64. package/dist/esm/form/RadioButton.js +178 -0
  65. package/dist/esm/form/Slider.d.ts +21 -0
  66. package/dist/esm/form/Slider.js +163 -0
  67. package/dist/esm/hooks/useSearchParams.d.ts +15 -0
  68. package/dist/esm/hooks/useSearchParams.js +50 -0
  69. package/dist/esm/hooks/useSubscription.d.ts +9 -0
  70. package/dist/esm/hooks/useSubscription.js +26 -0
  71. package/dist/esm/index.d.ts +60 -0
  72. package/dist/esm/index.js +73 -0
  73. package/dist/esm/layout/GridView.d.ts +23 -0
  74. package/dist/esm/layout/GridView.js +34 -0
  75. package/dist/esm/layout/Layout.css +5 -0
  76. package/dist/esm/misc/Misc.css +164 -0
  77. package/dist/esm/misc/ProgressBar.d.ts +22 -0
  78. package/dist/esm/misc/ProgressBar.js +86 -0
  79. package/dist/esm/overlay/Dialog.d.ts +46 -0
  80. package/dist/esm/overlay/Dialog.js +290 -0
  81. package/dist/esm/overlay/Message.d.ts +35 -0
  82. package/dist/esm/overlay/Message.js +187 -0
  83. package/dist/esm/overlay/Overlay.css +382 -0
  84. package/dist/esm/overlay/Popover.d.ts +30 -0
  85. package/dist/esm/overlay/Popover.js +245 -0
  86. package/dist/esm/overlay/Portal.d.ts +11 -0
  87. package/dist/esm/overlay/Portal.js +29 -0
  88. package/dist/esm/overlay/Toast.d.ts +49 -0
  89. package/dist/esm/overlay/Toast.js +341 -0
  90. package/dist/esm/panel/Accordion.d.ts +26 -0
  91. package/dist/esm/panel/Accordion.js +127 -0
  92. package/dist/esm/panel/Panel.css +317 -0
  93. package/dist/esm/panel/Panel.d.ts +43 -0
  94. package/dist/esm/panel/Panel.js +125 -0
  95. package/dist/esm/panel/ScrollPanel.d.ts +27 -0
  96. package/dist/esm/panel/ScrollPanel.js +43 -0
  97. package/dist/esm/panel/TabPane.d.ts +82 -0
  98. package/dist/esm/panel/TabPane.js +237 -0
  99. package/dist/esm/presentation/Chart.d.ts +49 -0
  100. package/dist/esm/presentation/Chart.js +62 -0
  101. package/dist/esm/presentation/Paginator.d.ts +90 -0
  102. package/dist/esm/presentation/Paginator.js +331 -0
  103. package/dist/esm/presentation/Presentation.css +23 -0
  104. package/dist/esm/sensor/DragSensor.d.ts +50 -0
  105. package/dist/esm/sensor/DragSensor.js +156 -0
  106. package/dist/esm/sensor/ViewportSensor.d.ts +18 -0
  107. package/dist/esm/sensor/ViewportSensor.js +85 -0
  108. package/dist/esm/utils/BoolHelper.d.ts +13 -0
  109. package/dist/esm/utils/BoolHelper.js +105 -0
  110. package/dist/esm/utils/Classname.d.ts +9 -0
  111. package/dist/esm/utils/Classname.js +20 -0
  112. package/dist/esm/utils/ColorHelper.d.ts +127 -0
  113. package/dist/esm/utils/ColorHelper.js +198 -0
  114. package/dist/esm/utils/DOMUtils.d.ts +142 -0
  115. package/dist/esm/utils/DOMUtils.js +759 -0
  116. package/dist/esm/utils/DateHelper.d.ts +115 -0
  117. package/dist/esm/utils/DateHelper.js +338 -0
  118. package/dist/esm/utils/Debugger.d.ts +12 -0
  119. package/dist/esm/utils/Debugger.js +30 -0
  120. package/dist/esm/utils/FileHelper.d.ts +8 -0
  121. package/dist/esm/utils/FileHelper.js +65 -0
  122. package/dist/esm/utils/FunctionStackManager.d.ts +13 -0
  123. package/dist/esm/utils/FunctionStackManager.js +59 -0
  124. package/dist/esm/utils/InputHelper.d.ts +37 -0
  125. package/dist/esm/utils/InputHelper.js +70 -0
  126. package/dist/esm/utils/MicroBuilder.d.ts +24 -0
  127. package/dist/esm/utils/MicroBuilder.js +61 -0
  128. package/dist/esm/utils/ObjectHelper.d.ts +51 -0
  129. package/dist/esm/utils/ObjectHelper.js +334 -0
  130. package/dist/esm/utils/StringHelper.d.ts +10 -0
  131. package/dist/esm/utils/StringHelper.js +54 -0
  132. package/dist/esm/utils/Subscriber.d.ts +14 -0
  133. package/dist/esm/utils/Subscriber.js +27 -0
  134. package/dist/esm/utils/Timer.d.ts +32 -0
  135. package/dist/esm/utils/Timer.js +68 -0
  136. package/dist/esm/utils/TypeChecker.d.ts +12 -0
  137. package/dist/esm/utils/TypeChecker.js +38 -0
  138. package/package.json +63 -0
@@ -0,0 +1,33 @@
1
+ import "../Composed.css";
2
+ import React from "react";
3
+ import { Scheme } from "../../constants/Scheme";
4
+ import { ComponentBaseProps } from "../../core/ComponentBaseProps";
5
+ import { NoseurLabel, NoseurObject, NoseurElement } from "../../constants/Types";
6
+ export interface FormControlProps extends ComponentBaseProps<HTMLDivElement> {
7
+ fill: boolean;
8
+ invalid: boolean;
9
+ labelFor: string;
10
+ tabIndex: number;
11
+ leftContent: any;
12
+ rightContent: any;
13
+ required: boolean;
14
+ highlight: boolean;
15
+ label: NoseurLabel;
16
+ borderless: boolean;
17
+ isFieldset: boolean;
18
+ invalidScheme: Scheme;
19
+ infoLabel: NoseurLabel;
20
+ validClassname: string;
21
+ helpLabel: NoseurLabel;
22
+ children?: NoseurElement;
23
+ invalidClassname: string;
24
+ centerOverlayContent: any;
25
+ fieldsetLegendBackground: string;
26
+ childrenProps: NoseurObject<any>;
27
+ childrenValidPropsMap: NoseurObject<any>;
28
+ childrenInvalidPropsMap: NoseurObject<any>;
29
+ validStyle: React.CSSProperties | undefined;
30
+ invalidStyle: React.CSSProperties | undefined;
31
+ contentStyle: React.CSSProperties | undefined;
32
+ }
33
+ export declare const FormControl: ({ ref, ...props }: Partial<FormControlProps>) => React.JSX.Element;
@@ -0,0 +1,163 @@
1
+ import "../Composed.css";
2
+ import React from "react";
3
+ import { Scheme } from "../../constants/Scheme";
4
+ import { Classname } from "../../utils/Classname";
5
+ import { TypeChecker } from "../../utils/TypeChecker";
6
+ import { ObjectHelper } from "../../utils/ObjectHelper";
7
+ import { MicroBuilder } from "../../utils/MicroBuilder";
8
+ import { DOMHelper } from "../../utils/DOMUtils";
9
+ ;
10
+ // TODO implement manageRef to control contents, label, invalid, children, helpLabel, highlight, borderless
11
+ class FormControlComponent extends React.Component {
12
+ static defaultProps = {
13
+ tabIndex: 0,
14
+ invalid: false,
15
+ invalidStyle: {},
16
+ contentStyle: {},
17
+ invalidScheme: Scheme.DANGER,
18
+ childrenValidPropsMap: {
19
+ "borderless": true,
20
+ "scheme": "{scheme}"
21
+ },
22
+ childrenInvalidPropsMap: {
23
+ "highlight": true,
24
+ "borderless": true,
25
+ "scheme": "{invalidScheme}"
26
+ }
27
+ };
28
+ state = {};
29
+ constructor(props) {
30
+ super(props);
31
+ }
32
+ mapComponentProperties(childrenProps, propsMap) {
33
+ Object.keys(propsMap || {}).forEach((prop) => {
34
+ let propValue = propsMap[prop];
35
+ if (TypeChecker.isString(propValue) && propValue.startsWith("{") && propValue.endsWith("}")) {
36
+ propValue = this.props[propValue.substring(1, propValue.length - 1)];
37
+ }
38
+ const previousValue = childrenProps[prop];
39
+ if (previousValue && !TypeChecker.isString(previousValue)) {
40
+ childrenProps[prop] = ObjectHelper.joinValues(previousValue, propValue);
41
+ }
42
+ else {
43
+ childrenProps[prop] = propValue;
44
+ }
45
+ });
46
+ }
47
+ renderLeftContent() {
48
+ if (!this.props.leftContent)
49
+ return;
50
+ let className = "noseur-fctrl-lc";
51
+ let leftContent = this.props.leftContent;
52
+ const scheme = !this.props.invalid ? this.props.scheme : this.props.invalidScheme;
53
+ if (TypeChecker.isString(leftContent)) {
54
+ if (scheme)
55
+ className += ` ${scheme}-tx`;
56
+ leftContent = React.createElement("i", { className: leftContent });
57
+ }
58
+ return (React.createElement("div", { className: className }, leftContent));
59
+ }
60
+ renderRightContent() {
61
+ if (!this.props.rightContent)
62
+ return;
63
+ let className = "noseur-fctrl-rc";
64
+ let rightContent = this.props.rightContent;
65
+ const scheme = !this.props.invalid ? this.props.scheme : this.props.invalidScheme;
66
+ if (TypeChecker.isString(rightContent)) {
67
+ if (scheme)
68
+ className += ` ${scheme}-tx`;
69
+ rightContent = React.createElement("i", { className: rightContent });
70
+ }
71
+ return (React.createElement("div", { className: className }, rightContent));
72
+ }
73
+ renderFieldsetLegend() {
74
+ if (!this.props.isFieldset)
75
+ return;
76
+ let className = "noseur-fieldset-legend";
77
+ const label = MicroBuilder.buildLabel(this.props.label, { scheme: this.props.scheme, type: "label", htmlFor: this.props.labelFor, className: "noseur-fctrl-l" });
78
+ return (React.createElement("legend", { className: className, ref: (r) => {
79
+ if (!r)
80
+ return;
81
+ if (this.props.fieldsetLegendBackground === "dynamic") {
82
+ console.log(DOMHelper.getElementStyle(r.parentElement?.parentElement?.parentElement)?.backgroundColor);
83
+ r.style.backgroundColor = DOMHelper.getElementStyle(r.parentElement?.parentElement)?.backgroundColor;
84
+ }
85
+ }, style: { backgroundColor: (this.props.fieldsetLegendBackground && this.props.fieldsetLegendBackground !== "dynamic" ? this.props.fieldsetLegendBackground : undefined) } }, label));
86
+ }
87
+ renderCenterOverlayContent() {
88
+ if (!this.props.centerOverlayContent)
89
+ return;
90
+ let className = "noseur-fctrl-coc";
91
+ let centerOverlayContent = this.props.centerOverlayContent;
92
+ const scheme = !this.props.invalid ? this.props.scheme : this.props.invalidScheme;
93
+ if (TypeChecker.isString(centerOverlayContent)) {
94
+ if (scheme)
95
+ className += ` ${scheme}-tx`;
96
+ centerOverlayContent = React.createElement("i", { className: centerOverlayContent });
97
+ }
98
+ return (React.createElement("div", { className: className }, centerOverlayContent));
99
+ }
100
+ renderChildren(hasLeftContent, hasRightContent) {
101
+ const children = [].concat(this.props.children);
102
+ return children.map((child, index) => {
103
+ if (!child)
104
+ return child;
105
+ const childrenOwnScheme = child.props?.scheme;
106
+ const childrenProps = { ...(this.props.childrenProps || {}), ...(child.props || {}) };
107
+ if (this.props.required)
108
+ childrenProps.required = true;
109
+ if (!childrenOwnScheme)
110
+ childrenProps.scheme = this.props.scheme;
111
+ childrenProps.className = Classname.build("noseur-fctrl-cc", childrenProps.className, {
112
+ 'noseur-pd-l-0': hasLeftContent,
113
+ 'noseur-pd-r-0': hasRightContent,
114
+ });
115
+ if (!childrenProps.key)
116
+ childrenProps.key = index;
117
+ this.mapComponentProperties(childrenProps, (!this.props.invalid ? this.props.childrenValidPropsMap : this.props.childrenInvalidPropsMap));
118
+ return React.cloneElement(child, childrenProps);
119
+ });
120
+ }
121
+ render() {
122
+ const leftContent = this.renderLeftContent();
123
+ const rightContent = this.renderRightContent();
124
+ const fieldsetLegend = this.renderFieldsetLegend();
125
+ const centerOverlayContent = this.renderCenterOverlayContent();
126
+ const scheme = this.props.invalid ? this.props.invalidScheme : this.props.scheme;
127
+ const helpLabelClassName = this.props.invalid && !this.props.scheme ? "noseur-fctrl-hl noseur-invalid-tx" : "noseur-fctrl-hl";
128
+ const infoLabel = !this.props.invalid ? MicroBuilder.buildLabel(this.props.infoLabel, { scheme: this.props.scheme, className: "noseur-fctrl-il" }) : null;
129
+ const helpLabel = this.props.invalid ? MicroBuilder.buildLabel(this.props.helpLabel, { scheme: this.props.scheme, className: helpLabelClassName }) : null;
130
+ const label = (this.props.isFieldset ? null : MicroBuilder.buildLabel(this.props.label, { scheme: this.props.scheme, type: "label", htmlFor: this.props.labelFor, className: "noseur-fctrl-l" }));
131
+ const eventProps = ObjectHelper.extractEventProps(this.props);
132
+ const props = {
133
+ ...eventProps,
134
+ id: this.props.id,
135
+ key: this.props.key,
136
+ style: this.props.style,
137
+ required: this.props.required,
138
+ className: Classname.build("noseur-fctrl", (this.props.fill ? "noseur-wd-100-pct" : null), this.props.className),
139
+ };
140
+ delete props.children;
141
+ const contentStyle = {
142
+ ...this.props.contentStyle,
143
+ ...(this.props.invalid ? this.props.invalidStyle : this.props.validStyle),
144
+ };
145
+ const tagName = (this.props.isFieldset ? "fieldset" : "div");
146
+ const className = Classname.build("noseur-fctrl-c", { 'noseur-no-bd': this.props.borderless, "noseur-fieldset": this.props.isFieldset }, (scheme && this.props.highlight) ? `${scheme}-bd-cl` : null, this.props.invalid ? `${this.props.invalidScheme}-bd-cl` : null, (this.props.invalid ? this.props.invalidClassname : this.props.validClassname), (scheme) ? `${scheme}-bd-3px-bx-sw-fc ${scheme}-bd-cl-fc ${scheme}-bd-cl-hv` : null);
147
+ const children = this.renderChildren(!!leftContent, !!rightContent);
148
+ return (React.createElement("div", { ref: this.props.forwardRef, ...props },
149
+ label,
150
+ React.createElement(tagName, {
151
+ className,
152
+ style: contentStyle,
153
+ tabIndex: this.props.tabIndex,
154
+ }, (React.createElement(React.Fragment, null,
155
+ fieldsetLegend,
156
+ leftContent,
157
+ children,
158
+ centerOverlayContent,
159
+ rightContent))),
160
+ !this.props.invalid ? infoLabel : helpLabel));
161
+ }
162
+ }
163
+ export const FormControl = ({ ref, ...props }) => (React.createElement(FormControlComponent, { ...props, forwardRef: ref }));
@@ -0,0 +1,14 @@
1
+ import "../Composed.css";
2
+ import React from "react";
3
+ import { NoseurObject } from "../../constants/Types";
4
+ import { ComponentBaseProps } from "../../core/ComponentBaseProps";
5
+ export interface FormGroupProps extends ComponentBaseProps<HTMLFormElement> {
6
+ method: string;
7
+ action: string;
8
+ childrenClassname: string;
9
+ childrenProps: NoseurObject<any>;
10
+ childrenStyle: React.CSSProperties | undefined;
11
+ onSubmit: React.FormEventHandler<HTMLFormElement>;
12
+ }
13
+ export declare const FormGroup: ({ ref, ...props }: Partial<FormGroupProps>) => React.JSX.Element;
14
+ export declare const Form: ({ ref, ...props }: Partial<FormGroupProps>) => React.JSX.Element;
@@ -0,0 +1,58 @@
1
+ import "../Composed.css";
2
+ import React from "react";
3
+ import { ObjectHelper } from "../../utils/ObjectHelper";
4
+ import { Classname } from "../../utils/Classname";
5
+ import { TypeChecker } from "../../utils/TypeChecker";
6
+ ;
7
+ class FormGroupComponent extends React.Component {
8
+ static defaultProps = {
9
+ method: "POST",
10
+ childrenStyle: {},
11
+ childrenProps: {},
12
+ };
13
+ state = {};
14
+ constructor(props) {
15
+ super(props);
16
+ this.resolveChildren = this.resolveChildren.bind(this);
17
+ }
18
+ resolveChildren(parent) {
19
+ if (!parent)
20
+ return;
21
+ const children = parent.length != undefined ? parent : [parent];
22
+ if (!children.length)
23
+ return;
24
+ return children.map((child, index) => {
25
+ if (!child)
26
+ return;
27
+ if (TypeChecker.isArray(child))
28
+ return this.resolveChildren(child);
29
+ if (!React.isValidElement(child))
30
+ return child;
31
+ const props = {
32
+ ...child.props,
33
+ ...this.props.childrenProps,
34
+ scheme: child.props.scheme || this.props.scheme,
35
+ };
36
+ if (!props.key)
37
+ props.key = index;
38
+ const cachedStyle = props.style || {};
39
+ const cachedClassname = props.className;
40
+ props.style = { ...this.props.childrenStyle, ...cachedStyle };
41
+ props.className = Classname.build(this.props.childrenClassname, cachedClassname);
42
+ return React.cloneElement(child, props);
43
+ });
44
+ }
45
+ render() {
46
+ const eventProps = ObjectHelper.extractEventProps(this.props);
47
+ const props = {
48
+ ...eventProps,
49
+ key: this.props.key,
50
+ style: this.props.style,
51
+ className: Classname.build("noseur-fgrp", this.props.className),
52
+ };
53
+ delete props.children;
54
+ return (React.createElement("form", { ...props, method: this.props.method, action: this.props.action, onSubmit: this.props.onSubmit || ((e) => e.preventDefault()), ref: this.props.forwardRef }, this.resolveChildren(this.props.children)));
55
+ }
56
+ }
57
+ export const FormGroup = ({ ref, ...props }) => (React.createElement(FormGroupComponent, { ...props, forwardRef: ref }));
58
+ export const Form = FormGroup;
@@ -0,0 +1,56 @@
1
+ import "../Composed.css";
2
+ import React from "react";
3
+ import { DialogProps } from "../../overlay/Dialog";
4
+ import { PopoverProps } from "../../overlay/Popover";
5
+ import { Alignment } from "../../constants/Alignment";
6
+ import { ButtonProps, Scheme } from "../../";
7
+ import { ComponentBaseProps, TransitionProps } from "../../core/ComponentBaseProps";
8
+ import { NoseurDivElement, NoseurElement, NoseurIconElement, NoseurRawElement } from "../../constants/Types";
9
+ export type AlertEvent = () => void;
10
+ export type AlertControl = {
11
+ scheme?: Scheme;
12
+ label?: NoseurElement;
13
+ icon?: NoseurIconElement;
14
+ props?: Partial<ButtonProps>;
15
+ action?: AlertEvent;
16
+ ref?: React.ForwardedRef<any>;
17
+ };
18
+ export interface AlertProps<T> extends ComponentBaseProps<HTMLDivElement>, TransitionProps {
19
+ visible: boolean;
20
+ alignment: Alignment;
21
+ alignFooter: Alignment;
22
+ message: NoseurElement;
23
+ icon: NoseurIconElement;
24
+ dismissibleModal: boolean;
25
+ componentProps: Partial<T>;
26
+ container: NoseurRawElement;
27
+ cancel: AlertControl | null;
28
+ confirm: AlertControl | null;
29
+ footerElements: NoseurElement;
30
+ component: React.FunctionComponent<Partial<ComponentBaseProps<NoseurDivElement, any>> & React.RefAttributes<NoseurDivElement>>;
31
+ onHide: Function;
32
+ onCancel: AlertEvent;
33
+ onConfirm: AlertEvent;
34
+ }
35
+ export interface AlertInterface<T = DialogProps> {
36
+ hide: (onUnMount?: Function) => void;
37
+ destroy: (onUnMount?: Function) => void;
38
+ doneLoading: (onMount?: Function) => void;
39
+ startLoading: (onMount?: Function) => void;
40
+ show: (onMount?: Function) => AlertInterface<T>;
41
+ update: (newProps: Partial<AlertProps<T>>, onMount?: Function, onUnMount?: Function) => void;
42
+ }
43
+ export declare function alert<T>(props: Partial<AlertProps<T>>): AlertInterface<T>;
44
+ export interface LoadingAlertDialog<T, C> extends AlertProps<C> {
45
+ loadingProps: Partial<AlertProps<C>>;
46
+ loadingElement: NoseurIconElement;
47
+ onLoading: (alert: AlertInterface<T>, params?: T) => Promise<boolean | undefined>;
48
+ }
49
+ export declare function loadingAlert<T, C>(props: Partial<LoadingAlertDialog<T, C>>, params?: T): AlertInterface<DialogProps>;
50
+ export declare const AlertDialog: <T>({ ref, ...props }: Partial<AlertProps<T>>) => React.JSX.Element;
51
+ export declare const AlertPopover: <T>({ ref, ...props }: Partial<AlertProps<T>>) => React.JSX.Element;
52
+ export declare const Alert: <T>({ ref, ...props }: Partial<AlertProps<T>>) => React.JSX.Element;
53
+ export declare const alertDialog: ({ ref, ...props }: Partial<AlertProps<DialogProps>>) => AlertInterface<DialogProps>;
54
+ export declare const alertPopover: ({ ref, ...props }: Partial<AlertProps<PopoverProps>>) => AlertInterface<PopoverProps<HTMLDivElement, import("../../").PopoverManageRef, {}>>;
55
+ export declare const loadingAlertDialog: <T>({ ref, ...props }: Partial<LoadingAlertDialog<T, DialogProps>>, params?: T) => AlertInterface<DialogProps>;
56
+ export declare const loadingAlertPopover: <T>({ ref, ...props }: Partial<LoadingAlertDialog<T, PopoverProps>>, params?: T) => AlertInterface<DialogProps>;
@@ -0,0 +1,267 @@
1
+ import "../Composed.css";
2
+ import React from "react";
3
+ import ReactDOM from 'react-dom/client';
4
+ import { Dialog } from "../../overlay/Dialog";
5
+ import { Popover } from "../../overlay/Popover";
6
+ import { Classname } from "../../utils/Classname";
7
+ import { Alignment } from "../../constants/Alignment";
8
+ import { MicroBuilder } from "../../utils/MicroBuilder";
9
+ import { Button, DOMHelper, ObjectHelper, Scheme } from "../../";
10
+ ;
11
+ class AlertComponent extends React.Component {
12
+ static defaultProps = {
13
+ component: Dialog,
14
+ componentProps: {},
15
+ dismissibleModal: true,
16
+ transitionTimeout: 500,
17
+ alignment: Alignment.CENTER,
18
+ alignFooter: Alignment.RIGHT,
19
+ confirm: {
20
+ label: "OK",
21
+ scheme: Scheme.SUCCESS
22
+ },
23
+ cancel: {
24
+ label: "Cancel",
25
+ scheme: Scheme.SECONDARY
26
+ }
27
+ };
28
+ state = {
29
+ visible: this.props.visible,
30
+ };
31
+ lastClickedElement;
32
+ internalComponentRef;
33
+ internalComponentSelfRef;
34
+ documentClickListener;
35
+ constructor(props) {
36
+ super(props);
37
+ this.onHide = this.onHide.bind(this);
38
+ this.onCancel = this.onCancel.bind(this);
39
+ this.onConfirm = this.onConfirm.bind(this);
40
+ }
41
+ componentDidMount() {
42
+ this.documentClickListener = (event) => {
43
+ this.lastClickedElement = event.target || event.currentTarget;
44
+ };
45
+ document.addEventListener('click', this.documentClickListener);
46
+ }
47
+ componentDidUpdate(prevProps) {
48
+ if (prevProps.visible !== this.props.visible) {
49
+ const isVisible = this.state.visible;
50
+ this.setState({ visible: this.props.visible });
51
+ if (isVisible && this.props.dismissibleModal)
52
+ return;
53
+ this.internalComponentSelfRef && this.internalComponentSelfRef.toggle && this.internalComponentSelfRef.toggle({}, this.getUsableTarget());
54
+ }
55
+ }
56
+ componentWillUnmount() {
57
+ if (!this.documentClickListener)
58
+ return;
59
+ document.removeEventListener('click', this.documentClickListener);
60
+ this.documentClickListener = undefined;
61
+ }
62
+ getUsableTarget(e) {
63
+ let target = (e || event)?.target || (e || event)?.currentTarget;
64
+ if (!DOMHelper.isElement(target))
65
+ target = this.lastClickedElement;
66
+ return target;
67
+ }
68
+ onHide(e) {
69
+ if (this.props.onHide)
70
+ return this.props.onHide();
71
+ this.setState({ visible: false });
72
+ this.internalComponentSelfRef && this.internalComponentSelfRef.toggle && this.internalComponentSelfRef.toggle({}, this.getUsableTarget(e));
73
+ }
74
+ onConfirm(e) {
75
+ if (this.props.onConfirm)
76
+ return this.props.onConfirm();
77
+ this.onHide(e);
78
+ }
79
+ onCancel(e) {
80
+ if (this.props.onCancel)
81
+ return this.props.onCancel();
82
+ this.onHide(e);
83
+ }
84
+ renderControl() {
85
+ if (!this.props.cancel && !this.props.confirm && !this.props.footerElements)
86
+ return;
87
+ const controlButtons = [this.props.cancel, this.props.confirm].map((control, index) => {
88
+ if (!control)
89
+ return null;
90
+ const cachedOnClick = control.props?.onClick;
91
+ const text = control.label || control.props?.text;
92
+ const icon = control.icon || control.props?.leftIcon;
93
+ const ref = control.ref || control.props?.ref;
94
+ const scheme = control.scheme || control.props?.scheme;
95
+ const onClick = (e) => {
96
+ if (cachedOnClick)
97
+ cachedOnClick(e);
98
+ if (control.action)
99
+ control.action();
100
+ if (index === 0)
101
+ this.onCancel(e);
102
+ if (index === 1)
103
+ this.onConfirm(e);
104
+ };
105
+ return (React.createElement(Button, { ...(control.props || {}), key: control.props?.key || index, text: text, leftIcon: icon, scheme: scheme, ref: ref, onClick: onClick }));
106
+ });
107
+ return (React.createElement("div", { className: `noseur-alert-footer noseur-alert-footer-${this.props.alignFooter}` },
108
+ controlButtons,
109
+ this.props.footerElements));
110
+ }
111
+ render() {
112
+ const controls = this.renderControl();
113
+ const closeIcon = this.props.componentProps.closeIcon ?? null;
114
+ const cachedComponentPropsRef = this.props.componentProps.ref;
115
+ const cachedComponentPropsSelfRef = this.props.componentProps.selfRef;
116
+ const cachedComponentPropsForwardRef = this.props.componentProps.forwardRef;
117
+ const container = this.props.componentProps.container ?? this.props.container;
118
+ const alignment = this.props.componentProps.alignment ?? this.props.alignment;
119
+ const style = { ...(this.props.style || {}), ...(this.props.componentProps.style ?? {}) };
120
+ const className = Classname.build("noseur-alert", this.props.className, this.props.componentProps.className);
121
+ const icon = MicroBuilder.buildIcon(this.props.icon, { scheme: this.props.scheme, className: "noseur-dialog-content-icon" });
122
+ const ref = (e) => {
123
+ if (!!this.internalComponentRef && !e)
124
+ this.componentWillUnmount();
125
+ else if (!this.documentClickListener && !!e)
126
+ this.componentDidMount();
127
+ this.internalComponentRef = e;
128
+ ObjectHelper.resolveRef(cachedComponentPropsRef, e);
129
+ };
130
+ const forwardRef = (e) => {
131
+ if (!!this.internalComponentRef && !e)
132
+ this.componentWillUnmount();
133
+ else if (!this.documentClickListener && !!e)
134
+ this.componentDidMount();
135
+ this.internalComponentRef = e;
136
+ ObjectHelper.resolveRef(cachedComponentPropsForwardRef, e);
137
+ };
138
+ const selfRef = (e) => {
139
+ this.internalComponentSelfRef = e;
140
+ ObjectHelper.resolveRef(cachedComponentPropsSelfRef, e);
141
+ };
142
+ return React.createElement(this.props.component, {
143
+ ...this.props.componentProps,
144
+ ref,
145
+ style,
146
+ selfRef,
147
+ className,
148
+ alignment,
149
+ container,
150
+ forwardRef,
151
+ onHide: this.onHide,
152
+ closeIcon: closeIcon,
153
+ visible: this.state.visible,
154
+ transition: this.props.transition,
155
+ dismissible: this.props.dismissibleModal,
156
+ dismissibleModal: this.props.dismissibleModal,
157
+ transitionOptions: this.props.transitionOptions,
158
+ transitionTimeout: this.props.transitionTimeout,
159
+ }, (React.createElement("div", { className: "noseur-alert-content", ref: this.props.forwardRef },
160
+ icon,
161
+ this.props.message)), controls);
162
+ }
163
+ }
164
+ export function alert(props) {
165
+ let container = props.container || document.body;
166
+ let alertWrapper = document.createDocumentFragment();
167
+ DOMHelper.appendChild(alertWrapper, container);
168
+ props = { ...props, ...{ isVisible: props.visible === undefined ? true : props.visible } };
169
+ let alertDialog = React.createElement(AlertDialog, props);
170
+ let root = ReactDOM.createRoot(alertWrapper);
171
+ root.render(alertDialog);
172
+ let destroyed = false;
173
+ let mounted = props.visible;
174
+ let updateAlert = (newProps, onMount, onUnMount) => {
175
+ if (destroyed)
176
+ return;
177
+ props = { ...props, ...newProps, onHide: onUnMount };
178
+ mounted = props.visible;
179
+ const cachedRef = props.ref;
180
+ props.ref = !onMount ? cachedRef : (r) => {
181
+ if (!r)
182
+ return;
183
+ onMount();
184
+ if (cachedRef)
185
+ ObjectHelper.resolveRef(cachedRef, r);
186
+ };
187
+ root.render(React.cloneElement(alertDialog, props));
188
+ };
189
+ const alertInterface = {
190
+ hide: (onUnMount) => updateAlert({ visible: false }, undefined, onUnMount),
191
+ update: (newProps, onMount, nUnMount) => updateAlert(newProps, onMount, nUnMount),
192
+ destroy: (onUnMount) => {
193
+ if (!mounted)
194
+ return;
195
+ root.unmount();
196
+ destroyed = true;
197
+ onUnMount && onUnMount();
198
+ },
199
+ show: (onMount, onUnMount) => {
200
+ mounted = true;
201
+ updateAlert({
202
+ visible: true, onHide: () => {
203
+ updateAlert({ visible: false }, undefined, onUnMount);
204
+ }
205
+ }, onMount);
206
+ return alertInterface;
207
+ },
208
+ doneLoading: (_) => { throw new Error("Alert is not of the loading type."); },
209
+ startLoading: (_) => { throw new Error("Alert is not of the loading type."); },
210
+ };
211
+ return alertInterface;
212
+ }
213
+ ;
214
+ export function loadingAlert(props, params) {
215
+ const icon = props.loadingElement || "fas fa-spinner fa-pulse";
216
+ const doneProps = {
217
+ icon: props.icon,
218
+ cancel: props.cancel,
219
+ confirm: props.confirm,
220
+ message: props.message,
221
+ className: props.className,
222
+ footerElements: props.footerElements,
223
+ dismissibleModal: props.dismissibleModal,
224
+ };
225
+ const loadingProps = {
226
+ ...props,
227
+ icon: icon,
228
+ cancel: null,
229
+ confirm: null,
230
+ message: null,
231
+ dismissibleModal: false,
232
+ className: "noseur-alert-loading",
233
+ ...(props.loadingProps || {})
234
+ };
235
+ const alert = alertDialog(loadingProps);
236
+ alert.show = (onMount, onUnMount) => {
237
+ if (props.onLoading) {
238
+ props.onLoading(alert, params).then((result) => {
239
+ if (result)
240
+ alert.update(doneProps, onMount);
241
+ else if (result === undefined)
242
+ alert.destroy();
243
+ });
244
+ }
245
+ alert.update({
246
+ ...loadingProps, visible: true, onHide: () => {
247
+ alert.update({ visible: false }, onMount, onUnMount);
248
+ }
249
+ }, onMount, onUnMount);
250
+ return alert;
251
+ };
252
+ alert.startLoading = (onMount) => {
253
+ alert.update(loadingProps, onMount);
254
+ };
255
+ alert.doneLoading = (onMount) => {
256
+ alert.update(doneProps, onMount);
257
+ };
258
+ return alert;
259
+ }
260
+ ;
261
+ export const AlertDialog = ({ ref, ...props }) => (React.createElement(AlertComponent, { ...props, forwardRef: ref }));
262
+ export const AlertPopover = ({ ref, ...props }) => (React.createElement(AlertComponent, { ...props, component: Popover, forwardRef: ref }));
263
+ export const Alert = AlertDialog;
264
+ export const alertDialog = ({ ref, ...props }) => alert({ ...props, forwardRef: ref });
265
+ export const alertPopover = ({ ref, ...props }) => alert({ ...props, forwardRef: ref, component: Popover });
266
+ export const loadingAlertDialog = ({ ref, ...props }, params) => loadingAlert({ ...props, forwardRef: ref }, params);
267
+ export const loadingAlertPopover = ({ ref, ...props }, params) => loadingAlert({ ...props, forwardRef: ref, component: Popover }, params);
@@ -0,0 +1,17 @@
1
+ export declare enum Alignment {
2
+ NONE = "",
3
+ TOP = "top",
4
+ LEFT = "left",
5
+ RIGHT = "right",
6
+ BOTTOM = "bottom",
7
+ CENTER = "center",
8
+ TOP_LEFT = "top-left",
9
+ TOP_RIGHT = "top-right",
10
+ TOP_CENTER = "top-center",
11
+ BOTTOM_LEFT = "bottom-left",
12
+ CENTER_LEFT = "center-left",
13
+ CENTER_RIGHT = "center-right",
14
+ BOTTOM_RIGHT = "bottom-right",
15
+ BOTTOM_CENTER = "bottom-center"
16
+ }
17
+ export declare const Position: typeof Alignment;
@@ -0,0 +1,18 @@
1
+ export var Alignment;
2
+ (function (Alignment) {
3
+ Alignment["NONE"] = "";
4
+ Alignment["TOP"] = "top";
5
+ Alignment["LEFT"] = "left";
6
+ Alignment["RIGHT"] = "right";
7
+ Alignment["BOTTOM"] = "bottom";
8
+ Alignment["CENTER"] = "center";
9
+ Alignment["TOP_LEFT"] = "top-left";
10
+ Alignment["TOP_RIGHT"] = "top-right";
11
+ Alignment["TOP_CENTER"] = "top-center";
12
+ Alignment["BOTTOM_LEFT"] = "bottom-left";
13
+ Alignment["CENTER_LEFT"] = "center-left";
14
+ Alignment["CENTER_RIGHT"] = "center-right";
15
+ Alignment["BOTTOM_RIGHT"] = "bottom-right";
16
+ Alignment["BOTTOM_CENTER"] = "bottom-center";
17
+ })(Alignment || (Alignment = {}));
18
+ export const Position = Alignment;
@@ -0,0 +1,26 @@
1
+ export declare enum Direction {
2
+ ALL = "",
3
+ WEST = "WEST",
4
+ EAST = "EAST",
5
+ NORTH = "NORTH",
6
+ SOUTH = "SOUTH",
7
+ EAST_WEST = "EAST_WEST",
8
+ NORTH_WEST = "NORTH_WEST",
9
+ NORTH_EAST = "NORTH_EAST",
10
+ SOUTH_WEST = "SOUTH_WEST",
11
+ SOUTH_EAST = "SOUTH_EAST",
12
+ NORTH_SOUTH = "NORTH_SOUTH"
13
+ }
14
+ export declare enum Bound {
15
+ ALL = "",
16
+ TOP = "TOP",
17
+ LEFT = "LEFT",
18
+ RIGHT = "RIGHT",
19
+ BOTTOM = "BOTTOM"
20
+ }
21
+ export interface Ceiling {
22
+ top?: number;
23
+ left?: number;
24
+ right?: number;
25
+ bottom?: number;
26
+ }