persian-number-input 3.0.4 → 3.0.7

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 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
- export interface PersianNumberInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
2
+ interface PersianNumberInputCustomProps {
3
3
  initialValue?: string;
4
4
  separatorCount?: number;
5
5
  separatorChar?: string;
6
- lang?: 'fa-ar' | 'in' | 'en';
6
+ lang?: 'fa' | 'in' | 'en';
7
7
  onChangeValue?: (englishNumber: string) => void;
8
8
  }
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;
9
11
  declare const PersianNumberInput: React.FC<PersianNumberInputProps>;
10
12
  export default PersianNumberInput;
@@ -11,15 +11,24 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import React, { useCallback } 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
+ };
14
19
  const PersianNumberInput = (_a) => {
15
- var { initialValue = '', separatorCount = 0, separatorChar = ',', lang = 'fa-ar', onChangeValue } = _a, rest = __rest(_a, ["initialValue", "separatorCount", "separatorChar", "lang", "onChangeValue"]);
20
+ var { initialValue = '', separatorCount = 0, separatorChar = ',', lang = 'fa', onChangeValue, style } = _a, rest = __rest(_a, ["initialValue", "separatorCount", "separatorChar", "lang", "onChangeValue", "style"]);
21
+ const [value, setValue] = React.useState(() => convertToEnglishDigits(initialValue).replace(/\D/g, ''));
16
22
  const handleChange = useCallback((e) => {
17
23
  const input = convertToEnglishDigits(e.target.value).replace(/\D/g, '');
24
+ setValue(input);
18
25
  if (onChangeValue)
19
26
  onChangeValue(input);
20
27
  }, [onChangeValue]);
21
- const formattedValue = groupDigits(convertToEnglishDigits(initialValue).replace(/\D/g, ''), separatorCount, separatorChar);
28
+ const formattedValue = groupDigits(value, separatorCount, separatorChar);
22
29
  const displayValue = lang === 'en' ? formattedValue : toLocalizedDigits(formattedValue, lang);
23
- return React.createElement("input", Object.assign({}, rest, { defaultValue: displayValue, onChange: handleChange }));
30
+ const mergedStyle = Object.assign(Object.assign({}, baseInputStyle), style);
31
+ return React.createElement("input", Object.assign({ value: displayValue, onChange: handleChange, style: mergedStyle }, rest));
24
32
  };
25
33
  export default PersianNumberInput;
34
+ //# sourceMappingURL=PersianNumberInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PersianNumberInput.js","sourceRoot":"","sources":["../../src/components/PersianNumberInput.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,qBA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e,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { default as PersianNumberInput } from "./components/PersianNumberInput";
2
+ //# sourceMappingURL=index.js.map
@@ -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-ar" | "in" | "en") => string;
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;
@@ -37,3 +37,4 @@ export const convertToEnglishDigits = (str) => {
37
37
  };
38
38
  return str.replace(/[۰-۹०-९]/g, (char) => map[char]);
39
39
  };
40
+ //# sourceMappingURL=digitUtils.js.map
@@ -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,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IACtD,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;CACvD,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,MAAmB,EAAE,EAAE;IACvE,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,MAAM,CA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",
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
  ],