@transferwise/components 0.0.0-experimental-dad389c → 0.0.0-experimental-5e78062

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.
Files changed (31) hide show
  1. package/build/alert/Alert.js +1 -1
  2. package/build/alert/Alert.mjs +1 -1
  3. package/build/button/legacyUtils/legacyUtils.js +1 -1
  4. package/build/button/legacyUtils/legacyUtils.mjs +1 -1
  5. package/build/drawer/Drawer.js +1 -1
  6. package/build/drawer/Drawer.mjs +1 -1
  7. package/build/markdown/Markdown.js +1 -1
  8. package/build/markdown/Markdown.mjs +1 -1
  9. package/build/popover/Popover.js +1 -1
  10. package/build/popover/Popover.mjs +1 -1
  11. package/build/types/test-utils/style-mock.d.ts +1 -0
  12. package/build/types/test-utils/style-mock.d.ts.map +1 -0
  13. package/build/types/utilities/deprecatedProperty/deprecatedProperty.d.ts +8 -6
  14. package/build/types/utilities/deprecatedProperty/deprecatedProperty.d.ts.map +1 -1
  15. package/build/types/utilities/deprecatedProperty/index.d.ts +1 -1
  16. package/build/types/utilities/deprecatedProperty/index.d.ts.map +1 -1
  17. package/build/types/utilities/index.d.ts +2 -2
  18. package/build/types/utilities/index.d.ts.map +1 -1
  19. package/build/types/utilities/logActionRequired.d.ts +2 -2
  20. package/build/types/utilities/logActionRequired.d.ts.map +1 -1
  21. package/build/utilities/logActionRequired.js.map +1 -1
  22. package/build/utilities/logActionRequired.mjs.map +1 -1
  23. package/package.json +1 -1
  24. package/src/inputWithDisplayFormat/InputWithDisplayFormat.story.tsx +78 -0
  25. package/src/utilities/deprecatedProperty/{deprecatedProperty.spec.js → deprecatedProperty.spec.ts} +7 -13
  26. package/src/utilities/deprecatedProperty/{deprecatedProperty.js → deprecatedProperty.ts} +23 -4
  27. package/src/utilities/{logActionRequired.js → logActionRequired.ts} +2 -2
  28. package/src/inputWithDisplayFormat/InputWithDisplayFormat.story.js +0 -85
  29. /package/src/test-utils/{style-mock.js → style-mock.ts} +0 -0
  30. /package/src/utilities/deprecatedProperty/{index.js → index.ts} +0 -0
  31. /package/src/utilities/{index.js → index.ts} +0 -0
@@ -7,10 +7,10 @@ var React = require('react');
7
7
  var Body = require('../body/Body.js');
8
8
  var StatusIcon = require('../statusIcon/StatusIcon.js');
9
9
  var Title = require('../title/Title.js');
10
+ var logActionRequired = require('../utilities/logActionRequired.js');
10
11
  var InlineMarkdown = require('./inlineMarkdown/InlineMarkdown.js');
11
12
  var Action = require('../common/action/Action.js');
12
13
  var jsxRuntime = require('react/jsx-runtime');
13
- var logActionRequired = require('../utilities/logActionRequired.js');
14
14
  var constants = require('../common/constants.js');
15
15
  var sentiment = require('../common/propsValues/sentiment.js');
16
16
  var CloseButton = require('../common/closeButton/CloseButton.js');
@@ -3,10 +3,10 @@ import { useEffect, useState, useRef } from 'react';
3
3
  import Body from '../body/Body.mjs';
4
4
  import StatusIcon from '../statusIcon/StatusIcon.mjs';
5
5
  import Title from '../title/Title.mjs';
6
+ import { logActionRequired } from '../utilities/logActionRequired.mjs';
6
7
  import InlineMarkdown from './inlineMarkdown/InlineMarkdown.mjs';
7
8
  import { Action } from '../common/action/Action.mjs';
8
9
  import { jsx, jsxs } from 'react/jsx-runtime';
