namirasoft-site-react 1.3.61 → 1.3.62

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 (121) hide show
  1. package/dist/App.js +2 -2
  2. package/dist/App.js.map +1 -1
  3. package/dist/Validator.d.ts +7 -2
  4. package/dist/Validator.js +57 -15
  5. package/dist/Validator.js.map +1 -1
  6. package/dist/components/NSButtonBlue.js +5 -4
  7. package/dist/components/NSButtonBlue.js.map +1 -1
  8. package/dist/components/NSButtonGreen.js +5 -4
  9. package/dist/components/NSButtonGreen.js.map +1 -1
  10. package/dist/components/NSButtonRed.js +5 -4
  11. package/dist/components/NSButtonRed.js.map +1 -1
  12. package/dist/components/NSInput.module.css +29 -0
  13. package/dist/components/NSInputDate.d.ts +3 -1
  14. package/dist/components/NSInputDate.js +14 -4
  15. package/dist/components/NSInputDate.js.map +1 -1
  16. package/dist/components/NSInputDate.module.css +4 -1
  17. package/dist/components/NSInputDuration.d.ts +6 -1
  18. package/dist/components/NSInputDuration.js +15 -6
  19. package/dist/components/NSInputDuration.js.map +1 -1
  20. package/dist/components/NSInputEmail.d.ts +1 -1
  21. package/dist/components/NSInputEmail.js +5 -3
  22. package/dist/components/NSInputEmail.js.map +1 -1
  23. package/dist/components/NSInputFloat.d.ts +4 -4
  24. package/dist/components/NSInputFloat.js +8 -9
  25. package/dist/components/NSInputFloat.js.map +1 -1
  26. package/dist/components/NSInputIP.d.ts +5 -1
  27. package/dist/components/NSInputIP.js +17 -7
  28. package/dist/components/NSInputIP.js.map +1 -1
  29. package/dist/components/NSInputInteger.d.ts +9 -5
  30. package/dist/components/NSInputInteger.js +16 -8
  31. package/dist/components/NSInputInteger.js.map +1 -1
  32. package/dist/components/NSInputPassword.d.ts +5 -1
  33. package/dist/components/NSInputPassword.js +15 -6
  34. package/dist/components/NSInputPassword.js.map +1 -1
  35. package/dist/components/NSInputPhone.d.ts +8 -3
  36. package/dist/components/NSInputPhone.js +18 -12
  37. package/dist/components/NSInputPhone.js.map +1 -1
  38. package/dist/components/NSInputPrice.d.ts +7 -2
  39. package/dist/components/NSInputPrice.js +15 -7
  40. package/dist/components/NSInputPrice.js.map +1 -1
  41. package/dist/components/NSInputSearch.d.ts +6 -1
  42. package/dist/components/NSInputSearch.js +15 -6
  43. package/dist/components/NSInputSearch.js.map +1 -1
  44. package/dist/components/NSInputString.d.ts +5 -1
  45. package/dist/components/NSInputString.js +15 -6
  46. package/dist/components/NSInputString.js.map +1 -1
  47. package/dist/components/NSInputText.d.ts +5 -1
  48. package/dist/components/NSInputText.js +15 -6
  49. package/dist/components/NSInputText.js.map +1 -1
  50. package/dist/components/NSInputTime.d.ts +5 -1
  51. package/dist/components/NSInputTime.js +16 -6
  52. package/dist/components/NSInputTime.js.map +1 -1
  53. package/dist/components/NSSectionBars.d.ts +1 -0
  54. package/dist/components/NSSectionBars.js.map +1 -1
  55. package/dist/components/NSSectionCards.d.ts +1 -2
  56. package/dist/components/NSSectionCards.js +1 -1
  57. package/dist/components/NSSectionCards.js.map +1 -1
  58. package/dist/components/NSSectionTitle.d.ts +1 -2
  59. package/dist/components/NSSectionTitle.js +1 -1
  60. package/dist/components/NSSectionTitle.js.map +1 -1
  61. package/dist/components/NSSelectBox.d.ts +6 -3
  62. package/dist/components/NSSelectBox.js +21 -6
  63. package/dist/components/NSSelectBox.js.map +1 -1
  64. package/dist/components/NSTable.js +1 -1
  65. package/dist/components/NSTable.js.map +1 -1
  66. package/dist/props/ValidationNumberProps.d.ts +1 -2
  67. package/dist/props/ValidationProps.d.ts +1 -0
  68. package/dist/props/ValidationStringProps.d.ts +1 -2
  69. package/package.json +3 -3
  70. package/src/App.tsx +13 -3
  71. package/src/Validator.ts +67 -18
  72. package/src/components/NSButtonBlue.tsx +6 -4
  73. package/src/components/NSButtonGreen.tsx +5 -4
  74. package/src/components/NSButtonRed.tsx +5 -4
  75. package/src/components/NSInput.module.css +29 -0
  76. package/src/components/NSInputDate.module.css +4 -1
  77. package/src/components/NSInputDate.tsx +29 -12
  78. package/src/components/NSInputDuration.tsx +44 -23
  79. package/src/components/NSInputEmail.tsx +10 -5
  80. package/src/components/NSInputFloat.tsx +33 -32
  81. package/src/components/NSInputIP.tsx +44 -24
  82. package/src/components/NSInputInteger.tsx +48 -31
  83. package/src/components/NSInputPassword.tsx +42 -23
  84. package/src/components/NSInputPhone.tsx +45 -29
  85. package/src/components/NSInputPrice.tsx +45 -23
  86. package/src/components/NSInputSearch.tsx +43 -21
  87. package/src/components/NSInputString.tsx +42 -23
  88. package/src/components/NSInputText.tsx +42 -23
  89. package/src/components/NSInputTime.tsx +44 -23
  90. package/src/components/NSSectionBars.tsx +1 -0
  91. package/src/components/NSSectionCards.tsx +3 -3
  92. package/src/components/NSSectionTitle.tsx +3 -3
  93. package/src/components/NSSelectBox.tsx +48 -23
  94. package/src/components/NSTable.tsx +1 -1
  95. package/src/props/ValidationNumberProps.ts +1 -3
  96. package/src/props/ValidationProps.ts +1 -0
  97. package/src/props/ValidationStringProps.ts +1 -3
  98. package/dist/components/NSInputDuration.module.css +0 -26
  99. package/dist/components/NSInputEmail.module.css +0 -38
  100. package/dist/components/NSInputFloat.module.css +0 -26
  101. package/dist/components/NSInputIP.module.css +0 -26
  102. package/dist/components/NSInputInteger.module.css +0 -26
  103. package/dist/components/NSInputPassword.module.css +0 -27
  104. package/dist/components/NSInputPhone.module.css +0 -33
  105. package/dist/components/NSInputPrice.module.css +0 -27
  106. package/dist/components/NSInputSearch.module.css +0 -27
  107. package/dist/components/NSInputString.module.css +0 -27
  108. package/dist/components/NSInputText.module.css +0 -28
  109. package/dist/components/NSInputTime.module.css +0 -27
  110. package/src/components/NSInputDuration.module.css +0 -26
  111. package/src/components/NSInputEmail.module.css +0 -38
  112. package/src/components/NSInputFloat.module.css +0 -26
  113. package/src/components/NSInputIP.module.css +0 -26
  114. package/src/components/NSInputInteger.module.css +0 -26
  115. package/src/components/NSInputPassword.module.css +0 -27
  116. package/src/components/NSInputPhone.module.css +0 -33
  117. package/src/components/NSInputPrice.module.css +0 -27
  118. package/src/components/NSInputSearch.module.css +0 -27
  119. package/src/components/NSInputString.module.css +0 -27
  120. package/src/components/NSInputText.module.css +0 -28
  121. package/src/components/NSInputTime.module.css +0 -27
