namirasoft-site-react 1.3.47 → 1.3.48

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 (38) hide show
  1. package/dist/Validator.d.ts +9 -0
  2. package/dist/Validator.js +52 -0
  3. package/dist/Validator.js.map +1 -0
  4. package/dist/components/NSInputEmail.d.ts +6 -2
  5. package/dist/components/NSInputEmail.js +12 -13
  6. package/dist/components/NSInputEmail.js.map +1 -1
  7. package/dist/components/NSInputFloat.d.ts +6 -1
  8. package/dist/components/NSInputFloat.js +11 -1
  9. package/dist/components/NSInputFloat.js.map +1 -1
  10. package/dist/components/NSSpace.d.ts +0 -4
  11. package/dist/components/NSSpace.js +1 -14
  12. package/dist/components/NSSpace.js.map +1 -1
  13. package/dist/props/BaseComponentProps.d.ts +5 -0
  14. package/dist/props/BaseComponentProps.js +2 -0
  15. package/dist/props/BaseComponentProps.js.map +1 -0
  16. package/dist/props/ValidationNumberProps.d.ts +5 -0
  17. package/dist/props/ValidationNumberProps.js +2 -0
  18. package/dist/props/ValidationNumberProps.js.map +1 -0
  19. package/dist/props/ValidationProps.d.ts +5 -0
  20. package/dist/props/ValidationProps.js +2 -0
  21. package/dist/props/ValidationProps.js.map +1 -0
  22. package/dist/props/ValidationRegexProps.d.ts +4 -0
  23. package/dist/props/ValidationRegexProps.js +2 -0
  24. package/dist/props/ValidationRegexProps.js.map +1 -0
  25. package/dist/props/ValidationStringProps.d.ts +5 -0
  26. package/dist/props/ValidationStringProps.js +2 -0
  27. package/dist/props/ValidationStringProps.js.map +1 -0
  28. package/package.json +2 -2
  29. package/src/App.tsx +1 -1
  30. package/src/Validator.ts +62 -0
  31. package/src/components/NSInputEmail.tsx +34 -30
  32. package/src/components/NSInputFloat.tsx +29 -9
  33. package/src/components/NSSpace.tsx +1 -19
  34. package/src/props/BaseComponentProps.ts +7 -0
  35. package/src/props/ValidationNumberProps.ts +7 -0
  36. package/src/props/ValidationProps.ts +7 -0
  37. package/src/props/ValidationRegexProps.ts +5 -0
  38. package/src/props/ValidationStringProps.ts +7 -0
