@popsure/dirty-swan 0.41.13 → 0.41.14

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.
@@ -58,7 +58,7 @@ var CurrencyInput = function (_a) {
58
58
  inputRef.current.selectionStart = newCursor;
59
59
  inputRef.current.selectionEnd = newCursor;
60
60
  }, [cursor, formattedShadowValue, shadowValue]);
61
- return (jsx(Input, __assign({ prefix: "\u20AC", ref: inputRef, type: "string", value: formattedShadowValue, onChange: function (e) {
61
+ return (jsx(Input, __assign({ inputMode: 'decimal', prefix: "\u20AC", ref: inputRef, type: "string", value: formattedShadowValue, onChange: function (e) {
62
62
  setCursor(e.target.selectionStart);
63
63
  setShadowValue(e.target.value);
64
64
  } }, props), void 0));
@@ -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;\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,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AC,KAAK,CAAC,CAAC,CAAC;IAEZ,SAAS,CAAC;QACR,IAAI,WAAW,KAAK,EAAE,IAAI,KAAK,EAAE;YAC/B,QAAQ,aAAR,QAAQ,uBAAR,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
+ {"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 inputMode='decimal'\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,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;KAC1D;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC,CAAC;SAEc,kBAAkB,CAAC,KAAa;IAC9C,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;AAC5D;;ICHM,aAAa,GAAG,UAAC,EAKF;QAJnB,KAAK,WAAA,EACL,QAAQ,cAAA,SACJ,MACD,KAAK,cAJa,6BAKtB;IACC,IAAM,QAAQ,GAAG,MAAM,CAA0B,IAAI,CAAC,CAAC;IACjD,IAAA,KAAsB,QAAQ,CAAgB,IAAI,CAAC,EAAlD,MAAM,QAAA,EAAE,SAAS,QA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C5C,QAAQ,CAAC,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;KAC3C,EAAE,CAAC,MAAM,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC,CAAC;IAEhD,QACEA,IAAC,KAAK,aACJ,SAAS,EAAC,SAAS,EACnB,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;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popsure/dirty-swan",
3
- "version": "0.41.13",
3
+ "version": "0.41.14",
4
4
  "author": "Vincent Audoire <vincent@getpopsure.com>",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -60,6 +60,7 @@ const CurrencyInput = ({
60
60
 
61
61
  return (
62
62
  <Input
63
+ inputMode='decimal'
63
64
  prefix="€"
64
65
  ref={inputRef}
65
66
  type="string"