@transferwise/components 0.0.0-experimental-5931a60 → 0.0.0-experimental-75d5cd4

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 (41) hide show
  1. package/build/i18n/en.json +1 -0
  2. package/build/index.js +2461 -2365
  3. package/build/index.js.map +1 -1
  4. package/build/index.mjs +2463 -2368
  5. package/build/index.mjs.map +1 -1
  6. package/build/main.css +33 -0
  7. package/build/styles/main.css +33 -0
  8. package/build/styles/selectOption/SelectOption.css +33 -0
  9. package/build/types/common/panel/Panel.d.ts.map +1 -1
  10. package/build/types/common/responsivePanel/ResponsivePanel.d.ts.map +1 -1
  11. package/build/types/field/Field.d.ts +1 -6
  12. package/build/types/field/Field.d.ts.map +1 -1
  13. package/build/types/index.d.ts +2 -0
  14. package/build/types/index.d.ts.map +1 -1
  15. package/build/types/inlineAlert/InlineAlert.d.ts +2 -2
  16. package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
  17. package/build/types/selectOption/SelectOption.d.ts +21 -0
  18. package/build/types/selectOption/SelectOption.d.ts.map +1 -0
  19. package/build/types/selectOption/SelectOption.messages.d.ts +8 -0
  20. package/build/types/selectOption/SelectOption.messages.d.ts.map +1 -0
  21. package/build/types/selectOption/index.d.ts +3 -0
  22. package/build/types/selectOption/index.d.ts.map +1 -0
  23. package/package.json +6 -6
  24. package/src/common/panel/Panel.tsx +8 -3
  25. package/src/common/responsivePanel/ResponsivePanel.tsx +2 -0
  26. package/src/field/Field.story.tsx +6 -20
  27. package/src/field/Field.tsx +13 -23
  28. package/src/i18n/en.json +1 -0
  29. package/src/index.ts +2 -0
  30. package/src/inlineAlert/InlineAlert.story.tsx +4 -8
  31. package/src/inlineAlert/InlineAlert.tsx +6 -42
  32. package/src/label/Label.tsx +1 -1
  33. package/src/main.css +33 -0
  34. package/src/main.less +1 -0
  35. package/src/selectOption/SelectOption.css +33 -0
  36. package/src/selectOption/SelectOption.less +28 -0
  37. package/src/selectOption/SelectOption.messages.ts +8 -0
  38. package/src/selectOption/SelectOption.story.tsx +212 -0
  39. package/src/selectOption/SelectOption.tsx +154 -0
  40. package/src/selectOption/index.ts +2 -0
  41. package/src/ssr.spec.js +1 -0
@@ -12,7 +12,7 @@ export const Label = ({ id, htmlFor, className, children }: LabelProps) => {
12
12
  <label
13
13
  id={id}
14
14
  htmlFor={htmlFor}
15
- className={classNames('control-label d-flex flex-column gap-y-xs m-b-0', className)}
15
+ className={classNames('control-label d-flex flex-column gap-y-1 m-b-0', className)}
16
16
  >
17
17
  {children}
18
18
  </label>
package/src/main.css CHANGED
@@ -1484,6 +1484,39 @@ button.np-option {
1484
1484
  border-radius: var(--radius-small);
1485
1485
  }
1486
1486
  }
