@transferwise/components 46.4.0 → 46.6.0
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/i18n/th.json +3 -3
- package/build/index.esm.js +177 -239
- package/build/index.esm.js.map +1 -1
- package/build/index.js +178 -240
- 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 +2 -2
- package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts.map +1 -1
- package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts +5 -1
- 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 +3 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +7 -11
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/index.d.ts +2 -1
- package/build/types/inputWithDisplayFormat/index.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 +7 -11
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
- package/build/types/textareaWithDisplayFormat/index.d.ts +2 -1
- package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +55 -83
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
- package/build/types/withDisplayFormat/index.d.ts +2 -1
- package/build/types/withDisplayFormat/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/textFormat/formatWithPattern/{formatWithPattern.js → formatWithPattern.ts} +8 -4
- package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.js → getCursorPositionAfterKeystroke.ts} +8 -8
- package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.js → getSymbolsInPatternWithPosition.ts} +7 -2
- package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.js → unformatWithPattern.ts} +3 -2
- package/src/flowNavigation/FlowNavigation.story.js +1 -1
- package/src/i18n/th.json +3 -3
- package/src/index.ts +8 -0
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +10 -0
- package/src/inputWithDisplayFormat/index.ts +2 -0
- 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.spec.js +3 -1
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +32 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +13 -0
- package/src/textareaWithDisplayFormat/index.ts +2 -0
- package/src/withDisplayFormat/WithDisplayFormat.spec.js +1 -1
- package/src/withDisplayFormat/{WithDisplayFormat.js → WithDisplayFormat.tsx} +127 -107
- package/src/withDisplayFormat/index.ts +2 -0
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +0 -14
- package/src/inputWithDisplayFormat/index.js +0 -1
- package/src/moneyInput/index.js +0 -1
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +0 -14
- package/src/textareaWithDisplayFormat/index.js +0 -1
- package/src/withDisplayFormat/index.js +0 -1
- /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,10 +7297,13 @@ 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(pattern => pattern.index === index);
|
|
7300
7301
|
// Add pattern's symbol at n position
|
|
7301
7302
|
if (patternSymbol.length === 1) {
|
|
7302
|
-
|
|
7303
|
+
const last = patternSymbol.pop();
|
|
7304
|
+
if (last) {
|
|
7305
|
+
valueArray.splice(index, 0, last.symbol);
|
|
7306
|
+
}
|
|
7303
7307
|
}
|
|
7304
7308
|
}
|
|
7305
7309
|
return valueArray.join('');
|
|
@@ -7345,7 +7349,7 @@ const countConsecutiveSymbols = (selectionStart, applicablePattern, direction) =
|
|
|
7345
7349
|
return groupSize;
|
|
7346
7350
|
};
|
|
7347
7351
|
|
|
7348
|
-
const
|
|
7352
|
+
const getCursorPositionAfterActionStroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
|
|
7349
7353
|
let cursorPosition = selectionStart;
|
|
7350
7354
|
switch (action) {
|
|
7351
7355
|
case 'Backspace':
|
|
@@ -7367,36 +7371,36 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
|
|
|
7367
7371
|
}
|
|
7368
7372
|
return cursorPosition;
|
|
7369
7373
|
};
|
|
7370
|
-
var getCursorPositionAfterKeystroke =
|
|
7374
|
+
var getCursorPositionAfterKeystroke = getCursorPositionAfterActionStroke;
|
|
7371
7375
|
|
|
7372
7376
|
class WithDisplayFormat extends React.Component {
|
|
7377
|
+
static defaultProps = {
|
|
7378
|
+
autoComplete: 'off',
|
|
7379
|
+
displayPattern: '',
|
|
7380
|
+
value: ''
|
|
7381
|
+
};
|
|
7373
7382
|
constructor(props) {
|
|
7374
7383
|
super(props);
|
|
7375
|
-
const
|
|
7376
|
-
value,
|
|
7377
|
-
displayPattern
|
|
7378
|
-
} = props;
|
|
7379
|
-
const unformattedValue = unformatWithPattern$1(value, displayPattern);
|
|
7384
|
+
const unformattedValue = unformatWithPattern$1(props.value ?? '', props.displayPattern);
|
|
7380
7385
|
this.state = {
|
|
7381
|
-
value: formatWithPattern$1(unformattedValue, displayPattern),
|
|
7386
|
+
value: formatWithPattern$1(unformattedValue, props.displayPattern),
|
|
7382
7387
|
historyNavigator: new HistoryNavigator$1(),
|
|
7383
7388
|
prevDisplayPattern: props.displayPattern,
|
|
7384
|
-
triggerType:
|
|
7385
|
-
triggerEvent: null
|
|
7389
|
+
triggerType: 'Initial',
|
|
7390
|
+
triggerEvent: null,
|
|
7391
|
+
selectionStart: 0,
|
|
7392
|
+
selectionEnd: 0,
|
|
7393
|
+
pastedLength: 0
|
|
7386
7394
|
};
|
|
7387
7395
|
}
|
|
7388
|
-
static getDerivedStateFromProps(
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
if (
|
|
7396
|
-
const {
|
|
7397
|
-
value,
|
|
7398
|
-
historyNavigator
|
|
7399
|
-
} = previousState;
|
|
7396
|
+
static getDerivedStateFromProps({
|
|
7397
|
+
displayPattern
|
|
7398
|
+
}, {
|
|
7399
|
+
prevDisplayPattern = displayPattern,
|
|
7400
|
+
value,
|
|
7401
|
+
historyNavigator
|
|
7402
|
+
}) {
|
|
7403
|
+
if (prevDisplayPattern !== displayPattern) {
|
|
7400
7404
|
const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
|
|
7401
7405
|
historyNavigator.reset();
|
|
7402
7406
|
return {
|
|
@@ -7418,29 +7422,31 @@ class WithDisplayFormat extends React.Component {
|
|
|
7418
7422
|
const {
|
|
7419
7423
|
displayPattern
|
|
7420
7424
|
} = this.props;
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
|
|
7425
|
+
if (triggerEvent) {
|
|
7426
|
+
const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
|
|
7427
|
+
if (triggerType === 'Paste' || triggerType === 'Cut') {
|
|
7428
|
+
return triggerType;
|
|
7429
|
+
}
|
|
7430
|
+
if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
|
|
7431
|
+
return triggerEvent.shiftKey ? 'Redo' : 'Undo';
|
|
7432
|
+
}
|
|
7433
|
+
// Detect mouse event redo
|
|
7434
|
+
if (triggerEvent.ctrlKey && charCode === 'd') {
|
|
7435
|
+
return 'Delete';
|
|
7436
|
+
}
|
|
7437
|
+
// Android Fix.
|
|
7438
|
+
if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
|
|
7436
7439
|
return 'Backspace';
|
|
7437
7440
|
}
|
|
7441
|
+
return triggerEvent.key;
|
|
7442
|
+
} else {
|
|
7443
|
+
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
7444
|
+
return 'Paste';
|
|
7438
7445
|
}
|
|
7439
|
-
return triggerEvent.key;
|
|
7440
7446
|
};
|
|
7441
7447
|
resetEvent = () => {
|
|
7442
7448
|
this.setState({
|
|
7443
|
-
triggerType:
|
|
7449
|
+
triggerType: 'Initial',
|
|
7444
7450
|
triggerEvent: null,
|
|
7445
7451
|
pastedLength: 0
|
|
7446
7452
|
});
|
|
@@ -7457,14 +7463,13 @@ class WithDisplayFormat extends React.Component {
|
|
|
7457
7463
|
const {
|
|
7458
7464
|
selectionStart,
|
|
7459
7465
|
selectionEnd
|
|
7460
|
-
} = event.
|
|
7466
|
+
} = event.currentTarget;
|
|
7461
7467
|
const {
|
|
7462
7468
|
historyNavigator
|
|
7463
7469
|
} = this.state;
|
|
7464
7470
|
const {
|
|
7465
7471
|
displayPattern
|
|
7466
7472
|
} = this.props;
|
|
7467
|
-
|
|
7468
7473
|
// Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
|
|
7469
7474
|
let newFormattedValue = '';
|
|
7470
7475
|
if (this.detectUndoRedo(event) === 'Undo') {
|
|
@@ -7483,8 +7488,8 @@ class WithDisplayFormat extends React.Component {
|
|
|
7483
7488
|
this.setState({
|
|
7484
7489
|
triggerEvent: event,
|
|
7485
7490
|
triggerType: 'KeyDown',
|
|
7486
|
-
selectionStart,
|
|
7487
|
-
selectionEnd
|
|
7491
|
+
selectionStart: selectionStart ?? 0,
|
|
7492
|
+
selectionEnd: selectionEnd ?? 0
|
|
7488
7493
|
});
|
|
7489
7494
|
}
|
|
7490
7495
|
};
|
|
@@ -7513,7 +7518,6 @@ class WithDisplayFormat extends React.Component {
|
|
|
7513
7518
|
handleOnChange = event => {
|
|
7514
7519
|
const {
|
|
7515
7520
|
historyNavigator,
|
|
7516
|
-
triggerEvent,
|
|
7517
7521
|
triggerType
|
|
7518
7522
|
} = this.state;
|
|
7519
7523
|
const {
|
|
@@ -7524,9 +7528,7 @@ class WithDisplayFormat extends React.Component {
|
|
|
7524
7528
|
value
|
|
7525
7529
|
} = event.target;
|
|
7526
7530
|
let unformattedValue = unformatWithPattern$1(value, displayPattern);
|
|
7527
|
-
const action =
|
|
7528
|
-
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
7529
|
-
'Paste' : this.getUserAction(unformattedValue);
|
|
7531
|
+
const action = this.getUserAction(unformattedValue);
|
|
7530
7532
|
if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
|
|
7531
7533
|
return;
|
|
7532
7534
|
}
|
|
@@ -7536,19 +7538,18 @@ class WithDisplayFormat extends React.Component {
|
|
|
7536
7538
|
const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
|
|
7537
7539
|
historyNavigator.add(unformattedValue);
|
|
7538
7540
|
this.handleCursorPositioning(action);
|
|
7539
|
-
const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
|
|
7540
7541
|
this.setState({
|
|
7541
7542
|
value: newFormattedValue
|
|
7542
|
-
},
|
|
7543
|
+
}, () => {
|
|
7544
|
+
this.resetEvent();
|
|
7545
|
+
if (onChange) {
|
|
7546
|
+
const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
|
|
7547
|
+
onChange(broadcastValue);
|
|
7548
|
+
}
|
|
7549
|
+
});
|
|
7543
7550
|
};
|
|
7544
7551
|
handleOnBlur = event => {
|
|
7545
|
-
|
|
7546
|
-
displayPattern,
|
|
7547
|
-
onBlur
|
|
7548
|
-
} = this.props;
|
|
7549
|
-
if (onBlur) {
|
|
7550
|
-
onBlur(unformatWithPattern$1(event.target.value, displayPattern));
|
|
7551
|
-
}
|
|
7552
|
+
this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
|
|
7552
7553
|
};
|
|
7553
7554
|
handleOnFocus = event => {
|
|
7554
7555
|
const {
|
|
@@ -7597,7 +7598,7 @@ class WithDisplayFormat extends React.Component {
|
|
|
7597
7598
|
const cursorPosition = getCursorPositionAfterKeystroke(action, selectionStart, selectionEnd, displayPattern, pastedLength);
|
|
7598
7599
|
setTimeout(() => {
|
|
7599
7600
|
if (triggerEvent) {
|
|
7600
|
-
triggerEvent.
|
|
7601
|
+
triggerEvent.currentTarget.setSelectionRange(cursorPosition, cursorPosition);
|
|
7601
7602
|
}
|
|
7602
7603
|
this.setState({
|
|
7603
7604
|
selectionStart: cursorPosition,
|
|
@@ -7607,7 +7608,6 @@ class WithDisplayFormat extends React.Component {
|
|
|
7607
7608
|
};
|
|
7608
7609
|
render() {
|
|
7609
7610
|
const {
|
|
7610
|
-
type,
|
|
7611
7611
|
inputMode,
|
|
7612
7612
|
className,
|
|
7613
7613
|
id,
|
|
@@ -7624,7 +7624,6 @@ class WithDisplayFormat extends React.Component {
|
|
|
7624
7624
|
value
|
|
7625
7625
|
} = this.state;
|
|
7626
7626
|
const renderProps = {
|
|
7627
|
-
type,
|
|
7628
7627
|
inputMode,
|
|
7629
7628
|
className,
|
|
7630
7629
|
id,
|
|
@@ -7647,62 +7646,13 @@ class WithDisplayFormat extends React.Component {
|
|
|
7647
7646
|
return this.props.render(renderProps);
|
|
7648
7647
|
}
|
|
7649
7648
|
}
|
|
7650
|
-
WithDisplayFormat.propTypes = {
|
|
7651
|
-
/**
|
|
7652
|
-
* autocomplete hides our form help so we need to disable it when help text
|
|
7653
|
-
* is present. Chrome ignores autocomplete=off, the only way to disable it is
|
|
7654
|
-
* to provide an 'invalid' value, for which 'disabled' serves.
|
|
7655
|
-
*/
|
|
7656
|
-
autoComplete: PropTypes__default.default.oneOf(['on', 'off', 'disabled']),
|
|
7657
|
-
className: PropTypes__default.default.string,
|
|
7658
|
-
disabled: PropTypes__default.default.bool,
|
|
7659
|
-
id: PropTypes__default.default.string,
|
|
7660
|
-
maxLength: PropTypes__default.default.number,
|
|
7661
|
-
minLength: PropTypes__default.default.number,
|
|
7662
|
-
name: PropTypes__default.default.string,
|
|
7663
|
-
onFocus: PropTypes__default.default.func,
|
|
7664
|
-
onBlur: PropTypes__default.default.func,
|
|
7665
|
-
onChange: PropTypes__default.default.func.isRequired,
|
|
7666
|
-
placeholder: PropTypes__default.default.string,
|
|
7667
|
-
readOnly: PropTypes__default.default.bool,
|
|
7668
|
-
render: PropTypes__default.default.func.isRequired,
|
|
7669
|
-
required: PropTypes__default.default.bool,
|
|
7670
|
-
displayPattern: PropTypes__default.default.string,
|
|
7671
|
-
type: PropTypes__default.default.string,
|
|
7672
|
-
inputMode: PropTypes__default.default.string,
|
|
7673
|
-
value: PropTypes__default.default.string
|
|
7674
|
-
};
|
|
7675
|
-
WithDisplayFormat.defaultProps = {
|
|
7676
|
-
autoComplete: 'off',
|
|
7677
|
-
className: null,
|
|
7678
|
-
disabled: false,
|
|
7679
|
-
id: null,
|
|
7680
|
-
maxLength: null,
|
|
7681
|
-
minLength: null,
|
|
7682
|
-
name: null,
|
|
7683
|
-
placeholder: null,
|
|
7684
|
-
readOnly: false,
|
|
7685
|
-
required: false,
|
|
7686
|
-
displayPattern: '',
|
|
7687
|
-
type: 'text',
|
|
7688
|
-
inputMode: null,
|
|
7689
|
-
value: '',
|
|
7690
|
-
onFocus: null,
|
|
7691
|
-
onBlur: null
|
|
7692
|
-
};
|
|
7693
|
-
var WithDisplayFormat$1 = WithDisplayFormat;
|
|
7694
7649
|
|
|
7695
|
-
const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat
|
|
7650
|
+
const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
|
|
7696
7651
|
...props,
|
|
7697
|
-
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(
|
|
7652
|
+
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(Input, {
|
|
7698
7653
|
...renderProps
|
|
7699
7654
|
})
|
|
7700
7655
|
});
|
|
7701
|
-
InputWithDisplayFormat.propTypes = {
|
|
7702
|
-
displayPattern: PropTypes__default.default.string.isRequired,
|
|
7703
|
-
onChange: PropTypes__default.default.func.isRequired
|
|
7704
|
-
};
|
|
7705
|
-
var InputWithDisplayFormat$1 = InputWithDisplayFormat;
|
|
7706
7656
|
|
|
7707
7657
|
const InstructionsList = ({
|
|
7708
7658
|
dos,
|
|
@@ -7866,20 +7816,17 @@ function getValidLocale(locale) {
|
|
|
7866
7816
|
Intl.NumberFormat(noUnderscoreLocale);
|
|
7867
7817
|
return noUnderscoreLocale;
|
|
7868
7818
|
} catch {
|
|
7869
|
-
return
|
|
7819
|
+
return DEFAULT_LOCALE;
|
|
7870
7820
|
}
|
|
7871
7821
|
}
|
|
7872
|
-
function getCurrencyDecimals(currency
|
|
7822
|
+
function getCurrencyDecimals(currency) {
|
|
7873
7823
|
const upperCaseCurrency = currency.toUpperCase();
|
|
7874
|
-
|
|
7875
|
-
return currencyDecimals[upperCaseCurrency];
|
|
7876
|
-
}
|
|
7877
|
-
return DEFAULT_CURRENCY_DECIMALS;
|
|
7824
|
+
return currencyDecimals[upperCaseCurrency] ?? DEFAULT_CURRENCY_DECIMALS;
|
|
7878
7825
|
}
|
|
7879
7826
|
function getDecimalSeparator(locale) {
|
|
7880
7827
|
return isNumberLocaleSupported() ? 1.1.toLocaleString(locale)[1] : '.';
|
|
7881
7828
|
}
|
|
7882
|
-
function parseAmount(number, currency, locale) {
|
|
7829
|
+
function parseAmount(number, currency, locale = DEFAULT_LOCALE) {
|
|
7883
7830
|
const validLocale = getValidLocale(locale);
|
|
7884
7831
|
const precision = getCurrencyDecimals(currency);
|
|
7885
7832
|
const groupSeparator = isNumberLocaleSupported() ? 10000 .toLocaleString(validLocale)[2] : ',';
|
|
@@ -7889,53 +7836,67 @@ function parseAmount(number, currency, locale) {
|
|
|
7889
7836
|
return Math.abs(parsedAmount);
|
|
7890
7837
|
}
|
|
7891
7838
|
|
|
7892
|
-
const Currency = PropTypes__default.default.shape({
|
|
7893
|
-
header: PropTypes__default.default.string,
|
|
7894
|
-
value: PropTypes__default.default.string,
|
|
7895
|
-
label: PropTypes__default.default.string,
|
|
7896
|
-
currency: PropTypes__default.default.string,
|
|
7897
|
-
note: PropTypes__default.default.string,
|
|
7898
|
-
searchable: PropTypes__default.default.string
|
|
7899
|
-
});
|
|
7900
7839
|
const isNumberOrNull = v => neptuneValidation.isNumber(v) || neptuneValidation.isNull(v);
|
|
7901
|
-
const formatAmountIfSet = (
|
|
7840
|
+
const formatAmountIfSet = ({
|
|
7841
|
+
amount,
|
|
7842
|
+
currency,
|
|
7843
|
+
locale,
|
|
7844
|
+
maxLengthOverride
|
|
7845
|
+
}) => {
|
|
7902
7846
|
if (maxLengthOverride) {
|
|
7903
|
-
return amount
|
|
7847
|
+
return amount != null ? String(amount) : '';
|
|
7904
7848
|
} else {
|
|
7905
7849
|
return typeof amount === 'number' ? formatting.formatAmount(amount, currency, locale) : '';
|
|
7906
7850
|
}
|
|
7907
7851
|
};
|
|
7908
|
-
const parseNumber = (
|
|
7852
|
+
const parseNumber = ({
|
|
7853
|
+
amount,
|
|
7854
|
+
currency,
|
|
7855
|
+
locale,
|
|
7856
|
+
maxLengthOverride
|
|
7857
|
+
}) => {
|
|
7909
7858
|
if (!maxLengthOverride) {
|
|
7910
7859
|
return parseAmount(amount, currency, locale);
|
|
7911
7860
|
}
|
|
7912
7861
|
if (maxLengthOverride && amount.length > maxLengthOverride) {
|
|
7913
7862
|
return 0;
|
|
7914
7863
|
}
|
|
7915
|
-
return
|
|
7864
|
+
return Number(amount);
|
|
7916
7865
|
};
|
|
7917
7866
|
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]);
|
|
7918
7867
|
const inputKeyAllowlist = new Set([Key.PERIOD, Key.COMMA]);
|
|
7919
7868
|
class MoneyInput extends React.Component {
|
|
7869
|
+
static defaultProps = {
|
|
7870
|
+
size: exports.Size.LARGE,
|
|
7871
|
+
classNames: {},
|
|
7872
|
+
selectProps: {}
|
|
7873
|
+
};
|
|
7874
|
+
amountFocused = false;
|
|
7920
7875
|
constructor(props) {
|
|
7921
7876
|
super(props);
|
|
7922
|
-
const {
|
|
7923
|
-
locale
|
|
7924
|
-
} = this.props.intl;
|
|
7925
|
-
this.formatMessage = this.props.intl.formatMessage;
|
|
7926
7877
|
this.state = {
|
|
7927
7878
|
searchQuery: '',
|
|
7928
|
-
formattedAmount: formatAmountIfSet(
|
|
7929
|
-
|
|
7879
|
+
formattedAmount: formatAmountIfSet({
|
|
7880
|
+
amount: props.amount,
|
|
7881
|
+
currency: props.selectedCurrency.currency,
|
|
7882
|
+
locale: props.intl.locale,
|
|
7883
|
+
maxLengthOverride: props.maxLengthOverride
|
|
7884
|
+
}),
|
|
7885
|
+
locale: props.intl.locale
|
|
7930
7886
|
};
|
|
7931
7887
|
}
|
|
7932
7888
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
7933
7889
|
this.setState({
|
|
7934
|
-
locale: nextProps
|
|
7890
|
+
locale: nextProps.intl.locale
|
|
7935
7891
|
});
|
|
7936
7892
|
if (!this.amountFocused) {
|
|
7937
7893
|
this.setState({
|
|
7938
|
-
formattedAmount: formatAmountIfSet(
|
|
7894
|
+
formattedAmount: formatAmountIfSet({
|
|
7895
|
+
amount: nextProps.amount,
|
|
7896
|
+
currency: nextProps.selectedCurrency.currency,
|
|
7897
|
+
locale: nextProps.intl.locale,
|
|
7898
|
+
maxLengthOverride: nextProps.maxLengthOverride
|
|
7899
|
+
})
|
|
7939
7900
|
});
|
|
7940
7901
|
}
|
|
7941
7902
|
}
|
|
@@ -7955,16 +7916,26 @@ class MoneyInput extends React.Component {
|
|
|
7955
7916
|
}
|
|
7956
7917
|
};
|
|
7957
7918
|
handlePaste = event => {
|
|
7958
|
-
const paste =
|
|
7919
|
+
const paste = event.clipboardData.getData('text');
|
|
7959
7920
|
const {
|
|
7960
7921
|
locale
|
|
7961
7922
|
} = this.state;
|
|
7962
|
-
const parsed = neptuneValidation.isEmpty(paste) ? null : parseNumber(
|
|
7923
|
+
const parsed = neptuneValidation.isEmpty(paste) ? null : parseNumber({
|
|
7924
|
+
amount: paste,
|
|
7925
|
+
currency: this.props.selectedCurrency.currency,
|
|
7926
|
+
locale: locale,
|
|
7927
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
7928
|
+
});
|
|
7963
7929
|
if (isNumberOrNull(parsed)) {
|
|
7964
7930
|
this.setState({
|
|
7965
|
-
formattedAmount: formatAmountIfSet(
|
|
7931
|
+
formattedAmount: formatAmountIfSet({
|
|
7932
|
+
amount: parsed,
|
|
7933
|
+
currency: this.props.selectedCurrency.currency,
|
|
7934
|
+
locale: locale,
|
|
7935
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
7936
|
+
})
|
|
7966
7937
|
});
|
|
7967
|
-
this.props.onAmountChange(parsed);
|
|
7938
|
+
this.props.onAmountChange?.(parsed);
|
|
7968
7939
|
}
|
|
7969
7940
|
event.preventDefault();
|
|
7970
7941
|
};
|
|
@@ -7975,9 +7946,14 @@ class MoneyInput extends React.Component {
|
|
|
7975
7946
|
this.setState({
|
|
7976
7947
|
formattedAmount: value
|
|
7977
7948
|
});
|
|
7978
|
-
const parsed = neptuneValidation.isEmpty(value) ? null : parseNumber(
|
|
7949
|
+
const parsed = neptuneValidation.isEmpty(value) ? null : parseNumber({
|
|
7950
|
+
amount: value,
|
|
7951
|
+
currency: this.props.selectedCurrency.currency,
|
|
7952
|
+
locale: this.state.locale,
|
|
7953
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
7954
|
+
});
|
|
7979
7955
|
if (isNumberOrNull(parsed)) {
|
|
7980
|
-
this.props.onAmountChange(parsed);
|
|
7956
|
+
this.props.onAmountChange?.(parsed);
|
|
7981
7957
|
}
|
|
7982
7958
|
};
|
|
7983
7959
|
onAmountBlur = () => {
|
|
@@ -7987,68 +7963,67 @@ class MoneyInput extends React.Component {
|
|
|
7987
7963
|
onAmountFocus = () => {
|
|
7988
7964
|
this.amountFocused = true;
|
|
7989
7965
|
};
|
|
7990
|
-
mapOption = item => {
|
|
7991
|
-
return {
|
|
7992
|
-
type: 'option',
|
|
7993
|
-
value: item,
|
|
7994
|
-
filterMatchers: [item.value, item.label, item.note, item.searchable]
|
|
7995
|
-
};
|
|
7996
|
-
};
|
|
7997
7966
|
getSelectOptions() {
|
|
7998
|
-
const selectOptions =
|
|
7999
|
-
|
|
8000
|
-
let
|
|
7967
|
+
const selectOptions = filterCurrenciesForQuery(this.props.currencies, this.state.searchQuery);
|
|
7968
|
+
const formattedOptions = [];
|
|
7969
|
+
let currentGroupOptions;
|
|
8001
7970
|
selectOptions.forEach(item => {
|
|
8002
|
-
if (item.header) {
|
|
7971
|
+
if (item.header != null) {
|
|
7972
|
+
currentGroupOptions = [];
|
|
8003
7973
|
formattedOptions.push({
|
|
8004
7974
|
type: 'group',
|
|
8005
7975
|
label: item.header,
|
|
8006
|
-
options:
|
|
7976
|
+
options: currentGroupOptions
|
|
8007
7977
|
});
|
|
8008
|
-
groupIndex = formattedOptions.length - 1;
|
|
8009
7978
|
} else {
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
}
|
|
7979
|
+
(currentGroupOptions ?? formattedOptions).push({
|
|
7980
|
+
type: 'option',
|
|
7981
|
+
value: item,
|
|
7982
|
+
filterMatchers: [item.value, item.label, item.note ?? '', item.searchable ?? '']
|
|
7983
|
+
});
|
|
8015
7984
|
}
|
|
8016
7985
|
});
|
|
8017
7986
|
return formattedOptions;
|
|
8018
7987
|
}
|
|
8019
7988
|
setAmount() {
|
|
8020
7989
|
this.setState(previousState => {
|
|
8021
|
-
const parsed = parseNumber(
|
|
7990
|
+
const parsed = parseNumber({
|
|
7991
|
+
amount: previousState.formattedAmount,
|
|
7992
|
+
currency: this.props.selectedCurrency.currency,
|
|
7993
|
+
locale: previousState.locale,
|
|
7994
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
7995
|
+
});
|
|
8022
7996
|
if (!isNumberOrNull(parsed)) {
|
|
8023
7997
|
return {
|
|
8024
7998
|
formattedAmount: previousState.formattedAmount
|
|
8025
7999
|
};
|
|
8026
8000
|
}
|
|
8027
8001
|
return {
|
|
8028
|
-
formattedAmount: formatAmountIfSet(
|
|
8002
|
+
formattedAmount: formatAmountIfSet({
|
|
8003
|
+
amount: parsed,
|
|
8004
|
+
currency: this.props.selectedCurrency.currency,
|
|
8005
|
+
locale: previousState.locale,
|
|
8006
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
8007
|
+
})
|
|
8029
8008
|
};
|
|
8030
8009
|
});
|
|
8031
8010
|
}
|
|
8032
8011
|
handleSelectChange = value => {
|
|
8033
8012
|
this.handleSearchChange('');
|
|
8034
|
-
this.props.onCurrencyChange(value);
|
|
8013
|
+
this.props.onCurrencyChange?.(value);
|
|
8035
8014
|
};
|
|
8036
8015
|
handleCustomAction = () => {
|
|
8037
8016
|
this.handleSearchChange('');
|
|
8038
|
-
|
|
8039
|
-
this.props.onCustomAction();
|
|
8040
|
-
}
|
|
8017
|
+
this.props.onCustomAction?.();
|
|
8041
8018
|
};
|
|
8042
8019
|
handleSearchChange = searchQuery => {
|
|
8043
8020
|
this.setState({
|
|
8044
8021
|
searchQuery
|
|
8045
8022
|
});
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
});
|
|
8051
|
-
}
|
|
8023
|
+
this.props.onSearchChange?.({
|
|
8024
|
+
searchQuery,
|
|
8025
|
+
filteredOptions: filterCurrenciesForQuery(this.props.currencies, searchQuery)
|
|
8026
|
+
});
|
|
8052
8027
|
};
|
|
8053
8028
|
style = className => this.props.classNames[className] || className;
|
|
8054
8029
|
render() {
|
|
@@ -8088,7 +8063,12 @@ class MoneyInput extends React.Component {
|
|
|
8088
8063
|
inputMode: "decimal",
|
|
8089
8064
|
disabled: disabled,
|
|
8090
8065
|
maxLength: maxLengthOverride,
|
|
8091
|
-
placeholder: formatAmountIfSet(
|
|
8066
|
+
placeholder: formatAmountIfSet({
|
|
8067
|
+
amount: this.props.placeholder,
|
|
8068
|
+
currency: this.props.selectedCurrency.currency,
|
|
8069
|
+
locale: this.state.locale,
|
|
8070
|
+
maxLengthOverride: this.props.maxLengthOverride
|
|
8071
|
+
}),
|
|
8092
8072
|
autoComplete: "off",
|
|
8093
8073
|
onKeyDown: this.handleKeyDown,
|
|
8094
8074
|
onChange: this.onAmountChange,
|
|
@@ -8133,11 +8113,11 @@ class MoneyInput extends React.Component {
|
|
|
8133
8113
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
|
|
8134
8114
|
jsxRuntime.jsx("div", {
|
|
8135
8115
|
role: "button",
|
|
8136
|
-
tabIndex:
|
|
8116
|
+
tabIndex: 0,
|
|
8137
8117
|
onClick: this.handleCustomAction,
|
|
8138
8118
|
children: this.props.customActionLabel
|
|
8139
|
-
}) :
|
|
8140
|
-
placeholder: this.formatMessage(messages$3.selectPlaceholder),
|
|
8119
|
+
}) : undefined,
|
|
8120
|
+
placeholder: this.props.intl.formatMessage(messages$3.selectPlaceholder),
|
|
8141
8121
|
filterable: true,
|
|
8142
8122
|
filterPlaceholder: this.props.searchPlaceholder,
|
|
8143
8123
|
disabled: disabled,
|
|
@@ -8154,25 +8134,25 @@ class MoneyInput extends React.Component {
|
|
|
8154
8134
|
});
|
|
8155
8135
|
}
|
|
8156
8136
|
}
|
|
8157
|
-
function
|
|
8137
|
+
function filterCurrenciesForQuery(currencies, query) {
|
|
8158
8138
|
if (!query) {
|
|
8159
|
-
return
|
|
8139
|
+
return [...currencies];
|
|
8160
8140
|
}
|
|
8161
|
-
const
|
|
8141
|
+
const options = currencies.filter(option => option.header == null);
|
|
8142
|
+
const filteredOptions = removeDuplicateValueOptions(options).filter(option => currencyOptionFitsQuery(option, query));
|
|
8162
8143
|
return sortOptionsLabelsToFirst(filteredOptions, query);
|
|
8163
8144
|
}
|
|
8164
8145
|
function removeDuplicateValueOptions(options) {
|
|
8165
|
-
const
|
|
8166
|
-
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
resultValues.push(option.value);
|
|
8146
|
+
const uniqueValues = new Set();
|
|
8147
|
+
return options.filter(option => {
|
|
8148
|
+
if (!uniqueValues.has(option.value)) {
|
|
8149
|
+
uniqueValues.add(option.value);
|
|
8150
|
+
return true;
|
|
8171
8151
|
}
|
|
8152
|
+
return false;
|
|
8172
8153
|
});
|
|
8173
|
-
return result;
|
|
8174
8154
|
}
|
|
8175
|
-
function
|
|
8155
|
+
function currencyOptionFitsQuery(option, query) {
|
|
8176
8156
|
if (!option.value) {
|
|
8177
8157
|
return false;
|
|
8178
8158
|
}
|
|
@@ -8197,43 +8177,6 @@ function sortOptionsLabelsToFirst(options, query) {
|
|
|
8197
8177
|
return 0;
|
|
8198
8178
|
});
|
|
8199
8179
|
}
|
|
8200
|
-
MoneyInput.propTypes = {
|
|
8201
|
-
id: PropTypes__default.default.string,
|
|
8202
|
-
currencies: PropTypes__default.default.arrayOf(Currency).isRequired,
|
|
8203
|
-
selectedCurrency: Currency.isRequired,
|
|
8204
|
-
onCurrencyChange: PropTypes__default.default.func,
|
|
8205
|
-
placeholder: PropTypes__default.default.number,
|
|
8206
|
-
amount: PropTypes__default.default.number,
|
|
8207
|
-
size: PropTypes__default.default.oneOf(['sm', 'md', 'lg']),
|
|
8208
|
-
onAmountChange: PropTypes__default.default.func,
|
|
8209
|
-
addon: PropTypes__default.default.node,
|
|
8210
|
-
searchPlaceholder: PropTypes__default.default.string,
|
|
8211
|
-
/**
|
|
8212
|
-
* Allows the consumer to react to searching, while the search itself is handled internally. Called with `{ searchQuery: string, filteredOptions: Currency[] }`
|
|
8213
|
-
*/
|
|
8214
|
-
onSearchChange: PropTypes__default.default.func,
|
|
8215
|
-
customActionLabel: PropTypes__default.default.node,
|
|
8216
|
-
onCustomAction: PropTypes__default.default.func,
|
|
8217
|
-
classNames: PropTypes__default.default.objectOf(PropTypes__default.default.string),
|
|
8218
|
-
selectProps: PropTypes__default.default.object,
|
|
8219
|
-
maxLengthOverride: PropTypes__default.default.number
|
|
8220
|
-
};
|
|
8221
|
-
MoneyInput.defaultProps = {
|
|
8222
|
-
id: null,
|
|
8223
|
-
size: exports.Size.LARGE,
|
|
8224
|
-
addon: null,
|
|
8225
|
-
searchPlaceholder: '',
|
|
8226
|
-
onSearchChange: undefined,
|
|
8227
|
-
onCurrencyChange: null,
|
|
8228
|
-
placeholder: null,
|
|
8229
|
-
amount: null,
|
|
8230
|
-
onAmountChange: null,
|
|
8231
|
-
customActionLabel: '',
|
|
8232
|
-
onCustomAction: null,
|
|
8233
|
-
classNames: {},
|
|
8234
|
-
selectProps: {},
|
|
8235
|
-
maxLengthOverride: null
|
|
8236
|
-
};
|
|
8237
8180
|
var MoneyInput$1 = reactIntl.injectIntl(MoneyInput);
|
|
8238
8181
|
|
|
8239
8182
|
const NavigationOptionList = ({
|
|
@@ -12386,17 +12329,12 @@ Tabs.defaultProps = {
|
|
|
12386
12329
|
};
|
|
12387
12330
|
var Tabs$1 = Tabs;
|
|
12388
12331
|
|
|
12389
|
-
const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat
|
|
12332
|
+
const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
|
|
12390
12333
|
...props,
|
|
12391
|
-
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(
|
|
12334
|
+
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(TextArea, {
|
|
12392
12335
|
...renderProps
|
|
12393
12336
|
})
|
|
12394
12337
|
});
|
|
12395
|
-
TextareaWithDisplayFormat.propTypes = {
|
|
12396
|
-
displayPattern: PropTypes__default.default.string.isRequired,
|
|
12397
|
-
onChange: PropTypes__default.default.func.isRequired
|
|
12398
|
-
};
|
|
12399
|
-
var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
|
|
12400
12338
|
|
|
12401
12339
|
/* eslint-disable jsx-a11y/no-autofocus */
|
|
12402
12340
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
@@ -15398,16 +15336,16 @@ var th = {
|
|
|
15398
15336
|
"neptune.DateInput.year.label": "ปี",
|
|
15399
15337
|
"neptune.DateInput.year.placeholder": "YYYY",
|
|
15400
15338
|
"neptune.DateLookup.day": "วัน",
|
|
15401
|
-
"neptune.DateLookup.goTo20YearView": "
|
|
15339
|
+
"neptune.DateLookup.goTo20YearView": "ไปที่มุมมอง 20 ปี",
|
|
15402
15340
|
"neptune.DateLookup.month": "เดือน",
|
|
15403
15341
|
"neptune.DateLookup.next": "ถัดไป",
|
|
15404
15342
|
"neptune.DateLookup.previous": "ก่อนหน้า",
|
|
15405
15343
|
"neptune.DateLookup.selected": "เลือกแล้ว",
|
|
15406
15344
|
"neptune.DateLookup.twentyYears": "20 ปี",
|
|
15407
15345
|
"neptune.DateLookup.year": "ปี",
|
|
15408
|
-
"neptune.FlowNavigation.back": "
|
|
15346
|
+
"neptune.FlowNavigation.back": "กลับไปที่ขั้นก่อนหน้า",
|
|
15409
15347
|
"neptune.Info.ariaLabel": "ข้อมูลเพิ่มเติม",
|
|
15410
|
-
"neptune.Link.opensInNewTab": "(
|
|
15348
|
+
"neptune.Link.opensInNewTab": "(เปิดในแท็บใหม่)",
|
|
15411
15349
|
"neptune.MoneyInput.Select.placeholder": "เลือกตัวเลือก...",
|
|
15412
15350
|
"neptune.Select.searchPlaceholder": "ค้นหา...",
|
|
15413
15351
|
"neptune.SelectInput.noResultsFound": "ไม่พบผลลัพธ์",
|
|
@@ -15733,7 +15671,7 @@ exports.Info = Info;
|
|
|
15733
15671
|
exports.InlineAlert = InlineAlert;
|
|
15734
15672
|
exports.Input = Input;
|
|
15735
15673
|
exports.InputGroup = InputGroup;
|
|
15736
|
-
exports.InputWithDisplayFormat = InputWithDisplayFormat
|
|
15674
|
+
exports.InputWithDisplayFormat = InputWithDisplayFormat;
|
|
15737
15675
|
exports.InstructionsList = InstructionsList$1;
|
|
15738
15676
|
exports.LanguageProvider = LanguageProvider;
|
|
15739
15677
|
exports.Link = Link;
|
|
@@ -15781,7 +15719,7 @@ exports.Switch = Switch;
|
|
|
15781
15719
|
exports.SwitchOption = SwitchOption;
|
|
15782
15720
|
exports.Tabs = Tabs$1;
|
|
15783
15721
|
exports.TextArea = TextArea;
|
|
15784
|
-
exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat
|
|
15722
|
+
exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat;
|
|
15785
15723
|
exports.Title = Title;
|
|
15786
15724
|
exports.Tooltip = Tooltip$1;
|
|
15787
15725
|
exports.Typeahead = Typeahead;
|