@transferwise/components 0.0.0-experimental-c1fc9b6 → 0.0.0-experimental-3d0a13d
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/build/index.esm.js +252 -184
- package/build/index.esm.js.map +1 -1
- package/build/index.js +253 -185
- package/build/index.js.map +1 -1
- package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts +1 -1
- package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts.map +1 -1
- package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts +1 -2
- package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts.map +1 -1
- package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts +1 -5
- package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts.map +1 -1
- package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts +1 -1
- package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +11 -5
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/index.d.ts +1 -2
- package/build/types/inputWithDisplayFormat/index.d.ts.map +1 -1
- package/build/types/inputs/Input.d.ts +6 -8
- package/build/types/inputs/Input.d.ts.map +1 -1
- package/build/types/inputs/SelectInput.d.ts +2 -2
- package/build/types/inputs/SelectInput.d.ts.map +1 -1
- package/build/types/moneyInput/MoneyInput.d.ts +45 -31
- package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
- package/build/types/moneyInput/MoneyInput.messages.d.ts +6 -6
- package/build/types/moneyInput/MoneyInput.messages.d.ts.map +1 -1
- package/build/types/moneyInput/currencyFormatting.d.ts +2 -2
- package/build/types/moneyInput/currencyFormatting.d.ts.map +1 -1
- package/build/types/moneyInput/index.d.ts +2 -1
- package/build/types/moneyInput/index.d.ts.map +1 -1
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +11 -5
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
- package/build/types/textareaWithDisplayFormat/index.d.ts +1 -2
- package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +82 -55
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
- package/build/types/withDisplayFormat/index.d.ts +1 -2
- package/build/types/withDisplayFormat/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/textFormat/formatWithPattern/{formatWithPattern.ts → formatWithPattern.js} +4 -8
- package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.ts → getCursorPositionAfterKeystroke.js} +6 -7
- package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.ts → getSymbolsInPatternWithPosition.js} +2 -7
- package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.ts → unformatWithPattern.js} +2 -3
- package/src/index.ts +6 -2
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +14 -0
- package/src/inputWithDisplayFormat/index.js +1 -0
- package/src/inputs/Input.tsx +11 -6
- package/src/inputs/SelectInput.tsx +2 -2
- package/src/moneyInput/{MoneyInput.rtl.spec.js → MoneyInput.rtl.spec.tsx} +4 -4
- package/src/moneyInput/MoneyInput.spec.js +109 -49
- package/src/moneyInput/MoneyInput.story.tsx +6 -14
- package/src/moneyInput/{MoneyInput.js → MoneyInput.tsx} +189 -173
- package/src/moneyInput/{currencyFormatting.spec.js → currencyFormatting.spec.ts} +2 -2
- package/src/moneyInput/{currencyFormatting.js → currencyFormatting.ts} +7 -10
- package/src/moneyInput/index.ts +7 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +14 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +1 -3
- package/src/textareaWithDisplayFormat/index.js +1 -0
- package/src/withDisplayFormat/WithDisplayFormat.js +312 -0
- package/src/withDisplayFormat/index.js +1 -0
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +0 -11
- package/src/inputWithDisplayFormat/index.ts +0 -2
- package/src/moneyInput/index.js +0 -1
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +0 -30
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +0 -11
- package/src/textareaWithDisplayFormat/index.ts +0 -2
- package/src/withDisplayFormat/WithDisplayFormat.tsx +0 -303
- package/src/withDisplayFormat/index.ts +0 -2
- /package/src/moneyInput/{MoneyInput.messages.js → MoneyInput.messages.ts} +0 -0
package/build/index.js
CHANGED
|
@@ -1557,7 +1557,7 @@ class DimmerManager {
|
|
|
1557
1557
|
/**
|
|
1558
1558
|
* Dimmer refs
|
|
1559
1559
|
*/
|
|
1560
|
-
|
|
1560
|
+
dimmers;
|
|
1561
1561
|
constructor() {
|
|
1562
1562
|
this.dimmers = [];
|
|
1563
1563
|
}
|
|
@@ -5433,6 +5433,7 @@ var DynamicFieldDefinitionList$1 = DynamicFieldDefinitionList;
|
|
|
5433
5433
|
const ESCAPED_OPENING_CHEVRON = '<';
|
|
5434
5434
|
const ESCAPED_CLOSING_CHEVRON = '>';
|
|
5435
5435
|
class EmphasisHtmlTransformer {
|
|
5436
|
+
tags;
|
|
5436
5437
|
constructor(whitelistedTags) {
|
|
5437
5438
|
this.tags = (whitelistedTags || []).map(tag => {
|
|
5438
5439
|
return {
|
|
@@ -7296,13 +7297,10 @@ const formatWithPattern = (value, pattern) => {
|
|
|
7296
7297
|
let patternSymbol = [];
|
|
7297
7298
|
// valueArray.length increments during the cycle cause we are adding new elements.
|
|
7298
7299
|
for (let index = 0; index < valueArray.length; index += 1) {
|
|
7299
|
-
patternSymbol = patternWithSymbolsPosition.filter(
|
|
7300
|
+
patternSymbol = patternWithSymbolsPosition.filter(symbol => symbol.index === index);
|
|
7300
7301
|
// Add pattern's symbol at n position
|
|
7301
7302
|
if (patternSymbol.length === 1) {
|
|
7302
|
-
|
|
7303
|
-
if (last) {
|
|
7304
|
-
valueArray.splice(index, 0, last.symbol);
|
|
7305
|
-
}
|
|
7303
|
+
valueArray.splice(index, 0, patternSymbol.pop().symbol);
|
|
7306
7304
|
}
|
|
7307
7305
|
}
|
|
7308
7306
|
return valueArray.join('');
|
|
@@ -7373,31 +7371,33 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
|
|
|
7373
7371
|
var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
|
|
7374
7372
|
|
|
7375
7373
|
class WithDisplayFormat extends React.Component {
|
|
7376
|
-
static defaultProps = {
|
|
7377
|
-
autoComplete: 'off',
|
|
7378
|
-
displayPattern: '',
|
|
7379
|
-
type: 'text',
|
|
7380
|
-
value: ''
|
|
7381
|
-
};
|
|
7382
7374
|
constructor(props) {
|
|
7383
7375
|
super(props);
|
|
7384
|
-
const
|
|
7376
|
+
const {
|
|
7377
|
+
value,
|
|
7378
|
+
displayPattern
|
|
7379
|
+
} = props;
|
|
7380
|
+
const unformattedValue = unformatWithPattern$1(value, displayPattern);
|
|
7385
7381
|
this.state = {
|
|
7386
|
-
value: formatWithPattern$1(unformattedValue,
|
|
7382
|
+
value: formatWithPattern$1(unformattedValue, displayPattern),
|
|
7387
7383
|
historyNavigator: new HistoryNavigator$1(),
|
|
7388
7384
|
prevDisplayPattern: props.displayPattern,
|
|
7389
7385
|
triggerType: null,
|
|
7390
7386
|
triggerEvent: null
|
|
7391
7387
|
};
|
|
7392
7388
|
}
|
|
7393
|
-
static getDerivedStateFromProps({
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
if (prevDisplayPattern !== displayPattern) {
|
|
7389
|
+
static getDerivedStateFromProps(nextProps, previousState) {
|
|
7390
|
+
const {
|
|
7391
|
+
displayPattern
|
|
7392
|
+
} = nextProps;
|
|
7393
|
+
const {
|
|
7394
|
+
prevDisplayPattern
|
|
7395
|
+
} = previousState;
|
|
7396
|
+
if (previousState.prevDisplayPattern !== displayPattern) {
|
|
7397
|
+
const {
|
|
7398
|
+
value,
|
|
7399
|
+
historyNavigator
|
|
7400
|
+
} = previousState;
|
|
7401
7401
|
const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
|
|
7402
7402
|
historyNavigator.reset();
|
|
7403
7403
|
return {
|
|
@@ -7419,27 +7419,25 @@ class WithDisplayFormat extends React.Component {
|
|
|
7419
7419
|
const {
|
|
7420
7420
|
displayPattern
|
|
7421
7421
|
} = this.props;
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7422
|
+
const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
|
|
7423
|
+
if (triggerType === 'Paste' || triggerType === 'Cut') {
|
|
7424
|
+
return triggerType;
|
|
7425
|
+
}
|
|
7426
|
+
if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
|
|
7427
|
+
return triggerEvent.shiftKey ? 'Redo' : 'Undo';
|
|
7428
|
+
}
|
|
7429
|
+
// Detect mouse event redo
|
|
7430
|
+
if (triggerEvent.ctrlKey && charCode === 'd') {
|
|
7431
|
+
return 'Delete';
|
|
7432
|
+
}
|
|
7433
|
+
|
|
7434
|
+
// Android Fix.
|
|
7435
|
+
if (typeof triggerEvent.key === 'undefined') {
|
|
7436
|
+
if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
|
|
7436
7437
|
return 'Backspace';
|
|
7437
7438
|
}
|
|
7438
|
-
return triggerEvent.key;
|
|
7439
|
-
} else {
|
|
7440
|
-
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
7441
|
-
return 'Paste';
|
|
7442
7439
|
}
|
|
7440
|
+
return triggerEvent.key;
|
|
7443
7441
|
};
|
|
7444
7442
|
resetEvent = () => {
|
|
7445
7443
|
this.setState({
|
|
@@ -7467,6 +7465,7 @@ class WithDisplayFormat extends React.Component {
|
|
|
7467
7465
|
const {
|
|
7468
7466
|
displayPattern
|
|
7469
7467
|
} = this.props;
|
|
7468
|
+
|
|
7470
7469
|
// Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
|
|
7471
7470
|
let newFormattedValue = '';
|
|
7472
7471
|
if (this.detectUndoRedo(event) === 'Undo') {
|
|
@@ -7515,6 +7514,7 @@ class WithDisplayFormat extends React.Component {
|
|
|
7515
7514
|
handleOnChange = event => {
|
|
7516
7515
|
const {
|
|
7517
7516
|
historyNavigator,
|
|
7517
|
+
triggerEvent,
|
|
7518
7518
|
triggerType
|
|
7519
7519
|
} = this.state;
|
|
7520
7520
|
const {
|
|
@@ -7525,7 +7525,9 @@ class WithDisplayFormat extends React.Component {
|
|
|
7525
7525
|
value
|
|
7526
7526
|
} = event.target;
|
|
7527
7527
|
let unformattedValue = unformatWithPattern$1(value, displayPattern);
|
|
7528
|
-
const action =
|
|
7528
|
+
const action = triggerEvent === null ?
|
|
7529
|
+
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
7530
|
+
'Paste' : this.getUserAction(unformattedValue);
|
|
7529
7531
|
if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
|
|
7530
7532
|
return;
|
|
7531
7533
|
}
|
|
@@ -7535,18 +7537,19 @@ class WithDisplayFormat extends React.Component {
|
|
|
7535
7537
|
const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
|
|
7536
7538
|
historyNavigator.add(unformattedValue);
|
|
7537
7539
|
this.handleCursorPositioning(action);
|
|
7540
|
+
const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
|
|
7538
7541
|
this.setState({
|
|
7539
7542
|
value: newFormattedValue
|
|
7540
|
-
}, ()
|
|
7541
|
-
this.resetEvent();
|
|
7542
|
-
if (onChange) {
|
|
7543
|
-
const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
|
|
7544
|
-
onChange(broadcastValue);
|
|
7545
|
-
}
|
|
7546
|
-
});
|
|
7543
|
+
}, this.resetEvent(), onChange(broadcastValue));
|
|
7547
7544
|
};
|
|
7548
7545
|
handleOnBlur = event => {
|
|
7549
|
-
|
|
7546
|
+
const {
|
|
7547
|
+
displayPattern,
|
|
7548
|
+
onBlur
|
|
7549
|
+
} = this.props;
|
|
7550
|
+
if (onBlur) {
|
|
7551
|
+
onBlur(unformatWithPattern$1(event.target.value, displayPattern));
|
|
7552
|
+
}
|
|
7550
7553
|
};
|
|
7551
7554
|
handleOnFocus = event => {
|
|
7552
7555
|
const {
|
|
@@ -7604,36 +7607,103 @@ class WithDisplayFormat extends React.Component {
|
|
|
7604
7607
|
}, 0);
|
|
7605
7608
|
};
|
|
7606
7609
|
render() {
|
|
7607
|
-
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7610
|
+
const {
|
|
7611
|
+
type,
|
|
7612
|
+
inputMode,
|
|
7613
|
+
className,
|
|
7614
|
+
id,
|
|
7615
|
+
name,
|
|
7616
|
+
placeholder,
|
|
7617
|
+
readOnly,
|
|
7618
|
+
required,
|
|
7619
|
+
minLength,
|
|
7620
|
+
maxLength,
|
|
7621
|
+
disabled,
|
|
7622
|
+
autoComplete
|
|
7623
|
+
} = this.props;
|
|
7624
|
+
const {
|
|
7625
|
+
value
|
|
7626
|
+
} = this.state;
|
|
7627
|
+
const renderProps = {
|
|
7628
|
+
type,
|
|
7629
|
+
inputMode,
|
|
7630
|
+
className,
|
|
7631
|
+
id,
|
|
7632
|
+
name,
|
|
7633
|
+
placeholder,
|
|
7634
|
+
readOnly,
|
|
7635
|
+
required,
|
|
7636
|
+
minLength,
|
|
7637
|
+
maxLength,
|
|
7638
|
+
disabled,
|
|
7639
|
+
autoComplete,
|
|
7640
|
+
value,
|
|
7621
7641
|
onFocus: this.handleOnFocus,
|
|
7622
7642
|
onBlur: this.handleOnBlur,
|
|
7623
7643
|
onPaste: this.handleOnPaste,
|
|
7624
7644
|
onKeyDown: this.handleOnKeyDown,
|
|
7625
7645
|
onChange: this.handleOnChange,
|
|
7626
7646
|
onCut: this.handleOnCut
|
|
7627
|
-
}
|
|
7647
|
+
};
|
|
7648
|
+
return this.props.render(renderProps);
|
|
7628
7649
|
}
|
|
7629
7650
|
}
|
|
7651
|
+
WithDisplayFormat.propTypes = {
|
|
7652
|
+
/**
|
|
7653
|
+
* autocomplete hides our form help so we need to disable it when help text
|
|
7654
|
+
* is present. Chrome ignores autocomplete=off, the only way to disable it is
|
|
7655
|
+
* to provide an 'invalid' value, for which 'disabled' serves.
|
|
7656
|
+
*/
|
|
7657
|
+
autoComplete: PropTypes__default.default.oneOf(['on', 'off', 'disabled']),
|
|
7658
|
+
className: PropTypes__default.default.string,
|
|
7659
|
+
disabled: PropTypes__default.default.bool,
|
|
7660
|
+
id: PropTypes__default.default.string,
|
|
7661
|
+
maxLength: PropTypes__default.default.number,
|
|
7662
|
+
minLength: PropTypes__default.default.number,
|
|
7663
|
+
name: PropTypes__default.default.string,
|
|
7664
|
+
onFocus: PropTypes__default.default.func,
|
|
7665
|
+
onBlur: PropTypes__default.default.func,
|
|
7666
|
+
onChange: PropTypes__default.default.func.isRequired,
|
|
7667
|
+
placeholder: PropTypes__default.default.string,
|
|
7668
|
+
readOnly: PropTypes__default.default.bool,
|
|
7669
|
+
render: PropTypes__default.default.func.isRequired,
|
|
7670
|
+
required: PropTypes__default.default.bool,
|
|
7671
|
+
displayPattern: PropTypes__default.default.string,
|
|
7672
|
+
type: PropTypes__default.default.string,
|
|
7673
|
+
inputMode: PropTypes__default.default.string,
|
|
7674
|
+
value: PropTypes__default.default.string
|
|
7675
|
+
};
|
|
7676
|
+
WithDisplayFormat.defaultProps = {
|
|
7677
|
+
autoComplete: 'off',
|
|
7678
|
+
className: null,
|
|
7679
|
+
disabled: false,
|
|
7680
|
+
id: null,
|
|
7681
|
+
maxLength: null,
|
|
7682
|
+
minLength: null,
|
|
7683
|
+
name: null,
|
|
7684
|
+
placeholder: null,
|
|
7685
|
+
readOnly: false,
|
|
7686
|
+
required: false,
|
|
7687
|
+
displayPattern: '',
|
|
7688
|
+
type: 'text',
|
|
7689
|
+
inputMode: null,
|
|
7690
|
+
value: '',
|
|
7691
|
+
onFocus: null,
|
|
7692
|
+
onBlur: null
|
|
7693
|
+
};
|
|
7694
|
+
var WithDisplayFormat$1 = WithDisplayFormat;
|
|
7630
7695
|
|
|
7631
|
-
const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
|
|
7696
|
+
const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat$1, {
|
|
7632
7697
|
...props,
|
|
7633
|
-
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(
|
|
7698
|
+
render: renderProps => /*#__PURE__*/jsxRuntime.jsx("input", {
|
|
7634
7699
|
...renderProps
|
|
7635
7700
|
})
|
|
7636
7701
|
});
|
|
7702
|
+
InputWithDisplayFormat.propTypes = {
|
|
7703
|
+
displayPattern: PropTypes__default.default.string.isRequired,
|
|
7704
|
+
onChange: PropTypes__default.default.func.isRequired
|
|
7705
|
+
};
|
|
7706
|
+
var InputWithDisplayFormat$1 = InputWithDisplayFormat;
|
|
7637
7707
|
|
|
7638
7708
|
const InstructionsList = ({
|
|
7639
7709
|
dos,
|
|
@@ -7797,20 +7867,17 @@ function getValidLocale(locale) {
|
|
|
7797
7867
|
Intl.NumberFormat(noUnderscoreLocale);
|
|
7798
7868
|
return noUnderscoreLocale;
|
|
7799
7869
|
} catch {
|
|
7800
|
-
return
|
|
7870
|
+
return DEFAULT_LOCALE;
|
|
7801
7871
|
}
|
|
7802
7872
|
}
|
|
7803
|
-
function getCurrencyDecimals(currency
|
|
7873
|
+
function getCurrencyDecimals(currency) {
|
|
7804
7874
|
const upperCaseCurrency = currency.toUpperCase();
|
|
7805
|
-
|
|
7806
|
-
return currencyDecimals[upperCaseCurrency];
|
|
7807
|
-
}
|
|
7808
|
-
return DEFAULT_CURRENCY_DECIMALS;
|
|
7875
|
+
return currencyDecimals[upperCaseCurrency] ?? DEFAULT_CURRENCY_DECIMALS;
|
|
7809
7876
|
}
|
|
7810
7877
|
function getDecimalSeparator(locale) {
|
|
7811
7878
|
return isNumberLocaleSupported() ? 1.1.toLocaleString(locale)[1] : '.';
|
|
7812
7879
|
}
|
|
7813
|
-
function parseAmount(number, currency, locale) {
|
|
7880
|
+
function parseAmount(number, currency, locale = DEFAULT_LOCALE) {
|
|
7814
7881
|
const validLocale = getValidLocale(locale);
|
|
7815
7882
|
const precision = getCurrencyDecimals(currency);
|
|
7816
7883
|
const groupSeparator = isNumberLocaleSupported() ? 10000 .toLocaleString(validLocale)[2] : ',';
|
|
@@ -7820,53 +7887,67 @@ function parseAmount(number, currency, locale) {
|
|
|
7820
7887
|
return Math.abs(parsedAmount);
|
|
7821
7888
|
}
|
|
7822
7889
|
|
|
7823
|
-
const Currency = PropTypes__default.default.shape({
|
|
7824
|
-
header: PropTypes__default.default.string,
|
|
7825
|
-
value: PropTypes__default.default.string,
|
|
7826
|
-
label: PropTypes__default.default.string,
|
|
7827
|
-
currency: PropTypes__default.default.string,
|
|
7828
|
-
note: PropTypes__default.default.string,
|
|
7829
|
-
searchable: PropTypes__default.default.string
|
|
7830
|
-
});
|
|
7831
7890
|
const isNumberOrNull = v => neptuneValidation.isNumber(v) || neptuneValidation.isNull(v);
|
|
7832
|
-
const formatAmountIfSet = (
|
|
7891
|
+
const formatAmountIfSet = ({
|
|
7892
|
+
amount,
|
|
7893
|
+
currency,
|
|
7894
|
+
locale,
|
|
7895
|
+
maxLengthOverride
|
|
7896
|
+
}) => {
|
|
7833
7897
|
if (maxLengthOverride) {
|
|
7834
|
-
return amount
|
|
7898
|
+
return amount != null ? String(amount) : '';
|
|
7835
7899
|
} else {
|
|
7836
7900
|
return typeof amount === 'number' ? formatting.formatAmount(amount, currency, locale) : '';
|
|
7837
7901
|
}
|
|
7838
7902
|
};
|
|
7839
|
-
const parseNumber = (
|
|
7903
|
+
const parseNumber = ({
|
|
7904
|
+
amount,
|
|
7905
|
+
currency,
|
|
7906
|
+
locale,
|
|
7907
|
+
maxLengthOverride
|
|
7908
|
+
}) => {
|
|
7840
7909
|
if (!maxLengthOverride) {
|
|
7841
7910
|
return parseAmount(amount, currency, locale);
|
|
7842
7911
|
}
|
|
7843
7912
|
if (maxLengthOverride && amount.length > maxLengthOverride) {
|
|
7844
7913
|
return 0;
|
|
7845
7914
|
}
|
|
7846
|
-
return
|
|
7915
|
+
return Number(amount);
|
|
7847
7916
|
};
|
|
7848
7917
|
const inputKeyCodeAllowlist = new Set([KeyCodes.BACKSPACE, KeyCodes.DELETE, KeyCodes.COMMA, KeyCodes.PERIOD, KeyCodes.DOWN, KeyCodes.UP, KeyCodes.LEFT, KeyCodes.RIGHT, KeyCodes.ENTER, KeyCodes.ESCAPE, KeyCodes.TAB]);
|
|
7849
7918
|
const inputKeyAllowlist = new Set([Key.PERIOD, Key.COMMA]);
|
|
7850
7919
|
class MoneyInput extends React.Component {
|
|
7920
|
+
static defaultProps = {
|
|
7921
|
+
size: exports.Size.LARGE,
|
|
7922
|
+
classNames: {},
|
|
7923
|
+
selectProps: {}
|
|
7924
|
+
};
|
|
7925
|
+
amountFocused = false;
|
|
7851
7926
|
constructor(props) {
|
|
7852
7927
|
super(props);
|
|
7853
|
-
const {
|
|
7854
|
-
locale
|
|
7855
|
-
} = this.props.intl;
|
|
7856
|
-
this.formatMessage = this.props.intl.formatMessage;
|
|
7857
7928
|
this.state = {
|
|
7858
7929
|
searchQuery: '',
|
|
7859
|
-
formattedAmount: formatAmountIfSet(
|
|
7860
|
-
|
|
7930
|
+
formattedAmount: formatAmountIfSet({
|
|
7931
|
+
amount: props.amount,
|
|
7932
|
+
currency: props.selectedCurrency.currency,
|
|
7933
|
+
locale: props.intl.locale,
|
|
7934
|
+
maxLengthOverride: props.maxLengthOverride
|
|
7935
|
+
}),
|
|
7936
|
+
locale: props.intl.locale
|
|
7861
7937
|
};
|
|
7862
7938
|
}
|
|
7863
7939
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
7864
7940
|
this.setState({
|
|
7865
|
-
locale: nextProps
|
|
7941
|
+
locale: nextProps.intl.locale
|
|
7866
7942
|
});
|
|
7867
7943
|
if (!this.amountFocused) {
|
|
7868
7944
|
this.setState({
|
|
7869
|
-
formattedAmount: formatAmountIfSet(
|
|
7945
|
+
formattedAmount: formatAmountIfSet({
|
|
7946
|
+
amount: nextProps.amount,
|
|
7947
|
+
currency: nextProps.selectedCurrency.currency,
|
|
7948
|
+
locale: nextProps.intl.locale,
|
|
7949
|
+
maxLengthOverride: nextProps.maxLengthOverride
|
|
7950
|
+
})
|
|
7870
7951
|
});
|
|
7871
7952
|
}
|
|
7872
7953
|
}
|
|
@@ -7886,16 +7967,26 @@ class MoneyInput extends React.Component {
|
|
|
7886
7967
|
}
|
|
7887
7968
|
};
|
|
7888
7969
|
handlePaste = event => {
|
|
7889
|
-
const paste =
|
|
7970
|
+
const paste = event.clipboardData.getData('text');
|
|
7890
7971
|
const {
|
|
7891
7972
|
locale
|
|
7892
7973
|
} = this.state;
|
|
7893
|
-
const parsed = neptuneValidation.isEmpty(paste) ? null : parseNumber(
|
|
7974
|
+
const parsed = neptuneValidation.isEmpty(paste) ? null : parseNumber({
|
|
7975
|
+
amount: paste,
|
|
7976
|
+
currency: this.props.selectedCurrency.currency,
|
|
7977
|
+
locale: locale,
|
|
7978
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
7979
|
+
});
|
|
7894
7980
|
if (isNumberOrNull(parsed)) {
|
|
7895
7981
|
this.setState({
|
|
7896
|
-
formattedAmount: formatAmountIfSet(
|
|
7982
|
+
formattedAmount: formatAmountIfSet({
|
|
7983
|
+
amount: parsed,
|
|
7984
|
+
currency: this.props.selectedCurrency.currency,
|
|
7985
|
+
locale: locale,
|
|
7986
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
7987
|
+
})
|
|
7897
7988
|
});
|
|
7898
|
-
this.props.onAmountChange(parsed);
|
|
7989
|
+
this.props.onAmountChange?.(parsed);
|
|
7899
7990
|
}
|
|
7900
7991
|
event.preventDefault();
|
|
7901
7992
|
};
|
|
@@ -7906,9 +7997,14 @@ class MoneyInput extends React.Component {
|
|
|
7906
7997
|
this.setState({
|
|
7907
7998
|
formattedAmount: value
|
|
7908
7999
|
});
|
|
7909
|
-
const parsed = neptuneValidation.isEmpty(value) ? null : parseNumber(
|
|
8000
|
+
const parsed = neptuneValidation.isEmpty(value) ? null : parseNumber({
|
|
8001
|
+
amount: value,
|
|
8002
|
+
currency: this.props.selectedCurrency.currency,
|
|
8003
|
+
locale: this.state.locale,
|
|
8004
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
8005
|
+
});
|
|
7910
8006
|
if (isNumberOrNull(parsed)) {
|
|
7911
|
-
this.props.onAmountChange(parsed);
|
|
8007
|
+
this.props.onAmountChange?.(parsed);
|
|
7912
8008
|
}
|
|
7913
8009
|
};
|
|
7914
8010
|
onAmountBlur = () => {
|
|
@@ -7918,68 +8014,67 @@ class MoneyInput extends React.Component {
|
|
|
7918
8014
|
onAmountFocus = () => {
|
|
7919
8015
|
this.amountFocused = true;
|
|
7920
8016
|
};
|
|
7921
|
-
mapOption = item => {
|
|
7922
|
-
return {
|
|
7923
|
-
type: 'option',
|
|
7924
|
-
value: item,
|
|
7925
|
-
filterMatchers: [item.value, item.label, item.note, item.searchable]
|
|
7926
|
-
};
|
|
7927
|
-
};
|
|
7928
8017
|
getSelectOptions() {
|
|
7929
|
-
const selectOptions =
|
|
7930
|
-
|
|
7931
|
-
let
|
|
8018
|
+
const selectOptions = filterCurrenciesForQuery(this.props.currencies, this.state.searchQuery);
|
|
8019
|
+
const formattedOptions = [];
|
|
8020
|
+
let currentGroupOptions;
|
|
7932
8021
|
selectOptions.forEach(item => {
|
|
7933
|
-
if (item.header) {
|
|
8022
|
+
if (item.header != null) {
|
|
8023
|
+
currentGroupOptions = [];
|
|
7934
8024
|
formattedOptions.push({
|
|
7935
8025
|
type: 'group',
|
|
7936
8026
|
label: item.header,
|
|
7937
|
-
options:
|
|
8027
|
+
options: currentGroupOptions
|
|
7938
8028
|
});
|
|
7939
|
-
groupIndex = formattedOptions.length - 1;
|
|
7940
8029
|
} else {
|
|
7941
|
-
|
|
7942
|
-
|
|
7943
|
-
|
|
7944
|
-
|
|
7945
|
-
}
|
|
8030
|
+
(currentGroupOptions ?? formattedOptions).push({
|
|
8031
|
+
type: 'option',
|
|
8032
|
+
value: item,
|
|
8033
|
+
filterMatchers: [item.value, item.label, item.note ?? '', item.searchable ?? '']
|
|
8034
|
+
});
|
|
7946
8035
|
}
|
|
7947
8036
|
});
|
|
7948
8037
|
return formattedOptions;
|
|
7949
8038
|
}
|
|
7950
8039
|
setAmount() {
|
|
7951
8040
|
this.setState(previousState => {
|
|
7952
|
-
const parsed = parseNumber(
|
|
8041
|
+
const parsed = parseNumber({
|
|
8042
|
+
amount: previousState.formattedAmount,
|
|
8043
|
+
currency: this.props.selectedCurrency.currency,
|
|
8044
|
+
locale: previousState.locale,
|
|
8045
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
8046
|
+
});
|
|
7953
8047
|
if (!isNumberOrNull(parsed)) {
|
|
7954
8048
|
return {
|
|
7955
8049
|
formattedAmount: previousState.formattedAmount
|
|
7956
8050
|
};
|
|
7957
8051
|
}
|
|
7958
8052
|
return {
|
|
7959
|
-
formattedAmount: formatAmountIfSet(
|
|
8053
|
+
formattedAmount: formatAmountIfSet({
|
|
8054
|
+
amount: parsed,
|
|
8055
|
+
currency: this.props.selectedCurrency.currency,
|
|
8056
|
+
locale: previousState.locale,
|
|
8057
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
8058
|
+
})
|
|
7960
8059
|
};
|
|
7961
8060
|
});
|
|
7962
8061
|
}
|
|
7963
8062
|
handleSelectChange = value => {
|
|
7964
8063
|
this.handleSearchChange('');
|
|
7965
|
-
this.props.onCurrencyChange(value);
|
|
8064
|
+
this.props.onCurrencyChange?.(value);
|
|
7966
8065
|
};
|
|
7967
8066
|
handleCustomAction = () => {
|
|
7968
8067
|
this.handleSearchChange('');
|
|
7969
|
-
|
|
7970
|
-
this.props.onCustomAction();
|
|
7971
|
-
}
|
|
8068
|
+
this.props.onCustomAction?.();
|
|
7972
8069
|
};
|
|
7973
8070
|
handleSearchChange = searchQuery => {
|
|
7974
8071
|
this.setState({
|
|
7975
8072
|
searchQuery
|
|
7976
8073
|
});
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
});
|
|
7982
|
-
}
|
|
8074
|
+
this.props.onSearchChange?.({
|
|
8075
|
+
searchQuery,
|
|
8076
|
+
filteredOptions: filterCurrenciesForQuery(this.props.currencies, searchQuery)
|
|
8077
|
+
});
|
|
7983
8078
|
};
|
|
7984
8079
|
style = className => this.props.classNames[className] || className;
|
|
7985
8080
|
render() {
|
|
@@ -8019,7 +8114,12 @@ class MoneyInput extends React.Component {
|
|
|
8019
8114
|
inputMode: "decimal",
|
|
8020
8115
|
disabled: disabled,
|
|
8021
8116
|
maxLength: maxLengthOverride,
|
|
8022
|
-
placeholder: formatAmountIfSet(
|
|
8117
|
+
placeholder: formatAmountIfSet({
|
|
8118
|
+
amount: this.props.placeholder,
|
|
8119
|
+
currency: this.props.selectedCurrency.currency,
|
|
8120
|
+
locale: this.state.locale,
|
|
8121
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
8122
|
+
}),
|
|
8023
8123
|
autoComplete: "off",
|
|
8024
8124
|
onKeyDown: this.handleKeyDown,
|
|
8025
8125
|
onChange: this.onAmountChange,
|
|
@@ -8064,11 +8164,11 @@ class MoneyInput extends React.Component {
|
|
|
8064
8164
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
|
|
8065
8165
|
jsxRuntime.jsx("div", {
|
|
8066
8166
|
role: "button",
|
|
8067
|
-
tabIndex:
|
|
8167
|
+
tabIndex: 0,
|
|
8068
8168
|
onClick: this.handleCustomAction,
|
|
8069
8169
|
children: this.props.customActionLabel
|
|
8070
|
-
}) :
|
|
8071
|
-
placeholder: this.formatMessage(messages$3.selectPlaceholder),
|
|
8170
|
+
}) : undefined,
|
|
8171
|
+
placeholder: this.props.intl.formatMessage(messages$3.selectPlaceholder),
|
|
8072
8172
|
filterable: true,
|
|
8073
8173
|
filterPlaceholder: this.props.searchPlaceholder,
|
|
8074
8174
|
disabled: disabled,
|
|
@@ -8085,25 +8185,25 @@ class MoneyInput extends React.Component {
|
|
|
8085
8185
|
});
|
|
8086
8186
|
}
|
|
8087
8187
|
}
|
|
8088
|
-
function
|
|
8188
|
+
function filterCurrenciesForQuery(currencies, query) {
|
|
8089
8189
|
if (!query) {
|
|
8090
|
-
return
|
|
8190
|
+
return [...currencies];
|
|
8091
8191
|
}
|
|
8092
|
-
const
|
|
8192
|
+
const options = currencies.filter(option => option.header == null);
|
|
8193
|
+
const filteredOptions = removeDuplicateValueOptions(options).filter(option => currencyOptionFitsQuery(option, query));
|
|
8093
8194
|
return sortOptionsLabelsToFirst(filteredOptions, query);
|
|
8094
8195
|
}
|
|
8095
8196
|
function removeDuplicateValueOptions(options) {
|
|
8096
|
-
const
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
resultValues.push(option.value);
|
|
8197
|
+
const uniqueValues = new Set();
|
|
8198
|
+
return options.filter(option => {
|
|
8199
|
+
if (!uniqueValues.has(option.value)) {
|
|
8200
|
+
uniqueValues.add(option.value);
|
|
8201
|
+
return true;
|
|
8102
8202
|
}
|
|
8203
|
+
return false;
|
|
8103
8204
|
});
|
|
8104
|
-
return result;
|
|
8105
8205
|
}
|
|
8106
|
-
function
|
|
8206
|
+
function currencyOptionFitsQuery(option, query) {
|
|
8107
8207
|
if (!option.value) {
|
|
8108
8208
|
return false;
|
|
8109
8209
|
}
|
|
@@ -8128,43 +8228,6 @@ function sortOptionsLabelsToFirst(options, query) {
|
|
|
8128
8228
|
return 0;
|
|
8129
8229
|
});
|
|
8130
8230
|
}
|
|
8131
|
-
MoneyInput.propTypes = {
|
|
8132
|
-
id: PropTypes__default.default.string,
|
|
8133
|
-
currencies: PropTypes__default.default.arrayOf(Currency).isRequired,
|
|
8134
|
-
selectedCurrency: Currency.isRequired,
|
|
8135
|
-
onCurrencyChange: PropTypes__default.default.func,
|
|
8136
|
-
placeholder: PropTypes__default.default.number,
|
|
8137
|
-
amount: PropTypes__default.default.number,
|
|
8138
|
-
size: PropTypes__default.default.oneOf(['sm', 'md', 'lg']),
|
|
8139
|
-
onAmountChange: PropTypes__default.default.func,
|
|
8140
|
-
addon: PropTypes__default.default.node,
|
|
8141
|
-
searchPlaceholder: PropTypes__default.default.string,
|
|
8142
|
-
/**
|
|
8143
|
-
* Allows the consumer to react to searching, while the search itself is handled internally. Called with `{ searchQuery: string, filteredOptions: Currency[] }`
|
|
8144
|
-
*/
|
|
8145
|
-
onSearchChange: PropTypes__default.default.func,
|
|
8146
|
-
customActionLabel: PropTypes__default.default.node,
|
|
8147
|
-
onCustomAction: PropTypes__default.default.func,
|
|
8148
|
-
classNames: PropTypes__default.default.objectOf(PropTypes__default.default.string),
|
|
8149
|
-
selectProps: PropTypes__default.default.object,
|
|
8150
|
-
maxLengthOverride: PropTypes__default.default.number
|
|
8151
|
-
};
|
|
8152
|
-
MoneyInput.defaultProps = {
|
|
8153
|
-
id: null,
|
|
8154
|
-
size: exports.Size.LARGE,
|
|
8155
|
-
addon: null,
|
|
8156
|
-
searchPlaceholder: '',
|
|
8157
|
-
onSearchChange: undefined,
|
|
8158
|
-
onCurrencyChange: null,
|
|
8159
|
-
placeholder: null,
|
|
8160
|
-
amount: null,
|
|
8161
|
-
onAmountChange: null,
|
|
8162
|
-
customActionLabel: '',
|
|
8163
|
-
onCustomAction: null,
|
|
8164
|
-
classNames: {},
|
|
8165
|
-
selectProps: {},
|
|
8166
|
-
maxLengthOverride: null
|
|
8167
|
-
};
|
|
8168
8231
|
var MoneyInput$1 = reactIntl.injectIntl(MoneyInput);
|
|
8169
8232
|
|
|
8170
8233
|
const NavigationOptionList = ({
|
|
@@ -12317,12 +12380,17 @@ Tabs.defaultProps = {
|
|
|
12317
12380
|
};
|
|
12318
12381
|
var Tabs$1 = Tabs;
|
|
12319
12382
|
|
|
12320
|
-
const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
|
|
12383
|
+
const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat$1, {
|
|
12321
12384
|
...props,
|
|
12322
|
-
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(
|
|
12385
|
+
render: renderProps => /*#__PURE__*/jsxRuntime.jsx("textarea", {
|
|
12323
12386
|
...renderProps
|
|
12324
12387
|
})
|
|
12325
12388
|
});
|
|
12389
|
+
TextareaWithDisplayFormat.propTypes = {
|
|
12390
|
+
displayPattern: PropTypes__default.default.string.isRequired,
|
|
12391
|
+
onChange: PropTypes__default.default.func.isRequired
|
|
12392
|
+
};
|
|
12393
|
+
var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
|
|
12326
12394
|
|
|
12327
12395
|
/* eslint-disable jsx-a11y/no-autofocus */
|
|
12328
12396
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
@@ -15659,7 +15727,7 @@ exports.Info = Info;
|
|
|
15659
15727
|
exports.InlineAlert = InlineAlert;
|
|
15660
15728
|
exports.Input = Input;
|
|
15661
15729
|
exports.InputGroup = InputGroup;
|
|
15662
|
-
exports.InputWithDisplayFormat = InputWithDisplayFormat;
|
|
15730
|
+
exports.InputWithDisplayFormat = InputWithDisplayFormat$1;
|
|
15663
15731
|
exports.InstructionsList = InstructionsList$1;
|
|
15664
15732
|
exports.LanguageProvider = LanguageProvider;
|
|
15665
15733
|
exports.Link = Link;
|
|
@@ -15707,7 +15775,7 @@ exports.Switch = Switch;
|
|
|
15707
15775
|
exports.SwitchOption = SwitchOption;
|
|
15708
15776
|
exports.Tabs = Tabs$1;
|
|
15709
15777
|
exports.TextArea = TextArea;
|
|
15710
|
-
exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat;
|
|
15778
|
+
exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat$1;
|
|
15711
15779
|
exports.Title = Title;
|
|
15712
15780
|
exports.Tooltip = Tooltip$1;
|
|
15713
15781
|
exports.Typeahead = Typeahead;
|