@@ -1,10 +1,11 @@
1
- .ns_parent_input {
1
+ .ns_input_parent {
2
2
  display: flex;
3
3
  flex-direction: column;
4
4
  width: 326px;
5
5
  color: #fff;
6
6
  position: relative;
7
7
  max-width: 100%;
8
+ padding: 8px;
8
9
  }
9
10
 
10
11
  .ns_input {
@@ -12,12 +13,14 @@
12
13
  padding: 10px 12px;
13
14
  font-size: 16px;
14
15
  font-weight: 400;
16
+ border: 1px solid rgba(47, 0, 236, 0.6);
15
17
  }
16
18
 
17
19
  .ns_input_icon {
18
20
  position: absolute;
19
21
  right: 20px;
20
22
  top: 51%;
23
+ z-index: 1;
21
24
  }
22
25
 
23
26
  .ns_input_title {
@@ -2,10 +2,13 @@
2
2
 
3
3
  import React from "react";
4
4
  import Styles from "./NSInputDate.module.css";
5
+ import IconInputDate from '../assets/images/icon-input-date.svg';
5
6
  import { BaseComponentProps } from "../props/BaseComponentProps";
6
7
  import { NSInputErrorNotifier } from "./NSInputErrorNotifier";
8
+ import { ValidationProps } from "../props/ValidationProps";
9
+ import { Validator } from "../Validator";
7
10
 
8
- export interface NSInputDateProps extends BaseComponentProps
11
+ export interface NSInputDateProps extends BaseComponentProps, ValidationProps
9
12
  {
10
13
  title: string;
11
14
  defaultValue?: string;
@@ -24,15 +27,26 @@ export class NSInputDate extends React.Component<NSInputDateProps, NSInputDateSt
24
27
  constructor(props: NSInputDateProps)
25
28
  {
26
29
  super(props);
27
- this.state = {
28
- value: ""
29
- };
30
+ this.state = { value: props.defaultValue ?? "" };
30
31
  this.setValue = this.setValue.bind(this);
31
32
  this.getValue = this.getValue.bind(this);
32
33
  this.onChanged = this.onChanged.bind(this);
33
34
  }
35
+ getError(): string | null
36
+ {
37
+ return (
38
+ Validator.getError(this.props.title, this.state.value, this.props) &&
39
+ Validator.getErrorDate(this.props.title, this.state.value)
40
+ );
41
+ }
34
42
  getValue(): string
35
43
  {
44
+ let error = this.getError();
45
+ if (error)
46
+ {
47
+ this.setState({ error });
48
+ throw new Error(error);
49
+ }
36
50
  return this.state.value;
37
51
  }
38
52
  setValue(value: string): void
@@ -49,17 +63,22 @@ export class NSInputDate extends React.Component<NSInputDateProps, NSInputDateSt
49
63
  {
50
64
  return (
51
65
  <>
52
- <div className={`${Styles.ns_parent_input} p-2 ${this.props.classList?.join(" ")}`}
53
- style={this.props.style}
54
- >
55
- <span className={Styles.ns_input_title}>{this.props.title}</span>
66
+ <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
67
+ <span className={Styles.ns_input_title}> {this.props.required && <span style={{ color: "red" }} >*</span>} {this.props.title} </span>
68
+ <img
69
+ className={Styles.ns_input_icon}
70
+ src={IconInputDate}
71
+ alt="Date Icon"
72
+ width={24}
73
+ height={24}
74
+ />
56
75
  <input
76
+ id={this.props.id}
57
77
  value={this.state.value}
58
78
  onChange={this.onChanged}
59
79
  type="date"
60
80
  className={Styles.ns_input}
61
81
  placeholder={this.props.placeholder}
62
- id={this.props.id}
63
82
  onClick={() => { }}
64
83
  />
65
84
  </div>
@@ -67,6 +86,4 @@ export class NSInputDate extends React.Component<NSInputDateProps, NSInputDateSt
67
86
  </>
68
87
  );
69
88
  }
70
- }
71
-
72
-
89
+ }
@@ -1,11 +1,16 @@
1
1
  "use client";
2
2
 
3
3
  import React from "react";
4
- import Styles from "./NSInputDuration.module.css";
4
+ import Styles from "./NSInput.module.css";
5
5
  import IconInputDuration from '../assets/images/icon-input-duration.svg';
6
6
  import { BaseComponentProps } from "../props/BaseComponentProps";
7
+ import { ValidationProps } from "../props/ValidationProps";
8
+ import { ValidationNumberProps } from "../props/ValidationNumberProps";
9
+ import { ValidationStringProps } from "../props/ValidationStringProps";
10
+ import { Validator } from "../Validator";
11
+ import { NSInputErrorNotifier } from "./NSInputErrorNotifier";
7
12
 
8
- export interface NSInputDurationProps extends BaseComponentProps
13
+ export interface NSInputDurationProps extends BaseComponentProps, ValidationProps, ValidationStringProps, ValidationNumberProps
9
14
  {
10
15
  title: string;
11
16
  defaultValue?: string;
@@ -16,6 +21,7 @@ export interface NSInputDurationProps extends BaseComponentProps
16
21
  export interface NSInputDurationState
17
22
  {
18
23
  value: string;
24
+ error?: string;
19
25
  }
20
26
 
21
27
  export class NSInputDuration extends React.Component<NSInputDurationProps, NSInputDurationState>
@@ -23,15 +29,26 @@ export class NSInputDuration extends React.Component<NSInputDurationProps, NSInp
23
29
  constructor(props: NSInputDurationProps)
24
30
  {
25
31
  super(props);
26
- this.state = {
27
- value: props.defaultValue ?? "",
28
- };
32
+ this.state = { value: props.defaultValue ?? "" };
29
33
  this.getValue = this.getValue.bind(this);
30
34
  this.setValue = this.setValue.bind(this);
31
35
  this.onChanged = this.onChanged.bind(this);
32
36
  }
37
+ getError(): string | null
38
+ {
39
+ return (
40
+ Validator.getError(this.props.title, this.state.value, this.props) &&
41
+ Validator.getErrorDuration(this.props.title, this.state.value)
42
+ );
43
+ }
33
44
  getValue(): string
34
45
  {
46
+ let error = this.getError();
47
+ if (error)
48
+ {
49
+ this.setState({ error });
50
+ throw new Error(error);
51
+ }
35
52
  return this.state.value;
36
53
  }
37
54
  setValue(value: string): void
@@ -47,24 +64,28 @@ export class NSInputDuration extends React.Component<NSInputDurationProps, NSInp
47
64
  override render()
48
65
  {
49
66
  return (
50
- <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
51
- <span className={Styles.ns_input_title}>{this.props.title}</span>
52
- <img
53
- className={Styles.ns_input_icon}
54
- src={IconInputDuration}
55
- alt="icon"
56
- width={24}
57
- height={24}
58
- />
59
- <input
60
- value={this.state.value}
61
- onChange={this.onChanged}
62
- type="time"
63
- className={Styles.ns_input}
64
- placeholder={this.props.placeholder}
65
- step="2"
66
- />
67
- </div>
67
+ <>
68
+ <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
69
+ <span className={Styles.ns_input_title}> {this.props.required && <span style={{ color: "red" }} >*</span>} {this.props.title} </span>
70
+ <img
71
+ className={Styles.ns_input_icon}
72
+ src={IconInputDuration}
73
+ alt="Duration Icon"
74
+ width={24}
75
+ height={24}
76
+ />
77
+ <input
78
+ id={this.props.id}
79
+ value={this.state.value}
80
+ onChange={this.onChanged}
81
+ type="time"
82
+ className={Styles.ns_input}
83
+ placeholder={this.props.placeholder}
84
+ step="2"
85
+ />
86
+ </div>
87
+ <NSInputErrorNotifier error={this.state.error} />
88
+ </>
68
89
  );
69
90
  }
70
91
  }
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import React from "react";
4
- import Styles from "./NSInputEmail.module.css";
4
+ import Styles from "./NSInput.module.css";
5
5
  import IconInputEmail from '../assets/images/icon-input-email.svg';
6
6
  import { Validator } from "../Validator";
7
7
  import { ValidationProps } from "../props/ValidationProps";
@@ -13,8 +13,8 @@ export interface NSInputEmailProps extends BaseComponentProps, ValidationProps,
13
13
  {
14
14
  title: string;
15
15
  defaultValue?: string;
16
- placeholder?: string;
17
16
  onChanged?: (e: React.ChangeEvent<HTMLInputElement>) => void;
17
+ placeholder?: string;
18
18
  }
19
19
 
20
20
  export interface NSInputEmailState
@@ -35,7 +35,11 @@ export class NSInputEmail extends React.Component<NSInputEmailProps, NSInputEmai
35
35
  }