@@ -0,0 +1,9 @@
1
+ import { ValidationNumberProps } from "./props/ValidationNumberProps";
2
+ import { ValidationProps } from "./props/ValidationProps";
3
+ import { ValidationStringProps } from "./props/ValidationStringProps";
4
+ export declare class Validator {
5
+ static getError(name: string, value: string | null | undefined, validator: ValidationProps): string | null;
6
+ static getErrorString(name: string, value: string | null | undefined, validator: ValidationStringProps): string | null;
7
+ static getErrorNumber(name: string, value: string | null | undefined, validator: ValidationNumberProps): string | null;
8
+ static getErrorEmail(name: string, value: string | null | undefined): string | null;
9
+ }
@@ -0,0 +1,52 @@
1
+ export class Validator {
2
+ static getError(name, value, validator) {
3
+ if (validator.required)
4
+ if (!value)
5
+ return `${name} is required.`;
6
+ if (value)
7
+ if (validator.regex)
8
+ if (!validator.regex.regex.test(value))
9
+ return `${name} is not a valid ${validator.regex.name}.`;
10
+ return null;
11
+ }
12
+ static getErrorString(name, value, validator) {
13
+ let error = this.getError(name, value, validator);
14
+ if (error)
15
+ return error;
16
+ if (value) {
17
+ if (validator.max_length != null)
18
+ if (validator.max_length < value.length)
19
+ return `Max length of ${name} should be ${validator.max_length} characters.`;
20
+ if (validator.min_length != null)
21
+ if (validator.min_length > value.length)
22
+ return `Minlength of ${name} should be ${validator.min_length} characters.`;
23
+ }
24
+ return null;
25
+ }
26
+ static getErrorNumber(name, value, validator) {
27
+ let error = this.getError(name, value, validator);
28
+ if (error)
29
+ return error;
30
+ if (value) {
31
+ let numValue = parseFloat(value);
32
+ if (isNaN(numValue))
33
+ return `${name} is not a number.`;
34
+ if (validator.max != null)
35
+ if (validator.max < numValue)
36
+ return `Max value of ${name} should be ${validator.max} characters.`;
37
+ if (validator.min != null)
38
+ if (validator.min > numValue)
39
+ return `Min value of ${name} should be ${validator.min} characters.`;
40
+ }
41
+ return null;
42
+ }
43
+ static getErrorEmail(name, value) {
44
+ return Validator.getError(name, value, {
45
+ required: true, regex: {
46
+ name: "Email",
47
+ regex: /^[\w]+@([\w]+\.)+\w{2,}$/gm
48
+ }
49
+ });
50
+ }
51
+ }
52
+ //# sourceMappingURL=Validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Validator.js","sourceRoot":"","sources":["../src/Validator.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,SAAS;IAElB,MAAM,CAAC,QAAQ,CAAC,IAAY,EAAE,KAAgC,EAAE,SAA0B;QAEtF,IAAI,SAAS,CAAC,QAAQ;YAClB,IAAI,CAAC,KAAK;gBACN,OAAO,GAAG,IAAI,eAAe,CAAC;QACtC,IAAI,KAAK;YACL,IAAI,SAAS,CAAC,KAAK;gBACf,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;oBAClC,OAAO,GAAG,IAAI,mBAAmB,SAAS,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC;QACrE,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,CAAC,cAAc,CAAC,IAAY,EAAE,KAAgC,EAAE,SAAgC;QAElG,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QAClD,IAAI,KAAK;YACL,OAAO,KAAK,CAAC;QACjB,IAAI,KAAK,EACT,CAAC;YACG,IAAI,SAAS,CAAC,UAAU,IAAI,IAAI;gBAC5B,IAAI,SAAS,CAAC,UAAU,GAAG,KAAK,CAAC,MAAM;oBACnC,OAAO,iBAAiB,IAAI,cAAc,SAAS,CAAC,UAAU,cAAc,CAAC;YACrF,IAAI,SAAS,CAAC,UAAU,IAAI,IAAI;gBAC5B,IAAI,SAAS,CAAC,UAAU,GAAG,KAAK,CAAC,MAAM;oBACnC,OAAO,gBAAgB,IAAI,cAAc,SAAS,CAAC,UAAU,cAAc,CAAC;QACxF,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,CAAC,cAAc,CAAC,IAAY,EAAE,KAAgC,EAAE,SAAgC;QAElG,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QAClD,IAAI,KAAK;YACL,OAAO,KAAK,CAAC;QACjB,IAAI,KAAK,EACT,CAAC;YACG,IAAI,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;YACjC,IAAI,KAAK,CAAC,QAAQ,CAAC;gBACf,OAAO,GAAG,IAAI,mBAAmB,CAAC;YACtC,IAAI,SAAS,CAAC,GAAG,IAAI,IAAI;gBACrB,IAAI,SAAS,CAAC,GAAG,GAAG,QAAQ;oBACxB,OAAO,gBAAgB,IAAI,cAAc,SAAS,CAAC,GAAG,cAAc,CAAC;YAC7E,IAAI,SAAS,CAAC,GAAG,IAAI,IAAI;gBACrB,IAAI,SAAS,CAAC,GAAG,GAAG,QAAQ;oBACxB,OAAO,gBAAgB,IAAI,cAAc,SAAS,CAAC,GAAG,cAAc,CAAC;QACjF,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,CAAC,aAAa,CAAC,IAAY,EAAE,KAAgC;QAE/D,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE;YACnC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE;gBACnB,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,4BAA4B;aACtC;SACJ,CAAC,CAAA;IACN,CAAC;CACJ"}
@@ -1,15 +1,19 @@
1
1
  import React from "react";
