@transferwise/components 0.0.0-experimental-75d5cd4 → 0.0.0-experimental-4990089
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/i18n/en.json +0 -1
- package/build/index.js +2380 -2514
- package/build/index.js.map +1 -1
- package/build/index.mjs +2383 -2516
- package/build/index.mjs.map +1 -1
- package/build/main.css +0 -33
- package/build/styles/main.css +0 -33
- package/build/types/common/panel/Panel.d.ts.map +1 -1
- package/build/types/common/responsivePanel/ResponsivePanel.d.ts.map +1 -1
- package/build/types/dateInput/DateInput.d.ts.map +1 -1
- package/build/types/index.d.ts +0 -2
- package/build/types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/common/panel/Panel.tsx +3 -8
- package/src/common/responsivePanel/ResponsivePanel.tsx +0 -2
- package/src/dateInput/DateInput.spec.tsx +245 -0
- package/src/dateInput/DateInput.story.tsx +3 -76
- package/src/dateInput/DateInput.tests.story.tsx +238 -0
- package/src/dateInput/DateInput.tsx +50 -53
- package/src/i18n/en.json +0 -1
- package/src/index.ts +0 -2
- package/src/main.css +0 -33
- package/src/main.less +0 -1
- package/src/ssr.spec.js +0 -1
- package/build/styles/selectOption/SelectOption.css +0 -33
- package/build/types/selectOption/SelectOption.d.ts +0 -21
- package/build/types/selectOption/SelectOption.d.ts.map +0 -1
- package/build/types/selectOption/SelectOption.messages.d.ts +0 -8
- package/build/types/selectOption/SelectOption.messages.d.ts.map +0 -1
- package/build/types/selectOption/index.d.ts +0 -3
- package/build/types/selectOption/index.d.ts.map +0 -1
- package/src/dateInput/DateInput.spec.js +0 -477
- package/src/selectOption/SelectOption.css +0 -33
- package/src/selectOption/SelectOption.less +0 -28
- package/src/selectOption/SelectOption.messages.ts +0 -8
- package/src/selectOption/SelectOption.story.tsx +0 -212
- package/src/selectOption/SelectOption.tsx +0 -154
- package/src/selectOption/index.ts +0 -2
|
@@ -1,212 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,154 +0,0 @@
|
|
|
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
|
-
}
|