1487
+ .np-select-option {
1488
+ border-radius: 10px;
1489
+ border-radius: var(--radius-small);
1490
+ background-color: rgba(134,167,189,0.10196);
1491
+ background-color: var(--color-background-neutral);
1492
+ }
1493
+ .np-select-option-selected {
1494
+ background-color: #ffffff;
1495
+ background-color: var(--color-background-screen);
1496
+ border: 1px solid #c9cbce;
1497
+ border: 1px solid var(--color-interactive-secondary);
1498
+ }
1499
+ .np-select-option-list {
1500
+ max-height: 350px;
1501
+ overflow-y: auto;
1502
+ }
1503
+ .np-select-option-section {
1504
+ margin-top: 0 !important;
1505
+ }
1506
+ .has-error * .np-select-option {
1507
+ --ring-outline-color: var(--color-sentiment-negative);
1508
+ --ring-outline-offset: 0;
1509
+ outline: var(--ring-outline-color) solid var(--ring-outline-width);
1510
+ outline-offset: 0;
1511
+ outline-offset: var(--ring-outline-offset);
1512
+ }
1513
+ .has-error * .np-select-option:focus {
1514
+ outline: none;
1515
+ }
1516
+ .has-error * .np-select-option:focus-visible {
1517
+ outline: var(--ring-outline-color) solid var(--ring-outline-width);
1518
+ outline-offset: var(--ring-outline-offset);
1519
+ }
1487
1520
  .np-panel__content {
1488
1521
  opacity: 0;
1489
1522
  visibility: hidden;
package/src/main.less CHANGED
@@ -13,6 +13,7 @@
13
13
  @import "./common/card/Card.less";
14
14
  @import "./common/closeButton/CloseButton.less";
15
15
  @import "./common/Option/Option.less";
16
+ @import "./selectOption/SelectOption.less";
16
17
  @import "./common/panel/Panel.less";
17
18
  @import "./common/RadioButton/RadioButton.less";
18
19
  @import "./dateInput/DateInput.less";
@@ -0,0 +1,33 @@
1
+ .np-select-option {
2
+ border-radius: 10px;
3
+ border-radius: var(--radius-small);
4
+ background-color: rgba(134,167,189,0.10196);
5
+ background-color: var(--color-background-neutral);
6
+ }
7
+ .np-select-option-selected {
8
+ background-color: #ffffff;
9
+ background-color: var(--color-background-screen);
10
+ border: 1px solid #c9cbce;
11
+ border: 1px solid var(--color-interactive-secondary);
12
+ }
13
+ .np-select-option-list {
14
+ max-height: 350px;
15
+ overflow-y: auto;
16
+ }
17
+ .np-select-option-section {
18
+ margin-top: 0 !important;
19
+ }
20
+ .has-error * .np-select-option {
21
+ --ring-outline-color: var(--color-sentiment-negative);
22
+ --ring-outline-offset: 0;
23
+ outline: var(--ring-outline-color) solid var(--ring-outline-width);
24
+ outline-offset: 0;
25
+ outline-offset: var(--ring-outline-offset);
26
+ }
27
+ .has-error * .np-select-option:focus {
28
+ outline: none;
29
+ }
30
+ .has-error * .np-select-option:focus-visible {
31
+ outline: var(--ring-outline-color) solid var(--ring-outline-width);
32
+ outline-offset: var(--ring-outline-offset);
33
+ }
@@ -0,0 +1,28 @@
1
+ @import (reference) "../../node_modules/@transferwise/neptune-css/src/less/ring.less";
2
+
3
+ .np-select-option {
4
+ border-radius: var(--radius-small);
5
+ background-color: var(--color-background-neutral);
6
+
7
+ &-selected {
8
+ background-color: var(--color-background-screen);
9
+ border: 1px solid var(--color-interactive-secondary);
10
+ }
11
+
12
+ &-list {
13
+ max-height: 350px;
14
+ overflow-y: auto;
15
+ }
16
+
17
+ &-section {
18
+ // override large margin from Section & Header
19
+ margin-top: 0 !important;
20
+ }
21
+
22
+ .has-error * & {
23
+ .ring-negative();
24
+ .ring-offset-0();
25
+ .ring();
26
+ .focus-ring();
27
+ }
28
+ }
@@ -0,0 +1,8 @@
1
+ import { defineMessages } from 'react-intl';
2
+
3
+ export default defineMessages({
4
+ actionLabel: {
5
+ id: 'neptune.SelectOption.action.label',
6
+ defaultMessage: 'Choose',
7
+ },
8
+ });
@@ -0,0 +1,212 @@
1
+ import type { StoryObj } from '@storybook/react';
2
+ import { Flag } from '@wise/art';
3
+ import SelectOption, { SelectOptionValue, SelectOptiopsSection } from './SelectOption';
4
+ import { Bank, BankTransfer, Beach, Briefcase, Card, Plane } from '@transferwise/icons';
5
+ import { Field } from '../field/Field';
6
+ import { lorem10 } from '../test-utils';
7
+ import Badge from '../badge';
8
+ import Avatar from '../avatar';
9
+
10
+ export default {
11
+ title: 'Option/SelectOption',
12
+ };
13
+
14
+ type Story = StoryObj<typeof SelectOption>;
15
+
16
+ type CustomData = { data?: string };
17
+
18
+ function cardPaymentMethod(index?: number): SelectOptionValue<CustomData> {
19
+ return {
20
+ media: <Card />,
21
+ title: `Credit card ${index}`,
22
+ content: (
23
+ <>
24
+ <div>Transfer the money to Wise using your bank account.</div>
25
+ <div>0.32 GBP in fees, should arrive in seconds</div>
26
+ </>
27
+ ),
28
+ };
29
+ }
30
+
31
+ const recentPaymentMethods: SelectOptionValue<CustomData>[] = [
32
+ cardPaymentMethod(1),
33
+ cardPaymentMethod(2),
34
+ ];
35
+
36
+ const allOtherPaymentMethods: SelectOptionValue<CustomData>[] = [
37
+ {
38
+ media: <Flag code="gbp" />,
39
+ title: 'Wise GBP balance',
40
+ content: (
41
+ <>
42
+ <span>300 GBP available</span>
43
+ <span>0 GBP in fees, should arrive in seconds</span>
44
+ </>
45
+ ),
46
+ disabled: true,
47
+ value: { data: lorem10 },
48
+ },
49
+ cardPaymentMethod(),
50
+ {
51
+ media: <Card />,
52
+ title: 'Debit card',
53
+ content: (
54
+ <>
55
+ <span>Send from your Visa or Mastercard.</span>
56
+ <span>0.74 GBP in fees, should arrive in seconds</span>
57
+ </>
58
+ ),
59
+ },
60
+ {
61
+ media: <Bank />,
62
+ title: 'Swift Transfer',
63
+ content: (
64
+ <>
65
+ <span>Send money internationally. Your bank will charge you extra fees.</span>
66
+ <span>0.32 GBP in fees, should arrive by Thursday</span>
67
+ </>
68
+ ),
69
+ },
70
+ {
71
+ media: <BankTransfer />,
72
+ title: 'Bank Transfer',
73
+ content: (
74
+ <>
75
+ <span>Transfer the money to Wise using your bank account.</span>
76
+ <span>0.32 GBP in fees, should arrive in seconds</span>
77
+ </>
78
+ ),
79
+ },
80
+ {
81
+ media: <BankTransfer />,
82
+ title: 'Withdraw from your U.S. bank account (ACH)',
83
+ content: (
84
+ <>
85
+ <span>1.63 USD in total fees.</span>
86
+ <span>
87
+ Pay with ACH using the bank account you’ve connected to Wise. Should arrive in seconds.
88
+ </span>
89
+ </>
90
+ ),
91
+ },
92
+ cardPaymentMethod(1),
93
+ cardPaymentMethod(2),
94
+ cardPaymentMethod(3),
95
+ cardPaymentMethod(4),
96
+ cardPaymentMethod(5),
97
+ cardPaymentMethod(6),
98
+ {
99
+ media: <BankTransfer />,
100
+ title: 'Last One',
101
+ content: <span>1.63 USD in total fees.</span>,
102
+ },
103
+ ];
104
+
105
+ const paymentMethods: SelectOptiopsSection<CustomData>[] = [
106
+ {
107
+ title: 'Recently used',
108
+ options: recentPaymentMethods,
109
+ },
110
+ {
111
+ title: 'Payment methods',
112
+ options: allOtherPaymentMethods,
113
+ },
114
+ ];
115
+
116
+ const balances: SelectOptiopsSection[] = [
117
+ {
118
+ title: 'Balances',
119
+ options: [
120
+ {
121
+ media: <Flag code="gbp" />,
122
+ title: 'Wise GBP balance',
123
+ },
124
+ {
125
+ media: <Flag code="eur" />,
126
+ title: 'Wise EUR balance',
127
+ },
128
+ ],
129
+ },
130
+ {
131
+ title: 'Jars',
132
+ options: [
133
+ {
134
+ media: (
135
+ <Badge badge={<Flag code="usd" />} size="md">
136
+ <Avatar type="icon" size="md" backgroundColor="var(--color-bright-pink)">
137
+ <Beach size="24" />
138
+ </Avatar>
139
+ </Badge>
140
+ ),
141
+ title: 'Hawaii Holiday',
142
+ content: 'Wise USD jar',
143
+ },
144
+ {
145
+ media: (
146
+ <Badge badge={<Flag code="aed" />} size="md">
147
+ <Avatar type="icon" size="md" backgroundColor="var(--color-bright-yellow)">
148
+ <Briefcase size="24" />
149
+ </Avatar>
150
+ </Badge>
151
+ ),
152
+ title: 'Emirates Business Trip',
153
+ content: 'Wise AED jar',
154
+ },
155
+ {
156
+ media: (
157
+ <Badge badge={<Flag code="jpy" />} size="md">
158
+ <Avatar type="icon" size="md" backgroundColor="var(--color-bright-blue)">
159
+ <Plane size="24" />
160
+ </Avatar>
161
+ </Badge>
162
+ ),
163
+ title: 'Trip to Mars',
164
+ content: 'Wise Jpy jar',
165
+ },
166
+ ],
167
+ },
168
+ ];
169
+
170
+ export const Basic: Story = {
171
+ render: (args) => {
172
+ function onChange(value: SelectOptionValue<CustomData>): void {
173
+ console.log(value);
174
+ }
175
+ return (
176
+ <div className="row">
177
+ <div className="col-md-8 col-md-offset-2">
178
+ <Field label="Balances">
179
+ <SelectOption
180
+ placeholder={{ title: 'No balance selected' }}
181
+ options={balances}
182
+ onChange={(value) => {
183
+ console.log('selected balance', value);
184
+ }}
185
+ />
186
+ </Field>
187
+ </div>
188
+
189
+ <div className="col-md-8 col-md-offset-2">
190
+ <Field label={<>Payment method</>} error="Just an example of validation message">
191
+ <SelectOption<CustomData>
192
+ placeholder={{ title: 'No method selected', actionLabel: 'Select' }}
193
+ options={paymentMethods}
194
+ onChange={onChange}
195
+ />
196
+ </Field>
197
+ </div>
198
+
199
+ <div className="col-md-8 col-md-offset-2">
200
+ <Field label={<>Payment method</>} error="Example of disabled select option">
201
+ <SelectOption<CustomData>
202
+ disabled
203
+ placeholder={{ title: 'No method selected' }}
204
+ options={paymentMethods}
205
+ onChange={onChange}
206
+ />
207
+ </Field>
208
+ </div>
209
+ </div>
210
+ );
211
+ },
212
+ };
@@ -0,0 +1,154 @@
1
+ import { useRef, useState } from 'react';
2
+ import ActionButton, { ActionButtonProps } from '../actionButton';
3
+ import Chevron from '../chevron';
4
+ import classNames from 'classnames';
5
+ import Option from '../common/Option';
6
+ import type { OptionProps } from '../common/Option/Option';
7
+ import { Breakpoint, Position } from '../common';
8
+ import Section from '../section';
9
+ import Header from '../header';
10
+ import { HeaderProps } from '../header/Header';
11
+ import NavigationOption from '../navigationOption';
12
+ import NavigationOptionsList from '../navigationOptionsList';
13
+ import { useInputAttributes } from '../inputs/contexts';
14
+ import messages from './SelectOption.messages';
15
+ import { useIntl } from 'react-intl';
16
+ import ResponsivePanel from '../common/responsivePanel';
17
+ import { useScreenSize } from '../common/hooks/useScreenSize';
18
+ import { Plus } from '@transferwise/icons';
19
+
20
+ export type SelectOptiopsSection<T = unknown> = {
21
+ title?: HeaderProps['title'];
22
+ options: SelectOptionValue<T>[];
23
+ };
24
+
25
+ export type SelectOptionValue<T = unknown> = Pick<
26
+ OptionProps,
27
+ 'media' | 'title' | 'content' | 'disabled'
28
+ > & {
29
+ value?: T;
30
+ };
31
+
32
+ export type SelectOptionPlaceholder = Pick<OptionProps, 'media' | 'title' | 'content'> & {
33
+ actionLabel?: ActionButtonProps['children'];
34
+ };
35
+
36
+ export type SelectOptionProps<T> = {
37
+ onChange: (selected: SelectOptionValue<T>) => void;
38
+ selected?: SelectOptionValue<T>;
39
+ options: SelectOptiopsSection<T>[];
40
+ placeholder: SelectOptionPlaceholder;
41
+ } & Omit<
42
+ OptionProps,
43
+ 'as' | 'title' | 'media' | 'content' | 'onClick' | 'onChange' | 'showMediaAtAllSizes' | 'decision'
44
+ >;
45
+
46
+ export default function SelectOption<T>({
47
+ selected: selectedValueProp = undefined,
48
+ options,
49
+ onChange,
50
+ placeholder,
51
+ disabled,
52
+ ...props
53
+ }: SelectOptionProps<T>) {
54
+ const intl = useIntl();
55
+ const rootRef = useRef(null);
56
+ const [selected, setSelected] = useState(selectedValueProp);
57
+ const [showOptions, setShowOptions] = useState(false);
58
+
59
+ const hasSelected = selected !== undefined;
60
+ const isLargeScreen = useScreenSize(Breakpoint.SMALL);
61
+
62
+ const inputAttributes = useInputAttributes();
63
+ const ariaLabelledBy = props['aria-labelledby'] ?? inputAttributes?.['aria-labelledby'];
64
+
65
+ function handleOnClick(showOptionsStatus: boolean) {
66
+ return () => {
67
+ setShowOptions(showOptionsStatus);
68
+ };
69
+ }
70
+
71
+ function handleOnChange(data: SelectOptionValue<T>) {
72
+ return () => {
73
+ setShowOptions(false);
74
+ setSelected(data);
75
+ onChange(data);
76
+ };
77
+ }
78
+
79
+ function getOptions(isLargeScreen = false) {
80
+ return (
81
+ <div className={classNames({ 'np-select-option-list': isLargeScreen })}>
82
+ {options.map((optionsSection) => (
83
+ // eslint-disable-next-line react/jsx-key
84
+ <Section
85
+ className={classNames('np-select-option-section', { 'p-x-2 p-y-1': isLargeScreen })}
86
+ >
87
+ {optionsSection.title && <Header title={optionsSection.title} />}
88
+ <NavigationOptionsList>
89
+ {optionsSection.options.map((option) => {
90
+ const isOptionSelected = hasSelected ? selected === option : false;
91
+ return (
92
+ // eslint-disable-next-line react/jsx-key
93
+ <NavigationOption
94
+ as="div"
95
+ role="option"
96
+ aria-selected={isOptionSelected}
97
+ isContainerAligned={!isLargeScreen}
98
+ showMediaCircle
99
+ showMediaAtAllSizes
100
+ onClick={handleOnChange(option)}
101
+ {...option}
102
+ />
103
+ );
104
+ })}
105
+ </NavigationOptionsList>
106
+ </Section>
107
+ ))}
108
+ </div>
109
+ );
110
+ }
111
+
112
+ return (
113
+ <>
114
+ <Option
115
+ ref={rootRef}
116
+ {...props}
117
+ role="button"
118
+ aria-haspopup="dialog"
119
+ aria-expanded={showOptions}
120
+ aria-labelledby={ariaLabelledBy}
121
+ showMediaAtAllSizes
122
+ disabled={disabled}
123
+ media={hasSelected ? selected.media : placeholder.media ?? <Plus size={24} />}
124
+ title={(hasSelected ? selected : placeholder).title}
125
+ content={(hasSelected ? selected : placeholder).content}
126
+ className={classNames(
127
+ 'np-select-option',
128
+ { 'np-select-option-selected': hasSelected },
129
+ props.className,
130
+ )}
131
+ button={
132
+ hasSelected ? (
133
+ <Chevron />
134
+ ) : (
135
+ <ActionButton disabled={disabled} onClick={handleOnClick(true)}>
136
+ {placeholder.actionLabel || intl.formatMessage(messages.actionLabel)}
137
+ </ActionButton>
138
+ )
139
+ }
140
+ {...(hasSelected && !disabled && { onClick: handleOnClick(!showOptions) })}
141
+ />
142
+ <ResponsivePanel
143
+ altAxis
144
+ anchorWidth
145
+ anchorRef={rootRef}
146
+ open={showOptions}
147
+ position={Position.BOTTOM}
148
+ onClose={handleOnClick(false)}
149
+ >
150
+ {getOptions(isLargeScreen)}
151
+ </ResponsivePanel>
152
+ </>
153
+ );
154
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './SelectOption';
2
+ export type { SelectOptionProps, SelectOptionValue, SelectOptiopsSection } from './SelectOption';
package/src/ssr.spec.js CHANGED
@@ -226,6 +226,7 @@ describe('Server side rendering', () => {
226
226
  DateLookup: { value: new Date() },
227
227
  Link: { size: 16 },
228
228
  Tooltip: { children: <>yo</> },
229
+ SelectOption: { placeholder: { media: <img alt="img" /> } },
229
230
  };
230
231
 
231
232
  const { Provider } = exposedLibraryItems;