36
36
  getError(): string | null
37
37
  {
38
- return Validator.getErrorString(this.props.title, this.state.value, this.props) && Validator.getErrorEmail(this.props.title, this.state.value);
38
+ return (
39
+ Validator.getError(this.props.title, this.state.value, this.props) &&
40
+ Validator.getErrorString(this.props.title, this.state.value, this.props) &&
41
+ Validator.getErrorEmail(this.props.title, this.state.value)
42
+ );
39
43
  }
40
44
  getValue(): string
41
45
  {
@@ -62,7 +66,7 @@ export class NSInputEmail extends React.Component<NSInputEmailProps, NSInputEmai
62
66
  return (
63
67
  <>
64
68
  <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
65
- <span className={Styles.ns_input_title}>{this.props.title}</span>
69
+ <span className={Styles.ns_input_title}> {this.props.required && <span style={{ color: "red" }} >*</span>} {this.props.title} </span>
66
70
  <img
67
71
  className={Styles.ns_input_icon}
68
72
  src={IconInputEmail}
@@ -71,10 +75,11 @@ export class NSInputEmail extends React.Component<NSInputEmailProps, NSInputEmai
71
75
  height={24}
72
76
  />
73
77
  <input
78
+ id={this.props.id}
74
79
  value={this.state.value}
75
80
  onChange={this.onChanged}
76
81
  type="email"
77
- className={`${this.state.error ? Styles.ns_input_red : ""} ${Styles.ns_input}`}
82
+ className={Styles.ns_input}
78
83
  placeholder={this.props.placeholder}
79
84
  />
80
85
  </div>
@@ -1,24 +1,25 @@
1
1
  "use client";
2
2
 
3
3
  import React from "react";
4
- import Styles from "./NSInputFloat.module.css";
4
+ import Styles from "./NSInput.module.css";
5
5
  import IconInputFloat from '../assets/images/icon-input-float.svg';
6
6
  import { BaseComponentProps } from "../props/BaseComponentProps";
7
7
  import { ValidationProps } from "../props/ValidationProps";
8
8
  import { ValidationNumberProps } from "../props/ValidationNumberProps";
9
9
  import { Validator } from "../Validator";
10
+ import { NSInputErrorNotifier } from "./NSInputErrorNotifier";
10
11
 
11
12
  export interface NSInputFloatProps extends BaseComponentProps, ValidationProps, ValidationNumberProps
12
13
  {
13
14
  title: string;
14
- defaultValue?: string;
15
+ defaultValue?: number;
15
16
  onChanged?: (e: React.ChangeEvent<HTMLInputElement>) => void;
16
17
  placeholder?: string;
17
18
  }
18
19
 
19
20
  export interface NSInputFloatState
20
21
  {
21
- value: string;
22
+ value?: number;
22
23
  error?: string;
23
24
  }
24
25
 
@@ -27,18 +28,19 @@ export class NSInputFloat extends React.Component<NSInputFloatProps, NSInputFloa
27
28
  constructor(props: NSInputFloatProps)
28
29
  {
29
30
  super(props);
30
- this.state = {
31
- value: props.defaultValue ?? "",
32
- };
31
+ this.state = { value: props.defaultValue };
33
32
  this.setValue = this.setValue.bind(this);
34
33
  this.getValue = this.getValue.bind(this);
35
34
  this.onChanged = this.onChanged.bind(this);
36
35
  }
37
36
  getError(): string | null
38
37
  {
39
- return Validator.getErrorNumber(this.props.title, this.state.value, this.props);
38
+ return (
39
+ Validator.getError(this.props.title, this.state.value, this.props) &&
40
+ Validator.getErrorNumber(this.props.title, this.state.value, this.props)
41
+ );
40
42
  }
41
- getValue(): string
43
+ getValue(): number | undefined
42
44
  {
43
45
  let error = this.getError();
44
46
  if (error)
@@ -48,41 +50,40 @@ export class NSInputFloat extends React.Component<NSInputFloatProps, NSInputFloa
48
50
  }
49
51
  return this.state.value;
50
52
  }
51
- setValue(value: string): void
53
+ setValue(value: number | undefined): void
52
54
  {
53
55
  this.setState({ value });
54
56
  }
55
57
  private onChanged(e: React.ChangeEvent<HTMLInputElement>): void
56
58
  {
57
- this.setValue(e.target.value);
59
+ this.setValue(parseFloat(e.target.value));
58
60
  if (this.props.onChanged)
59
61
  this.props.onChanged(e);
60
62
  }
61
63
  override render()
62
64
  {
63
65
  return (
64
- <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
65
- <span className={Styles.ns_input_title}>
66
- {
67
- this.props.required && <span>*</span>
68
- }
69
- {this.props.title}
70
- </span>
71
- <img
72
- className={Styles.ns_input_icon}
73
- src={IconInputFloat}
74
- alt="icon"
75
- width={24}
76
- height={24}
77
- />
78
- <input
79
- value={this.state.value}
80
- onChange={this.onChanged}
81
- type="number"
82
- className={Styles.ns_input}
83
- placeholder={this.props.placeholder}
84
- />
85
- </div>
66
+ <>
67
+ <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
68
+ <span className={Styles.ns_input_title}> {this.props.required && <span style={{ color: "red" }} >*</span>} {this.props.title} </span>
69
+ <img
70
+ className={Styles.ns_input_icon}
71
+ src={IconInputFloat}
72
+ alt="Flaot Icon"
73
+ width={24}
74
+ height={24}
75
+ />
76
+ <input
77
+ id={this.props.id}
78
+ value={this.state.value}
79
+ onChange={this.onChanged}
80
+ type="number"
81
+ className={Styles.ns_input}
82
+ placeholder={this.props.placeholder}
83
+ />
84
+ </div>
85
+ <NSInputErrorNotifier error={this.state.error} />
86
+ </>
86
87
  );
87
88
  }
88
89
  }