9
- import { logActionRequired } from '../utilities/logActionRequired.mjs';
10
10
  import { WDS_LIVE_REGION_DELAY_MS } from '../common/constants.mjs';
11
11
  import { Sentiment } from '../common/propsValues/sentiment.mjs';
12
12
  import { CloseButton } from '../common/closeButton/CloseButton.mjs';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var type = require('../../common/propsValues/type.js');
4
3
  var logActionRequired = require('../../utilities/logActionRequired.js');
4
+ var type = require('../../common/propsValues/type.js');
5
5
  var control = require('../../common/propsValues/control.js');
6
6
  var size = require('../../common/propsValues/size.js');
7
7
 
@@ -1,5 +1,5 @@
1
- import { Type } from '../../common/propsValues/type.mjs';
2
1
  import { logActionRequiredIf } from '../../utilities/logActionRequired.mjs';
2
+ import { Type } from '../../common/propsValues/type.mjs';
3
3
  import { ControlType, Priority } from '../../common/propsValues/control.mjs';
4
4
  import { Size } from '../../common/propsValues/size.mjs';
5
5
 
@@ -7,8 +7,8 @@ var Dimmer = require('../dimmer/Dimmer.js');
7
7
  var OverlayIdProvider = require('../provider/overlay/OverlayIdProvider.js');
8
8
  var SlidingPanel = require('../slidingPanel/SlidingPanel.js');
9
9
  var Title = require('../title/Title.js');
10
- var jsxRuntime = require('react/jsx-runtime');
11
10
  var logActionRequired = require('../utilities/logActionRequired.js');
11
+ var jsxRuntime = require('react/jsx-runtime');
12
12
  var useLayout = require('../common/hooks/useLayout/useLayout.js');
13
13
  var position = require('../common/propsValues/position.js');
14
14
  var typography = require('../common/propsValues/typography.js');
@@ -5,8 +5,8 @@ import Dimmer from '../dimmer/Dimmer.mjs';
5
5
  import { OverlayIdContext } from '../provider/overlay/OverlayIdProvider.mjs';
6
6
  import SlidingPanel from '../slidingPanel/SlidingPanel.mjs';
7
7
  import Title from '../title/Title.mjs';
8
- import { jsx, jsxs } from 'react/jsx-runtime';
9
8
  import { logActionRequiredIf } from '../utilities/logActionRequired.mjs';
9
+ import { jsx, jsxs } from 'react/jsx-runtime';
10
10
  import { useLayout } from '../common/hooks/useLayout/useLayout.mjs';
11
11
  import { Position } from '../common/propsValues/position.mjs';
12
12
  import { Typography } from '../common/propsValues/typography.mjs';
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var commonmark = require('commonmark');
4
+ var logActionRequired = require('../utilities/logActionRequired.js');
4
5
  var jsxRuntime = require('react/jsx-runtime');
5
6
  var markdownNodeType = require('../common/propsValues/markdownNodeType.js');
6
- var logActionRequired = require('../utilities/logActionRequired.js');
7
7
 
8
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
@@ -1,7 +1,7 @@
1
1
  import commonmark from 'commonmark';
2
+ import { logActionRequired } from '../utilities/logActionRequired.mjs';
2
3
  import { jsx } from 'react/jsx-runtime';
3
4
  import { MarkdownNodeType } from '../common/propsValues/markdownNodeType.mjs';
4
- import { logActionRequired } from '../utilities/logActionRequired.mjs';
5
5
 
6
6
  const reader = new commonmark.Parser();