2
- export interface NSInputEmailProps {
2
+ import { ValidationProps } from "../props/ValidationProps";
3
+ import { ValidationStringProps } from "../props/ValidationStringProps";
4
+ export interface NSInputEmailProps extends ValidationProps, ValidationStringProps {
3
5
  title: string;
4
6
  defaultValue?: string;
7
+ placeholder?: string;
5
8
  onChanged?: (e: React.ChangeEvent<HTMLInputElement>) => void;
6
9
  }
7
10
  export interface NSInputEmailState {
8
11
  value: string;
9
- error: boolean;
12
+ error?: string;
10
13
  }
11
14
  export declare class NSInputEmail extends React.Component<NSInputEmailProps, NSInputEmailState> {
12
15
  constructor(props: NSInputEmailProps);
16
+ getError(): string | null;
13
17
  getValue(): string;
14
18
  setValue(value: string): void;
15
19
  private onChanged;
@@ -4,30 +4,29 @@ import React from "react";
4
4
  import Styles from "./NSInputEmail.module.css";
5
5
  import IconInputEmail from '../assets/images/icon-input-email.svg';
6
6
  import Danger from '../assets/images/danger.svg';
7
+ import { Validator } from "../Validator";
7
8
  export class NSInputEmail extends React.Component {
8
9
  constructor(props) {
9
10
  var _a;
10
11
  super(props);
11
- this.state = {
12
- value: (_a = props.defaultValue) !== null && _a !== void 0 ? _a : "",
13
- error: false,
14
- };
12
+ this.state = { value: (_a = props.defaultValue) !== null && _a !== void 0 ? _a : "" };
15
13
  this.setValue = this.setValue.bind(this);
16
14
  this.getValue = this.getValue.bind(this);
17
15
  this.onChanged = this.onChanged.bind(this);
18
16
  }
17
+ getError() {
18
+ return Validator.getErrorString(this.props.title, this.state.value, this.props) && Validator.getErrorEmail(this.props.title, this.state.value);
19
+ }
19
20
  getValue() {
21
+ let error = this.getError();
22
+ if (error) {
23
+ this.setState({ error });
24
+ throw new Error(error);
25
+ }
20
26
  return this.state.value;
21
27
  }
22
28
  setValue(value) {
23
- let email = /^(([^<>()[]\\.,;:\s@"]+(\.[^<>()[]\\.,;:\s@"]+)*)|(".+"))@(([[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
24
- debugger;
25
- if (!email.test(value)) {
26
- this.setState({ error: true, value });
27
- }
28
- else {
29
- this.setState({ error: false, value });
30
- }
29
+ this.setState({ value });
31
30
  }
32
31
  onChanged(e) {
33
32
  this.setValue(e.target.value);
@@ -35,7 +34,7 @@ export class NSInputEmail extends React.Component {
35
34
  this.props.onChanged(e);
36
35
  }
37
36
  render() {
38
- return (_jsxs(_Fragment, { children: [_jsxs("div", { className: `${Styles.ns_input_parent} p-2`, children: [_jsx("span", { className: Styles.ns_input_title, children: this.props.title }), _jsx("img", { className: Styles.ns_input_icon, src: IconInputEmail, alt: "icon", width: 24, height: 24 }), _jsx("input", { value: this.state.value, onChange: this.onChanged, type: "email", className: `${this.state.error === true ? Styles.ns_input_red : ""} ${Styles.ns_input}`, placeholder: "Sample@gmail.com" })] }), this.state.error === true ? (_jsx(_Fragment, { children: _jsxs("div", { className: "d-flex justify-content-start align-items-center gap-2 ms-2 ", children: [_jsx("img", { className: "", src: Danger, alt: "icon", width: 13, height: 13 }), _jsx("span", { className: Styles.ns_input_error, children: "Enter a valid email." })] }) })) : null] }));
37
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: `${Styles.ns_input_parent} p-2`, children: [_jsx("span", { className: Styles.ns_input_title, children: this.props.title }), _jsx("img", { className: Styles.ns_input_icon, src: IconInputEmail, alt: "Email Icon", width: 24, height: 24 }), _jsx("input", { value: this.state.value, onChange: this.onChanged, type: "email", className: `${this.state.error ? Styles.ns_input_red : ""} ${Styles.ns_input}`, placeholder: this.props.placeholder })] }), this.state.error && (_jsx(_Fragment, { children: _jsxs("div", { className: "d-flex justify-content-start align-items-center gap-2 ms-2", children: [_jsx("img", { className: "", src: Danger, alt: "Error Icon", width: 13, height: 13 }), _jsx("span", { className: Styles.ns_input_error, children: this.state.error })] }) }))] }));
39
38
  }
40
39
  }
41
40
  //# sourceMappingURL=NSInputEmail.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NSInputEmail.js","sourceRoot":"","sources":["../../src/components/NSInputEmail.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,cAAc,MAAM,uCAAuC,CAAC;AACnE,OAAO,MAAM,MAAM,6BAA6B,CAAC;AAejD,MAAM,OAAO,YAAa,SAAQ,KAAK,CAAC,SAA+C;IACnF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C,CAAC;IAChC,CAAC;IACQ,MAAM;QAEX,OAAO,CACH,8BACI,eAAK,SAAS,EAAE,GAAG,MAAM,CAAC,eAAe,MAAM,aAC3C,eAAM,SAAS,EAAE,MAAM,CAAC,cAAc,YAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAQ,EACjE,cACI,SAAS,EAAE,MAAM,CAAC,aAAa,EAC/B,GAAG,EAAE,cAAc,EACnB,GAAG,EAAC,YAAY,EAChB,KAAK,EAAE,EAAE,EACT,MAAM,EAAE,EAAE,GACZ,EACF,gBACI,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,QAAQ,EAAE,IAAI,CAAC,SAAS,EACxB,IAAI,EAAC,OAAO,EACZ,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,MAAM,CAAC,QAAQ,EAAE,EAC9E,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,GACrC,IACA,EAGF,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,CAChB,4BACI,eAAK,SAAS,EAAC,4DAA4D,aACvE,cACI,SAAS,EAAE,EAAE,EACb,GAAG,EAAE,MAAM,EACX,GAAG,EAAC,YAAY,EAChB,KAAK,EAAE,EAAE,EACT,MAAM,EAAE,EAAE,GACZ,EACF,eAAM,SAAS,EAAE,MAAM,CAAC,cAAc,YAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAQ,IAC/D,GACP,CAAC,IAEb,CACN,CAAC;IACN,CAAC;CACJ"}
