@transferwise/components 0.0.0-experimental-93bf218 → 0.0.0-experimental-4aed95c

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 (40) hide show
  1. package/build/i18n/en.json +0 -2
  2. package/build/index.js +2384 -2478
  3. package/build/index.js.map +1 -1
  4. package/build/index.mjs +2387 -2480
  5. package/build/index.mjs.map +1 -1
  6. package/build/main.css +41 -98
  7. package/build/styles/inputs/SelectInput.css +41 -51
  8. package/build/styles/main.css +41 -98
  9. package/build/types/common/hooks/useVirtualKeyboard.d.ts +7 -0
  10. package/build/types/common/hooks/useVirtualKeyboard.d.ts.map +1 -0
  11. package/build/types/common/responsivePanel/ResponsivePanel.d.ts.map +1 -1
  12. package/build/types/index.d.ts +0 -2
  13. package/build/types/index.d.ts.map +1 -1
  14. package/build/types/inputs/_BottomSheet.d.ts.map +1 -1
  15. package/package.json +3 -3
  16. package/src/common/hooks/useVirtualKeyboard.ts +21 -0
  17. package/src/common/responsivePanel/ResponsivePanel.tsx +0 -2
  18. package/src/i18n/en.json +0 -2
  19. package/src/index.ts +0 -2
  20. package/src/inputs/SelectInput.css +41 -51
  21. package/src/inputs/_BottomSheet.less +35 -49
  22. package/src/inputs/_BottomSheet.tsx +22 -27
  23. package/src/inputs/_Popover.less +2 -2
  24. package/src/main.css +41 -98
  25. package/src/main.less +0 -1
  26. package/src/ssr.spec.js +0 -1
  27. package/build/styles/selectOption/SelectOption.css +0 -47
  28. package/build/types/selectOption/SelectOption.d.ts +0 -21
  29. package/build/types/selectOption/SelectOption.d.ts.map +0 -1
  30. package/build/types/selectOption/SelectOption.messages.d.ts +0 -12
  31. package/build/types/selectOption/SelectOption.messages.d.ts.map +0 -1
  32. package/build/types/selectOption/index.d.ts +0 -3
  33. package/build/types/selectOption/index.d.ts.map +0 -1
  34. package/src/selectOption/SelectOption.css +0 -47
  35. package/src/selectOption/SelectOption.less +0 -45
  36. package/src/selectOption/SelectOption.messages.ts +0 -12
  37. package/src/selectOption/SelectOption.spec.tsx +0 -89
  38. package/src/selectOption/SelectOption.story.tsx +0 -269
  39. package/src/selectOption/SelectOption.tsx +0 -152
  40. package/src/selectOption/index.ts +0 -2