7
7
  const writer = new commonmark.HtmlRenderer({
@@ -3,8 +3,8 @@
3
3
  var clsx = require('clsx');
4
4
  var React = require('react');
5
5
  var Title = require('../title/Title.js');
6
- var jsxRuntime = require('react/jsx-runtime');
7
6
  var logActionRequired = require('../utilities/logActionRequired.js');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
8
  var ResponsivePanel = require('../common/responsivePanel/ResponsivePanel.js');
9
9
  var typography = require('../common/propsValues/typography.js');
10
10
  var position = require('../common/propsValues/position.js');
@@ -1,8 +1,8 @@
1
1
  import { clsx } from 'clsx';
2
2
  import { useId, useEffect, useRef, useState, isValidElement, cloneElement } from 'react';
3
3
  import Title from '../title/Title.mjs';
4
- import { jsxs, jsx } from 'react/jsx-runtime';
5
4
  import { logActionRequired } from '../utilities/logActionRequired.mjs';
5
+ import { jsxs, jsx } from 'react/jsx-runtime';
6
6
  import ResponsivePanel from '../common/responsivePanel/ResponsivePanel.mjs';
7
7
  import { Typography } from '../common/propsValues/typography.mjs';
8
8
  import { Position } from '../common/propsValues/position.mjs';
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=style-mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style-mock.d.ts","sourceRoot":"","sources":["../../../src/test-utils/style-mock.ts"],"names":[],"mappings":""}
@@ -1,8 +1,10 @@
1
+ type ValidatorType = (props: Record<string, any>, propName: string, ...rest: any[]) => Error | null;
2
+ type DeprecatedOptionsType = {
3
+ component: string;
4
+ message?: string;
5
+ newProp?: string;
6
+ expiryDate?: Date;
7
+ };
8
+ declare const deprecated: (validator: ValidatorType, { component, message, newProp: newProperty, expiryDate }: DeprecatedOptionsType) => (props: Record<string, any>, propertyName: string, ...rest: any[]) => Error | null;
1
9
  export default deprecated;
2
- declare function deprecated(validator: any, { component, message, newProp: newProperty, expiryDate }: {
3
- component: any;
4
- message?: string | undefined;
5
- newProp?: null | undefined;
6
- expiryDate?: null | undefined;
7
- }): (props: any, propertyName: any, ...rest: any[]) => any;
8
10
  //# sourceMappingURL=deprecatedProperty.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deprecatedProperty.d.ts","sourceRoot":"","sources":["../../../../src/utilities/deprecatedProperty/deprecatedProperty.js"],"names":[],"mappings":";AAsBA;;;;;2DAgBG"}
1
+ {"version":3,"file":"deprecatedProperty.d.ts","sourceRoot":"","sources":["../../../../src/utilities/deprecatedProperty/deprecatedProperty.ts"],"names":[],"mappings":"AASA,KAAK,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,CAAC;AAEpG,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,IAAI,CAAC;CACnB,CAAC;AAsBF,QAAA,MAAM,UAAU,cAED,aAAa,4DACuC,qBAAqB,aAE9E,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,gBAAgB,MAAM,WAAW,GAAG,EAAE,iBAchE,CAAC;AAEJ,eAAe,UAAU,CAAC"}
@@ -1,2 +1,2 @@
1
- export { default } from "./deprecatedProperty";
1
+ export { default } from './deprecatedProperty';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utilities/deprecatedProperty/index.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utilities/deprecatedProperty/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,3 +1,3 @@
1
- export { default as deprecated } from "./deprecatedProperty";
2
- export { logActionRequired, logActionRequiredIf } from "./logActionRequired";
1
+ export { default as deprecated } from './deprecatedProperty';
2
+ export { logActionRequired, logActionRequiredIf } from './logActionRequired';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/index.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,3 +1,3 @@
1
- export function logActionRequired(message: any): void;
2
- export function logActionRequiredIf(message: any, conditional: any): void;
1
+ export declare function logActionRequired(message: string): void;
2
+ export declare function logActionRequiredIf(message: string, conditional: boolean): void;
3
3
  //# sourceMappingURL=logActionRequired.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logActionRequired.d.ts","sourceRoot":"","sources":["../../../src/utilities/logActionRequired.js"],"names":[],"mappings":"AAAA,sDAKC;AAED,0EAIC"}
1
+ {"version":3,"file":"logActionRequired.d.ts","sourceRoot":"","sources":["../../../src/utilities/logActionRequired.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,QAKhD;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,QAIxE"}
@@ -1 +1 @@
1
- {"version":3,"file":"logActionRequired.js","sources":["../../src/utilities/logActionRequired.js"],"sourcesContent":["export function logActionRequired(message) {\n if (typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(message);\n }\n}\n\nexport function logActionRequiredIf(message, conditional) {\n if (conditional) {\n logActionRequired(message);\n }\n}\n"],"names":["logActionRequired","message","process","env","NODE_ENV","console","warn","logActionRequiredIf","conditional"],"mappings":";;AAAO,SAASA,iBAAiBA,CAACC,OAAO,EAAE;AACzC,EAAA,IAAI,OAAOC,OAAO,KAAK,WAAW,IAAIA,OAAO,CAACC,GAAG,EAAEC,QAAQ,KAAK,YAAY,EAAE;AAC5E;AACAC,IAAAA,OAAO,CAACC,IAAI,CAACL,OAAO,CAAC,CAAA;AACvB,GAAA;AACF,CAAA;AAEO,SAASM,mBAAmBA,CAACN,OAAO,EAAEO,WAAW,EAAE;AACxD,EAAA,IAAIA,WAAW,EAAE;IACfR,iBAAiB,CAACC,OAAO,CAAC,CAAA;AAC5B,GAAA;AACF;;;;;"}
1
+ {"version":3,"file":"logActionRequired.js","sources":["../../src/utilities/logActionRequired.ts"],"sourcesContent":["export function logActionRequired(message: string) {\n if (typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(message);\n }\n}\n\nexport function logActionRequiredIf(message: string, conditional: boolean) {\n if (conditional) {\n logActionRequired(message);\n }\n}\n"],"names":["logActionRequired","message","process","env","NODE_ENV","console","warn","logActionRequiredIf","conditional"],"mappings":";;AAAM,SAAUA,iBAAiBA,CAACC,OAAe,EAAA;AAC/C,EAAA,IAAI,OAAOC,OAAO,KAAK,WAAW,IAAIA,OAAO,CAACC,GAAG,EAAEC,QAAQ,KAAK,YAAY,EAAE;AAC5E;AACAC,IAAAA,OAAO,CAACC,IAAI,CAACL,OAAO,CAAC,CAAA;AACvB,GAAA;AACF,CAAA;AAEgB,SAAAM,mBAAmBA,CAACN,OAAe,EAAEO,WAAoB,EAAA;AACvE,EAAA,IAAIA,WAAW,EAAE;IACfR,iBAAiB,CAACC,OAAO,CAAC,CAAA;AAC5B,GAAA;AACF;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"logActionRequired.mjs","sources":["../../src/utilities/logActionRequired.js"],"sourcesContent":["export function logActionRequired(message) {\n if (typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(message);\n }\n}\n\nexport function logActionRequiredIf(message, conditional) {\n if (conditional) {\n logActionRequired(message);\n }\n}\n"],"names":["logActionRequired","message","process","env","NODE_ENV","console","warn","logActionRequiredIf","conditional"],"mappings":"AAAO,SAASA,iBAAiBA,CAACC,OAAO,EAAE;AACzC,EAAA,IAAI,OAAOC,OAAO,KAAK,WAAW,IAAIA,OAAO,CAACC,GAAG,EAAEC,QAAQ,KAAK,YAAY,EAAE;AAC5E;AACAC,IAAAA,OAAO,CAACC,IAAI,CAACL,OAAO,CAAC,CAAA;AACvB,GAAA;AACF,CAAA;AAEO,SAASM,mBAAmBA,CAACN,OAAO,EAAEO,WAAW,EAAE;AACxD,EAAA,IAAIA,WAAW,EAAE;IACfR,iBAAiB,CAACC,OAAO,CAAC,CAAA;AAC5B,GAAA;AACF;;;;"}
1
+ {"version":3,"file":"logActionRequired.mjs","sources":["../../src/utilities/logActionRequired.ts"],"sourcesContent":["export function logActionRequired(message: string) {\n if (typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(message);\n }\n}\n\nexport function logActionRequiredIf(message: string, conditional: boolean) {\n if (conditional) {\n logActionRequired(message);\n }\n}\n"],"names":["logActionRequired","message","process","env","NODE_ENV","console","warn","logActionRequiredIf","conditional"],"mappings":"AAAM,SAAUA,iBAAiBA,CAACC,OAAe,EAAA;AAC/C,EAAA,IAAI,OAAOC,OAAO,KAAK,WAAW,IAAIA,OAAO,CAACC,GAAG,EAAEC,QAAQ,KAAK,YAAY,EAAE;AAC5E;AACAC,IAAAA,OAAO,CAACC,IAAI,CAACL,OAAO,CAAC,CAAA;AACvB,GAAA;AACF,CAAA;AAEgB,SAAAM,mBAAmBA,CAACN,OAAe,EAAEO,WAAoB,EAAA;AACvE,EAAA,IAAIA,WAAW,EAAE;IACfR,iBAAiB,CAACC,OAAO,CAAC,CAAA;AAC5B,GAAA;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-dad389c",
3
+ "version": "0.0.0-experimental-5e78062",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -0,0 +1,78 @@
1
+ import { userEvent, within, fn } from '@storybook/test';
2
+
3
+ import InputWithDisplayFormat, { InputWithDisplayFormatProps } from '.';
4
+ import { Field, FieldProps } from '../field/Field';
5
+ import { Meta, type StoryObj } from '@storybook/react';
6
+
7
+ type Story = StoryObj<InputWithDisplayFormatProps & { label: string }>;
8
+
9
+ const meta = {
10
+ title: 'Forms/InputWithDisplayFormat',
11
+ component: InputWithDisplayFormat,
12
+ render: function Render({ label, ...args }: InputWithDisplayFormatProps & FieldProps) {
13
+ return (
14
+ <Field label={label} id={args.id}>
15
+ <InputWithDisplayFormat id={args.id} {...args} />
16
+ </Field>
17
+ );
18
+ },
19
+ args: {
20
+ onFocus: fn(),
21
+ onBlur: fn(),
22
+ onChange: fn(),
23
+ },
24
+ } satisfies Meta<typeof InputWithDisplayFormat>;
25
+ export default meta;
26
+
27
+ export const Basic: Story = {
28
+ args: {
29
+ label: 'Sort Code',
30
+ placeholder: '**-**-**',
31
+ displayPattern: '**-**-**',
32
+ },
33
+ };
34
+
35
+ export const CardNumber: Story = {
36
+ args: {
37
+ label: 'Card Number',
38
+ placeholder: '**** **** **** **** ***',
39
+ displayPattern: '**** **** **** **** ***',
40
+ },
41
+ };
42
+
43
+ export const CVC: Story = {
44
+ args: {
45
+ label: 'CVC',
46
+ placeholder: '***',
47
+ displayPattern: '***',
48
+ value: '',
49
+ },
50
+ };
51
+
52
+ export const ExpiryDate: Story = {
53
+ args: {
54
+ label: 'Expiry Date',
55
+ placeholder: '** / **',
56
+ displayPattern: '** / **',
57
+ },
58
+ };
59
+
60
+ export const SecurityPin: Story = {
61
+ args: {
62
+ label: 'Security Pin',
63
+ placeholder: '*-*-*-*-*-*',
64
+ displayPattern: '*-*-*-*-*-*',
65
+ },
66
+ };
67
+
68
+ export const SecurityPinPlay: Story = {
69
+ args: {
70
+ label: 'Security Pin Play',
71
+ placeholder: '*-*-*-*-*-*',
72
+ displayPattern: '*-*-*-*-*-*',
73
+ },
74
+ play: async ({ canvasElement }) => {
75
+ const canvas = within(canvasElement);
76
+ await userEvent.type(canvas.getByPlaceholderText('*-*-*-*-*-*'), '123456');
77
+ },
78
+ };
@@ -5,6 +5,7 @@ const props = { prop1: 'prop1', prop2: 'prop2' };
5
5
  const validator = jest.fn();
6
6
 
7
7
  describe('deprecated', () => {
8
+ const component = 'Test';
8
9
  const origWarn = console.warn;
9
10
  let mockedWarn;
10
11
 
@@ -22,11 +23,10 @@ describe('deprecated', () => {
22
23
  });
23
24
 
24
25
  describe('if prop has been listed as deprecated', () => {
26
+ const propertyName = 'prop1';
27
+
25
28
  it('calls console.warn with the correct message', () => {
26
- const component = 'Test';
27
29
  const newProperty = 'newProp';
28
- const propertyName = 'prop1';
29
-
30
30
  const expiryDate = new Date('01-01-2000');
31
31
  const expiryDateString = expiryDate.toLocaleString('en-GB', {
32
32
  year: 'numeric',
@@ -42,10 +42,6 @@ describe('deprecated', () => {
42
42
  });
43
43
 
44
44
  it('calls console.warn with correct message if newProp is not provided', () => {
45
- const component = 'Test';
46
-
47
- const propertyName = 'prop1';
48
-
49
45
  const expiryDate = new Date('01-01-2000');
50
46
  const expiryDateString = expiryDate.toLocaleString('en-GB', {
51
47
  year: 'numeric',
@@ -61,8 +57,6 @@ describe('deprecated', () => {
61
57
  });
62
58
 
63
59
  it('calls console.warn with correct message if message is provided', () => {
64
- const component = 'Test';
65
- const propertyName = 'prop1';
66
60
  const message = 'Some custom message.';
67
61
 
68
62
  deprecated(validator, { component, message })(props, propertyName);
@@ -74,15 +68,15 @@ describe('deprecated', () => {
74
68
  });
75
69
 
76
70
  describe('if prop has not been listed as deprecated', () => {
71
+ const propertyName = 'prop3';
72
+
77
73
  it('calls validator with props', () => {
78
- const propertyName = 'prop3';
79
- deprecated(validator, {})(props, propertyName);
74
+ deprecated(validator, { component })(props, propertyName);
80
75
  expect(console.warn).not.toHaveBeenCalled();
81
76
  });
82
77
 
83
78
  it('calls validator with expected args', () => {
84
- const propertyName = 'prop3';
85
- deprecated(validator, {})(props, propertyName);
79
+ deprecated(validator, { component })(props, propertyName);
86
80
  expect(validator).toHaveBeenCalledWith({ prop1: 'prop1', prop2: 'prop2' }, 'prop3');
87
81
  });
88
82
  });
@@ -1,6 +1,22 @@
1
1
  import { logActionRequired } from '../logActionRequired';
2
2
 
3
- const deprecatedMessage = ({ component, propName, message, expiryDate }) => {
3
+ type DeprecatedMessageType = {
4
+ component: string;
5
+ propName: string;
6
+ message: string;
7
+ expiryDate?: Date;
8
+ };
9
+
10
+ type ValidatorType = (props: Record<string, any>, propName: string, ...rest: any[]) => Error | null;
11
+
12
+ type DeprecatedOptionsType = {
13
+ component: string;
14
+ message?: string;
15
+ newProp?: string;
16
+ expiryDate?: Date;
17
+ };
18
+
19
+ const deprecatedMessage = ({ component, propName, message, expiryDate }: DeprecatedMessageType) => {
4
20
  const messages = [`${component} has deprecated the use of ${propName}.`];
5
21
 
6
22
  if (message) {
@@ -21,11 +37,14 @@ const deprecatedMessage = ({ component, propName, message, expiryDate }) => {
21
37
  };
22
38
 
23
39
  const deprecated =
24
- (validator, { component, message = '', newProp: newProperty = null, expiryDate = null }) =>
25
- (props, propertyName, ...rest) => {
40
+ (
41
+ validator: ValidatorType,
42
+ { component, message = '', newProp: newProperty, expiryDate }: DeprecatedOptionsType,
43
+ ) =>
44
+ (props: Record<string, any>, propertyName: string, ...rest: any[]) => {
26
45
  const newPropertyMessage = newProperty ? `Please use ${newProperty} instead.` : message;
27
46
 
28
- if (props[propertyName] != null && typeof props[propertyName] !== 'undefined') {
47
+ if (props[propertyName] !== null && props[propertyName] !== undefined) {
29
48
  logActionRequired(
30
49
  deprecatedMessage({
31
50
  component,
@@ -1,11 +1,11 @@
1
- export function logActionRequired(message) {
1
+ export function logActionRequired(message: string) {
2
2
  if (typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production') {
3
3
  // eslint-disable-next-line no-console
4
4
  console.warn(message);
5
5
  }
6
6
  }
7
7
 
8
- export function logActionRequiredIf(message, conditional) {
8
+ export function logActionRequiredIf(message: string, conditional: boolean) {
9
9
  if (conditional) {
10
10
  logActionRequired(message);
11
11
  }
@@ -1,85 +0,0 @@
1
- import { text } from '@storybook/addon-knobs';
2
- import { userEvent, within } from '@storybook/test';
3
-
4
- import InputWithDisplayFormat from '.';
5
- import { Field } from '../field/Field';
6
-
7
- export default {
8
- component: InputWithDisplayFormat,
9
- title: 'Forms/InputWithDisplayFormat',
10
- };
11
-
12
- export const Basic = () => {
13
- const placeholder = text('Placeholder', '**-**-**');
14
- const displayPattern = text('DisplayPattern', '**-**-**');
15
-
16
- return (
17
- <Field label="Display pattern is controlled via knobs" id="Basic">
18
- <InputWithDisplayFormat
19
- id="Basic"
20
- placeholder={placeholder}
21
- displayPattern={displayPattern}
22
- className="form-control"
23
- onChange={(v) => console.log(v)}
24
- onBlur={(v) => console.log(v)}
25
- onFocus={(v) => console.log(v)}
26
- />
27
- </Field>
28
- );
29
- };
30
-
31
- const Template = (args) => {
32
- const placeholder = args.pattern;
33
- const displayPattern = args.pattern;
34
- const label = args.label;
35
- const id = label.replaceAll(' ', '-').toLowerCase();
36
-
37
- return (
38
- <Field label={label} id={id}>
39
- <InputWithDisplayFormat
40
- id={id}
41
- placeholder={placeholder}
42
- displayPattern={displayPattern}
43
- className="form-control"
44
- onChange={(v) => console.log(v)}
45
- onBlur={(v) => console.log(v)}
46
- onFocus={(v) => console.log(v)}
47
- />
48
- </Field>
49
- );
50
- };
51
-
52
- export const CardNumber = Template.bind({});
53
- CardNumber.args = {
54
- label: 'Card Number',
55
- pattern: '**** **** **** **** ***',
56
- };
57
-
58
- export const CVC = Template.bind({});
59
- CVC.args = {
60
- label: 'CVC',
61
- pattern: '***',
62
- };
63
-
64
- export const ExpiryDate = Template.bind({});
65
- ExpiryDate.args = {
66
- label: 'Expiry Date',
67
- pattern: '** / **',
68
- };
69
-
70
- export const SecurityPin = Template.bind({});
71
- SecurityPin.args = {
72
- label: 'Security Pin',
73
- pattern: '*-*-*-*-*-*',
74
- };
75
-
76
- export const SecurityPinPlay = Template.bind({});
77
- SecurityPinPlay.args = {
78
- label: 'Security Pin',
79
- pattern: '*-*-*-*-*-*',
80
- };
81
-
82
- SecurityPinPlay.play = async ({ canvasElement }) => {
83
- const canvas = within(canvasElement);
84
- await userEvent.type(canvas.getByPlaceholderText('*-*-*-*-*-*'), '123456');
85
- };
File without changes
File without changes