@transferwise/components 0.0.0-experimental-1f8ed05 → 0.0.0-experimental-adcaf57
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 +68 -142
- package/build/index.esm.js.map +1 -1
- package/build/index.js +69 -143
- 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 -1
- 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 +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +5 -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/Input.d.ts +8 -6
- package/build/types/inputs/Input.d.ts.map +1 -1
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +5 -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 -82
- 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} +7 -6
- package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.js → getSymbolsInPatternWithPosition.ts} +7 -2
- package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.js → unformatWithPattern.ts} +3 -2
- package/src/index.ts +2 -0
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +11 -0
- package/src/inputWithDisplayFormat/index.ts +2 -0
- package/src/inputs/Input.tsx +6 -11
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +3 -1
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +30 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +11 -0
- package/src/textareaWithDisplayFormat/index.ts +2 -0
- package/src/withDisplayFormat/WithDisplayFormat.tsx +303 -0
- package/src/withDisplayFormat/index.ts +2 -0
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +0 -14
- package/src/inputWithDisplayFormat/index.js +0 -1
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +0 -14
- package/src/textareaWithDisplayFormat/index.js +0 -1
- package/src/withDisplayFormat/WithDisplayFormat.js +0 -312
- package/src/withDisplayFormat/index.js +0 -1
package/build/index.js
CHANGED
|
@@ -7297,10 +7297,13 @@ const formatWithPattern = (value, pattern) => {
|
|
|
7297
7297
|
let patternSymbol = [];
|
|
7298
7298
|
// valueArray.length increments during the cycle cause we are adding new elements.
|
|
7299
7299
|
for (let index = 0; index < valueArray.length; index += 1) {
|
|
7300
|
-
patternSymbol = patternWithSymbolsPosition.filter(
|
|
7300
|
+
patternSymbol = patternWithSymbolsPosition.filter(pattern => pattern.index === index);
|
|
7301
7301
|
// Add pattern's symbol at n position
|
|
7302
7302
|
if (patternSymbol.length === 1) {
|
|
7303
|
-
|
|
7303
|
+
const last = patternSymbol.pop();
|
|
7304
|
+
if (last) {
|
|
7305
|
+
valueArray.splice(index, 0, last.symbol);
|
|
7306
|
+
}
|
|
7304
7307
|
}
|
|
7305
7308
|
}
|
|
7306
7309
|
return valueArray.join('');
|
|
@@ -7371,33 +7374,31 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
|
|
|
7371
7374
|
var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
|
|
7372
7375
|
|
|
7373
7376
|
class WithDisplayFormat extends React.Component {
|
|
7377
|
+
static defaultProps = {
|
|
7378
|
+
autoComplete: 'off',
|
|
7379
|
+
displayPattern: '',
|
|
7380
|
+
type: 'text',
|
|
7381
|
+
value: ''
|
|
7382
|
+
};
|
|
7374
7383
|
constructor(props) {
|
|
7375
7384
|
super(props);
|
|
7376
|
-
const
|
|
7377
|
-
value,
|
|
7378
|
-
displayPattern
|
|
7379
|
-
} = props;
|
|
7380
|
-
const unformattedValue = unformatWithPattern$1(value, displayPattern);
|
|
7385
|
+
const unformattedValue = unformatWithPattern$1(props.value, props.displayPattern);
|
|
7381
7386
|
this.state = {
|
|
7382
|
-
value: formatWithPattern$1(unformattedValue, displayPattern),
|
|
7387
|
+
value: formatWithPattern$1(unformattedValue, props.displayPattern),
|
|
7383
7388
|
historyNavigator: new HistoryNavigator$1(),
|
|
7384
7389
|
prevDisplayPattern: props.displayPattern,
|
|
7385
7390
|
triggerType: null,
|
|
7386
7391
|
triggerEvent: null
|
|
7387
7392
|
};
|
|
7388
7393
|
}
|
|
7389
|
-
static getDerivedStateFromProps(
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
if (
|
|
7397
|
-
const {
|
|
7398
|
-
value,
|
|
7399
|
-
historyNavigator
|
|
7400
|
-
} = previousState;
|
|
7394
|
+
static getDerivedStateFromProps({
|
|
7395
|
+
displayPattern
|
|
7396
|
+
}, {
|
|
7397
|
+
prevDisplayPattern = displayPattern,
|
|
7398
|
+
value,
|
|
7399
|
+
historyNavigator
|
|
7400
|
+
}) {
|
|
7401
|
+
if (prevDisplayPattern !== displayPattern) {
|
|
7401
7402
|
const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
|
|
7402
7403
|
historyNavigator.reset();
|
|
7403
7404
|
return {
|
|
@@ -7419,25 +7420,27 @@ class WithDisplayFormat extends React.Component {
|
|
|
7419
7420
|
const {
|
|
7420
7421
|
displayPattern
|
|
7421
7422
|
} = this.props;
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
|
|
7423
|
+
if (triggerEvent) {
|
|
7424
|
+
const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
|
|
7425
|
+
if (triggerType === 'Paste' || triggerType === 'Cut') {
|
|
7426
|
+
return triggerType;
|
|
7427
|
+
}
|
|
7428
|
+
if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
|
|
7429
|
+
return triggerEvent.shiftKey ? 'Redo' : 'Undo';
|
|
7430
|
+
}
|
|
7431
|
+
// Detect mouse event redo
|
|
7432
|
+
if (triggerEvent.ctrlKey && charCode === 'd') {
|
|
7433
|
+
return 'Delete';
|
|
7434
|
+
}
|
|
7435
|
+
// Android Fix.
|
|
7436
|
+
if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
|
|
7437
7437
|
return 'Backspace';
|
|
7438
7438
|
}
|
|
7439
|
+
return triggerEvent.key;
|
|
7440
|
+
} else {
|
|
7441
|
+
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
7442
|
+
return 'Paste';
|
|
7439
7443
|
}
|
|
7440
|
-
return triggerEvent.key;
|
|
7441
7444
|
};
|
|
7442
7445
|
resetEvent = () => {
|
|
7443
7446
|
this.setState({
|
|
@@ -7465,7 +7468,6 @@ class WithDisplayFormat extends React.Component {
|
|
|
7465
7468
|
const {
|
|
7466
7469
|
displayPattern
|
|
7467
7470
|
} = this.props;
|
|
7468
|
-
|
|
7469
7471
|
// Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
|
|
7470
7472
|
let newFormattedValue = '';
|
|
7471
7473
|
if (this.detectUndoRedo(event) === 'Undo') {
|
|
@@ -7514,7 +7516,6 @@ class WithDisplayFormat extends React.Component {
|
|
|
7514
7516
|
handleOnChange = event => {
|
|
7515
7517
|
const {
|
|
7516
7518
|
historyNavigator,
|
|
7517
|
-
triggerEvent,
|
|
7518
7519
|
triggerType
|
|
7519
7520
|
} = this.state;
|
|
7520
7521
|
const {
|
|
@@ -7525,9 +7526,7 @@ class WithDisplayFormat extends React.Component {
|
|
|
7525
7526
|
value
|
|
7526
7527
|
} = event.target;
|
|
7527
7528
|
let unformattedValue = unformatWithPattern$1(value, displayPattern);
|
|
7528
|
-
const action =
|
|
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
|
+
const action = this.getUserAction(unformattedValue);
|
|
7531
7530
|
if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
|
|
7532
7531
|
return;
|
|
7533
7532
|
}
|
|
@@ -7537,19 +7536,18 @@ class WithDisplayFormat extends React.Component {
|
|
|
7537
7536
|
const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
|
|
7538
7537
|
historyNavigator.add(unformattedValue);
|
|
7539
7538
|
this.handleCursorPositioning(action);
|
|
7540
|
-
const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
|
|
7541
7539
|
this.setState({
|
|
7542
7540
|
value: newFormattedValue
|
|
7543
|
-
},
|
|
7541
|
+
}, () => {
|
|
7542
|
+
this.resetEvent();
|
|
7543
|
+
if (onChange) {
|
|
7544
|
+
const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
|
|
7545
|
+
onChange(broadcastValue);
|
|
7546
|
+
}
|
|
7547
|
+
});
|
|
7544
7548
|
};
|
|
7545
7549
|
handleOnBlur = event => {
|
|
7546
|
-
|
|
7547
|
-
displayPattern,
|
|
7548
|
-
onBlur
|
|
7549
|
-
} = this.props;
|
|
7550
|
-
if (onBlur) {
|
|
7551
|
-
onBlur(unformatWithPattern$1(event.target.value, displayPattern));
|
|
7552
|
-
}
|
|
7550
|
+
this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
|
|
7553
7551
|
};
|
|
7554
7552
|
handleOnFocus = event => {
|
|
7555
7553
|
const {
|
|
@@ -7607,103 +7605,36 @@ class WithDisplayFormat extends React.Component {
|
|
|
7607
7605
|
}, 0);
|
|
7608
7606
|
};
|
|
7609
7607
|
render() {
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
|
|
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,
|
|
7608
|
+
return this.props.render({
|
|
7609
|
+
value: this.state.value,
|
|
7610
|
+
type: this.props.type,
|
|
7611
|
+
inputMode: this.props.inputMode,
|
|
7612
|
+
className: this.props.className,
|
|
7613
|
+
id: this.props.id,
|
|
7614
|
+
name: this.props.name,
|
|
7615
|
+
placeholder: this.props.placeholder,
|
|
7616
|
+
readOnly: this.props.readOnly,
|
|
7617
|
+
required: this.props.required,
|
|
7618
|
+
minLength: this.props.minLength,
|
|
7619
|
+
maxLength: this.props.maxLength,
|
|
7620
|
+
disabled: this.props.disabled,
|
|
7621
|
+
autoComplete: this.props.autoComplete,
|
|
7641
7622
|
onFocus: this.handleOnFocus,
|
|
7642
7623
|
onBlur: this.handleOnBlur,
|
|
7643
7624
|
onPaste: this.handleOnPaste,
|
|
7644
7625
|
onKeyDown: this.handleOnKeyDown,
|
|
7645
7626
|
onChange: this.handleOnChange,
|
|
7646
7627
|
onCut: this.handleOnCut
|
|
7647
|
-
};
|
|
7648
|
-
return this.props.render(renderProps);
|
|
7628
|
+
});
|
|
7649
7629
|
}
|
|
7650
7630
|
}
|
|
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;
|
|
7695
7631
|
|
|
7696
|
-
const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat
|
|
7632
|
+
const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
|
|
7697
7633
|
...props,
|
|
7698
|
-
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(
|
|
7634
|
+
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(Input, {
|
|
7699
7635
|
...renderProps
|
|
7700
7636
|
})
|
|
7701
7637
|
});
|
|
7702
|
-
InputWithDisplayFormat.propTypes = {
|
|
7703
|
-
displayPattern: PropTypes__default.default.string.isRequired,
|
|
7704
|
-
onChange: PropTypes__default.default.func.isRequired
|
|
7705
|
-
};
|
|
7706
|
-
var InputWithDisplayFormat$1 = InputWithDisplayFormat;
|
|
7707
7638
|
|
|
7708
7639
|
const InstructionsList = ({
|
|
7709
7640
|
dos,
|
|
@@ -12380,17 +12311,12 @@ Tabs.defaultProps = {
|
|
|
12380
12311
|
};
|
|
12381
12312
|
var Tabs$1 = Tabs;
|
|
12382
12313
|
|
|
12383
|
-
const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat
|
|
12314
|
+
const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
|
|
12384
12315
|
...props,
|
|
12385
|
-
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(
|
|
12316
|
+
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(TextArea, {
|
|
12386
12317
|
...renderProps
|
|
12387
12318
|
})
|
|
12388
12319
|
});
|
|
12389
|
-
TextareaWithDisplayFormat.propTypes = {
|
|
12390
|
-
displayPattern: PropTypes__default.default.string.isRequired,
|
|
12391
|
-
onChange: PropTypes__default.default.func.isRequired
|
|
12392
|
-
};
|
|
12393
|
-
var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
|
|
12394
12320
|
|
|
12395
12321
|
/* eslint-disable jsx-a11y/no-autofocus */
|
|
12396
12322
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
@@ -15727,7 +15653,7 @@ exports.Info = Info;
|
|
|
15727
15653
|
exports.InlineAlert = InlineAlert;
|
|
15728
15654
|
exports.Input = Input;
|
|
15729
15655
|
exports.InputGroup = InputGroup;
|
|
15730
|
-
exports.InputWithDisplayFormat = InputWithDisplayFormat
|
|
15656
|
+
exports.InputWithDisplayFormat = InputWithDisplayFormat;
|
|
15731
15657
|
exports.InstructionsList = InstructionsList$1;
|
|
15732
15658
|
exports.LanguageProvider = LanguageProvider;
|
|
15733
15659
|
exports.Link = Link;
|
|
@@ -15775,7 +15701,7 @@ exports.Switch = Switch;
|
|
|
15775
15701
|
exports.SwitchOption = SwitchOption;
|
|
15776
15702
|
exports.Tabs = Tabs$1;
|
|
15777
15703
|
exports.TextArea = TextArea;
|
|
15778
|
-
exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat
|
|
15704
|
+
exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat;
|
|
15779
15705
|
exports.Title = Title;
|
|
15780
15706
|
exports.Tooltip = Tooltip$1;
|
|
15781
15707
|
exports.Typeahead = Typeahead;
|