@@ -1,21 +0,0 @@
1
- import { ActionButtonProps } from '../actionButton';
2
- import type { OptionProps } from '../common/Option/Option';
3
- import { HeaderProps } from '../header/Header';
4
- export type SelectOptiopsSection<T = unknown> = {
5
- title?: HeaderProps['title'];
6
- options: SelectOptionValue<T>[];
7
- };
8
- export type SelectOptionValue<T = unknown> = Pick<OptionProps, 'media' | 'title' | 'content' | 'disabled'> & {
9
- value?: T;
10
- };
11
- export type SelectOptionPlaceholder = Pick<OptionProps, 'media' | 'title' | 'content'> & {
12
- actionLabel?: ActionButtonProps['children'];
13
- };
14
- export type SelectOptionProps<T = unknown> = {
15
- onChange: (selected: SelectOptionValue<T>) => void;
16
- selected?: SelectOptionValue<T>;
17
- options: SelectOptiopsSection<T>[];
18
- placeholder: SelectOptionPlaceholder;
19
- } & Omit<OptionProps, 'as' | 'title' | 'media' | 'content' | 'onClick' | 'onChange' | 'showMediaAtAllSizes' | 'decision'>;
20
- export default function SelectOption<T>({ selected: selectedValueProp, options, onChange, placeholder, disabled, ...props }: SelectOptionProps<T>): import("react").JSX.Element;
21
- //# sourceMappingURL=SelectOption.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SelectOption.d.ts","sourceRoot":"","sources":["../../../src/selectOption/SelectOption.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAI3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAU/C,MAAM,MAAM,oBAAoB,CAAC,CAAC,GAAG,OAAO,IAAI;IAC9C,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7B,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,CAC/C,WAAW,EACX,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,CAC3C,GAAG;IACF,KAAK,CAAC,EAAE,CAAC,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC,GAAG;IACvF,WAAW,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,GAAG,OAAO,IAAI;IAC3C,QAAQ,EAAE,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACnD,QAAQ,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAChC,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC;IACnC,WAAW,EAAE,uBAAuB,CAAC;CACtC,GAAG,IAAI,CACN,WAAW,EACX,IAAI,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,qBAAqB,GAAG,UAAU,CACnG,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,EAAE,EACtC,QAAQ,EAAE,iBAA6B,EACvC,OAAO,EACP,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,iBAAiB,CAAC,CAAC,CAAC,+BAoGtB"}
@@ -1,12 +0,0 @@
1
- declare const _default: {
2
- actionLabel: {
3
- id: string;
4
- defaultMessage: string;
5
- };
6
- selectedActionLabel: {
7
- id: string;
8
- defaultMessage: string;
9
- };
10
- };
11
- export default _default;
12
- //# sourceMappingURL=SelectOption.messages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SelectOption.messages.d.ts","sourceRoot":"","sources":["../../../src/selectOption/SelectOption.messages.ts"],"names":[],"mappings":";;;;;;;;;;AAEA,wBASG"}
@@ -1,3 +0,0 @@
1
- export { default } from './SelectOption';
2
- export type { SelectOptionProps, SelectOptionValue, SelectOptiopsSection } from './SelectOption';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/selectOption/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,47 +0,0 @@
1
- .np-select-option {
2
- border-radius: 10px;
3
- border-radius: var(--radius-small);
4
- padding: 16px;
5
- padding: var(--size-16);
6
- }
7
- .np-select-option-placeholder {
8
- background-color: rgba(134,167,189,0.10196);
9
- background-color: var(--color-background-neutral);
10
- }
11
- .np-select-option-placeholder:not(.disabled):hover {
12
- background-color: var(--color-background-neutral-hover);
13
- }
14
- .np-select-option-placeholder:not(.disabled):focus,
15
- .np-select-option-placeholder:not(.disabled):active {
16
- background-color: var(--color-background-neutral-active);
17
- }
18
- .np-select-option-selected {
19
- border: 1px solid #c9cbce;
20
- border: 1px solid var(--color-interactive-secondary);
21
- }
22
- .np-select-option-list {
23
- max-height: 350px;
24
- overflow-y: auto;
25
- }
26
- .np-select-option-list > .np-section {
27
- margin-top: 0;
28
- }
29
- .form-group label > .np-select-option {
30
- margin-bottom: 0;
31
- }
32
- .has-error * .np-select-option {
33
- --ring-outline-color: var(--color-sentiment-negative);
34
- --ring-outline-width: 3px;
35
- --ring-outline-offset: calc(-1 * var(--ring-outline-width));
36
- outline: var(--ring-outline-color) solid 3px;
37
- outline: var(--ring-outline-color) solid var(--ring-outline-width);
38
- outline-offset: calc(-1 * 3px);
39
- outline-offset: var(--ring-outline-offset);
40
- }
41
- .has-error * .np-select-option:focus {
42
- outline: none;
43
- }
44
- .has-error * .np-select-option:focus-visible {
45
- outline: var(--ring-outline-color) solid var(--ring-outline-width);
46
- outline-offset: var(--ring-outline-offset);
47
- }
@@ -1,45 +0,0 @@
1
- @import (reference) "../../node_modules/@transferwise/neptune-css/src/less/ring.less";
2
-
3
- .np-select-option {
4
- border-radius: var(--radius-small);
5
- padding: var(--size-16);
6
-
7
- &-placeholder {
8
- background-color: var(--color-background-neutral);
9
-
10
- &:not(.disabled):hover {
11
- background-color: var(--color-background-neutral-hover);
12
- }
13
-
14
- &:not(.disabled):focus,
15
- &:not(.disabled):active {
16
- background-color: var(--color-background-neutral-active);
17
- }
18
- }
19
-
20
- &-selected {
21
- border: 1px solid var(--color-interactive-secondary);
22
- }
23
-
24
- &-list {
25
- max-height: 350px;
26
- overflow-y: auto;
27
-
28
- & > .np-section {
29
- // remove large margin in Section & Header
30
- margin-top: 0;
31
- }
32
- }
33
-
34
- .form-group label > & {
35
- // remove margin-bottom for label
36
- margin-bottom: 0;
37
- }
38
-
39
- .has-error * & {
40
- .ring-negative();
41
- .ring-inset();
42
- .ring();
43
- .focus-ring();
44
- }
45
- }
@@ -1,12 +0,0 @@
1
- import { defineMessages } from 'react-intl';
2
-
3
- export default defineMessages({
4
- actionLabel: {
5
- id: 'neptune.SelectOption.action.label',
6
- defaultMessage: 'Choose',
7
- },
8
- selectedActionLabel: {
9
- id: 'neptune.SelectOption.selected.action.label',
10
- defaultMessage: 'Change chosen option',
11
- },
12
- });
@@ -1,89 +0,0 @@
1
- import { render, userEvent, screen, within, mockMatchMedia } from '../test-utils';
2
- import { composeStories } from '@storybook/react';
3
- import * as stories from './SelectOption.story';
4
- import { Breakpoint } from '../common';
5
- import { wait } from '../test-utils/wait';
6
-
7
- const { Basic: SelectOptionExample } = composeStories(stories);
8
-
9
- mockMatchMedia();
10
-
11
- describe('Select Option', () => {
12
- it('opens dropdown on desktop view', async () => {
13
- render(<SelectOptionExample />);
14
-
15
- let dialog = screen.queryByRole('dialog');
16
- expect(dialog).not.toBeInTheDocument();
17
-
18
- const button = screen.getByRole('button');
19
-
20
- await userEvent.click(button);
21
-
22
- dialog = screen.queryByRole('dialog');
23
- expect(dialog).toBeInTheDocument();
24
- });
25
-
26
- it('opens bottom sheet on mobile view', async () => {
27
- // mock mobile view
28
- window.innerWidth = Breakpoint.EXTRA_SMALL;
29
-
30
- render(<SelectOptionExample />);
31
-
32
- let dialog = screen.queryByRole('dialog');
33
- expect(dialog).not.toBeInTheDocument();
34
-
35
- const button = screen.getByRole('button');
36
-
37
- await userEvent.click(button);
38
-
39
- dialog = screen.queryByRole('dialog');
40
- expect(dialog).toBeInTheDocument();
41
- });
42
-
43
- it('shows options', async () => {
44
- render(<SelectOptionExample />);
45
-
46
- const button = screen.getByRole('button');
47
-
48
- await userEvent.click(button);
49
-
50
- const dialog = screen.getByRole('dialog');
51
- const sectionHeaders = within(dialog).getAllByRole('heading', { name: /balances|jars/i });
52
- expect(sectionHeaders).toHaveLength(2);
53
-
54
- const options = within(dialog).getAllByRole('heading', { level: 4 });
55
- expect(options).toHaveLength(5);
56
- });
57
-
58
- it('choose option', async () => {
59
- // mock mobile view
60
- window.innerWidth = Breakpoint.EXTRA_SMALL;
61
-
62
- const onClickHandler = jest.fn();
63
- render(
64
- <SelectOptionExample
65
- placeholder={{ title: 'Please choose balance', actionLabel: 'Pick' }}
66
- onChange={onClickHandler}
67
- />,
68
- );
69
-
70
- const button = screen.getByRole('button');
71
-
72
- expect(button).toHaveTextContent('Pick');
73
- expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
74
- await userEvent.click(button);
75
- expect(screen.getByRole('dialog')).toBeInTheDocument();
76
-
77
- const pickedOption = within(screen.getByRole('dialog')).getByText('Trip to Mars');
78
-
79
- expect(onClickHandler).not.toHaveBeenCalled();
80
- await userEvent.click(pickedOption);
81
- expect(onClickHandler).toHaveBeenCalledTimes(1);
82
-
83
- // wait for dialog to close
84
- await wait(500);
85
- expect(screen.getByText('Trip to Mars')).toBeInTheDocument();
86
- expect(screen.queryAllByTestId('chevron-down-icon')).toHaveLength(1);
87
- expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
88
- });
89
- });
@@ -1,269 +0,0 @@
1
- import type { StoryObj } from '@storybook/react';
2
- import { Flag } from '@wise/art';
3
- import SelectOption, {
4
- SelectOptionProps,
5
- SelectOptionValue,
6
- SelectOptiopsSection,
7
- } from './SelectOption';
8
- import { Bank, BankTransfer, Beach, Briefcase, Card, Plane } from '@transferwise/icons';
9
- import { Field } from '../field/Field';
10
- import { lorem10 } from '../test-utils';
11
- import Badge from '../badge';
12
- import Avatar from '../avatar';
13
- import { Sentiment } from '../common';
14
-
15
- export default {
16
- title: 'Option/SelectOption',
17
- };
18
-
19
- type Story = StoryObj<typeof SelectOption>;
20
-
21
- type CustomData = { data?: string };
22
-
23
- function cardPaymentMethod(index?: number): SelectOptionValue<CustomData> {
24
- return {
25
- media: <Card />,
26
- title: `Credit card ${index}`,
27
- content: (
28
- <>
29
- <div>Transfer the money to Wise using your bank account.</div>
30
- <div>0.32 GBP in fees, should arrive in seconds</div>
31
- </>
32
- ),
33
- };
34
- }
35
-
36
- const recentPaymentMethods: SelectOptionValue<CustomData>[] = [
37
- cardPaymentMethod(1),
38
- cardPaymentMethod(2),
39
- ];
40
-
41
- const allOtherPaymentMethods: SelectOptionValue<CustomData>[] = [
42
- {
43
- media: <Flag code="gbp" />,
44
- title: 'Wise GBP balance',
45
- content: (
46
- <>
47
- <span>300 GBP available</span>
48
- <span>0 GBP in fees, should arrive in seconds</span>
49
- </>
50
- ),
51
- disabled: true,
52
- value: { data: lorem10 },
53
- },
54
- cardPaymentMethod(1),
55
- {
56
- media: <Card />,
57
- title: 'Debit card',
58
- content: (
59
- <>
60
- <span>Send from your Visa or Mastercard.</span>
61
- <span>0.74 GBP in fees, should arrive in seconds</span>
62
- </>
63
- ),
64
- },
65
- {
66
- media: <Bank />,
67
- title: 'Swift Transfer',
68
- content: (
69
- <>
70
- <span>Send money internationally. Your bank will charge you extra fees.</span>
71
- <span>0.32 GBP in fees, should arrive by Thursday</span>
72
- </>
73
- ),
74
- },
75
- {
76
- media: <BankTransfer />,
77
- title: 'Bank Transfer',
78
- content: (
79
- <>
80
- <span>Transfer the money to Wise using your bank account.</span>
81
- <span>0.32 GBP in fees, should arrive in seconds</span>
82
- </>
83
- ),
84
- },
85
- {
86
- media: <BankTransfer />,
87
- title: 'Withdraw from your U.S. bank account (ACH)',
88
- content: (
89
- <>
90
- <span>1.63 USD in total fees.</span>
91
- <span>
92
- Pay with ACH using the bank account you’ve connected to Wise. Should arrive in seconds.
93
- </span>
94
- </>
95
- ),
96
- },
97
- cardPaymentMethod(1),
98
- cardPaymentMethod(2),
99
- cardPaymentMethod(3),
100
- cardPaymentMethod(4),
101
- cardPaymentMethod(5),
102
- cardPaymentMethod(6),
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
- args: {
172
- placeholder: { title: 'No balance selected' },
173
- options: balances,
174
- onChange: (value) => {
175
- console.log('selected balance', value);
176
- },
177
- },
178
- render: (args: SelectOptionProps) => {
179
- return (
180
- <div className="row">
181
- <div className="col-md-8 col-md-offset-2">
182
- <Field label="Balances">
183
- <SelectOption {...args} />
184
- </Field>
185
- </div>
186
- </div>
187
- );
188
- },
189
- };
190
-
191
- export const Variants: Story = {
192
- render: () => {
193
- function onChange(value: SelectOptionValue<CustomData>): void {
194
- console.log(value);
195
- }
196
- return (
197
- <div className="row">
198
- <div className="col-md-8 col-md-offset-2">
199
- <SelectOption<CustomData>
200
- className="d-block"
201
- aria-label="Choose one of payment methods"
202
- placeholder={{ title: 'No method selected', actionLabel: 'Select' }}
203
- selected={paymentMethods[1].options[1]}
204
- options={paymentMethods}
205
- onChange={onChange}
206
- />
207
- </div>
208
-
209
- <div className="col-md-8 col-md-offset-2">
210
- <Field label={<>Payment method</>}>
211
- <SelectOption<CustomData>
212
- aria-label="Choose one of payment methods"
213
- placeholder={{ title: 'No method selected', actionLabel: 'Select' }}
214
- selected={paymentMethods[1].options[1]}
215
- options={paymentMethods}
216
- onChange={onChange}
217
- />
218
- </Field>
219
- </div>
220
-
221
- <div className="col-md-8 col-md-offset-2">
222
- <Field
223
- label={<>Payment method</>}
224
- sentiment={Sentiment.NEGATIVE}
225
- message="Just an example of validation message"
226
- >
227
- <SelectOption<CustomData>
228
- aria-label="Choose one of payment methods"
229
- placeholder={{ title: 'No method selected', actionLabel: 'Select' }}
230
- selected={paymentMethods[1].options[1]}
231
- options={paymentMethods}
232
- onChange={onChange}
233
- />
234
- </Field>
235
- </div>
236
-
237
- <div className="col-md-8 col-md-offset-2">
238
- <Field
239
- label={<>Payment method</>}
240
- sentiment={Sentiment.NEGATIVE}
241
- message="Just an example of validation message"
242
- >
243
- <SelectOption<CustomData>
244
- aria-label="Choose one of payment methods"
245
- placeholder={{ title: 'No method selected', actionLabel: 'Select' }}
246
- options={paymentMethods}
247
- onChange={onChange}
248
- />
249
- </Field>
250
- </div>
251
-
252
- <div className="col-md-8 col-md-offset-2">
253
- <Field
254
- label={<>Payment method</>}
255
- sentiment={Sentiment.NEGATIVE}
256
- message="Example of disabled select option"
257
- >
258
- <SelectOption<CustomData>
259
- disabled
260
- placeholder={{ title: 'No method selected' }}
261
- options={paymentMethods}
262
- onChange={onChange}
263
- />
264
- </Field>
265
- </div>
266
- </div>
267
- );
268
- },
269
- };
@@ -1,152 +0,0 @@
1
- import { useRef, useState } from 'react';
2
- import { ActionButtonProps } from '../actionButton';
3
- import classNames from 'classnames';
4
- import Option from '../common/Option';
5
- import type { OptionProps } from '../common/Option/Option';
6
- import { Breakpoint, Position } from '../common';
7
- import Section from '../section';
8
- import Header from '../header';
9
- import { HeaderProps } from '../header/Header';
10
- import NavigationOption from '../navigationOption';
11
- import NavigationOptionsList from '../navigationOptionsList';
12
- import { useInputAttributes } from '../inputs/contexts';
13
- import messages from './SelectOption.messages';
14
- import { useIntl } from 'react-intl';
15
- import ResponsivePanel from '../common/responsivePanel';
16
- import { useScreenSize } from '../common/hooks/useScreenSize';
17
- import { ChevronDown, Plus } from '@transferwise/icons';
18
-
19
- export type SelectOptiopsSection<T = unknown> = {
20
- title?: HeaderProps['title'];
21
- options: SelectOptionValue<T>[];
22
- };
23
-
24
- export type SelectOptionValue<T = unknown> = Pick<
25
- OptionProps,
26
- 'media' | 'title' | 'content' | 'disabled'
27
- > & {
28
- value?: T;
29
- };
30
-
31
- export type SelectOptionPlaceholder = Pick<OptionProps, 'media' | 'title' | 'content'> & {
32
- actionLabel?: ActionButtonProps['children'];
33
- };
34
-
35
- export type SelectOptionProps<T = unknown> = {
36
- onChange: (selected: SelectOptionValue<T>) => void;
37
- selected?: SelectOptionValue<T>;
38
- options: SelectOptiopsSection<T>[];
39
- placeholder: SelectOptionPlaceholder;
40
- } & Omit<
41
- OptionProps,
42
- 'as' | 'title' | 'media' | 'content' | 'onClick' | 'onChange' | 'showMediaAtAllSizes' | 'decision'
43
- >;
44
-
45
- export default function SelectOption<T>({
46
- selected: selectedValueProp = undefined,
47
- options,
48
- onChange,
49
- placeholder,
50
- disabled,
51
- ...props
52
- }: SelectOptionProps<T>) {
53
- const intl = useIntl();
54
- const rootRef = useRef(null);
55
- const [selected, setSelected] = useState(selectedValueProp);
56
- const [showOptions, setShowOptions] = useState(false);
57
-
58
- const hasSelected = selected !== undefined;
59
- const isLargeScreen = useScreenSize(Breakpoint.SMALL);
60
-
61
- const inputAttributes = useInputAttributes();
62
- const ariaLabelledBy = props['aria-labelledby'] ?? inputAttributes?.['aria-labelledby'];
63
-
64
- function handleOnClick(showOptionsStatus: boolean) {
65
- return () => {
66
- setShowOptions(showOptionsStatus);
67
- };
68
- }
69
-
70
- function handleOnChange(data: SelectOptionValue<T>) {
71
- return () => {
72
- setShowOptions(false);
73
- setSelected(data);
74
- onChange(data);
75
- };
76
- }
77
-
78
- function getOptions(isLargeScreen = false) {
79
- return (
80
- <div className={classNames({ 'np-select-option-list': isLargeScreen })}>
81
- {options.map((optionsSection, index) => (
82
- <Section key={index} className={classNames({ 'p-x-2 p-y-1': isLargeScreen })}>
83
- {optionsSection.title && <Header title={optionsSection.title} />}
84
- <NavigationOptionsList>
85
- {optionsSection.options.map((option, index) => {
86
- return (
87
- <NavigationOption
88
- key={index}
89
- isContainerAligned={!isLargeScreen}
90
- showMediaCircle
91
- showMediaAtAllSizes
92
- onClick={handleOnChange(option)}
93
- {...option}
94
- />
95
- );
96
- })}
97
- </NavigationOptionsList>
98
- </Section>
99
- ))}
100
- </div>
101
- );
102
- }
103
-
104
- return (
105
- <>
106
- <Option
107
- ref={rootRef}
108
- showMediaAtAllSizes
109
- disabled={disabled}
110
- decision={false}
111
- media={hasSelected ? selected.media : placeholder.media ?? <Plus size={24} />}
112
- title={(hasSelected ? selected : placeholder).title}
113
- content={(hasSelected ? selected : placeholder).content}
114
- className={classNames(
115
- 'np-select-option',
116
- 'clickable',
117
- hasSelected ? 'np-select-option-selected' : 'np-select-option-placeholder',
118
- props.className,
119
- )}
120
- button={
121
- <button
122
- {...inputAttributes}
123
- type="button"
124
- disabled={disabled}
125
- aria-labelledby={ariaLabelledBy}
126
- aria-haspopup="dialog"
127
- aria-expanded={showOptions}
128
- className={hasSelected ? 'btn-unstyled' : 'np-action-btn'}
129
- aria-label={hasSelected ? undefined : props['aria-label']}
130
- onClick={handleOnClick(true)}
131
- >
132
- {hasSelected ? (
133
- <ChevronDown title={intl.formatMessage(messages.selectedActionLabel)} />
134
- ) : (
135
- placeholder.actionLabel || intl.formatMessage(messages.actionLabel)
136
- )}
137
- </button>
138
- }
139
- />
140
- <ResponsivePanel
141
- anchorWidth
142
- altAxis
143
- anchorRef={rootRef}
144
- open={showOptions}
145
- position={Position.BOTTOM}
146
- onClose={handleOnClick(false)}
147
- >
148
- {getOptions(isLargeScreen)}
149
- </ResponsivePanel>
150
- </>
151
- );
152
- }
@@ -1,2 +0,0 @@
1
- export { default } from './SelectOption';
2
- export type { SelectOptionProps, SelectOptionValue, SelectOptiopsSection } from './SelectOption';