@apexcura/ui-components 0.0.1 → 0.0.2

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/dist/index.d.mts CHANGED
@@ -15,9 +15,10 @@ type ElementType = {
15
15
  label?: string;
16
16
  name?: string;
17
17
  suffix?: React.ReactNode;
18
+ maxLength?: number;
18
19
  };
19
20
 
20
- declare const InputElement: (props: ElementType) => React$1.JSX.Element;
21
+ declare const TextElement: (props: ElementType) => React$1.JSX.Element;
21
22
 
22
23
  interface InputData {
23
24
  placeholder?: string;
@@ -31,11 +32,6 @@ interface PasswordProps {
31
32
  }
32
33
  declare const PasswordElement: React$1.FC<PasswordProps>;
33
34
 
34
- interface SelectProps {
35
- placeholder: string;
36
- defaultValue: string;
37
- id: string;
38
- }
39
- declare const SelectElement: React$1.FC<SelectProps>;
35
+ declare const NumberInput: (props: ElementType) => React$1.JSX.Element;
40
36
 
41
- export { InputElement, PasswordElement, SelectElement };
37
+ export { NumberInput, PasswordElement, TextElement };
package/dist/index.d.ts CHANGED
@@ -15,9 +15,10 @@ type ElementType = {
15
15
  label?: string;
16
16
  name?: string;
17
17
  suffix?: React.ReactNode;
18
+ maxLength?: number;
18
19
  };
19
20
 
20
- declare const InputElement: (props: ElementType) => React$1.JSX.Element;
21
+ declare const TextElement: (props: ElementType) => React$1.JSX.Element;
21
22
 
22
23
  interface InputData {
23
24
  placeholder?: string;
@@ -31,11 +32,6 @@ interface PasswordProps {
31
32
  }
32
33
  declare const PasswordElement: React$1.FC<PasswordProps>;
33
34
 
34
- interface SelectProps {
35
- placeholder: string;
36
- defaultValue: string;
37
- id: string;
38
- }
39
- declare const SelectElement: React$1.FC<SelectProps>;
35
+ declare const NumberInput: (props: ElementType) => React$1.JSX.Element;
40
36
 
41
- export { InputElement, PasswordElement, SelectElement };
37
+ export { NumberInput, PasswordElement, TextElement };
package/dist/index.js CHANGED
@@ -30,19 +30,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- InputElement: () => InputElement,
33
+ NumberInput: () => NumberInput,
34
34
  PasswordElement: () => PasswordElement,
35
- SelectElement: () => SelectElement
35
+ TextElement: () => TextElement
36
36
  });
37
37
  module.exports = __toCommonJS(src_exports);
38
38
 
39
- // src/Components/InputElement.tsx
39
+ // src/Components/TextElement.tsx
40
40
  var import_react = __toESM(require("react"));
41
41
  var import_antd = require("antd");
42
42
  var onHandleChange = ($event) => {
43
43
  console.log($event);
44
44
  };
