@transferwise/components 0.0.0-experimental-ffd4b26 → 0.0.0-experimental-dfa8310

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/main.css CHANGED
@@ -4198,14 +4198,16 @@ html:not([dir="rtl"]) .np-navigation-option {
4198
4198
  height: var(--size-32);
4199
4199
  }
4200
4200
  }
4201
- .status-circle.negative {
4201
+ .status-circle.negative,
4202
+ .status-circle.error {
4202
4203
  background-color: var(--color-sentiment-negative);
4203
4204
  }
4204
4205
  .status-circle.neutral {
4205
4206
  background-color: #5d7079;
4206
4207
  background-color: var(--color-content-secondary);
4207
4208
  }
4208
- .status-circle.positive {
4209
+ .status-circle.positive,
4210
+ .status-circle.success {
4209
4211
  background-color: var(--color-sentiment-positive);
4210
4212
  }
4211
4213
  .tw-stepper {
@@ -4198,14 +4198,16 @@ html:not([dir="rtl"]) .np-navigation-option {
4198
4198
  height: var(--size-32);
4199
4199
  }
4200
4200
  }
4201
- .status-circle.negative {
4201
+ .status-circle.negative,
4202
+ .status-circle.error {
4202
4203
  background-color: var(--color-sentiment-negative);
4203
4204
  }
4204
4205
  .status-circle.neutral {
4205
4206
  background-color: #5d7079;
4206
4207
  background-color: var(--color-content-secondary);
4207
4208
  }
4208
- .status-circle.positive {
4209
+ .status-circle.positive,
4210
+ .status-circle.success {
4209
4211
  background-color: var(--color-sentiment-positive);
4210
4212
  }
4211
4213
  .tw-stepper {
@@ -66,13 +66,15 @@
66
66
  height: var(--size-32);
67
67
  }
68
68
  }
69
- .status-circle.negative {
69
+ .status-circle.negative,
70
+ .status-circle.error {
70
71
  background-color: var(--color-sentiment-negative);
71
72
  }
72
73
  .status-circle.neutral {
73
74
  background-color: #5d7079;
74
75
  background-color: var(--color-content-secondary);
75
76
  }
76
- .status-circle.positive {
77
+ .status-circle.positive,
78
+ .status-circle.success {
77
79
  background-color: var(--color-sentiment-positive);
78
80
  }
@@ -1,2 +1,7 @@
1
+ /**
2
+ * This progressive enhancement uses an experimental API, it might change,
3
+ * and at the time of authoring is not supported on iOS or mobile Firefox.
4
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard
5
+ */
1
6
  export declare function useVirtualKeyboard(): void;
2
7
  //# sourceMappingURL=useVirtualKeyboard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useVirtualKeyboard.d.ts","sourceRoot":"","sources":["../../../../src/common/hooks/useVirtualKeyboard.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,SAajC"}
1
+ {"version":3,"file":"useVirtualKeyboard.d.ts","sourceRoot":"","sources":["../../../../src/common/hooks/useVirtualKeyboard.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,kBAAkB,SAajC"}
@@ -1,11 +1,16 @@
1
+ import { Sentiment } from '../common';
1
2
  export type FieldProps = {
2
3
  /** `null` disables auto-generating the `id` attribute, falling back to nesting-based label association over setting `htmlFor` explicitly. */
3
4
  id?: string | null;
4
5
  label: React.ReactNode;
6
+ /** @deprecated use `message` and `type={Sentiment.NEUTRAL}` prop instead */
5
7
  hint?: React.ReactNode;
8
+ message?: React.ReactNode;
9
+ /** @deprecated use `message` and `type={Sentiment.NEGATIVE}` prop instead */
6
10
  error?: React.ReactNode;
11
+ sentiment?: `${Sentiment.NEGATIVE | Sentiment.NEUTRAL | Sentiment.POSITIVE | Sentiment.WARNING}`;
7
12
  className?: string;
8
13
  children?: React.ReactNode;
9
14
  };
10
- export declare const Field: ({ id, label, hint, error, className, children }: FieldProps) => import("react").JSX.Element;
15
+ export declare const Field: ({ id, label, message: propMessage, sentiment: propType, className, children, ...props }: FieldProps) => import("react").JSX.Element;
11
16
  //# sourceMappingURL=Field.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../../src/field/Field.tsx"],"names":[],"mappings":"AAaA,MAAM,MAAM,UAAU,GAAG;IACvB,6IAA6I;IAC7I,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,KAAK,oDAAqD,UAAU,gCA8ChF,CAAC"}
1
+ {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../../src/field/Field.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAUtC,MAAM,MAAM,UAAU,GAAG;IACvB,6IAA6I;IAC7I,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,6EAA6E;IAC7E,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;IACjG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,KAAK,4FAQf,UAAU,gCA4CZ,CAAC"}
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { Sentiment } from '../common';
3
3
  export interface InlineAlertProps {
4
4
  id?: string;
@@ -6,5 +6,5 @@ export interface InlineAlertProps {
6
6
  className?: string;
7
7
  children: ReactNode;
8
8
  }
9
- export default function InlineAlert({ id, type, className, children, }: InlineAlertProps): import("react").JSX.Element;
9
+ export default function InlineAlert({ id, type, className, children, }: InlineAlertProps): React.JSX.Element;
10
10
  //# sourceMappingURL=InlineAlert.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"InlineAlert.d.ts","sourceRoot":"","sources":["../../../src/inlineAlert/InlineAlert.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,WAAW,gBAAgB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,EAAE,EACF,IAAgB,EAChB,SAAS,EACT,QAAQ,GACT,EAAE,gBAAgB,+BAYlB"}
1
+ {"version":3,"file":"InlineAlert.d.ts","sourceRoot":"","sources":["../../../src/inlineAlert/InlineAlert.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAQ,MAAM,WAAW,CAAC;AAG5C,MAAM,WAAW,gBAAgB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,EAAE,EACF,IAAgB,EAChB,SAAS,EACT,QAAQ,GACT,EAAE,gBAAgB,qBAmBlB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-ffd4b26",
3
+ "version": "0.0.0-experimental-dfa8310",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -93,7 +93,7 @@
93
93
  "rollup": "^4.17.2",
94
94
  "storybook": "^8.1.10",
95
95
  "@transferwise/less-config": "3.1.0",
96
- "@transferwise/neptune-css": "14.10.0",
96
+ "@transferwise/neptune-css": "14.11.0",
97
97
  "@wise/components-theming": "1.3.0"
98
98
  },
99
99
  "peerDependencies": {
@@ -1,5 +1,10 @@
1
1
  import { useEffect } from 'react';
2
2
 
3
+ /**
4
+ * This progressive enhancement uses an experimental API, it might change,
5
+ * and at the time of authoring is not supported on iOS or mobile Firefox.
6
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard
7
+ */
3
8
  export function useVirtualKeyboard() {
4
9
  useEffect(() => {
5
10
  /* eslint-disable @typescript-eslint/no-unsafe-member-access, functional/immutable-data */
@@ -2,10 +2,12 @@ import { useState } from 'react';
2
2
 
3
3
  import { Input } from '../inputs/Input';
4
4
  import { Field } from './Field';
5
+ import { Sentiment } from '../common';
5
6
 
6
7
  export default {
7
8
  component: Field,
8
9
  title: 'Field',
10
+ tags: ['autodocs'],
9
11
  };
10
12
 
11
13
  export const Basic = () => {
@@ -17,43 +19,22 @@ export const Basic = () => {
17
19
  );
18
20
  };
19
21
 
20
- export const WithErrorMessage = () => {
22
+ export const WithStatusMessages = () => {
21
23
  const [value, setValue] = useState<string | undefined>('This is some text');
22
24
  return (
23
- <Field label="Phone number" error="This is a required field">
24
- <Input value={value} onChange={({ target }) => setValue(target.value)} />
25
- </Field>
26
- );
27
- };
28
-
29
- export const WithHelp = () => {
30
- const [value, setValue] = useState<string | undefined>('This is some text');
31
- return (
32
- <Field label="Phone number" hint="This is a helpful message">
33
- <Input value={value} onChange={({ target }) => setValue(target.value)} />
34
- </Field>
35
- );
36
- };
37
-
38
- export const WithHelpAndErrorOnBlur = () => {
39
- const [value, setValue] = useState<string | undefined>('This is some text');
40
- const [error, setError] = useState<string | undefined>(undefined);
41
- return (
42
- <Field label="Phone number" hint="Please include country code" error={error}>
43
- <Input
44
- value={value}
45
- onChange={({ target }) => {
46
- setValue(target.value);
47
- setError(undefined);
48
- }}
49
- onBlur={() => {
50
- if (!value) {
51
- setError('This is a required field');
52
- } else {
53
- setError(undefined);
54
- }
55
- }}
56
- />
57
- </Field>
25
+ <div>
26
+ <Field label="Phone number" sentiment={Sentiment.POSITIVE} message="Positive message">
27
+ <Input value={value} onChange={({ target }) => setValue(target.value)} />
28
+ </Field>
29
+ <Field label="Phone number" sentiment={Sentiment.WARNING} message="Warning message">
30
+ <Input value={value} onChange={({ target }) => setValue(target.value)} />
31
+ </Field>
32
+ <Field label="Phone number" sentiment={Sentiment.NEGATIVE} message="This is a required field">
33
+ <Input value={value} onChange={({ target }) => setValue(target.value)} />
34
+ </Field>
35
+ <Field label="Phone number" message="This is a helpful message">
36
+ <Input value={value} onChange={({ target }) => setValue(target.value)} />
37
+ </Field>
38
+ </div>
58
39
  );
59
40
  };
@@ -0,0 +1,33 @@
1
+ import { useState } from 'react';
2
+
3
+ import { Input } from '../inputs/Input';
4
+ import { Field } from './Field';
5
+ import { Sentiment } from '../common';
6
+
7
+ export default {
8
+ component: Field,
9
+ title: 'Field/Tests',
10
+ };
11
+
12
+ export const WithHelpAndErrorOnBlur = () => {
13
+ const [value, setValue] = useState('This is some text');
14
+ const [error, setError] = useState<string | undefined>(undefined);
15
+ return (
16
+ <Field
17
+ label="Phone number"
18
+ sentiment={error ? Sentiment.NEGATIVE : Sentiment.NEUTRAL}
19
+ message={error || 'Please include country code'}
20
+ >
21
+ <Input
22
+ value={value}
23
+ onChange={({ target }) => {
24
+ setValue(target.value);
25
+ setError(undefined);
26
+ }}
27
+ onBlur={() => {
28
+ setError('Something went wrong');
29
+ }}
30
+ />
31
+ </Field>
32
+ );
33
+ };
@@ -15,15 +15,28 @@ export type FieldProps = {
15
15
  /** `null` disables auto-generating the `id` attribute, falling back to nesting-based label association over setting `htmlFor` explicitly. */
16
16
  id?: string | null;
17
17
  label: React.ReactNode;
18
+ /** @deprecated use `message` and `type={Sentiment.NEUTRAL}` prop instead */
18
19
  hint?: React.ReactNode;
20
+ message?: React.ReactNode;
21
+ /** @deprecated use `message` and `type={Sentiment.NEGATIVE}` prop instead */
19
22
  error?: React.ReactNode;
23
+ sentiment?: `${Sentiment.NEGATIVE | Sentiment.NEUTRAL | Sentiment.POSITIVE | Sentiment.WARNING}`;
20
24
  className?: string;
21
25
  children?: React.ReactNode;
22
26
  };
23
27
 
24
- export const Field = ({ id, label, hint, error, className, children }: FieldProps) => {
25
- const hasError = Boolean(error);
26
- const hasHint = Boolean(hint) && !hasError;
28
+ export const Field = ({
29
+ id,
30
+ label,
31
+ message: propMessage,
32
+ sentiment: propType = Sentiment.NEUTRAL,
33
+ className,
34
+ children,
35
+ ...props
36
+ }: FieldProps) => {
37
+ const sentiment = props.error ? Sentiment.NEGATIVE : propType;
38
+ const message = props.error || props.hint || propMessage;
39
+ const hasError = sentiment === Sentiment.NEGATIVE;
27
40
 
28
41
  const labelId = useId();
29
42
 
@@ -35,14 +48,16 @@ export const Field = ({ id, label, hint, error, className, children }: FieldProp
35
48
  return (
36
49
  <FieldLabelIdContextProvider value={labelId}>
37
50
  <InputIdContextProvider value={inputId}>
38
- <InputDescribedByProvider value={hasError || hasHint ? descriptionId : undefined}>
51
+ <InputDescribedByProvider value={message ? descriptionId : undefined}>
39
52
  <InputInvalidProvider value={hasError}>
40
53
  <div
41
54
  className={classNames(
42
55
  'form-group d-block',
43
56
  {
57
+ 'has-success': sentiment === Sentiment.POSITIVE,
58
+ 'has-warning': sentiment === Sentiment.WARNING,
44
59
  'has-error': hasError,
45
- 'has-info': hasHint,
60
+ 'has-info': sentiment === Sentiment.NEUTRAL,
46
61
  },
47
62
  className,
48
63
  )}
@@ -51,14 +66,9 @@ export const Field = ({ id, label, hint, error, className, children }: FieldProp
51
66
  {label}
52
67
  {children}
53
68
  </Label>
54
- {hasHint && (
55
- <InlineAlert type={Sentiment.NEUTRAL} id={descriptionId}>
56
- {hint}
57
- </InlineAlert>
58
- )}
59
- {hasError && (
60
- <InlineAlert type={Sentiment.NEGATIVE} id={descriptionId}>
61
- {error}
69
+ {message && (
70
+ <InlineAlert type={sentiment} id={descriptionId}>
71
+ {message}
62
72
  </InlineAlert>
63
73
  )}
64
74
  </div>
@@ -51,7 +51,7 @@ export const Basic = () => {
51
51
 
52
52
  return (
53
53
  <>
54
- {/*eslint-disable-next-line react/no-adjacent-inline-elements */}
54
+ {/* eslint-disable-next-line react/no-adjacent-inline-elements */}
55
55
  <p>
56
56
  The styling for the input (the coloured border) and the visibility of the inline alert is
57
57
  controlled through the use of <code>has-***</code> classes which are applied to the{' '}
@@ -60,7 +60,11 @@ export const Basic = () => {
60
60
  element. The available classes are <code>has-error</code>, <code>has-info</code>,{' '}
61
61
  <code>has-warning</code> and <code>has-success</code>.
62
62
  </p>
63
- <p>Where possible consumers should use Field instead of doing this manually.</p>
63
+ <p>
64
+ Where possible consumers should use{' '}
65
+ <a href="https://storybook.wise.design/?path=/story/field--basic">Field</a> instead of doing
66
+ this manually.
67
+ </p>
64
68
  <div className={`form-group ${typeClass}`}>
65
69
  <label className="control-label" htmlFor="id0">
66
70
  Toggleable
@@ -73,14 +77,18 @@ export const Basic = () => {
73
77
  Negative
74
78
  </label>
75
79
  <Input id="id1" value="Neptune is cool" />
76
- <InlineAlert type="error">{message}</InlineAlert>
80
+ <InlineAlert type="negative">{message}</InlineAlert>
77
81
  </div>
78
- <div className="form-group has-positive">
82
+ <div className="form-group has-success">
79
83
  <label className="control-label" htmlFor="id2">
80
84
  Positive
81
85
  </label>
82
86
  <Input id="id2" value="Neptune is cool" />
83
- <InlineAlert type="positive">{message}</InlineAlert>
87
+ <InlineAlert type="positive">
88
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
89
+ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
90
+ ullamco laboris nisi ut aliquip ex ea commodo consequat.
91
+ </InlineAlert>
84
92
  </div>
85
93
  <div className="form-group has-neutral">
86
94
  <label className="control-label" htmlFor="id3">
@@ -1,8 +1,8 @@
1
- import { AlertCircle as AlertCircleIcon } from '@transferwise/icons';
2
1
  import classNames from 'classnames';
3
- import { ReactNode } from 'react';
2
+ import React, { ReactNode } from 'react';
4
3
 
5
- import { Sentiment } from '../common';
4
+ import { Sentiment, Size } from '../common';
5
+ import StatusIcon from '../statusIcon';
6
6
 
7
7
  export interface InlineAlertProps {
8
8
  id?: string;
@@ -17,15 +17,22 @@ export default function InlineAlert({
17
17
  className,
18
18
  children,
19
19
  }: InlineAlertProps) {
20
- const danger = type === 'negative' || type === 'error';
21
20
  return (
22
21
  <div
23
22
  role="alert"
24
23
  id={id}
25
- className={classNames('alert alert-detach', `alert-${danger ? 'danger' : type}`, className)}
24
+ className={classNames(
25
+ 'alert alert-detach',
26
+ `alert-${type === Sentiment.NEGATIVE || type === Sentiment.ERROR ? 'danger' : type}`,
27
+ className,
28
+ )}
26
29
  >
27
- {danger && <AlertCircleIcon />}
28
- <div>{children}</div>
30
+ <div className="d-inline-flex">
31
+ {type !== Sentiment.NEUTRAL && type !== Sentiment.PENDING && (
32
+ <StatusIcon sentiment={type} size={Size.SMALL} />
33
+ )}
34
+ <div className="np-text-body-default">{children}</div>
35
+ </div>
29
36
  </div>
30
37
  );
31
38
  }
package/src/main.css CHANGED
@@ -4198,14 +4198,16 @@ html:not([dir="rtl"]) .np-navigation-option {
4198
4198
  height: var(--size-32);
4199
4199
  }
4200
4200
  }
4201
- .status-circle.negative {
4201
+ .status-circle.negative,
4202
+ .status-circle.error {
4202
4203
  background-color: var(--color-sentiment-negative);
4203
4204
  }
4204
4205
  .status-circle.neutral {
4205
4206
  background-color: #5d7079;
4206
4207
  background-color: var(--color-content-secondary);
4207
4208
  }
4208
- .status-circle.positive {
4209
+ .status-circle.positive,
4210
+ .status-circle.success {
4209
4211
  background-color: var(--color-sentiment-positive);
4210
4212
  }
4211
4213
  .tw-stepper {
@@ -66,13 +66,15 @@
66
66
  height: var(--size-32);
67
67
  }
68
68
  }
69
- .status-circle.negative {
69
+ .status-circle.negative,
70
+ .status-circle.error {
70
71
  background-color: var(--color-sentiment-negative);
71
72
  }
72
73
  .status-circle.neutral {
73
74
  background-color: #5d7079;
74
75
  background-color: var(--color-content-secondary);
75
76
  }
76
- .status-circle.positive {
77
+ .status-circle.positive,
78
+ .status-circle.success {
77
79
  background-color: var(--color-sentiment-positive);
78
80
  }
@@ -60,7 +60,8 @@
60
60
  }
61
61
  }
62
62
 
63
- .status-circle.negative {
63
+ .status-circle.negative,
64
+ .status-circle.error {
64
65
  background-color: var(--color-sentiment-negative);
65
66
  }
66
67
 
@@ -68,6 +69,7 @@
68
69
  background-color: var(--color-content-secondary);
69
70
  }
70
71
 
71
- .status-circle.positive {
72
+ .status-circle.positive,
73
+ .status-circle.success {
72
74
  background-color: var(--color-sentiment-positive);
73
75
  }
@@ -26,7 +26,7 @@ const StatusIcon = ({ sentiment = 'neutral', size = 'md' }: StatusIconProps) =>
26
26
  return (
27
27
  <span
28
28
  data-testid="status-icon"
29
- className={classNames('status-circle', 'status-circle-' + size, sentiment)}
29
+ className={classNames('status-circle', `status-circle-${size}`, sentiment)}
30
30
  >
31
31
  <Icon className={classNames('status-icon', iconColor)} />
32
32
  </span>