import { FormatterInitializer, Money } from "moneydew"; export default class IntlCurrencyInput { private _input; private _money; private _min; private _max; private _inputValue; private _formatter; private _eventListener; private _validCallback; private _invalidCallback; private _strictMode; private _posPrefix; private _posSuffix; private _negPrefix; private _negSuffix; private _posPrefixPattern; private _posSuffixPattern; private _negPrefixPattern; private _negSuffixPattern; private _allowNegativeZero; /** * @desc Checks if currently held value is within boundaries and adjusts value accordingly. * @returns A bool representing whether the previous value was out of bounds and an adjustment was made. */ private fitInBoundaries; private handleInput; /** * @param inputElement - An HTML element inside which to place the currency input * @param initializer - A Moneydew MoneyFormatter initializer. Refer to Moneydew documentation. This controls the * formatting of the input. When omitted defaults to settings of default constructor for MoneyFormatter. * @param initialValue - The default value to display. This also controls the amount of digits after the decimal separator. * When omitted defaults to 0.00 (value 0 with two values after separator). */ constructor(inputElement: HTMLInputElement, initialValue?: string, initializer?: FormatterInitializer); /** * @desc Detaches the input from the current input, and attaches to new one. * Does nothing if old container is same as new one. * @param inputElement The new element to mount to */ remount(inputElement: HTMLInputElement): void; /** * @desc Unmounts the currency input. Trying to use member functions other than {@link remount} after unmounting will * result in undefined behaviour until {@link remount} is called or the variable has been overwritten by a new * instance of IntlCurrencyInput. Note that you don't have to call this function before {@link remount}. This function * is useful if you want to stop input restrictions on the input element. It is recommended to unmount before the * currency input gets destroyed by the garbage collector. Otherwise, you end up with a rogue event listener on your * input element. */ unmount(): void; /** * @desc Replaces the Moneydew formatter currently in use with a new one and automatically adjusts displayed value. * It is not recommended to change this formatter afterward as the currency will not automatically register those * changes. * @param f The new formatter - refer to Moneydew documentation for details */ format(f: FormatterInitializer): void; /** * @desc Add a value to the current input */ add(value: Money | string): void; /** * @desc Subtract a value from the current input */ subtract(value: Money | string): void; /** * @desc Sets the current value held by the input. This implicitly determines the amount of decimal places displayed. * If the input currently has a minimum and/or maximum defined and those have a different floating point precision * from {@link value}, then those limits are removed. */ setValue(value: string): void; /** * @returns a string representing the currently held value matching the following pattern: ^(0|[1-9]\d*)\\.\d{x,x}$ * where x is the amount of current decimal places. Missing decimal places are filled with zeroes. This string * can be easily converted to a number but be careful as it may be larger than the largest integer. */ getValue(): string; /** * @returns the current value of the input that is displayed. Missing decimal places are filled with zeroes. */ getFormattedValue(): string; /** * @desc Disables the input element. */ disable(): void; /** * @desc Enables the input element. */ enable(): void; /** * @returns whether the input is disabled */ isDisabled(): boolean; /** * @desc Enables strict mode. In strict mode the decimal separator cannot be removed and typing with the caret touching * the digits right of the decimal separator will overwrite the digit to the right of the caret. This implicitly means * that the value held by the currency input is always valid. Keep in my that {@link getFormattedValue} and * {@link getValue} always return a valid value. Strict mode only controls the displayed value and user interaction. */ enableStrictMode(): void; /** * @desc Disables strict mode after {@link enableStrictMode} was called. When strict mode is disabled, the decimal * separator can be deleted and so can the numbers to the right of the decimal separator. This allows for more flexibility * when the user is typing but may require extra validation. Keep in my that {@link getFormattedValue} and * {@link getValue} always return a valid value. Strict mode only controls the displayed value and user interaction. */ disableStrictMode(): void; /** * @desc Allows specifying a callback function that is called after the user makes a valid input. If a callback * (for valid input) has already been specified, the old one will be overwritten by the new one. * @param callback A parameterless function returning void */ validCallback(callback: (() => void)): void; /** * @desc Allows specifying a callback function that is called after the user makes an invalid input. If a callback * (for invalid input) has already been specified, the old one will be overwritten by the new one. * @param callback A parameterless function returning void */ invalidCallback(callback: (() => void)): void; /** * @desc Sets the lowest possible value that the input can hold. Defaults to zero. Set to null to remove lower limit. * Use this function to allow input of negative values. */ setMin(min: string | null): void; setMax(max: string | null): void; /** * @desc If set to true, values like -0 or -0.00 cannot be entered. This only has an effect on the displayed value. * Note that {@link getValue} doesn't return zero values with a leading dash either way, so it's not affected by this. */ allowNegativeZero(yes: boolean): void; }