@popsure/dirty-swan 0.41.6 → 0.41.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/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/components/input/currency/index.d.ts +2 -2
- package/dist/esm/components/input/currency/index.js +1 -1
- package/dist/esm/components/input/currency/index.js.map +1 -1
- package/dist/esm/components/input/currency/input.stories.js.map +1 -1
- package/dist/esm/lib/components/input/currency/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/lib/components/input/currency/index.tsx +3 -3
- package/src/lib/components/input/currency/input.stories.tsx +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InputProps } from '..';
|
|
2
2
|
export declare type CurrencyInputProps = {
|
|
3
|
-
value?: number
|
|
3
|
+
value?: number;
|
|
4
4
|
placeholder?: string;
|
|
5
|
-
onChange?: (value: number
|
|
5
|
+
onChange?: (value: number) => void;
|
|
6
6
|
} & Omit<InputProps, 'onChange' | 'value' | 'ref'>;
|
|
7
7
|
declare const CurrencyInput: ({ value, onChange, type, ...props }: CurrencyInputProps) => JSX.Element;
|
|
8
8
|
export { CurrencyInput };
|
|
@@ -42,7 +42,7 @@ var CurrencyInput = function (_a) {
|
|
|
42
42
|
}, [value]);
|
|
43
43
|
useEffect(function () {
|
|
44
44
|
if (shadowValue === '' && value) {
|
|
45
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(
|
|
45
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(0);
|
|
46
46
|
}
|
|
47
47
|
else if (shadowValue) {
|
|
48
48
|
onChange === null || onChange === void 0 ? void 0 : onChange(reverseFormatInput(shadowValue));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../../src/lib/components/input/currency/format/index.ts","../../../../../../src/lib/components/input/currency/index.tsx"],"sourcesContent":["export const formatInput = (input: string): string => {\n const decimalSeparator = input.includes(',') ? ',' : '.';\n const parts = input.split(decimalSeparator);\n const floor = parts[0];\n const ceiling = parts[1];\n parts[0] = floor.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ' ');\n if (ceiling) {\n parts[1] = ceiling.slice(0, Math.min(ceiling.length, 2));\n }\n return parts.join('.');\n};\n\nexport function reverseFormatInput(input: string): number {\n return Number(input.replace(/,/, '.').replace(/\\s/g, ''));\n}\n","import { useEffect, useRef, useState } from 'react';\n\nimport { formatInput, reverseFormatInput } from './format';\nimport { Input, InputProps } from '..';\n\nexport type CurrencyInputProps = {\n value?: number
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../src/lib/components/input/currency/format/index.ts","../../../../../../src/lib/components/input/currency/index.tsx"],"sourcesContent":["export const formatInput = (input: string): string => {\n const decimalSeparator = input.includes(',') ? ',' : '.';\n const parts = input.split(decimalSeparator);\n const floor = parts[0];\n const ceiling = parts[1];\n parts[0] = floor.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ' ');\n if (ceiling) {\n parts[1] = ceiling.slice(0, Math.min(ceiling.length, 2));\n }\n return parts.join('.');\n};\n\nexport function reverseFormatInput(input: string): number {\n return Number(input.replace(/,/, '.').replace(/\\s/g, ''));\n}\n","import { useEffect, useRef, useState } from 'react';\n\nimport { formatInput, reverseFormatInput } from './format';\nimport { Input, InputProps } from '..';\n\nexport type CurrencyInputProps = {\n value?: number;\n placeholder?: string;\n onChange?: (value: number) => void;\n} & Omit<InputProps, 'onChange' | 'value' | 'ref'>\n\nconst CurrencyInput = ({\n value,\n onChange,\n type,\n ...props\n}: CurrencyInputProps) => {\n const inputRef = useRef<HTMLInputElement | null>(null);\n const [cursor, setCursor] = useState<number | null>(null);\n const [shadowValue, setShadowValue] = useState('');\n\n const formattedShadowValue = formatInput(\n shadowValue\n .replace(/ /g, '') // remove all whitespace\n .replace(',', '.') // change commas to dot for decimal separator\n .replace('.', 'DECIMAL_SEPARATOR') // Gymnastic to remove all the but the first decimal separators 🤸\n .replace(/\\./g, '')\n .replace('DECIMAL_SEPARATOR', '.') // End of the Gymnastic 🤸\n .replace(/[^\\d\\\\.]/g, '') // remove all non decimal and dot\n );\n\n useEffect(() => {\n if (value && value !== reverseFormatInput(shadowValue)) {\n setShadowValue(formatInput(value.toString()));\n }\n // eslint-disable-next-line\n }, [value]);\n\n useEffect(() => {\n if (shadowValue === '' && value) {\n onChange?.(0);\n } else if (shadowValue) {\n onChange?.(reverseFormatInput(shadowValue));\n }\n // eslint-disable-next-line\n }, [shadowValue]);\n\n useEffect(() => {\n if (!inputRef.current || !cursor) {\n return;\n }\n\n const cursorDiff =\n String(formattedShadowValue).length - String(shadowValue).length;\n const newCursor = cursorDiff + cursor;\n\n inputRef.current.selectionStart = newCursor;\n inputRef.current.selectionEnd = newCursor;\n }, [cursor, formattedShadowValue, shadowValue]);\n\n return (\n <Input\n prefix=\"€\"\n ref={inputRef}\n type=\"string\"\n value={formattedShadowValue}\n onChange={(e) => {\n setCursor(e.target.selectionStart);\n setShadowValue(e.target.value);\n }}\n {...props}\n />\n );\n};\n\nexport { CurrencyInput };\n"],"names":["_jsx"],"mappings":";;;;;;;;AAAO,IAAM,WAAW,GAAG,UAAC,KAAa;IACvC,IAAM,gBAAgB,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC;IACzD,IAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC5C,IAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,IAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACzB,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;IACvD,IAAI,OAAO,EAAE;QACX,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,M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R,QAAQ,CAAG,CAAC,CAAC,CAAC;SACf;aAAM,IAAI,WAAW,EAAE;YACtB,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC;SAC7C;;KAEF,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAElB,SAAS,CAAC;QACR,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,MAAM,EAAE;YAChC,OAAO;SACR;QAED,IAAM,UAAU,GACd,MAAM,CAAC,oBAAoB,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC;QACnE,IAAM,SAAS,GAAG,UAAU,GAAG,MAAM,CAAC;QAEtC,QAAQ,CAAC,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;QAC5C,QAAQ,CAAC,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;KAC3C,EAAE,CAAC,MAAM,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC,CAAC;IAEhD,QACEA,IAAC,KAAK,aACJ,MAAM,EAAC,QAAG,EACV,GAAG,EAAE,QAAQ,EACb,IAAI,EAAC,QAAQ,EACb,KAAK,EAAE,oBAAoB,EAC3B,QAAQ,EAAE,UAAC,CAAC;YACV,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YACnC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAChC,IACG,KAAK,UACT,EACF;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.stories.js","sources":["../../../../../../src/lib/components/input/currency/input.stories.tsx"],"sourcesContent":["\nimport { useState } from 'react';\nimport { CurrencyInput, CurrencyInputProps } from '.';\nimport sharedConfig from '../stories/config';\n\nconst story = {\n title: 'JSX/Inputs',\n component: CurrencyInput,\n argTypes: sharedConfig,\n parameters: {\n componentSubtitle: 'The default input component is used to gather informations from the user.'\n }\n};\n\nexport const CurrencyInputStory = ({ \n onChange,\n className,\n placeholder,\n value,\n label,\n hideLabel,\n prefix,\n error\n}: CurrencyInputProps) => {\n const [newValue, setValue] = useState<number
|
|
1
|
+
{"version":3,"file":"input.stories.js","sources":["../../../../../../src/lib/components/input/currency/input.stories.tsx"],"sourcesContent":["\nimport { useState } from 'react';\nimport { CurrencyInput, CurrencyInputProps } from '.';\nimport sharedConfig from '../stories/config';\n\nconst story = {\n title: 'JSX/Inputs',\n component: CurrencyInput,\n argTypes: sharedConfig,\n parameters: {\n componentSubtitle: 'The default input component is used to gather informations from the user.'\n }\n};\n\nexport const CurrencyInputStory = ({ \n onChange,\n className,\n placeholder,\n value,\n label,\n hideLabel,\n prefix,\n error\n}: CurrencyInputProps) => {\n const [newValue, setValue] = useState<number>(Number);\n\n const handleOnChange = (value: number) => {\n setValue(value)\n onChange?.(value);\n }\n\n return (\n <CurrencyInput \n onChange={handleOnChange}\n value={newValue}\n className={className}\n placeholder={placeholder}\n label={label}\n hideLabel={hideLabel}\n prefix={prefix}\n error={error}\n />\n );\n};\n\nCurrencyInputStory.storyName = 'CurrencyInput';\n\nexport default story;\n"],"names":["_jsx"],"mappings":";;;;;;;;;;IAKM,KAAK,GAAG;IACZ,KAAK,EAAE,YAAY;IACnB,SAAS,EAAE,aAAa;IACxB,QAAQ,EAAE,YAAY;IACtB,UAAU,EAAE;QACV,iBAAiB,EAAE,2EAA2E;KAC/F;EACD;IAEW,kBAAkB,GAAG,UAAC,EASd;QARnB,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,WAAW,iBAAA,UACN,MACL,KAAK,WAAA,EACL,SAAS,eAAA,EACT,MAAM,YAAA,EACN,KAAK;IAEC,IAAA,KAAuB,QAAQ,CAAS,MAAM,CAAC,EAA9C,QAAQ,QAAA,EAAE,QAAQ,QAA4B,CAAC;IAEtD,IAAM,cAAc,GAAG,UAAC,KAAa;QACnC,QAAQ,CAAC,KAAK,CAAC,CAAA;QACf,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,KAAK,CAAC,CAAC;KACnB,CAAA;IAED,QACEA,IAAC,aAAa,IACZ,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,QAAQ,EACf,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,WACZ,EACF;AACJ,EAAE;AAEF,kBAAkB,CAAC,SAAS,GAAG,eAAe;;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InputProps } from '..';
|
|
2
2
|
export declare type CurrencyInputProps = {
|
|
3
|
-
value?: number
|
|
3
|
+
value?: number;
|
|
4
4
|
placeholder?: string;
|
|
5
|
-
onChange?: (value: number
|
|
5
|
+
onChange?: (value: number) => void;
|
|
6
6
|
} & Omit<InputProps, 'onChange' | 'value' | 'ref'>;
|
|
7
7
|
declare const CurrencyInput: ({ value, onChange, type, ...props }: CurrencyInputProps) => JSX.Element;
|
|
8
8
|
export { CurrencyInput };
|
package/package.json
CHANGED
|
@@ -4,9 +4,9 @@ import { formatInput, reverseFormatInput } from './format';
|
|
|
4
4
|
import { Input, InputProps } from '..';
|
|
5
5
|
|
|
6
6
|
export type CurrencyInputProps = {
|
|
7
|
-
value?: number
|
|
7
|
+
value?: number;
|
|
8
8
|
placeholder?: string;
|
|
9
|
-
onChange?: (value: number
|
|
9
|
+
onChange?: (value: number) => void;
|
|
10
10
|
} & Omit<InputProps, 'onChange' | 'value' | 'ref'>
|
|
11
11
|
|
|
12
12
|
const CurrencyInput = ({
|
|
@@ -38,7 +38,7 @@ const CurrencyInput = ({
|
|
|
38
38
|
|
|
39
39
|
useEffect(() => {
|
|
40
40
|
if (shadowValue === '' && value) {
|
|
41
|
-
onChange?.(
|
|
41
|
+
onChange?.(0);
|
|
42
42
|
} else if (shadowValue) {
|
|
43
43
|
onChange?.(reverseFormatInput(shadowValue));
|
|
44
44
|
}
|
|
@@ -22,9 +22,9 @@ export const CurrencyInputStory = ({
|
|
|
22
22
|
prefix,
|
|
23
23
|
error
|
|
24
24
|
}: CurrencyInputProps) => {
|
|
25
|
-
const [newValue, setValue] = useState<number
|
|
25
|
+
const [newValue, setValue] = useState<number>(Number);
|
|
26
26
|
|
|
27
|
-
const handleOnChange = (value: number
|
|
27
|
+
const handleOnChange = (value: number) => {
|
|
28
28
|
setValue(value)
|
|
29
29
|
onChange?.(value);
|
|
30
30
|
}
|