persian-number-input 3.0.4 → 3.0.6
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/README.md +2 -2
- package/dist/components/PersianNumberInput.d.ts +7 -5
- package/dist/components/PersianNumberInput.js +21 -9
- package/dist/components/PersianNumberInput.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/digitUtils.d.ts +1 -1
- package/dist/utils/digitUtils.js +1 -0
- package/dist/utils/digitUtils.js.map +1 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Simple usage example:
|
|
|
33
33
|
|
|
34
34
|
```jsx
|
|
35
35
|
import React, { useState } from "react";
|
|
36
|
-
import PersianNumberInput from "persian-number-input";
|
|
36
|
+
import { PersianNumberInput } from "persian-number-input";
|
|
37
37
|
|
|
38
38
|
const App = () => {
|
|
39
39
|
const [number, setNumber] = useState("");
|
|
@@ -133,7 +133,7 @@ npm install persian-number-input
|
|
|
133
133
|
|
|
134
134
|
```jsx
|
|
135
135
|
import React, { useState } from "react";
|
|
136
|
-
import PersianNumberInput from "persian-number-input";
|
|
136
|
+
import { PersianNumberInput } from "persian-number-input";
|
|
137
137
|
|
|
138
138
|
const App = () => {
|
|
139
139
|
const [number, setNumber] = useState("");
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
interface PersianNumberInputCustomProps {
|
|
3
|
+
value: string;
|
|
4
4
|
separatorCount?: number;
|
|
5
5
|
separatorChar?: string;
|
|
6
|
-
lang?: 'fa
|
|
7
|
-
|
|
6
|
+
lang?: 'fa' | 'in' | 'en';
|
|
7
|
+
onChange: (value: string) => void;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
type AllowedInputProps = Pick<React.InputHTMLAttributes<HTMLInputElement>, 'className' | 'style' | 'placeholder' | 'disabled' | 'readOnly' | 'id' | 'name' | 'autoComplete' | 'autoFocus' | 'maxLength' | 'minLength' | 'required' | 'title' | 'dir' | 'onClick' | 'onKeyDown' | 'onKeyUp' | 'onKeyPress' | 'onFocus' | 'onBlur' | 'onMouseDown' | 'onMouseUp' | 'onMouseEnter' | 'onMouseLeave' | 'onTouchStart' | 'onTouchEnd' | 'onPaste'>;
|
|
10
|
+
export type PersianNumberInputProps = PersianNumberInputCustomProps & AllowedInputProps;
|
|
11
|
+
declare const PersianNumberInput: ({ value, separatorCount, separatorChar, lang, onChange, style, ...rest }: PersianNumberInputProps) => React.JSX.Element;
|
|
10
12
|
export default PersianNumberInput;
|
|
@@ -9,17 +9,29 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React
|
|
12
|
+
import React from 'react';
|
|
13
13
|
import { toLocalizedDigits, groupDigits, convertToEnglishDigits } from '../utils/digitUtils';
|
|
14
|
+
// استایل پایه برای input
|
|
15
|
+
const baseInputStyle = {
|
|
16
|
+
border: '1px solid #ccc',
|
|
17
|
+
borderRadius: '4px',
|
|
18
|
+
padding: '8px 12px',
|
|
19
|
+
fontSize: '14px',
|
|
20
|
+
outline: 'none',
|
|
21
|
+
};
|
|
14
22
|
const PersianNumberInput = (_a) => {
|
|
15
|
-
var {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
onChangeValue(input);
|
|
20
|
-
}, [onChangeValue]);
|
|
21
|
-
const formattedValue = groupDigits(convertToEnglishDigits(initialValue).replace(/\D/g, ''), separatorCount, separatorChar);
|
|
23
|
+
var { value, separatorCount = 0, separatorChar = ',', lang = 'fa', onChange, style } = _a, rest = __rest(_a, ["value", "separatorCount", "separatorChar", "lang", "onChange", "style"]);
|
|
24
|
+
// تبدیل مقدار به فرمت نمایشی
|
|
25
|
+
const numericValue = convertToEnglishDigits(value).replace(/\D/g, '');
|
|
26
|
+
const formattedValue = groupDigits(numericValue, separatorCount, separatorChar);
|
|
22
27
|
const displayValue = lang === 'en' ? formattedValue : toLocalizedDigits(formattedValue, lang);
|
|
23
|
-
|
|
28
|
+
// هندل تغییرات
|
|
29
|
+
const handleChange = (e) => {
|
|
30
|
+
const newValue = convertToEnglishDigits(e.target.value).replace(/\D/g, '');
|
|
31
|
+
onChange(newValue);
|
|
32
|
+
};
|
|
33
|
+
const mergedStyle = Object.assign(Object.assign({}, baseInputStyle), style);
|
|
34
|
+
return React.createElement("input", Object.assign({ value: displayValue, onChange: handleChange, style: mergedStyle }, rest));
|
|
24
35
|
};
|
|
25
36
|
export default PersianNumberInput;
|
|
37
|
+
//# sourceMappingURL=PersianNumberInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PersianNumberInput.js","sourceRoot":"","sources":["../../src/components/PersianNumberInput.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AA4C7F,yBAAyB;AACzB,MAAM,cAAc,GAAwB;IACxC,MAAM,EAAE,gBAAgB;IACxB,YAAY,EAAE,KAAK;IACnB,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE,MAAM;CAClB,CAAC;AAKF,MAAM,kBAAkB,GAAG,CAAC,EAQF,EAAE,EAAE;QARF,EACxB,KAAK,EACL,cAAc,GAAG,CAAC,EAClB,aAAa,GAAG,GAAG,EACnB,IAAI,GAAG,IAAI,EACX,QAAQ,EACR,KAAK,OAEiB,EADnB,IAAI,cAPiB,yEAQ3B,CADU;IAEP,6BAA6B;IAC7B,MAAM,YAAY,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACtE,MAAM,cAAc,GAAG,WAAW,CAAC,YAAY,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IAChF,MAAM,YAAY,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,iBAAiB,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAE9F,eAAe;IACf,MAAM,YAAY,GAAG,CAAC,CAAsC,EAAE,EAAE;QAC5D,MAAM,QAAQ,GAAG,sBAAsB,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC3E,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,MAAM,WAAW,mCAAQ,cAAc,GAAK,KAAK,CAAE,CAAC;IAEpD,OAAO,6CACH,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,WAAW,IACd,IAAI,EACV,CAAC;AACP,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const digitsMap: {
|
|
2
2
|
[key: string]: string[];
|
|
3
3
|
};
|
|
4
|
-
export declare const toLocalizedDigits: (numStr: string, locale: "fa
|
|
4
|
+
export declare const toLocalizedDigits: (numStr: string, locale: "fa" | "in") => string;
|
|
5
5
|
export declare const groupDigits: (numStr: string, separatorCount: number, separatorChar?: string) => string;
|
|
6
6
|
export declare const convertToEnglishDigits: (str: string) => string;
|
package/dist/utils/digitUtils.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digitUtils.js","sourceRoot":"","sources":["../../src/utils/digitUtils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAgC;IACpD,EAAE,E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AAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG;KACT,CAAC;IACF,OAAO,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "persian-number-input",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "React component for Persian, Indic, or English localized number input with customizable digit grouping",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"typings": "dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
7
10
|
"files": [
|
|
8
11
|
"dist"
|
|
9
12
|
],
|