@@ -1,11 +1,15 @@
1
1
  "use client";
2
2
 
3
3
  import React from "react";
4
- import Styles from "./NSInputIP.module.css";
5
- import IconInputId from '../assets/images/icon-input-id.svg';
4
+ import Styles from "./NSInput.module.css";
5
+ import IconInputIP from '../assets/images/icon-input-ip.svg';
6
6
  import { BaseComponentProps } from "../props/BaseComponentProps";
7
+ import { ValidationProps } from "../props/ValidationProps";
8
+ import { ValidationStringProps } from "../props/ValidationStringProps";
9
+ import { Validator } from "../Validator";
10
+ import { NSInputErrorNotifier } from "./NSInputErrorNotifier";
7
11
 
8
- export interface NSInputIPProps extends BaseComponentProps
12
+ export interface NSInputIPProps extends BaseComponentProps, ValidationProps, ValidationStringProps
9
13
  {
10
14
  title: string;
11
15
  defaultValue?: string;
@@ -16,6 +20,7 @@ export interface NSInputIPProps extends BaseComponentProps
16
20
  export interface NSInputIPState
17
21
  {
18
22
  value: string;
23
+ error?: string;
19
24
  }
20
25
 
21
26
  export class NSInputIP extends React.Component<NSInputIPProps, NSInputIPState>
@@ -23,15 +28,27 @@ export class NSInputIP extends React.Component<NSInputIPProps, NSInputIPState>
23
28
  constructor(props: NSInputIPProps)
24
29
  {
25
30
  super(props);
26
- this.state = {
27
- value: props.defaultValue ?? "",
28
- };
31
+ this.state = { value: props.defaultValue ?? "" };
29
32
  this.getValue = this.getValue.bind(this);
30
33
  this.setValue = this.setValue.bind(this);
31
34
  this.onChanged = this.onChanged.bind(this);
32
35
  }
36
+ getError(): string | null
37
+ {
38
+ return (
39
+ Validator.getError(this.props.title, this.state.value, this.props) &&
40
+ Validator.getErrorString(this.props.title, this.state.value, this.props) &&
41
+ Validator.getErrorIP(this.props.title, this.state.value)
42
+ );
43
+ }
33
44
  getValue(): string
34
45
  {
46
+ let error = this.getError();
47
+ if (error)
48
+ {
49
+ this.setState({ error });
50
+ throw new Error(error);
51
+ }
35
52
  return this.state.value;
36
53
  }
37
54
  setValue(value: string): void
@@ -47,24 +64,27 @@ export class NSInputIP extends React.Component<NSInputIPProps, NSInputIPState>
47
64
  override render()
48
65
  {
49
66
  return (
50
- <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
51
- <span className={Styles.ns_input_title}>{this.props.title}</span>
52
- <img
53
- className={Styles.ns_input_icon}
54
- src={IconInputId}
55
- alt="icon"
56
- width={24}
57
- height={24}
58
- />
59
- <input
60
- value={this.state.value}
61
- onChange={this.onChanged}
62
- type="number"
63
- className={Styles.ns_input}
64
- placeholder={this.props.placeholder}
65
- />
66
-
67
- </div>
67
+ <>
68
+ <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
69
+ <span className={Styles.ns_input_title}> {this.props.required && <span style={{ color: "red" }} >*</span>} {this.props.title} </span>
70
+ <img
71
+ className={Styles.ns_input_icon}
72
+ src={IconInputIP}
73
+ alt="IP Icon"
74
+ width={24}
75
+ height={24}
76
+ />
77
+ <input
78
+ id={this.props.id}
79
+ value={this.state.value}
80
+ onChange={this.onChanged}
81
+ type="text"
82
+ className={Styles.ns_input}
83
+ placeholder={this.props.placeholder}
84
+ />
85
+ </div>
86
+ <NSInputErrorNotifier error={this.state.error} />
87
+ </>
68
88
  );
69
89
  }
70
90
  }
