@transferwise/components 0.0.0-experimental-1f8ed05 → 0.0.0-experimental-d0bd4b4
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 +53 -109
- package/build/index.esm.js.map +1 -1
- package/build/index.js +54 -110
- 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 +32 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +11 -0
- package/src/textareaWithDisplayFormat/index.ts +2 -0
- package/src/withDisplayFormat/{WithDisplayFormat.js → WithDisplayFormat.tsx} +111 -104
- 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/index.js +0 -1
package/build/index.esm.js
CHANGED
|
@@ -7263,10 +7263,13 @@ const formatWithPattern = (value, pattern) => {
|
|
|
7263
7263
|
let patternSymbol = [];
|
|
7264
7264
|
// valueArray.length increments during the cycle cause we are adding new elements.
|
|
7265
7265
|
for (let index = 0; index < valueArray.length; index += 1) {
|
|
7266
|
-
patternSymbol = patternWithSymbolsPosition.filter(
|
|
7266
|
+
patternSymbol = patternWithSymbolsPosition.filter(pattern => pattern.index === index);
|
|
7267
7267
|
// Add pattern's symbol at n position
|
|
7268
7268
|
if (patternSymbol.length === 1) {
|
|
7269
|
-
|
|
7269
|
+
const last = patternSymbol.pop();
|
|
7270
|
+
if (last) {
|
|
7271
|
+
valueArray.splice(index, 0, last.symbol);
|
|
7272
|
+
}
|
|
7270
7273
|
}
|
|
7271
7274
|
}
|
|
7272
7275
|
return valueArray.join('');
|
|
@@ -7337,33 +7340,31 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
|
|
|
7337
7340
|
var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
|
|
7338
7341
|
|
|
7339
7342
|
class WithDisplayFormat extends Component {
|
|
7343
|
+
static defaultProps = {
|
|
7344
|
+
autoComplete: 'off',
|
|
7345
|
+
displayPattern: '',
|
|
7346
|
+
type: 'text',
|
|
7347
|
+
value: ''
|
|
7348
|
+
};
|
|
7340
7349
|
constructor(props) {
|
|
7341
7350
|
super(props);
|
|
7342
|
-
const
|
|
7343
|
-
value,
|
|
7344
|
-
displayPattern
|
|
7345
|
-
} = props;
|
|
7346
|
-
const unformattedValue = unformatWithPattern$1(value, displayPattern);
|
|
7351
|
+
const unformattedValue = unformatWithPattern$1(props.value, props.displayPattern);
|
|
7347
7352
|
this.state = {
|
|
7348
|
-
value: formatWithPattern$1(unformattedValue, displayPattern),
|
|
7353
|
+
value: formatWithPattern$1(unformattedValue, props.displayPattern),
|
|
7349
7354
|
historyNavigator: new HistoryNavigator$1(),
|
|
7350
7355
|
prevDisplayPattern: props.displayPattern,
|
|
7351
7356
|
triggerType: null,
|
|
7352
7357
|
triggerEvent: null
|
|
7353
7358
|
};
|
|
7354
7359
|
}
|
|
7355
|
-
static getDerivedStateFromProps(
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
if (
|
|
7363
|
-
const {
|
|
7364
|
-
value,
|
|
7365
|
-
historyNavigator
|
|
7366
|
-
} = previousState;
|
|
7360
|
+
static getDerivedStateFromProps({
|
|
7361
|
+
displayPattern
|
|
7362
|
+
}, {
|
|
7363
|
+
prevDisplayPattern = displayPattern,
|
|
7364
|
+
value,
|
|
7365
|
+
historyNavigator
|
|
7366
|
+
}) {
|
|
7367
|
+
if (prevDisplayPattern !== displayPattern) {
|
|
7367
7368
|
const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
|
|
7368
7369
|
historyNavigator.reset();
|
|
7369
7370
|
return {
|
|
@@ -7385,25 +7386,27 @@ class WithDisplayFormat extends Component {
|
|
|
7385
7386
|
const {
|
|
7386
7387
|
displayPattern
|
|
7387
7388
|
} = this.props;
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
|
|
7389
|
+
if (triggerEvent) {
|
|
7390
|
+
const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
|
|
7391
|
+
if (triggerType === 'Paste' || triggerType === 'Cut') {
|
|
7392
|
+
return triggerType;
|
|
7393
|
+
}
|
|
7394
|
+
if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
|
|
7395
|
+
return triggerEvent.shiftKey ? 'Redo' : 'Undo';
|
|
7396
|
+
}
|
|
7397
|
+
// Detect mouse event redo
|
|
7398
|
+
if (triggerEvent.ctrlKey && charCode === 'd') {
|
|
7399
|
+
return 'Delete';
|
|
7400
|
+
}
|
|
7401
|
+
// Android Fix.
|
|
7402
|
+
if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
|
|
7403
7403
|
return 'Backspace';
|
|
7404
7404
|
}
|
|
7405
|
+
return triggerEvent.key;
|
|
7406
|
+
} else {
|
|
7407
|
+
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
7408
|
+
return 'Paste';
|
|
7405
7409
|
}
|
|
7406
|
-
return triggerEvent.key;
|
|
7407
7410
|
};
|
|
7408
7411
|
resetEvent = () => {
|
|
7409
7412
|
this.setState({
|
|
@@ -7431,7 +7434,6 @@ class WithDisplayFormat extends Component {
|
|
|
7431
7434
|
const {
|
|
7432
7435
|
displayPattern
|
|
7433
7436
|
} = this.props;
|
|
7434
|
-
|
|
7435
7437
|
// Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
|
|
7436
7438
|
let newFormattedValue = '';
|
|
7437
7439
|
if (this.detectUndoRedo(event) === 'Undo') {
|
|
@@ -7480,7 +7482,6 @@ class WithDisplayFormat extends Component {
|
|
|
7480
7482
|
handleOnChange = event => {
|
|
7481
7483
|
const {
|
|
7482
7484
|
historyNavigator,
|
|
7483
|
-
triggerEvent,
|
|
7484
7485
|
triggerType
|
|
7485
7486
|
} = this.state;
|
|
7486
7487
|
const {
|
|
@@ -7491,9 +7492,7 @@ class WithDisplayFormat extends Component {
|
|
|
7491
7492
|
value
|
|
7492
7493
|
} = event.target;
|
|
7493
7494
|
let unformattedValue = unformatWithPattern$1(value, displayPattern);
|
|
7494
|
-
const action =
|
|
7495
|
-
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
7496
|
-
'Paste' : this.getUserAction(unformattedValue);
|
|
7495
|
+
const action = this.getUserAction(unformattedValue);
|
|
7497
7496
|
if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
|
|
7498
7497
|
return;
|
|
7499
7498
|
}
|
|
@@ -7503,19 +7502,18 @@ class WithDisplayFormat extends Component {
|
|
|
7503
7502
|
const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
|
|
7504
7503
|
historyNavigator.add(unformattedValue);
|
|
7505
7504
|
this.handleCursorPositioning(action);
|
|
7506
|
-
const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
|
|
7507
7505
|
this.setState({
|
|
7508
7506
|
value: newFormattedValue
|
|
7509
|
-
},
|
|
7507
|
+
}, () => {
|
|
7508
|
+
this.resetEvent();
|
|
7509
|
+
if (onChange) {
|
|
7510
|
+
const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
|
|
7511
|
+
onChange(broadcastValue);
|
|
7512
|
+
}
|
|
7513
|
+
});
|
|
7510
7514
|
};
|
|
7511
7515
|
handleOnBlur = event => {
|
|
7512
|
-
|
|
7513
|
-
displayPattern,
|
|
7514
|
-
onBlur
|
|
7515
|
-
} = this.props;
|
|
7516
|
-
if (onBlur) {
|
|
7517
|
-
onBlur(unformatWithPattern$1(event.target.value, displayPattern));
|
|
7518
|
-
}
|
|
7516
|
+
this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
|
|
7519
7517
|
};
|
|
7520
7518
|
handleOnFocus = event => {
|
|
7521
7519
|
const {
|
|
@@ -7614,62 +7612,13 @@ class WithDisplayFormat extends Component {
|
|
|
7614
7612
|
return this.props.render(renderProps);
|
|
7615
7613
|
}
|
|
7616
7614
|
}
|
|
7617
|
-
WithDisplayFormat.propTypes = {
|
|
7618
|
-
/**
|
|
7619
|
-
* autocomplete hides our form help so we need to disable it when help text
|
|
7620
|
-
* is present. Chrome ignores autocomplete=off, the only way to disable it is
|
|
7621
|
-
* to provide an 'invalid' value, for which 'disabled' serves.
|
|
7622
|
-
*/
|
|
7623
|
-
autoComplete: PropTypes.oneOf(['on', 'off', 'disabled']),
|
|
7624
|
-
className: PropTypes.string,
|
|
7625
|
-
disabled: PropTypes.bool,
|
|
7626
|
-
id: PropTypes.string,
|
|
7627
|
-
maxLength: PropTypes.number,
|
|
7628
|
-
minLength: PropTypes.number,
|
|
7629
|
-
name: PropTypes.string,
|
|
7630
|
-
onFocus: PropTypes.func,
|
|
7631
|
-
onBlur: PropTypes.func,
|
|
7632
|
-
onChange: PropTypes.func.isRequired,
|
|
7633
|
-
placeholder: PropTypes.string,
|
|
7634
|
-
readOnly: PropTypes.bool,
|
|
7635
|
-
render: PropTypes.func.isRequired,
|
|
7636
|
-
required: PropTypes.bool,
|
|
7637
|
-
displayPattern: PropTypes.string,
|
|
7638
|
-
type: PropTypes.string,
|
|
7639
|
-
inputMode: PropTypes.string,
|
|
7640
|
-
value: PropTypes.string
|
|
7641
|
-
};
|
|
7642
|
-
WithDisplayFormat.defaultProps = {
|
|
7643
|
-
autoComplete: 'off',
|
|
7644
|
-
className: null,
|
|
7645
|
-
disabled: false,
|
|
7646
|
-
id: null,
|
|
7647
|
-
maxLength: null,
|
|
7648
|
-
minLength: null,
|
|
7649
|
-
name: null,
|
|
7650
|
-
placeholder: null,
|
|
7651
|
-
readOnly: false,
|
|
7652
|
-
required: false,
|
|
7653
|
-
displayPattern: '',
|
|
7654
|
-
type: 'text',
|
|
7655
|
-
inputMode: null,
|
|
7656
|
-
value: '',
|
|
7657
|
-
onFocus: null,
|
|
7658
|
-
onBlur: null
|
|
7659
|
-
};
|
|
7660
|
-
var WithDisplayFormat$1 = WithDisplayFormat;
|
|
7661
7615
|
|
|
7662
|
-
const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat
|
|
7616
|
+
const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
|
|
7663
7617
|
...props,
|
|
7664
|
-
render: renderProps => /*#__PURE__*/jsx(
|
|
7618
|
+
render: renderProps => /*#__PURE__*/jsx(Input, {
|
|
7665
7619
|
...renderProps
|
|
7666
7620
|
})
|
|
7667
7621
|
});
|
|
7668
|
-
InputWithDisplayFormat.propTypes = {
|
|
7669
|
-
displayPattern: PropTypes.string.isRequired,
|
|
7670
|
-
onChange: PropTypes.func.isRequired
|
|
7671
|
-
};
|
|
7672
|
-
var InputWithDisplayFormat$1 = InputWithDisplayFormat;
|
|
7673
7622
|
|
|
7674
7623
|
const InstructionsList = ({
|
|
7675
7624
|
dos,
|
|
@@ -12346,17 +12295,12 @@ Tabs.defaultProps = {
|
|
|
12346
12295
|
};
|
|
12347
12296
|
var Tabs$1 = Tabs;
|
|
12348
12297
|
|
|
12349
|
-
const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat
|
|
12298
|
+
const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
|
|
12350
12299
|
...props,
|
|
12351
|
-
render: renderProps => /*#__PURE__*/jsx(
|
|
12300
|
+
render: renderProps => /*#__PURE__*/jsx(TextArea, {
|
|
12352
12301
|
...renderProps
|
|
12353
12302
|
})
|
|
12354
12303
|
});
|
|
12355
|
-
TextareaWithDisplayFormat.propTypes = {
|
|
12356
|
-
displayPattern: PropTypes.string.isRequired,
|
|
12357
|
-
onChange: PropTypes.func.isRequired
|
|
12358
|
-
};
|
|
12359
|
-
var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
|
|
12360
12304
|
|
|
12361
12305
|
/* eslint-disable jsx-a11y/no-autofocus */
|
|
12362
12306
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
@@ -15653,5 +15597,5 @@ const translations = {
|
|
|
15653
15597
|
'zh-HK': zhHK
|
|
15654
15598
|
};
|
|
15655
15599
|
|
|
15656
|
-
export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$2 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat
|
|
15600
|
+
export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$2 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList$1 as InstructionsList, LanguageProvider, Layout$1 as Layout, Link, ListItem$1 as ListItem, Loader$1 as Loader, Logo$1 as Logo, LogoType, Markdown$1 as Markdown, MarkdownNodeType, Modal, Money$1 as Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList$1 as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput$1 as PhoneNumberInput, Popover$2 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCard$1 as PromoCardGroup, Provider$1 as Provider, RTL_LANGUAGES, Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioOption$1 as RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel$1 as SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider$1 as SnackbarProvider, Status, StatusIcon, Stepper, Sticky$1 as Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip$1 as Tooltip, Type$1 as Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
|
|
15657
15601
|
//# sourceMappingURL=index.esm.js.map
|