45
- var InputElement = (props) => {
45
+ var TextElement = (props) => {
46
46
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("label", { htmlFor: props.name }, props.label), /* @__PURE__ */ import_react.default.createElement(
47
47
  import_antd.Input,
48
48
  {
@@ -90,32 +90,53 @@ var PasswordElement = ({ inputData }) => {
90
90
  return /* @__PURE__ */ import_react2.default.createElement(import_antd2.Space, { direction: "vertical" }, renderPasswordInput(), /* @__PURE__ */ import_react2.default.createElement(import_antd2.Space, { direction: "horizontal" }, renderPasswordInput(), /* @__PURE__ */ import_react2.default.createElement(import_antd2.Button, { style: { width: 80 }, onClick: handleVisibilityToggle }, passwordVisible ? "Hide" : "Show")));
91
91
  };
92
92
 
93
- // src/Components/SelectElement.tsx
93
+ // src/Components/NumberElement.tsx
94
94
  var import_react3 = __toESM(require("react"));
95
95
  var import_antd3 = require("antd");
96
- var options = [
97
- {
98
- value: "zhejiang",
99
- label: "Zhejiang"
100
- },
101
- {
102
- value: "jiangsu",
103
- label: "Jiangsu"
104
- }
105
- ];
106
- var SelectElement = (props) => /* @__PURE__ */ import_react3.default.createElement(
107
- import_antd3.Select,
108
- {
109
- placeholder: props.placeholder,
110
- allowClear: true,
111
- defaultValue: props.defaultValue,
112
- id: props.id,
113
- options
114
- }
115
- );
96
+ var formatNumber = (value) => new Intl.NumberFormat().format(value);
97
+ var NumericInput = (props) => {
98
+ const { value, onChange } = props;
99
+ const handleChange = (e) => {
100
+ const { value: inputValue } = e.target;
101
+ const reg = /^-?\d*(\.\d*)?$/;
102
+ if (reg.test(inputValue) || inputValue === "" || inputValue === "-") {
103
+ onChange(inputValue);
104
+ }
105
+ };
106
+ const handleBlur = () => {
107
+ let valueTemp = value;
108
+ if (value.charAt(value.length - 1) === "." || value === "-") {
109
+ valueTemp = value.slice(0, -1);
110
+ }
111
+ onChange(valueTemp.replace(/0*(\d+)/, "$1"));
112
+ };
113
+ const title = value ? /* @__PURE__ */ import_react3.default.createElement("span", { className: "numeric-input-title" }, value !== "-" ? formatNumber(Number(value)) : "-") : "Input a number";
114
+ return /* @__PURE__ */ import_react3.default.createElement(import_antd3.Tooltip, { trigger: ["focus"], title, placement: "topLeft", overlayClassName: "numeric-input" }, /* @__PURE__ */ import_react3.default.createElement(
115
+ import_antd3.Input,
116
+ {
117
+ ...props,
118
+ onChange: handleChange,
119
+ onBlur: handleBlur,
120
+ placeholder: "Input a number",
121
+ maxLength: 16
122
+ }
123
+ ));
124
+ };
125
+ var NumberInput = (props) => {
126
+ const [value, setValue] = (0, import_react3.useState)("");
127
+ return /* @__PURE__ */ import_react3.default.createElement(
128
+ NumericInput,
129
+ {
130
+ ...props,
131
+ style: { width: 120 },
132
+ value,
133
+ onChange: setValue
134
+ }
135
+ );
136
+ };
116
137
  // Annotate the CommonJS export names for ESM import in node:
117
138
  0 && (module.exports = {
118
- InputElement,
139
+ NumberInput,
119
140
  PasswordElement,
120
- SelectElement
141
+ TextElement
121
142
  });
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- // src/Components/InputElement.tsx
1
+ // src/Components/TextElement.tsx
2
2
  import React from "react";
3
3
  import { Input as AntInput } from "antd";
4
4
  var onHandleChange = ($event) => {
5
5
  console.log($event);
6
6
  };
7
- var InputElement = (props) => {
7
+ var TextElement = (props) => {
8
8
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("label", { htmlFor: props.name }, props.label), /* @__PURE__ */ React.createElement(
9
9
  AntInput,
10
10
  {
@@ -52,31 +52,52 @@ var PasswordElement = ({ inputData }) => {
52
52
  return /* @__PURE__ */ React2.createElement(Space, { direction: "vertical" }, renderPasswordInput(), /* @__PURE__ */ React2.createElement(Space, { direction: "horizontal" }, renderPasswordInput(), /* @__PURE__ */ React2.createElement(Button, { style: { width: 80 }, onClick: handleVisibilityToggle }, passwordVisible ? "Hide" : "Show")));
53
53
  };
54
54
 
55
- // src/Components/SelectElement.tsx
56
- import React3 from "react";
57
- import { Select as AntSelect } from "antd";
58
- var options = [
59
- {
60
- value: "zhejiang",
61
- label: "Zhejiang"
62
- },
63
- {
64
- value: "jiangsu",
65
- label: "Jiangsu"
66
- }
67
- ];
68
- var SelectElement = (props) => /* @__PURE__ */ React3.createElement(
69
- AntSelect,
70
- {
71
- placeholder: props.placeholder,
72
- allowClear: true,
73
- defaultValue: props.defaultValue,
74
- id: props.id,
75
- options
76
- }
77
- );
55
+ // src/Components/NumberElement.tsx
56
+ import React3, { useState as useState2 } from "react";
57
+ import { Input as Input2, Tooltip } from "antd";
58
+ var formatNumber = (value) => new Intl.NumberFormat().format(value);
59
+ var NumericInput = (props) => {
60
+ const { value, onChange } = props;
61
+ const handleChange = (e) => {
62
+ const { value: inputValue } = e.target;
63
+ const reg = /^-?\d*(\.\d*)?$/;
64
+ if (reg.test(inputValue) || inputValue === "" || inputValue === "-") {
65
+ onChange(inputValue);
66
+ }
67
+ };
68
+ const handleBlur = () => {
69
+ let valueTemp = value;
70
+ if (value.charAt(value.length - 1) === "." || value === "-") {
71
+ valueTemp = value.slice(0, -1);
72
+ }
73
+ onChange(valueTemp.replace(/0*(\d+)/, "$1"));
74
+ };
75
+ const title = value ? /* @__PURE__ */ React3.createElement("span", { className: "numeric-input-title" }, value !== "-" ? formatNumber(Number(value)) : "-") : "Input a number";
76
+ return /* @__PURE__ */ React3.createElement(Tooltip, { trigger: ["focus"], title, placement: "topLeft", overlayClassName: "numeric-input" }, /* @__PURE__ */ React3.createElement(
77
+ Input2,
78
+ {
79
+ ...props,
80
+ onChange: handleChange,
81
+ onBlur: handleBlur,
82
+ placeholder: "Input a number",
83
+ maxLength: 16
84
+ }
85
+ ));
86
+ };
87
+ var NumberInput = (props) => {
88
+ const [value, setValue] = useState2("");
89
+ return /* @__PURE__ */ React3.createElement(
90
+ NumericInput,
91
+ {
92
+ ...props,
93
+ style: { width: 120 },
94
+ value,
95
+ onChange: setValue
96
+ }
97
+ );
98
+ };
78
99
  export {
79
- InputElement,
100
+ NumberInput,
80
101
  PasswordElement,
81
- SelectElement
102
+ TextElement
82
103
  };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@apexcura/ui-components",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Apex cura React components library",
5
- "keywords" : ["apec cura", "input", "ui", "react", "react-component"],
5
+ "keywords" : ["apex cura", "input", "ui", "react", "react-component"],
6
6
  "homepage": "https://www.apexcura.com/",
7
7
  "bugs": {
8
8
  "url": "https://github.com/apexcura/ui-components/issues"