@@ -1,14 +1,19 @@
1
1
  import React from "react";
2
- export interface NSInputFloatProps {
2
+ import { BaseComponentProps } from "../props/BaseComponentProps";
3
+ import { ValidationProps } from "../props/ValidationProps";
4
+ import { ValidationNumberProps } from "../props/ValidationNumberProps";
5
+ export interface NSInputFloatProps extends BaseComponentProps, ValidationProps, ValidationNumberProps {
3
6
  title: string;
4
7
  defaultValue?: string;
5
8
  onChanged?: (e: React.ChangeEvent<HTMLInputElement>) => void;
6
9
  }
7
10
  export interface NSInputFloatState {
8
11
  value: string;
12
+ error?: string;
9
13
  }
10
14
  export declare class NSInputFloat extends React.Component<NSInputFloatProps, NSInputFloatState> {
11
15
  constructor(props: NSInputFloatProps);
16
+ getError(): string | null;
12
17
  getValue(): string;
13
18
  setValue(value: string): void;
14
19
  private onChanged;
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import React from "react";
4
4
  import Styles from "./NSInputFloat.module.css";
5
5
  import IconInputFloat from '../assets/images/icon-input-float.svg';
6
+ import { Validator } from "../Validator";
6
7
  export class NSInputFloat extends React.Component {
7
8
  constructor(props) {
8
9
  var _a;
@@ -14,7 +15,15 @@ export class NSInputFloat extends React.Component {
14
15
  this.getValue = this.getValue.bind(this);
15
16
  this.onChanged = this.onChanged.bind(this);
16
17
  }
18
+ getError() {
19
+ return Validator.getErrorNumber(this.props.title, this.state.value, this.props);
20
+ }
17
21
  getValue() {
22
+ let error = this.getError();
23
+ if (error) {
24
+ this.setState({ error });
25
+ throw new Error(error);
26
+ }
18
27
  return this.state.value;
19
28
  }
20
29
  setValue(value) {
@@ -26,7 +35,8 @@ export class NSInputFloat extends React.Component {
26
35
  this.props.onChanged(e);
27
36
  }
28
37
  render() {
29
- return (_jsxs("div", { className: `${Styles.ns_input_parent} p-2`, children: [_jsx("span", { className: Styles.ns_input_title, children: this.props.title }), _jsx("img", { className: Styles.ns_input_icon, src: IconInputFloat, alt: "icon", width: 24, height: 24 }), _jsx("input", { value: this.state.value, onChange: this.onChanged, type: "number", className: Styles.ns_input, placeholder: "1.2" })] }));
38
+ var _a;
39
+ return (_jsxs("div", { className: `${Styles.ns_input_parent} p-2 ${(_a = this.props.classList) === null || _a === void 0 ? void 0 : _a.join(" ")}`, style: this.props.style, children: [_jsxs("span", { className: Styles.ns_input_title, children: [this.props.required && _jsx("span", { children: "*" }), this.props.title] }), _jsx("img", { className: Styles.ns_input_icon, src: IconInputFloat, alt: "icon", width: 24, height: 24 }), _jsx("input", { value: this.state.value, onChange: this.onChanged, type: "number", className: Styles.ns_input, placeholder: "1.2" })] }));
30
40
  }
31
41
  }
32
42
  //# sourceMappingURL=NSInputFloat.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NSInputFloat.js","sourceRoot":"","sources":["../../src/components/NSInputFloat.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,cAAc,MAAM,uCAAuC,CAAC;AAcnE,MAAM,OAAO,YAAa,SAAQ,KAAK,CAAC,SAA+C;IACnF,YAAY,KAAwB;;QAEhC,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,GAAG;YACT,KAAK,EAAE,MAAA,KAAK,CAAC,YAAY,mCAAI,EAAE;SAClC,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IACD,QAAQ;QAEJ,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;IAC/B,CAAC;IACE,QAAQ,CAAC,KAAa;QAElB,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAChC,CAAC;IAEU,SAAS,CAAC,CAAsC;QAEpD,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS;YACpB,IAAI,CAAC,KAAK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AAc,EACnB,GAAG,EAAC,MAAM,EACV,KAAK,EAAE,EAAE,EACT,MAAM,EAAE,EAAE,GACZ,EACF,gBACI,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,QAAQ,EAAE,IAAI,CAAC,SAAS,EACxB,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,MAAM,CAAC,QAAQ,EAC1B,WAAW,EAAC,KAAK,GACnB,IACA,CACT,CAAC;IACN,CAAC;CACJ"}
@@ -15,11 +15,7 @@ export declare enum NSSpaceSizeType {
15
15
  XXXLARGE = "128px"
16
16
  }
17
17
  export interface NSSpaceState {
18
- size: NSSpaceSizeType;
19
18
  }
20
19
  export declare class NSSpace extends React.Component<NSSpaceProps, NSSpaceState> {
21
- constructor(props: NSSpaceProps);
22
- setValue(size: NSSpaceSizeType): void;
23
- getValue(): NSSpaceSizeType;
24
20
  render(): import("react/jsx-runtime").JSX.Element;
25
21
  }
@@ -1,4 +1,3 @@
1
- "use client";
2
1
  import { jsx as _jsx } from "react/jsx-runtime";
3
2
  import React from "react";
4
3
  export var NSSpaceSizeType;
@@ -15,20 +14,8 @@ export var NSSpaceSizeType;
15
14
  NSSpaceSizeType["XXXLARGE"] = "128px";
16
15
  })(NSSpaceSizeType || (NSSpaceSizeType = {}));
17
16
  export class NSSpace extends React.Component {
18
- constructor(props) {
19
- super(props);
20
- this.state = { size: props.size };
21
- this.setValue = this.setValue.bind(this);
22
- this.getValue = this.getValue.bind(this);
23
- }
24
- setValue(size) {
25
- this.setState({ size });
26
- }
27
- getValue() {
28
- return this.state.size;
29
- }
30
17
  render() {
31
- return (_jsx("hr", { style: { width: "100%", height: this.state.size, margin: "0px", padding: "0px", background: "transparent", color: "transparent", border: 0 } }));
18
+ return (_jsx("hr", { style: { width: "100%", height: this.props.size, margin: "0px", padding: "0px", background: "transparent", color: "transparent", border: 0 } }));
32
19
  }
33
20
  }
34
21
  //# sourceMappingURL=NSSpace.js.map
@@ -1 +1 @@
1
- {"version":3,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1
+ {"version":3,"file":"NSSpace.js","sourceRoot":"","sources":["../../src/components/NSSpace.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,MAAM,CAAN,IAAY,eAYX;AAZD,WAAY,eAAe;IAEvB,+BAAY,CAAA;IACZ,gCAAa,CAAA;IACb,gCAAa,CAAA;IACb,iCAAc,CAAA;IACd,kCAAe,CAAA;IACf,kCAAe,CAAA;IACf,iCAAc,CAAA;IACd,kCAAe,CAAA;IACf,mCAAgB,CAAA;IAChB,qCAAkB,CAAA;AACtB,CAAC,EAZW,eAAe,KAAf,eAAe,QAY1B;AAMD,MAAM,OAAO,OAAQ,SAAQ,KAAK,CAAC,SAAqC;IAE3D,MAAM;QAEX,OAAO,CACH,aAAI,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,EAAE,GAAI,CACvJ,CAAC;IACN,CAAC;CACJ"}
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ export interface BaseComponentProps {
3
+ classList?: string[];
4
+ style?: React.CSSProperties;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=BaseComponentProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseComponentProps.js","sourceRoot":"","sources":["../../src/props/BaseComponentProps.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { ValidationProps } from "./ValidationProps";
2
+ export interface ValidationNumberProps extends ValidationProps {
3
+ min?: number;
4
+ max?: number;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ValidationNumberProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationNumberProps.js","sourceRoot":"","sources":["../../src/props/ValidationNumberProps.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { ValidationRegexProps } from "./ValidationRegexProps";
2
+ export interface ValidationProps {
3
+ required: boolean;
4
+ regex?: ValidationRegexProps;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ValidationProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationProps.js","sourceRoot":"","sources":["../../src/props/ValidationProps.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export interface ValidationRegexProps {
2
+ name: string;
3
+ regex: RegExp;
4
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ValidationRegexProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationRegexProps.js","sourceRoot":"","sources":["../../src/props/ValidationRegexProps.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { ValidationProps } from "./ValidationProps";
2
+ export interface ValidationStringProps extends ValidationProps {
3
+ min_length?: number;
4
+ max_length?: number;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ValidationStringProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationStringProps.js","sourceRoot":"","sources":["../../src/props/ValidationStringProps.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "framework": "npm",
9
9
  "application": "package",
10
10
  "private": false,
11
- "version": "1.3.47",
11
+ "version": "1.3.48",
12
12
  "author": "Amir Abolhasani, Alireza Esmaeeli, Hooman Shashaeh",
13
13
  "license": "MIT",
14
14
  "main": "./dist/main.js",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@types/node": "^20.12.7",
25
- "@types/react": "^18.2.78",
25
+ "@types/react": "^18.2.79",
26
26
  "@types/react-dom": "^18.2.25",
27
27
  "antd": "^5.16.2",
28
28
  "bootstrap": "^5.3.3",
package/src/App.tsx CHANGED
@@ -47,7 +47,7 @@ export function App()
47
47
  account={false}
48
48
  background={{ color: "transparent !important" }}
49
49
  />
50
-
50
+
51
51
  <div className="container">
52
52
  <NSTable<Row> columns={columns} rows={rows} getRowKey={row => row.id.toString()} />
53
53
  </div>
@@ -0,0 +1,62 @@
1
+ import { ValidationNumberProps } from "./props/ValidationNumberProps";
2
+ import { ValidationProps } from "./props/ValidationProps";
3
+ import { ValidationStringProps } from "./props/ValidationStringProps";
4
+
5
+ export class Validator
6
+ {
7
+ static getError(name: string, value: string | null | undefined, validator: ValidationProps): string | null
8
+ {
9
+ if (validator.required)
10
+ if (!value)
11
+ return `${name} is required.`;
12
+ if (value)
13
+ if (validator.regex)
14
+ if (!validator.regex.regex.test(value))
15
+ return `${name} is not a valid ${validator.regex.name}.`;
16
+ return null;
17
+ }
18
+ static getErrorString(name: string, value: string | null | undefined, validator: ValidationStringProps): string | null
19
+ {
20
+ let error = this.getError(name, value, validator);
21
+ if (error)
22
+ return error;
23
+ if (value)
24
+ {
25
+ if (validator.max_length != null)
26
+ if (validator.max_length < value.length)
27
+ return `Max length of ${name} should be ${validator.max_length} characters.`;
28
+ if (validator.min_length != null)
29
+ if (validator.min_length > value.length)
30
+ return `Minlength of ${name} should be ${validator.min_length} characters.`;
31
+ }
32
+ return null;
33
+ }
34
+ static getErrorNumber(name: string, value: string | null | undefined, validator: ValidationNumberProps): string | null
35
+ {
36
+ let error = this.getError(name, value, validator);
37
+ if (error)
38
+ return error;
39
+ if (value)
40
+ {
41
+ let numValue = parseFloat(value);
42
+ if (isNaN(numValue))
43
+ return `${name} is not a number.`;
44
+ if (validator.max != null)
45
+ if (validator.max < numValue)
46
+ return `Max value of ${name} should be ${validator.max} characters.`;
47
+ if (validator.min != null)
48
+ if (validator.min > numValue)
49
+ return `Min value of ${name} should be ${validator.min} characters.`;
50
+ }
51
+ return null;
52
+ }
53
+ static getErrorEmail(name: string, value: string | null | undefined): string | null
54
+ {
55
+ return Validator.getError(name, value, {
56
+ required: true, regex: {
57
+ name: "Email",
58
+ regex: /^[\w]+@([\w]+\.)+\w{2,}$/gm
59
+ }
60
+ })
61
+ }
62
+ }
@@ -4,49 +4,52 @@ import React from "react";
4
4
  import Styles from "./NSInputEmail.module.css";
5
5
  import IconInputEmail from '../assets/images/icon-input-email.svg';
6
6
  import Danger from '../assets/images/danger.svg';
7
+ import { Validator } from "../Validator";
8
+ import { ValidationProps } from "../props/ValidationProps";
9
+ import { ValidationStringProps } from "../props/ValidationStringProps";
7
10
 
8
- export interface NSInputEmailProps
11
+ export interface NSInputEmailProps extends ValidationProps, ValidationStringProps
9
12
  {
10
13
  title: string;
11
- defaultValue?: string;
14
+ defaultValue?: string;
15
+ placeholder?: string;
12
16
  onChanged?: (e: React.ChangeEvent<HTMLInputElement>) => void;
13
17
  }
14
18
 
15
19
  export interface NSInputEmailState
16
20
  {
17
21
  value: string;
18
- error: boolean;
22
+ error?: string;
19
23
  }
20
24
 
21
- export class NSInputEmail extends React.Component<NSInputEmailProps, NSInputEmailState> {
25
+ export class NSInputEmail extends React.Component<NSInputEmailProps, NSInputEmailState>
26
+ {
22
27
  constructor(props: NSInputEmailProps)
23
28
  {
24
29
  super(props);
25
- this.state = {
26
- value: props.defaultValue ?? "",
27
- error: false,
28
- };
30
+ this.state = { value: props.defaultValue ?? "" };
29
31
  this.setValue = this.setValue.bind(this);
30
32
  this.getValue = this.getValue.bind(this);
31
- this.onChanged = this.onChanged.bind(this);
32
- }
33
+ this.onChanged = this.onChanged.bind(this);
34
+ }
35
+ getError(): string | null
36
+ {
37
+ return Validator.getErrorString(this.props.title, this.state.value, this.props) && Validator.getErrorEmail(this.props.title, this.state.value);
38
+ }
33
39
  getValue(): string
34
40
  {
41
+ let error = this.getError();
42
+ if (error)
43
+ {
44
+ this.setState({ error });
45
+ throw new Error(error);
46
+ }
35
47
  return this.state.value;
36
- }
48
+ }
37
49
  setValue(value: string): void
38
50
  {
39
- let email = /^(([^<>()[]\\.,;:\s@"]+(\.[^<>()[]\\.,;:\s@"]+)*)|(".+"))@(([[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
40
- debugger
41
- if (!email.test(value))
42
- {
43
- this.setState({ error: true, value });
44
- }
45
- else
46
- {
47
- this.setState({ error: false, value });
48
- }
49
- }
51
+ this.setState({ value });
52
+ }
50
53
  private onChanged(e: React.ChangeEvent<HTMLInputElement>): void
51
54
  {
52
55
  this.setValue(e.target.value);
@@ -62,7 +65,7 @@ export class NSInputEmail extends React.Component<NSInputEmailProps, NSInputEmai
62
65
  <img
63
66
  className={Styles.ns_input_icon}
64
67
  src={IconInputEmail}
65
- alt="icon"
68
+ alt="Email Icon"
66
69
  width={24}
67
70
  height={24}
68
71
  />
@@ -70,24 +73,25 @@ export class NSInputEmail extends React.Component<NSInputEmailProps, NSInputEmai
70
73
  value={this.state.value}
71
74
  onChange={this.onChanged}
72
75
  type="email"
73
- className={`${this.state.error === true ? Styles.ns_input_red : ""} ${Styles.ns_input}`}
74
- placeholder="Sample@gmail.com"
76
+ className={`${this.state.error ? Styles.ns_input_red : ""} ${Styles.ns_input}`}
77
+ placeholder={this.props.placeholder}
75
78
  />
76
79
  </div>
77
80
  {
78
- this.state.error === true ? (
81
+ // todo make it a component
82
+ this.state.error && (
79
83
  <>
80
- <div className="d-flex justify-content-start align-items-center gap-2 ms-2 ">
84
+ <div className="d-flex justify-content-start align-items-center gap-2 ms-2">
81
85
  <img
82
86
  className={""}
83
87
  src={Danger}
84
- alt="icon"
88
+ alt="Error Icon"
85
89
  width={13}
86
90
  height={13}
87
91
  />
88
- <span className={Styles.ns_input_error}>Enter a valid email.</span>
92
+ <span className={Styles.ns_input_error}>{this.state.error}</span>
89
93
  </div>
90
- </>) : null
94
+ </>)
91
95
  }
92
96
  </>
93
97
  );
@@ -3,20 +3,26 @@
3
3
  import React from "react";
4
4
  import Styles from "./NSInputFloat.module.css";
5
5
  import IconInputFloat from '../assets/images/icon-input-float.svg';
6
+ import { BaseComponentProps } from "../props/BaseComponentProps";
7
+ import { ValidationProps } from "../props/ValidationProps";
8
+ import { ValidationNumberProps } from "../props/ValidationNumberProps";
9
+ import { Validator } from "../Validator";
6
10
 
7
- export interface NSInputFloatProps
11
+ export interface NSInputFloatProps extends BaseComponentProps, ValidationProps, ValidationNumberProps
8
12
  {
9
- title: string;
10
- defaultValue?: string;
13
+ title: string;
14
+ defaultValue?: string;
11
15
  onChanged?: (e: React.ChangeEvent<HTMLInputElement>) => void;
12
16
  }
13
17
 
14
18
  export interface NSInputFloatState
15
19
  {
16
20
  value: string;
21
+ error?: string;
17
22
  }
18
23
 
19
- export class NSInputFloat extends React.Component<NSInputFloatProps, NSInputFloatState> {
24
+ export class NSInputFloat extends React.Component<NSInputFloatProps, NSInputFloatState>
25
+ {
20
26
  constructor(props: NSInputFloatProps)
21
27
  {
22
28
  super(props);
@@ -27,15 +33,24 @@ export class NSInputFloat extends React.Component<NSInputFloatProps, NSInputFloa
27
33
  this.getValue = this.getValue.bind(this);
28
34
  this.onChanged = this.onChanged.bind(this);
29
35
  }
36
+ getError(): string | null
37
+ {
38
+ return Validator.getErrorNumber(this.props.title, this.state.value, this.props);
39
+ }
30
40
  getValue(): string
31
41
  {
42
+ let error = this.getError();
43
+ if (error)
44
+ {
45
+ this.setState({ error });
46
+ throw new Error(error);
47
+ }
32
48
  return this.state.value;
33
- }
49
+ }
34
50
  setValue(value: string): void
35
51
  {
36
52
  this.setState({ value });
37
- }
38
-
53
+ }
39
54
  private onChanged(e: React.ChangeEvent<HTMLInputElement>): void
40
55
  {
41
56
  this.setValue(e.target.value);
@@ -45,8 +60,13 @@ export class NSInputFloat extends React.Component<NSInputFloatProps, NSInputFloa
45
60
  override render()
46
61
  {
47
62
  return (
48
- <div className={`${Styles.ns_input_parent} p-2`}>
49
- <span className={Styles.ns_input_title}>{this.props.title}</span>
63
+ <div className={`${Styles.ns_input_parent} p-2 ${this.props.classList?.join(" ")}`} style={this.props.style}>
64
+ <span className={Styles.ns_input_title}>
65
+ {
66
+ this.props.required && <span>*</span>
67
+ }
68
+ {this.props.title}
69
+ </span>
50
70
  <img
51
71
  className={Styles.ns_input_icon}
52
72
  src={IconInputFloat}
@@ -1,5 +1,3 @@
1
- "use client";
2
-
3
1
  import React from "react";
4
2
 
5
3
  export interface NSSpaceProps
@@ -23,30 +21,14 @@ export enum NSSpaceSizeType
23
21
 
24
22
  export interface NSSpaceState
25
23
  {
26
- size: NSSpaceSizeType;
27
24
  }
28
25
 
29
26
  export class NSSpace extends React.Component<NSSpaceProps, NSSpaceState>
30
27
  {
31
- constructor(props: NSSpaceProps)
32
- {
33
- super(props);
34
- this.state = { size: props.size };
35
- this.setValue = this.setValue.bind(this);
36
- this.getValue = this.getValue.bind(this);
37
- }
38
- setValue(size: NSSpaceSizeType): void
39
- {
40
- this.setState({ size });
41
- }
42
- getValue(): NSSpaceSizeType
43
- {
44
- return this.state.size;
45
- }
46
28
  override render()
47
29
  {
48
30
  return (
49
- <hr style={{ width: "100%", height: this.state.size, margin: "0px", padding: "0px", background: "transparent", color: "transparent", border: 0 }} />
31
+ <hr style={{ width: "100%", height: this.props.size, margin: "0px", padding: "0px", background: "transparent", color: "transparent", border: 0 }} />
50
32
  );
51
33
  }
52
34
  }
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+
3
+ export interface BaseComponentProps
4
+ {
5
+ classList?: string[]
6
+ style?: React.CSSProperties
7
+ }
@@ -0,0 +1,7 @@
1
+ import { ValidationProps } from "./ValidationProps";
2
+
3
+ export interface ValidationNumberProps extends ValidationProps
4
+ {
5
+ min?: number;
6
+ max?: number;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { ValidationRegexProps } from "./ValidationRegexProps";
2
+
3
+ export interface ValidationProps
4
+ {
5
+ required: boolean;
6
+ regex?: ValidationRegexProps;
7
+ }
@@ -0,0 +1,5 @@
1
+ export interface ValidationRegexProps
2
+ {
3
+ name: string
4
+ regex: RegExp;
5
+ }
@@ -0,0 +1,7 @@
1
+ import { ValidationProps } from "./ValidationProps";
2
+
3
+ export interface ValidationStringProps extends ValidationProps
4
+ {
5
+ min_length?: number;
6
+ max_length?: number;
7
+ }