@@ -1,21 +1,26 @@
1
1
  "use client";
2
2
 
3
3
  import React from "react";
4
- import Styles from "./NSInputInteger.module.css";
4
+ import Styles from "./NSInput.module.css";
5
5
  import IconInputInteger from '../assets/images/icon-input-integer.svg';
6
6
  import { BaseComponentProps } from "../props/BaseComponentProps";
7
+ import { ValidationNumberProps } from "../props/ValidationNumberProps";
8
+ import { ValidationProps } from "../props/ValidationProps";
9
+ import { Validator } from "../Validator";
10
+ import { NSInputErrorNotifier } from "./NSInputErrorNotifier";
7
11
 
8
- export interface NSInputIntegerProps extends BaseComponentProps
12
+ export interface NSInputIntegerProps extends BaseComponentProps, ValidationProps, ValidationNumberProps
9
13
  {
10
14
  title: string;
11
- defaultValue?: string;
15
+ defaultValue?: number;
12
16
  onChanged?: (e: React.ChangeEvent<HTMLInputElement>) => void;
13
17
  placeholder?: string;
14
18
  }
15
19
 
16
20
  export interface NSInputIntegerState
17
21
  {
18
- value: string;
22
+ value?: number;
23
+ error?: string;
19
24
  }
20
25
 
