@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.
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/esm/Template.d.ts +7 -0
- package/dist/esm/Template.js +13 -0
- package/dist/esm/compose/Composed.css +437 -0
- package/dist/esm/compose/exotic/ColorPicker.d.ts +41 -0
- package/dist/esm/compose/exotic/ColorPicker.js +85 -0
- package/dist/esm/compose/exotic/ColorSlider.d.ts +30 -0
- package/dist/esm/compose/exotic/ColorSlider.js +99 -0
- package/dist/esm/compose/form/ComposedPassword.d.ts +25 -0
- package/dist/esm/compose/form/ComposedPassword.js +103 -0
- package/dist/esm/compose/form/DateTimeInput.d.ts +28 -0
- package/dist/esm/compose/form/DateTimeInput.js +154 -0
- package/dist/esm/compose/form/DateTimePicker.d.ts +341 -0
- package/dist/esm/compose/form/DateTimePicker.js +1265 -0
- package/dist/esm/compose/form/FormControl.d.ts +33 -0
- package/dist/esm/compose/form/FormControl.js +163 -0
- package/dist/esm/compose/form/FormGroup.d.ts +14 -0
- package/dist/esm/compose/form/FormGroup.js +58 -0
- package/dist/esm/compose/overlay/Alert.d.ts +56 -0
- package/dist/esm/compose/overlay/Alert.js +267 -0
- package/dist/esm/constants/Alignment.d.ts +17 -0
- package/dist/esm/constants/Alignment.js +18 -0
- package/dist/esm/constants/Direction.d.ts +26 -0
- package/dist/esm/constants/Direction.js +22 -0
- package/dist/esm/constants/Orientation.d.ts +8 -0
- package/dist/esm/constants/Orientation.js +9 -0
- package/dist/esm/constants/Scheme.d.ts +39 -0
- package/dist/esm/constants/Scheme.js +43 -0
- package/dist/esm/constants/Transition.d.ts +81 -0
- package/dist/esm/constants/Transition.js +85 -0
- package/dist/esm/constants/Types.d.ts +74 -0
- package/dist/esm/constants/Types.js +14 -0
- package/dist/esm/core/ComponentBaseProps.d.ts +53 -0
- package/dist/esm/core/ComponentBaseProps.js +33 -0
- package/dist/esm/core/noseur.css +2390 -0
- package/dist/esm/data/Column.d.ts +235 -0
- package/dist/esm/data/Column.js +98 -0
- package/dist/esm/data/Data.css +213 -0
- package/dist/esm/data/Data.d.ts +98 -0
- package/dist/esm/data/Data.js +142 -0
- package/dist/esm/data/List.d.ts +14 -0
- package/dist/esm/data/List.js +117 -0
- package/dist/esm/data/Table.d.ts +22 -0
- package/dist/esm/data/Table.js +236 -0
- package/dist/esm/form/Button.d.ts +35 -0
- package/dist/esm/form/Button.js +131 -0
- package/dist/esm/form/Calendar.d.ts +20 -0
- package/dist/esm/form/Calendar.js +46 -0
- package/dist/esm/form/Checkbox.d.ts +20 -0
- package/dist/esm/form/Checkbox.js +155 -0
- package/dist/esm/form/ColorMap.d.ts +22 -0
- package/dist/esm/form/ColorMap.js +43 -0
- package/dist/esm/form/ColorPalette.d.ts +28 -0
- package/dist/esm/form/ColorPalette.js +87 -0
- package/dist/esm/form/Dropdown.d.ts +78 -0
- package/dist/esm/form/Dropdown.js +360 -0
- package/dist/esm/form/FileInput.d.ts +134 -0
- package/dist/esm/form/FileInput.js +523 -0
- package/dist/esm/form/Form.css +467 -0
- package/dist/esm/form/Input.d.ts +45 -0
- package/dist/esm/form/Input.js +186 -0
- package/dist/esm/form/RadioButton.d.ts +21 -0
- package/dist/esm/form/RadioButton.js +178 -0
- package/dist/esm/form/Slider.d.ts +21 -0
- package/dist/esm/form/Slider.js +163 -0
- package/dist/esm/hooks/useSearchParams.d.ts +15 -0
- package/dist/esm/hooks/useSearchParams.js +50 -0
- package/dist/esm/hooks/useSubscription.d.ts +9 -0
- package/dist/esm/hooks/useSubscription.js +26 -0
- package/dist/esm/index.d.ts +60 -0
- package/dist/esm/index.js +73 -0
- package/dist/esm/layout/GridView.d.ts +23 -0
- package/dist/esm/layout/GridView.js +34 -0
- package/dist/esm/layout/Layout.css +5 -0
- package/dist/esm/misc/Misc.css +164 -0
- package/dist/esm/misc/ProgressBar.d.ts +22 -0
- package/dist/esm/misc/ProgressBar.js +86 -0
- package/dist/esm/overlay/Dialog.d.ts +46 -0
- package/dist/esm/overlay/Dialog.js +290 -0
- package/dist/esm/overlay/Message.d.ts +35 -0
- package/dist/esm/overlay/Message.js +187 -0
- package/dist/esm/overlay/Overlay.css +382 -0
- package/dist/esm/overlay/Popover.d.ts +30 -0
- package/dist/esm/overlay/Popover.js +245 -0
- package/dist/esm/overlay/Portal.d.ts +11 -0
- package/dist/esm/overlay/Portal.js +29 -0
- package/dist/esm/overlay/Toast.d.ts +49 -0
- package/dist/esm/overlay/Toast.js +341 -0
- package/dist/esm/panel/Accordion.d.ts +26 -0
- package/dist/esm/panel/Accordion.js +127 -0
- package/dist/esm/panel/Panel.css +317 -0
- package/dist/esm/panel/Panel.d.ts +43 -0
- package/dist/esm/panel/Panel.js +125 -0
- package/dist/esm/panel/ScrollPanel.d.ts +27 -0
- package/dist/esm/panel/ScrollPanel.js +43 -0
- package/dist/esm/panel/TabPane.d.ts +82 -0
- package/dist/esm/panel/TabPane.js +237 -0
- package/dist/esm/presentation/Chart.d.ts +49 -0
- package/dist/esm/presentation/Chart.js +62 -0
- package/dist/esm/presentation/Paginator.d.ts +90 -0
- package/dist/esm/presentation/Paginator.js +331 -0
- package/dist/esm/presentation/Presentation.css +23 -0
- package/dist/esm/sensor/DragSensor.d.ts +50 -0
- package/dist/esm/sensor/DragSensor.js +156 -0
- package/dist/esm/sensor/ViewportSensor.d.ts +18 -0
- package/dist/esm/sensor/ViewportSensor.js +85 -0
- package/dist/esm/utils/BoolHelper.d.ts +13 -0
- package/dist/esm/utils/BoolHelper.js +105 -0
- package/dist/esm/utils/Classname.d.ts +9 -0
- package/dist/esm/utils/Classname.js +20 -0
- package/dist/esm/utils/ColorHelper.d.ts +127 -0
- package/dist/esm/utils/ColorHelper.js +198 -0
- package/dist/esm/utils/DOMUtils.d.ts +142 -0
- package/dist/esm/utils/DOMUtils.js +759 -0
- package/dist/esm/utils/DateHelper.d.ts +115 -0
- package/dist/esm/utils/DateHelper.js +338 -0
- package/dist/esm/utils/Debugger.d.ts +12 -0
- package/dist/esm/utils/Debugger.js +30 -0
- package/dist/esm/utils/FileHelper.d.ts +8 -0
- package/dist/esm/utils/FileHelper.js +65 -0
- package/dist/esm/utils/FunctionStackManager.d.ts +13 -0
- package/dist/esm/utils/FunctionStackManager.js +59 -0
- package/dist/esm/utils/InputHelper.d.ts +37 -0
- package/dist/esm/utils/InputHelper.js +70 -0
- package/dist/esm/utils/MicroBuilder.d.ts +24 -0
- package/dist/esm/utils/MicroBuilder.js +61 -0
- package/dist/esm/utils/ObjectHelper.d.ts +51 -0
- package/dist/esm/utils/ObjectHelper.js +334 -0
- package/dist/esm/utils/StringHelper.d.ts +10 -0
- package/dist/esm/utils/StringHelper.js +54 -0
- package/dist/esm/utils/Subscriber.d.ts +14 -0
- package/dist/esm/utils/Subscriber.js +27 -0
- package/dist/esm/utils/Timer.d.ts +32 -0
- package/dist/esm/utils/Timer.js +68 -0
- package/dist/esm/utils/TypeChecker.d.ts +12 -0
- package/dist/esm/utils/TypeChecker.js +38 -0
- package/package.json +63 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import "../Composed.css";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Classname } from "../../utils/Classname";
|
|
4
|
+
import { ColorHelper } from "../../utils/ColorHelper";
|
|
5
|
+
import { Slider } from "../../form/Slider";
|
|
6
|
+
import { Orientation } from "../../constants/Orientation";
|
|
7
|
+
export const ColorSliderGradient = {
|
|
8
|
+
TRANSPARENT: "linear-gradient(to top, transparent, var(--primaryColor, #ffffff))",
|
|
9
|
+
TRANSPARENT_VERTICAL: "linear-gradient(to top, transparent, var(--primaryColor, #ffffff))",
|
|
10
|
+
TRANSPARENT_HORIZONTAL: "linear-gradient(to left, transparent, var(--primaryColor, #ffffff))",
|
|
11
|
+
RAINBOW: "linear-gradient(to bottom, red 0, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%)",
|
|
12
|
+
RAINBOW_VERTICAL: "linear-gradient(to bottom, red 0, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%)",
|
|
13
|
+
RAINBOW_HORIZONTAL: "linear-gradient(to right, red 0, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%)",
|
|
14
|
+
};
|
|
15
|
+
class ColorSliderComponent extends React.Component {
|
|
16
|
+
static defaultProps = {
|
|
17
|
+
hue: "#ff0000",
|
|
18
|
+
attrsRelay: {},
|
|
19
|
+
allowedOverflow: 5,
|
|
20
|
+
primaryColor: "#ffffff",
|
|
21
|
+
orientation: Orientation.VERTICAL,
|
|
22
|
+
colorGradient: ColorSliderGradient.RAINBOW,
|
|
23
|
+
};
|
|
24
|
+
state = {
|
|
25
|
+
primaryColor: this.props.primaryColor,
|
|
26
|
+
};
|
|
27
|
+
alpha;
|
|
28
|
+
cachedAttrs = {};
|
|
29
|
+
hsb;
|
|
30
|
+
constructor(props) {
|
|
31
|
+
super(props);
|
|
32
|
+
this.alpha = 1;
|
|
33
|
+
this.hsb = ColorHelper.hexToHsb(this.props.hue);
|
|
34
|
+
this.onChange = this.onChange.bind(this);
|
|
35
|
+
this.onHandleDrag = this.onHandleDrag.bind(this);
|
|
36
|
+
}
|
|
37
|
+
componentDidUpdate(prevProps, _) {
|
|
38
|
+
if (this.props.primaryColor !== prevProps.primaryColor || this.props.hue !== prevProps.hue) {
|
|
39
|
+
this.hsb = (this.props.hue !== prevProps.hue ? ColorHelper.hexToHsb(this.props.hue) : this.hsb);
|
|
40
|
+
this.setState({ primaryColor: this.props.primaryColor });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
onChange(evt) {
|
|
44
|
+
this.props.onChange && this.props.onChange(evt);
|
|
45
|
+
const value = evt.value + this.props.allowedOverflow;
|
|
46
|
+
this.alpha = (value / 100);
|
|
47
|
+
}
|
|
48
|
+
async onHandleDrag(evt) {
|
|
49
|
+
const { event } = evt;
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
let position = (event[this.cachedAttrs.page] !== undefined ? event[this.cachedAttrs.page] : (event.changedTouches !== undefined ? event.changedTouches[0][this.cachedAttrs.page] : 0));
|
|
52
|
+
const topOrLeft = (this.cachedAttrs.rect[this.cachedAttrs.topLeft] ?? 0) + (window[this.cachedAttrs.scrollXy] ?? document.documentElement[this.cachedAttrs.scrollTl] ?? document.body[this.cachedAttrs.scrollTl] ?? 0);
|
|
53
|
+
const hsb = ColorHelper.normalizeHsB({
|
|
54
|
+
s: this.hsb.s,
|
|
55
|
+
b: this.hsb.b,
|
|
56
|
+
h: Math.floor((360 * (Math.max(0, Math.min(224, position - topOrLeft)))) / 224),
|
|
57
|
+
});
|
|
58
|
+
const eventValue = { color: ColorHelper.hsbToColor(hsb, this.alpha), previousColor: ColorHelper.hsbToColor(this.hsb, this.alpha) };
|
|
59
|
+
if ((this.props.onSelectColor && this.props.onSelectColor(eventValue) === true))
|
|
60
|
+
return;
|
|
61
|
+
this.hsb = hsb;
|
|
62
|
+
}, 100);
|
|
63
|
+
}
|
|
64
|
+
renderRange() {
|
|
65
|
+
return (React.createElement("div", { className: Classname.build("noseur-color-slider-range", `noseur-color-slider-range-${this.props.orientation}`) }));
|
|
66
|
+
}
|
|
67
|
+
render() {
|
|
68
|
+
const range = this.renderRange();
|
|
69
|
+
const className = Classname.build("noseur-color-slider", `noseur-color-slider-${this.props.orientation}`, this.props.className, this.props.attrsRelay?.sliderProps?.className);
|
|
70
|
+
const style = {
|
|
71
|
+
...(this.props.style ?? {}),
|
|
72
|
+
"--primaryColor": this.state.primaryColor,
|
|
73
|
+
"--noseurSchemeMainColor": this.props.colorGradient,
|
|
74
|
+
...(this.props.attrsRelay?.sliderProps?.style ?? {}),
|
|
75
|
+
};
|
|
76
|
+
this.props.attrsRelay.sliderProps = {
|
|
77
|
+
...(this.props.attrsRelay.sliderProps ?? {}),
|
|
78
|
+
attrsRelay: {
|
|
79
|
+
...(this.props.attrsRelay?.sliderProps?.attrsRelay ?? {}),
|
|
80
|
+
dragSensorProps: {
|
|
81
|
+
...(this.props.attrsRelay?.sliderProps?.attrsRelay?.dragSensorProps ?? {}),
|
|
82
|
+
[this.props.reportOnDrag ? `onDragEvent` : `onDragEventEnd`]: this.onHandleDrag,
|
|
83
|
+
allowedOverflow: this.props.allowedOverflow,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return (React.createElement(Slider, { ...this.props.attrsRelay.sliderProps, range: range, onChange: this.onChange, orientation: this.props.orientation, id: this.props.id, key: this.props.key, className: className, style: style, ref: (e) => {
|
|
88
|
+
if (e) {
|
|
89
|
+
this.cachedAttrs.rect = e.getBoundingClientRect();
|
|
90
|
+
this.cachedAttrs.page = (this.props.orientation === Orientation.HORIZONTAL ? "pageX" : "pageY");
|
|
91
|
+
this.cachedAttrs.topLeft = (this.props.orientation === Orientation.HORIZONTAL ? "left" : "top");
|
|
92
|
+
this.cachedAttrs.scrollXy = (this.props.orientation === Orientation.HORIZONTAL ? "scrollX" : "scrollY");
|
|
93
|
+
this.cachedAttrs.scrollTl = (this.props.orientation === Orientation.HORIZONTAL ? "scrollLeft" : "scrollTop");
|
|
94
|
+
}
|
|
95
|
+
} }));
|
|
96
|
+
}
|
|
97
|
+
;
|
|
98
|
+
}
|
|
99
|
+
export const ColorSlider = ({ ref, ...props }) => (React.createElement(ColorSliderComponent, { ...props, forwardRef: ref }));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "../Composed.css";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { FormControlProps } from "./FormControl";
|
|
4
|
+
import { ComponentBaseProps } from "../../core/ComponentBaseProps";
|
|
5
|
+
import { NoseurElement, NumberRange, ToggleIcons } from "../../constants/Types";
|
|
6
|
+
import { InputOnInputCompleteHandler, InputProps } from "../../form/Input";
|
|
7
|
+
import { ProgressBarProps } from "../../misc/ProgressBar";
|
|
8
|
+
export type ComposedPasswordEventHandler = () => void;
|
|
9
|
+
export type ComposedPasswordStrengthHandler = (value: string) => NumberRange<0, 100>;
|
|
10
|
+
export interface ComposedPasswordProps extends ComponentBaseProps<HTMLDivElement> {
|
|
11
|
+
hidden: boolean;
|
|
12
|
+
toggleMask: boolean;
|
|
13
|
+
borderless: boolean;
|
|
14
|
+
toggleIcons: ToggleIcons;
|
|
15
|
+
inputProps: Partial<InputProps>;
|
|
16
|
+
progressProps: Partial<ProgressBarProps>;
|
|
17
|
+
strengthIndicator: boolean | NoseurElement;
|
|
18
|
+
formControlProps: Partial<FormControlProps>;
|
|
19
|
+
onShow: ComposedPasswordEventHandler;
|
|
20
|
+
onHide: ComposedPasswordEventHandler;
|
|
21
|
+
strengthComputer: ComposedPasswordStrengthHandler;
|
|
22
|
+
onInputComplete: InputOnInputCompleteHandler | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare const ComposedPassword: ({ ref, ...props }: Partial<ComposedPasswordProps>) => React.JSX.Element;
|
|
25
|
+
export declare function composedPasswordDefaultStrengthComputer(value: string): NumberRange<0, 100>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import "../Composed.css";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Classname } from "../../utils/Classname";
|
|
4
|
+
import { TypeChecker } from "../../utils/TypeChecker";
|
|
5
|
+
import { MicroBuilder } from "../../utils/MicroBuilder";
|
|
6
|
+
import { ObjectHelper } from "../../utils/ObjectHelper";
|
|
7
|
+
import { FormControl } from "./FormControl";
|
|
8
|
+
import { TextInput } from "../../form/Input";
|
|
9
|
+
import { ProgressBar } from "../../misc/ProgressBar";
|
|
10
|
+
;
|
|
11
|
+
class ComposedPasswordComponent extends React.Component {
|
|
12
|
+
static defaultProps = {
|
|
13
|
+
hidden: true,
|
|
14
|
+
toggleMask: true,
|
|
15
|
+
inputProps: {},
|
|
16
|
+
progressProps: {},
|
|
17
|
+
formControlProps: {},
|
|
18
|
+
toggleIcons: {
|
|
19
|
+
show: 'fa fa-eye',
|
|
20
|
+
hide: 'fa fa-eye-slash'
|
|
21
|
+
},
|
|
22
|
+
strengthComputer: composedPasswordDefaultStrengthComputer
|
|
23
|
+
};
|
|
24
|
+
state = {
|
|
25
|
+
hidden: true,
|
|
26
|
+
};
|
|
27
|
+
progressBarComponent;
|
|
28
|
+
constructor(props) {
|
|
29
|
+
super(props);
|
|
30
|
+
this.onInput = this.onInput.bind(this);
|
|
31
|
+
this.onToggle = this.onToggle.bind(this);
|
|
32
|
+
}
|
|
33
|
+
onInput(e) {
|
|
34
|
+
const value = e.target.value;
|
|
35
|
+
if (this.props.onInput)
|
|
36
|
+
this.props.onInput(e);
|
|
37
|
+
if (!TypeChecker.isBoolean(this.props.strengthIndicator) || !this.props.strengthIndicator || !this.progressBarComponent)
|
|
38
|
+
return;
|
|
39
|
+
this.progressBarComponent?.setValue(this.props.strengthComputer(value));
|
|
40
|
+
}
|
|
41
|
+
onToggle(_) {
|
|
42
|
+
if (this.state.hidden && this.props.onShow)
|
|
43
|
+
this.props.onShow();
|
|
44
|
+
else if (this.props.onHide)
|
|
45
|
+
this.props.onHide();
|
|
46
|
+
this.setState({ hidden: !this.state.hidden });
|
|
47
|
+
}
|
|
48
|
+
renderToggleIcon() {
|
|
49
|
+
if (!this.props.toggleMask || !this.props.toggleIcons)
|
|
50
|
+
return;
|
|
51
|
+
const icon = this.state.hidden ? this.props.toggleIcons.show : this.props.toggleIcons.hide;
|
|
52
|
+
return MicroBuilder.buildIcon(icon, { scheme: this.props.scheme, className: "noseur-cursor-pointer" }, {
|
|
53
|
+
onClick: this.onToggle
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
renderStrengthIndictor() {
|
|
57
|
+
if (!TypeChecker.isBoolean(this.props.strengthIndicator) || !this.props.strengthIndicator)
|
|
58
|
+
return this.props.strengthIndicator;
|
|
59
|
+
const cachedSelfRef = this.props.progressProps.manageRef;
|
|
60
|
+
const progressProps = {
|
|
61
|
+
...this.props.progressProps,
|
|
62
|
+
manageRef: (r) => {
|
|
63
|
+
this.progressBarComponent = r;
|
|
64
|
+
ObjectHelper.resolveRef(cachedSelfRef, r);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return (React.createElement(ProgressBar, { ...progressProps, noLabel: progressProps.noLabel || true, scheme: progressProps.scheme || this.props.scheme }));
|
|
68
|
+
}
|
|
69
|
+
render() {
|
|
70
|
+
const icon = this.renderToggleIcon();
|
|
71
|
+
const strengthIndicator = this.renderStrengthIndictor();
|
|
72
|
+
const inputType = (this.state.hidden ? "password" : "text");
|
|
73
|
+
const className = Classname.build("noseur-composed-password", this.props.className);
|
|
74
|
+
const onInputComplete = (value) => {
|
|
75
|
+
this.props.onInputComplete?.(value);
|
|
76
|
+
this.props.inputProps?.onInputComplete?.(value);
|
|
77
|
+
};
|
|
78
|
+
return (React.createElement("div", { className: className, style: this.props.style },
|
|
79
|
+
React.createElement(FormControl, { ...this.props.formControlProps, rightContent: icon, scheme: this.props.formControlProps.scheme ?? this.props.scheme, borderless: this.props.formControlProps.borderless ?? this.props.borderless },
|
|
80
|
+
React.createElement(TextInput, { ...this.props.inputProps, type: inputType, id: this.props.id, name: this.props.name, onInputComplete: onInputComplete, noStyle: this.props.inputProps.noStyle || true, scheme: this.props.inputProps.scheme || this.props.scheme, onInput: this.onInput })),
|
|
81
|
+
strengthIndicator));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export const ComposedPassword = ({ ref, ...props }) => (React.createElement(ComposedPasswordComponent, { ...props, forwardRef: ref }));
|
|
85
|
+
// 20% symbol
|
|
86
|
+
// 20% number
|
|
87
|
+
// 20% lowercase
|
|
88
|
+
// 20% uppercase
|
|
89
|
+
// 20% less than 6 char long
|
|
90
|
+
export function composedPasswordDefaultStrengthComputer(value) {
|
|
91
|
+
let progressValue = 100;
|
|
92
|
+
if (value.length < 6)
|
|
93
|
+
progressValue -= 20;
|
|
94
|
+
if (!(/\d/.test(value)))
|
|
95
|
+
progressValue -= 20;
|
|
96
|
+
if (!(/[a-z]/.test(value)))
|
|
97
|
+
progressValue -= 20;
|
|
98
|
+
if (!(/[A-Z]/.test(value)))
|
|
99
|
+
progressValue -= 20;
|
|
100
|
+
if (!(/[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/.test(value)))
|
|
101
|
+
progressValue -= 20;
|
|
102
|
+
return progressValue;
|
|
103
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "../Composed.css";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { BareInputManageRef, InputProps } from "../../form/Input";
|
|
4
|
+
import { DateTimePickerProps } from "./DateTimePicker";
|
|
5
|
+
import { FormControlProps } from "./FormControl";
|
|
6
|
+
export interface DateTimeInputManageRef extends BareInputManageRef<string> {
|
|
7
|
+
}
|
|
8
|
+
export interface DateTimeInputProps extends DateTimePickerProps<HTMLInputElement, DateTimeInputManageRef> {
|
|
9
|
+
fill: boolean;
|
|
10
|
+
leftContent: any;
|
|
11
|
+
rightContent: any;
|
|
12
|
+
separator: string;
|
|
13
|
+
editable: boolean;
|
|
14
|
+
highlight: boolean;
|
|
15
|
+
borderless: boolean;
|
|
16
|
+
placeholder: string;
|
|
17
|
+
value: Date | Date[];
|
|
18
|
+
textInputProps: Partial<InputProps>;
|
|
19
|
+
formControlProps: Partial<FormControlProps>;
|
|
20
|
+
dateTimePickerProps: Partial<DateTimePickerProps>;
|
|
21
|
+
textInputRef: React.ForwardedRef<HTMLInputElement>;
|
|
22
|
+
formatDate: (date: Date, locale?: string, dateFormat?: Intl.DateTimeFormatOptions) => string;
|
|
23
|
+
}
|
|
24
|
+
export declare const DateTimeInput: ({ ref, ...props }: Partial<DateTimeInputProps>) => React.JSX.Element;
|
|
25
|
+
export declare const YearInput: ({ ref, ...props }: Partial<DateTimeInputProps>) => React.JSX.Element;
|
|
26
|
+
export declare const MonthInput: ({ ref, ...props }: Partial<DateTimeInputProps>) => React.JSX.Element;
|
|
27
|
+
export declare const DateInput: ({ ref, ...props }: Partial<DateTimeInputProps>) => React.JSX.Element;
|
|
28
|
+
export declare const TimeInput: ({ ref, ...props }: Partial<DateTimeInputProps>) => React.JSX.Element;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import "../Composed.css";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { TextInput } from "../../form/Input";
|
|
4
|
+
import { DateTimePicker, DateTimePickerDefaultProps, DateTimePickerLayoutElement, DateTimePickerLayout, DateTimePickerMode, DateTimePickerSelectionMode } from "./DateTimePicker";
|
|
5
|
+
import { FormControl } from "./FormControl";
|
|
6
|
+
import { Classname } from "../../utils/Classname";
|
|
7
|
+
import { ObjectHelper } from "../../utils/ObjectHelper";
|
|
8
|
+
import { BoolHelper } from "../../utils/BoolHelper";
|
|
9
|
+
import { ComponentRenderType } from "../../core/ComponentBaseProps";
|
|
10
|
+
class DateTimeInputComponent extends React.Component {
|
|
11
|
+
static defaultProps = {
|
|
12
|
+
...DateTimePickerDefaultProps,
|
|
13
|
+
separator: " - ",
|
|
14
|
+
formControlProps: {},
|
|
15
|
+
dateFormat: undefined,
|
|
16
|
+
};
|
|
17
|
+
state = {
|
|
18
|
+
selectedDates: (this.props.value instanceof Array ? this.props.value : (this.props.value ? [this.props.value] : this.props.selectedDates)),
|
|
19
|
+
};
|
|
20
|
+
compoundElement;
|
|
21
|
+
internalTextInputElement;
|
|
22
|
+
dateTimePickerManageRef;
|
|
23
|
+
constructor(props) {
|
|
24
|
+
super(props);
|
|
25
|
+
this.onIncreaseOrDecrease = this.onIncreaseOrDecrease.bind(this);
|
|
26
|
+
this.toggleDateTimePicker = this.toggleDateTimePicker.bind(this);
|
|
27
|
+
}
|
|
28
|
+
componentDidMount() {
|
|
29
|
+
ObjectHelper.resolveManageRef(this, {
|
|
30
|
+
clear: () => this.dateTimePickerManageRef?.clear(),
|
|
31
|
+
value: () => {
|
|
32
|
+
return this.dateTimePickerManageRef?.formattedValue();
|
|
33
|
+
},
|
|
34
|
+
setValue: (value) => {
|
|
35
|
+
this.setState({ selectedDates: (typeof value === "string" ? [new Date(value)] : value.map((v) => new Date(v))) });
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
componentWillUnmount() {
|
|
40
|
+
ObjectHelper.resolveManageRef(this, null);
|
|
41
|
+
}
|
|
42
|
+
toggleDateTimePicker(e) {
|
|
43
|
+
e.stopPropagation();
|
|
44
|
+
this.dateTimePickerManageRef?.toggle(e);
|
|
45
|
+
}
|
|
46
|
+
formatDateInputValue(date) {
|
|
47
|
+
if (this.props.formatDate)
|
|
48
|
+
return this.props.formatDate(date, this.props.locale, this.props.dateFormat);
|
|
49
|
+
return date.toLocaleString(this.props.locale, this.props.dateFormat);
|
|
50
|
+
}
|
|
51
|
+
getFineDateValue(selectedDates) {
|
|
52
|
+
if (!selectedDates.length)
|
|
53
|
+
return "";
|
|
54
|
+
switch (this.props.selectionMode) {
|
|
55
|
+
case DateTimePickerSelectionMode.SINGLE:
|
|
56
|
+
return this.formatDateInputValue(selectedDates[0]);
|
|
57
|
+
case DateTimePickerSelectionMode.MULTIPLE:
|
|
58
|
+
return selectedDates.map((selectedDate) => this.formatDateInputValue(selectedDate)).join(this.props.separator);
|
|
59
|
+
case DateTimePickerSelectionMode.RANGE:
|
|
60
|
+
return selectedDates.slice(0, 2).map((selectedDate) => this.formatDateInputValue(selectedDate)).join(this.props.separator);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
onIncreaseOrDecrease(activeDate, layoutElement) {
|
|
64
|
+
if (!this.dateTimePickerManageRef || !(BoolHelper.equalsAny(layoutElement, [
|
|
65
|
+
DateTimePickerLayoutElement.HourElement,
|
|
66
|
+
DateTimePickerLayoutElement.MinutesElement,
|
|
67
|
+
DateTimePickerLayoutElement.SecondsElement,
|
|
68
|
+
DateTimePickerLayoutElement.MeridianElement,
|
|
69
|
+
])))
|
|
70
|
+
return;
|
|
71
|
+
this.setState({ selectedDates: [activeDate] });
|
|
72
|
+
}
|
|
73
|
+
renderInput() {
|
|
74
|
+
let defaultValue = this.getFineDateValue(this.state.selectedDates ?? []);
|
|
75
|
+
const inputProps = {
|
|
76
|
+
defaultValue,
|
|
77
|
+
noStyle: true,
|
|
78
|
+
borderless: true,
|
|
79
|
+
id: this.props.id,
|
|
80
|
+
fill: this.props.fill,
|
|
81
|
+
scheme: this.props.scheme,
|
|
82
|
+
onInput: this.props.onInput,
|
|
83
|
+
...this.props.textInputProps,
|
|
84
|
+
disabled: this.props.disabled,
|
|
85
|
+
readOnly: !this.props.editable,
|
|
86
|
+
highlight: this.props.highlight,
|
|
87
|
+
placeholder: this.props.placeholder,
|
|
88
|
+
style: { ...(this.props.style || {}) },
|
|
89
|
+
ref: (el) => {
|
|
90
|
+
if (!el)
|
|
91
|
+
return;
|
|
92
|
+
this.internalTextInputElement = el;
|
|
93
|
+
ObjectHelper.resolveRef(this.props.textInputRef, el);
|
|
94
|
+
},
|
|
95
|
+
className: Classname.build('noseur-date-time-input-inputtext', {
|
|
96
|
+
'noseur-cursor-pointer': !this.props.editable,
|
|
97
|
+
}, (this.props.textInputProps ?? {}).className, this.props.className),
|
|
98
|
+
};
|
|
99
|
+
if (!this.props.editable) {
|
|
100
|
+
inputProps.style.cursor = "pointer";
|
|
101
|
+
}
|
|
102
|
+
if (this.internalTextInputElement && this.internalTextInputElement.value !== defaultValue) {
|
|
103
|
+
this.internalTextInputElement.value = defaultValue;
|
|
104
|
+
}
|
|
105
|
+
return (React.createElement(TextInput, { ...inputProps, onClick: this.toggleDateTimePicker }));
|
|
106
|
+
}
|
|
107
|
+
renderDateTimePicker() {
|
|
108
|
+
const className = Classname.build("noseur-date-time-input-date-time-picker", this.props.dateTimePickerProps);
|
|
109
|
+
const cachedOnClear = this.props.onClear;
|
|
110
|
+
const cachedOnIncrease = this.props.onIncrease;
|
|
111
|
+
const cachedOnDecrease = this.props.onDecrease;
|
|
112
|
+
const cachedOnSelectDate = this.props.onSelectDate;
|
|
113
|
+
const onSelectDate = (options) => {
|
|
114
|
+
if (!options.selectedDate)
|
|
115
|
+
return;
|
|
116
|
+
cachedOnSelectDate?.(options);
|
|
117
|
+
this.setState({ selectedDates: options.selectedDates });
|
|
118
|
+
};
|
|
119
|
+
const onClear = () => {
|
|
120
|
+
cachedOnClear && cachedOnClear();
|
|
121
|
+
this.internalTextInputElement.value = "";
|
|
122
|
+
};
|
|
123
|
+
const onIncrease = (activeDate, layoutElement) => {
|
|
124
|
+
this.onIncreaseOrDecrease(activeDate, layoutElement);
|
|
125
|
+
cachedOnIncrease && cachedOnIncrease(activeDate, layoutElement);
|
|
126
|
+
};
|
|
127
|
+
const onDecrease = (activeDate, layoutElement) => {
|
|
128
|
+
this.onIncreaseOrDecrease(activeDate, layoutElement);
|
|
129
|
+
cachedOnDecrease && cachedOnDecrease(activeDate, layoutElement);
|
|
130
|
+
};
|
|
131
|
+
return (React.createElement(DateTimePicker, { ...this.props, manageRef: (m) => this.dateTimePickerManageRef = m, type: ComponentRenderType.POPOVER, className: className, onClear: onClear, onIncrease: onIncrease, onDecrease: onDecrease, onSelectDate: onSelectDate, selectedDates: this.state.selectedDates, id: this.props.dateTimePickerProps?.id, style: this.props.dateTimePickerProps?.style, popoverProps: { pointingArrowClassName: "" } }));
|
|
132
|
+
}
|
|
133
|
+
render() {
|
|
134
|
+
const input = this.renderInput();
|
|
135
|
+
const dateTimePIcker = this.renderDateTimePicker();
|
|
136
|
+
const formControlProps = (this.props.formControlProps || {});
|
|
137
|
+
const className = Classname.build('noseur-date-time-input', this.props.formControlProps?.className, { "noseur-disabled": this.props.disabled });
|
|
138
|
+
return (React.createElement(React.Fragment, null,
|
|
139
|
+
React.createElement(FormControl, { ...formControlProps, className: className, fill: this.props.fill, contentStyle: { width: "initial", ...(formControlProps.style || {}) }, borderless: this.props.borderless, leftContent: this.props.leftContent || this.props.formControlProps.leftContent, scheme: this.props.scheme || formControlProps.scheme, ref: (r) => this.compoundElement = r, rightContent: this.props.rightContent || this.props.formControlProps.rightContent, onClick: this.toggleDateTimePicker }, input),
|
|
140
|
+
dateTimePIcker));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export const DateTimeInput = ({ ref, ...props }) => (React.createElement(DateTimeInputComponent, { ...props, dateFormat: { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', hour12: !props.hourFormat || props.hourFormat === "12" }, showTime: true, forwardRef: ref }));
|
|
144
|
+
export const YearInput = ({ ref, ...props }) => (React.createElement(DateTimeInputComponent, { forwardRef: ref, dateFormat: { year: 'numeric' }, ...props, showTime: false, mode: DateTimePickerMode.YEAR }));
|
|
145
|
+
export const MonthInput = ({ ref, ...props }) => (React.createElement(DateTimeInputComponent, { forwardRef: ref, dateFormat: { month: 'long' }, ...props, showTime: false, mode: DateTimePickerMode.MONTH }));
|
|
146
|
+
export const DateInput = ({ ref, ...props }) => (React.createElement(DateTimeInputComponent, { forwardRef: ref, dateFormat: { day: '2-digit', month: '2-digit', year: 'numeric' }, ...props, showTime: false }));
|
|
147
|
+
export const TimeInput = ({ ref, ...props }) => {
|
|
148
|
+
const hourFormat12 = !props.hourFormat || props.hourFormat === "12";
|
|
149
|
+
const dateFormat = { hour: '2-digit', minute: '2-digit', hour12: hourFormat12 };
|
|
150
|
+
const timeLayout = props.timeLayout || hourFormat12 ? props.timeLayout : DateTimePickerLayout.TIME_LAYOUT_WITHOUT_MERIDIAN;
|
|
151
|
+
return (React.createElement(DateTimeInputComponent, { ...props, forwardRef: ref, showTime: true, timeOnly: true, timeLayout: timeLayout, dateFormat: dateFormat, layout: DateTimePickerLayoutElement.TimeElement, attrsRelay: {
|
|
152
|
+
popover: { pointingArrowClassName: "", ...(props?.attrsRelay?.popover ?? {}) }
|
|
153
|
+
} }));
|
|
154
|
+
};
|