21
26
  export class NSInputInteger extends React.Component<NSInputIntegerProps, NSInputIntegerState>
@@ -23,50 +28,62 @@ export class NSInputInteger extends React.Component<NSInputIntegerProps, NSInput
23
28
  constructor(props: NSInputIntegerProps)
24
29
  {
25
30
  super(props);
26
- this.state = {
27
- value: props.defaultValue ?? "",
28
- };
31
+ this.state = { value: props.defaultValue };
29
32
  this.getValue = this.getValue.bind(this);
30
33
  this.setValue = this.setValue.bind(this);
31
34
  this.onChanged = this.onChanged.bind(this);
32
35
  }
33
- getValue(): string
36
+ getError(): string | null
34
37
  {
38
+ return (
39
+ Validator.getError(this.props.title, this.state.value, this.props) &&
40
+ Validator.getErrorNumber(this.props.title, this.state.value, this.props)
41
+ );
42
+ }
43
+ getValue(): number | undefined
44
+ {
45
+ let error = this.getError();
46
+ if (error)
47
+ {
48
+ this.setState({ error });
49
+ throw new Error(error);
50
+ }
35
51
  return this.state.value;
36
52
  }
37
- setValue(value: string): void
53
+ setValue(value: number | undefined): void
38
54
  {
39
55
  this.setState({ value });
40
56
  }
41
57
  private onChanged(e: React.ChangeEvent<HTMLInputElement>): void
42
58
  {
43
- this.setValue(e.target.value);
59
+ this.setValue(parseInt(e.target.value));
44
60
  if (this.props.onChanged)
45
61
  this.props.onChanged(e);
46
62
  }
47
63
  override render()
48
64
  {
49
65
  return (
50
- <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
51
- <span className={Styles.ns_input_title}>{this.props.title}</span>
52
- <img
53
- className={Styles.ns_input_icon}
54
- src={IconInputInteger}
55
- alt="icon"
56
- width={24}
57
- height={24}
58
- />
59
- <input
60
- value={this.state.value}
61
- onChange={this.onChanged}
62
- type="number"
63
- className={Styles.ns_input}
64
- placeholder={this.props.placeholder}
65
- />
66
-
67
- </div>
66
+ <>
67
+ <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
68
+ <span className={Styles.ns_input_title}> {this.props.required && <span style={{ color: "red" }} >*</span>} {this.props.title} </span>
69
+ <img
70
+ className={Styles.ns_input_icon}
71
+ src={IconInputInteger}
72
+ alt="Integer Icon"
73
+ width={24}
74
+ height={24}
75
+ />
76
+ <input
77
+ id={this.props.id}
78
+ value={this.state.value}
79
+ onChange={this.onChanged}
80
+ type="number"
81
+ className={Styles.ns_input}
82
+ placeholder={this.props.placeholder}
83
+ />
84
+ </div>
85
+ <NSInputErrorNotifier error={this.state.error} />
86
+ </>
68
87
  );
69
88
  }
70
- }
71
-
72
-
89
+ }