@jobber/components-native 0.104.1 → 0.104.3-rename-sel-d7cc7c5.6
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/dist/docs/Chip/Chip.md +1 -1
- package/dist/docs/Form/Form.md +1 -1
- package/dist/docs/LegacySelect/LegacySelect.md +49 -0
- package/dist/docs/index.md +1 -1
- package/dist/package.json +2 -2
- package/dist/src/Form/Form.test.js +4 -4
- package/dist/src/{Select/Select.js → LegacySelect/LegacySelect.js} +7 -7
- package/dist/src/LegacySelect/LegacySelect.test.js +183 -0
- package/dist/src/{Select/components/SelectDefaultPicker/SelectDefaultPicker.ios.js → LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.ios.js} +4 -4
- package/dist/src/{Select/components/SelectDefaultPicker/SelectDefaultPicker.js → LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.js} +4 -4
- package/dist/src/{Select/components/SelectDefaultPicker/SelectDefaultPicker.test.js → LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.test.js} +7 -7
- package/dist/src/LegacySelect/components/LegacySelectDefaultPicker/index.js +1 -0
- package/dist/src/LegacySelect/components/LegacySelectIOSPicker/LegacySelectIOSPicker.js +2 -0
- package/dist/src/LegacySelect/components/LegacySelectIOSPicker/index.js +1 -0
- package/dist/src/LegacySelect/components/LegacySelectInternalPicker/LegacySelectInternalPicker.js +14 -0
- package/dist/src/{Select/components/SelectInternalPicker/SelectInternalPicker.test.js → LegacySelect/components/LegacySelectInternalPicker/LegacySelectInternalPicker.test.js} +8 -8
- package/dist/src/LegacySelect/components/LegacySelectInternalPicker/index.js +1 -0
- package/dist/src/{Select/components/SelectPressable/SelectPressable.js → LegacySelect/components/LegacySelectPressable/LegacySelectPressable.js} +2 -2
- package/dist/src/LegacySelect/components/LegacySelectPressable/index.js +1 -0
- package/dist/src/LegacySelect/index.js +2 -0
- package/dist/src/index.js +1 -1
- package/dist/src/utils/meta/meta.json +3 -3
- package/dist/tsconfig.build.json +2 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/src/{Select/Select.d.ts → LegacySelect/LegacySelect.d.ts} +5 -5
- package/dist/types/src/LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.d.ts +5 -0
- package/dist/types/src/LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.ios.d.ts +5 -0
- package/dist/types/src/LegacySelect/components/LegacySelectDefaultPicker/index.d.ts +1 -0
- package/dist/types/src/LegacySelect/components/LegacySelectIOSPicker/LegacySelectIOSPicker.d.ts +10 -0
- package/dist/types/src/LegacySelect/components/LegacySelectIOSPicker/index.d.ts +1 -0
- package/dist/types/src/LegacySelect/components/LegacySelectInternalPicker/LegacySelectInternalPicker.d.ts +3 -0
- package/dist/types/src/LegacySelect/components/LegacySelectInternalPicker/index.d.ts +1 -0
- package/dist/types/src/LegacySelect/components/LegacySelectInternalPicker/utils.d.ts +3 -0
- package/dist/types/src/LegacySelect/components/LegacySelectPressable/LegacySelectPressable.d.ts +11 -0
- package/dist/types/src/LegacySelect/components/LegacySelectPressable/index.d.ts +1 -0
- package/dist/types/src/LegacySelect/index.d.ts +3 -0
- package/dist/types/src/{Select → LegacySelect}/types.d.ts +4 -4
- package/dist/types/src/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/Form/Form.test.tsx +5 -5
- package/src/{Select/Select.stories.tsx → LegacySelect/LegacySelect.stories.tsx} +10 -10
- package/src/{Select/Select.test.tsx → LegacySelect/LegacySelect.test.tsx} +83 -81
- package/src/{Select/Select.tsx → LegacySelect/LegacySelect.tsx} +13 -13
- package/src/{Select/components/SelectDefaultPicker/SelectDefaultPicker.ios.tsx → LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.ios.tsx} +9 -7
- package/src/{Select/components/SelectDefaultPicker/SelectDefaultPicker.test.tsx → LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.test.tsx} +8 -8
- package/src/{Select/components/SelectDefaultPicker/SelectDefaultPicker.tsx → LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.tsx} +8 -8
- package/src/LegacySelect/components/LegacySelectDefaultPicker/index.ts +1 -0
- package/src/LegacySelect/components/LegacySelectIOSPicker/LegacySelectIOSPicker.tsx +17 -0
- package/src/LegacySelect/components/LegacySelectIOSPicker/index.ts +1 -0
- package/src/{Select/components/SelectInternalPicker/SelectInternalPicker.test.tsx → LegacySelect/components/LegacySelectInternalPicker/LegacySelectInternalPicker.test.tsx} +11 -11
- package/src/LegacySelect/components/LegacySelectInternalPicker/LegacySelectInternalPicker.tsx +34 -0
- package/src/LegacySelect/components/LegacySelectInternalPicker/index.ts +1 -0
- package/src/{Select/components/SelectInternalPicker → LegacySelect/components/LegacySelectInternalPicker}/utils.ts +6 -4
- package/src/{Select/components/SelectPressable/SelectPressable.tsx → LegacySelect/components/LegacySelectPressable/LegacySelectPressable.tsx} +10 -4
- package/src/LegacySelect/components/LegacySelectPressable/index.ts +1 -0
- package/src/LegacySelect/docs/LegacySelectBasic.tsx +14 -0
- package/src/LegacySelect/docs/LegacySelectInitialValue.tsx +20 -0
- package/src/LegacySelect/docs/index.ts +2 -0
- package/src/LegacySelect/index.ts +3 -0
- package/src/{Select → LegacySelect}/types.ts +4 -4
- package/src/index.ts +1 -1
- package/src/utils/meta/meta.json +3 -3
- package/dist/docs/Select/Select.md +0 -219
- package/dist/src/Select/Select.test.js +0 -183
- package/dist/src/Select/components/SelectDefaultPicker/index.js +0 -1
- package/dist/src/Select/components/SelectIOSPicker/SelectIOSPicker.js +0 -2
- package/dist/src/Select/components/SelectIOSPicker/index.js +0 -1
- package/dist/src/Select/components/SelectInternalPicker/SelectInternalPicker.js +0 -14
- package/dist/src/Select/components/SelectInternalPicker/index.js +0 -1
- package/dist/src/Select/components/SelectPressable/index.js +0 -1
- package/dist/src/Select/index.js +0 -2
- package/dist/types/src/Select/components/SelectDefaultPicker/SelectDefaultPicker.d.ts +0 -5
- package/dist/types/src/Select/components/SelectDefaultPicker/SelectDefaultPicker.ios.d.ts +0 -5
- package/dist/types/src/Select/components/SelectDefaultPicker/index.d.ts +0 -1
- package/dist/types/src/Select/components/SelectIOSPicker/SelectIOSPicker.d.ts +0 -10
- package/dist/types/src/Select/components/SelectIOSPicker/index.d.ts +0 -1
- package/dist/types/src/Select/components/SelectInternalPicker/SelectInternalPicker.d.ts +0 -3
- package/dist/types/src/Select/components/SelectInternalPicker/index.d.ts +0 -1
- package/dist/types/src/Select/components/SelectInternalPicker/utils.d.ts +0 -3
- package/dist/types/src/Select/components/SelectPressable/SelectPressable.d.ts +0 -11
- package/dist/types/src/Select/components/SelectPressable/index.d.ts +0 -1
- package/dist/types/src/Select/index.d.ts +0 -3
- package/src/Select/components/SelectDefaultPicker/index.ts +0 -1
- package/src/Select/components/SelectIOSPicker/SelectIOSPicker.tsx +0 -17
- package/src/Select/components/SelectIOSPicker/index.ts +0 -1
- package/src/Select/components/SelectInternalPicker/SelectInternalPicker.tsx +0 -34
- package/src/Select/components/SelectInternalPicker/index.ts +0 -1
- package/src/Select/components/SelectPressable/index.ts +0 -1
- package/src/Select/docs/SelectBasic.tsx +0 -14
- package/src/Select/docs/SelectInitialValue.tsx +0 -18
- package/src/Select/docs/index.ts +0 -2
- package/src/Select/index.ts +0 -3
- /package/dist/src/{Select/Select.style.js → LegacySelect/LegacySelect.style.js} +0 -0
- /package/dist/src/{Select/components/SelectDefaultPicker/SelectDefaultPicker.style.js → LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.style.js} +0 -0
- /package/dist/src/{Select/components/SelectInternalPicker → LegacySelect/components/LegacySelectInternalPicker}/utils.js +0 -0
- /package/dist/src/{Select/components/SelectPressable/SelectPressable.style.js → LegacySelect/components/LegacySelectPressable/LegacySelectPressable.style.js} +0 -0
- /package/dist/src/{Select → LegacySelect}/types.js +0 -0
- /package/dist/types/src/{Select/Select.style.d.ts → LegacySelect/LegacySelect.style.d.ts} +0 -0
- /package/dist/types/src/{Select/Select.test.d.ts → LegacySelect/LegacySelect.test.d.ts} +0 -0
- /package/dist/types/src/{Select/components/SelectDefaultPicker/SelectDefaultPicker.style.d.ts → LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.style.d.ts} +0 -0
- /package/dist/types/src/{Select/components/SelectDefaultPicker/SelectDefaultPicker.test.d.ts → LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.test.d.ts} +0 -0
- /package/dist/types/src/{Select/components/SelectInternalPicker/SelectInternalPicker.test.d.ts → LegacySelect/components/LegacySelectInternalPicker/LegacySelectInternalPicker.test.d.ts} +0 -0
- /package/dist/types/src/{Select/components/SelectPressable/SelectPressable.style.d.ts → LegacySelect/components/LegacySelectPressable/LegacySelectPressable.style.d.ts} +0 -0
- /package/src/{Select/Select.style.ts → LegacySelect/LegacySelect.style.ts} +0 -0
- /package/src/{Select/components/SelectDefaultPicker/SelectDefaultPicker.style.ts → LegacySelect/components/LegacySelectDefaultPicker/LegacySelectDefaultPicker.style.ts} +0 -0
- /package/src/{Select/components/SelectPressable/SelectPressable.style.ts → LegacySelect/components/LegacySelectPressable/LegacySelectPressable.style.ts} +0 -0
package/dist/docs/Chip/Chip.md
CHANGED
|
@@ -238,7 +238,7 @@ export function ChipInvalidExample(
|
|
|
238
238
|
single-select, multi-select, and add/dismiss functionality "out of the box"
|
|
239
239
|
* [Combobox](/components/Combobox) is most commonly triggered by a Chip, but is
|
|
240
240
|
a separate component
|
|
241
|
-
* [Select](
|
|
241
|
+
* [Select](/components/Select) is a simpler single-select "dropdown" that
|
|
242
242
|
presents as a form element and should be preferred in forms
|
|
243
243
|
* [RadioGroup](/components/RadioGroup) should be used to allow the user to
|
|
244
244
|
select "one-of-many" items (single-select) and the labels for the items are
|
package/dist/docs/Form/Form.md
CHANGED
|
@@ -18,7 +18,7 @@ have a `value` and `onChange` prop.
|
|
|
18
18
|
### Inputs
|
|
19
19
|
|
|
20
20
|
Form can accept various inputs and selection elements such as (but not limited
|
|
21
|
-
to) [InputText](../InputText/InputText.md), [Select](
|
|
21
|
+
to) [InputText](../InputText/InputText.md), [Select](/components/Select),
|
|
22
22
|
[Switch](../Switch/Switch.md), [Checkbox](../Checkbox/Checkbox.md), and
|
|
23
23
|
[Chips](/components/Chips). They should be placed [Cards](../Card/Card.md) to
|
|
24
24
|
indicate grouping when relevant, and groups of Cards can be spaced appropriately
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# LegacySelect
|
|
2
|
+
|
|
3
|
+
`LegacySelect` is the mobile select control that presents a defined list of
|
|
4
|
+
options in a native picker (iOS and Android). It is the renamed, behavior
|
|
5
|
+
identical continuation of the former mobile `Select` — a new mobile `Select` is
|
|
6
|
+
being introduced separately, after which existing call sites will migrate off
|
|
7
|
+
`LegacySelect`.
|
|
8
|
+
|
|
9
|
+
## Design & usage guidelines
|
|
10
|
+
|
|
11
|
+
Nested within `LegacySelect`, `LegacyOption` defines the options that can be
|
|
12
|
+
selected. Each `LegacyOption` takes a `value` and renders its children as the
|
|
13
|
+
label.
|
|
14
|
+
|
|
15
|
+
* Provide a `label` for the field and an optional `placeholder` to represent an
|
|
16
|
+
empty selection.
|
|
17
|
+
* Use `validations` for react-hook-form powered validation, and `disabled` to
|
|
18
|
+
prevent the picker from opening.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Props
|
|
22
|
+
|
|
23
|
+
### Mobile
|
|
24
|
+
|
|
25
|
+
#### LegacyOption
|
|
26
|
+
|
|
27
|
+
| Prop | Type | Required | Default | Description |
|
|
28
|
+
|------|------|----------|---------|-------------|
|
|
29
|
+
| `children` | `string` | Yes | — | Text that shows up as the option |
|
|
30
|
+
| `value` | `string` | Yes | — | The value that gets returned when an option is selected |
|
|
31
|
+
|
|
32
|
+
#### LegacySelect
|
|
33
|
+
|
|
34
|
+
| Prop | Type | Required | Default | Description |
|
|
35
|
+
|------|------|----------|---------|-------------|
|
|
36
|
+
| `children` | `ReactElement<LegacySelectOption, string | JSXElementConstructor<any>>[]` | Yes | — | The options to select from |
|
|
37
|
+
| `accessibilityHint` | `string` | No | — | Helps users understand what will happen when they perform an action |
|
|
38
|
+
| `accessibilityLabel` | `string` | No | — | VoiceOver will read this string when a user selects the element |
|
|
39
|
+
| `assistiveText` | `string` | No | — | Help text shown below the control. |
|
|
40
|
+
| `defaultValue` | `string` | No | — | Default value for when the component is uncontrolled |
|
|
41
|
+
| `disabled` | `boolean` | No | — | Disables input selection |
|
|
42
|
+
| `invalid` | `boolean` | No | — | Indicates the current selection is invalid |
|
|
43
|
+
| `label` | `string` | No | — | Label text shown above the selection. |
|
|
44
|
+
| `name` | `string` | No | — | Name of the input. |
|
|
45
|
+
| `onChange` | `(newValue?: string) => void` | No | — | Callback that provides the new value when the selection changes |
|
|
46
|
+
| `placeholder` | `string` | No | — | Adds a first option to let users select a "no value". Placeholder item selected by default until a selection is made. |
|
|
47
|
+
| `testID` | `string` | No | — | Used to locate this view in end-to-end tests. |
|
|
48
|
+
| `validations` | `RegisterOptions` | No | — | The validations that will mark this component as invalid |
|
|
49
|
+
| `value` | `string` | No | — | Current value of the component |
|
package/dist/docs/index.md
CHANGED
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
[InputText](./InputText/InputText.md)
|
|
45
45
|
[InputTime](./InputTime/InputTime.md)
|
|
46
46
|
[interaction](./interaction/interaction.md)
|
|
47
|
+
[LegacySelect](./LegacySelect/LegacySelect.md)
|
|
47
48
|
[Opacity](./Opacity/Opacity.md)
|
|
48
49
|
[page-layouts](./page-layouts/page-layouts.md)
|
|
49
50
|
[ProgressBar](./ProgressBar/ProgressBar.md)
|
|
50
51
|
[Radii](./Radii/Radii.md)
|
|
51
52
|
[ResponsiveBreakpoint](./ResponsiveBreakpoint/ResponsiveBreakpoint.md)
|
|
52
53
|
[scaffolding](./scaffolding/scaffolding.md)
|
|
53
|
-
[Select](./Select/Select.md)
|
|
54
54
|
[settings](./settings/settings.md)
|
|
55
55
|
[Spacing](./Spacing/Spacing.md)
|
|
56
56
|
[StatusLabel](./StatusLabel/StatusLabel.md)
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.104.
|
|
3
|
+
"version": "0.104.3-rename-sel-d7cc7c5.6+d7cc7c5c",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -122,5 +122,5 @@
|
|
|
122
122
|
"react-native-screens": ">=4.18.0",
|
|
123
123
|
"react-native-svg": ">=12.0.0"
|
|
124
124
|
},
|
|
125
|
-
"gitHead": "
|
|
125
|
+
"gitHead": "d7cc7c5c5e83b282c4d34b9cb721bcb431140881"
|
|
126
126
|
}
|
|
@@ -18,7 +18,7 @@ import { Text } from "../Text";
|
|
|
18
18
|
import { Checkbox } from "../Checkbox";
|
|
19
19
|
import { InputNumber } from "../InputNumber";
|
|
20
20
|
import { Switch } from "../Switch";
|
|
21
|
-
import {
|
|
21
|
+
import { LegacyOption, LegacySelect } from "../LegacySelect";
|
|
22
22
|
import { InputText } from "../InputText";
|
|
23
23
|
jest.mock("lodash/debounce", () => {
|
|
24
24
|
return jest.fn(fn => {
|
|
@@ -90,9 +90,9 @@ function MockForm({ onSubmit, sendBannerErrors = false, sendNetworkErrors = fals
|
|
|
90
90
|
minLength: { value: 3, message: minLengthText },
|
|
91
91
|
} }),
|
|
92
92
|
Array.isArray(localCacheExclude) && localCacheExclude.length > 0 && (React.createElement(InputText, { name: testInputTextNameExclude, placeholder: testInputTextPlaceholderExclude })),
|
|
93
|
-
React.createElement(
|
|
94
|
-
React.createElement(
|
|
95
|
-
React.createElement(
|
|
93
|
+
React.createElement(LegacySelect, { onChange: onChangeSelectMock, label: selectLabel, name: testSelectName },
|
|
94
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
95
|
+
React.createElement(LegacyOption, { value: "2" }, "2")),
|
|
96
96
|
React.createElement(Switch, { name: testSwitchName, label: "Test Switch", accessibilityLabel: switchLabel, onValueChange: onChangeSwitchMock }),
|
|
97
97
|
React.createElement(InputNumber, { name: testInputNumberName, placeholder: "Test Num" }),
|
|
98
98
|
React.createElement(Checkbox, { name: testCheckboxName, accessibilityLabel: checkboxLabel })));
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
|
-
import { useStyles } from "./
|
|
4
|
-
import {
|
|
3
|
+
import { useStyles } from "./LegacySelect.style";
|
|
4
|
+
import { LegacySelectInternalPicker } from "./components/LegacySelectInternalPicker";
|
|
5
5
|
import { InputFieldWrapper } from "../InputFieldWrapper";
|
|
6
6
|
import { Icon } from "../Icon";
|
|
7
7
|
import { Text } from "../Text";
|
|
8
8
|
import { useFormController } from "../hooks";
|
|
9
9
|
import { useAtlantisI18n } from "../hooks/useAtlantisI18n";
|
|
10
|
-
export function
|
|
10
|
+
export function LegacySelect({ value, defaultValue, onChange, children, placeholder, label, assistiveText, disabled, invalid, validations, accessibilityLabel, name, testID, }) {
|
|
11
11
|
const { field, error } = useFormController({
|
|
12
12
|
name,
|
|
13
13
|
validations,
|
|
@@ -26,7 +26,7 @@ export function Select({ value, defaultValue, onChange, children, placeholder, l
|
|
|
26
26
|
container: { paddingLeft: undefined },
|
|
27
27
|
}, assistiveText: assistiveText },
|
|
28
28
|
React.createElement(View, { testID: getTestID(testID), accessible: true, accessibilityLabel: getA11yLabel(), accessibilityValue: { text: getValue() }, accessibilityHint: t("Select.a11yHint"), accessibilityRole: "button", accessibilityState: { disabled: disabled } },
|
|
29
|
-
React.createElement(
|
|
29
|
+
React.createElement(LegacySelectInternalPicker, { disabled: disabled, options: getOptions(), onChange: handleChange },
|
|
30
30
|
React.createElement(View, { style: [styles.container, (invalid || !!error) && styles.invalid] },
|
|
31
31
|
label && (React.createElement(Text, { level: "textSupporting", variation: textVariation, hideFromScreenReader: true, selectable: false }, label)),
|
|
32
32
|
React.createElement(View, { style: styles.input },
|
|
@@ -75,10 +75,10 @@ function getTextVariation({ invalid, disabled, }) {
|
|
|
75
75
|
}
|
|
76
76
|
function getTestID(testID) {
|
|
77
77
|
if (testID) {
|
|
78
|
-
return `ATL-${testID}-
|
|
78
|
+
return `ATL-${testID}-LegacySelect`;
|
|
79
79
|
}
|
|
80
|
-
return "ATL-
|
|
80
|
+
return "ATL-LegacySelect";
|
|
81
81
|
}
|
|
82
|
-
export function
|
|
82
|
+
export function LegacyOption({ children }) {
|
|
83
83
|
return React.createElement(React.Fragment, null, children);
|
|
84
84
|
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import React from "react";
|
|
11
|
+
import { fireEvent, render } from "@testing-library/react-native";
|
|
12
|
+
import { tokens } from "@jobber/design";
|
|
13
|
+
import { AccessibilityInfo } from "react-native";
|
|
14
|
+
import { LegacyOption, LegacySelect } from ".";
|
|
15
|
+
import { LegacySelectInternalPicker } from "./components/LegacySelectInternalPicker";
|
|
16
|
+
const A11yInfoSpy = jest.spyOn(AccessibilityInfo, "isScreenReaderEnabled");
|
|
17
|
+
const onChange = jest.fn();
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
A11yInfoSpy.mockImplementation(() => Promise.resolve(false));
|
|
20
|
+
});
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
jest.resetAllMocks();
|
|
23
|
+
});
|
|
24
|
+
const defaultPlaceholder = "Select an option";
|
|
25
|
+
describe("LegacySelect", () => {
|
|
26
|
+
it("renders a LegacySelect", () => {
|
|
27
|
+
const component = render(React.createElement(LegacySelect, { onChange: onChange },
|
|
28
|
+
React.createElement(LegacyOption, { value: "one" }, "one"),
|
|
29
|
+
React.createElement(LegacyOption, { value: "2" }, "2")));
|
|
30
|
+
expect(component.getByTestId("arrowDown")).toBeDefined();
|
|
31
|
+
expect(component.getByText(defaultPlaceholder, {
|
|
32
|
+
includeHiddenElements: true,
|
|
33
|
+
})).toBeDefined();
|
|
34
|
+
});
|
|
35
|
+
it("renders a LegacySelect with a label", () => {
|
|
36
|
+
const label = "Press me";
|
|
37
|
+
const { getByText } = render(React.createElement(LegacySelect, { onChange: onChange, label: label },
|
|
38
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
39
|
+
React.createElement(LegacyOption, { value: "2" }, "2")));
|
|
40
|
+
expect(getByText(label, { includeHiddenElements: true })).toBeDefined();
|
|
41
|
+
});
|
|
42
|
+
it("renders a LegacySelect with a placeholder", () => {
|
|
43
|
+
const placeholder = "I am a placeholder";
|
|
44
|
+
const { getByText } = render(React.createElement(LegacySelect, { onChange: onChange, placeholder: placeholder },
|
|
45
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
46
|
+
React.createElement(LegacyOption, { value: "2" }, "2")));
|
|
47
|
+
expect(getByText(placeholder, { includeHiddenElements: true })).toBeDefined();
|
|
48
|
+
});
|
|
49
|
+
it("renders a LegacySelect with assistive text", () => {
|
|
50
|
+
const assistiveText = "You need to pick something";
|
|
51
|
+
const { getByText } = render(React.createElement(LegacySelect, { onChange: onChange, assistiveText: assistiveText },
|
|
52
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
53
|
+
React.createElement(LegacyOption, { value: "2" }, "2")));
|
|
54
|
+
expect(getByText(assistiveText, { includeHiddenElements: true })).toBeDefined();
|
|
55
|
+
});
|
|
56
|
+
it("renders a disabled LegacySelect", () => {
|
|
57
|
+
const labelText = "labelText";
|
|
58
|
+
const { getByText } = render(React.createElement(LegacySelect, { label: labelText, onChange: onChange, disabled: true },
|
|
59
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
60
|
+
React.createElement(LegacyOption, { value: "2" }, "2")));
|
|
61
|
+
expect(getByText(labelText, { includeHiddenElements: true }).props.style).toContainEqual({
|
|
62
|
+
color: tokens["color-disabled"],
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it("renders a LegacySelect with a value provided", () => {
|
|
66
|
+
const expectedValue = "That should be me";
|
|
67
|
+
const { getByText } = render(React.createElement(LegacySelect, { onChange: onChange, value: "2" },
|
|
68
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
69
|
+
React.createElement(LegacyOption, { value: "2" }, expectedValue)));
|
|
70
|
+
expect(getByText(expectedValue, { includeHiddenElements: true })).toBeDefined();
|
|
71
|
+
});
|
|
72
|
+
it("renders a LegacySelect with a defaultValue provided", () => {
|
|
73
|
+
const expectedValue = "It's the 3rd value";
|
|
74
|
+
const { getByText } = render(React.createElement(LegacySelect, { onChange: onChange, defaultValue: "3" },
|
|
75
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
76
|
+
React.createElement(LegacyOption, { value: "2" }, "2"),
|
|
77
|
+
React.createElement(LegacyOption, { value: "3" }, expectedValue)));
|
|
78
|
+
expect(getByText(expectedValue, { includeHiddenElements: true })).toBeDefined();
|
|
79
|
+
});
|
|
80
|
+
it("renders a LegacySelect with custom testID", () => {
|
|
81
|
+
const testID = "testID";
|
|
82
|
+
const { getByTestId } = render(React.createElement(LegacySelect, { onChange: onChange, testID: testID },
|
|
83
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
84
|
+
React.createElement(LegacyOption, { value: "2" }, "2")));
|
|
85
|
+
expect(getByTestId(`ATL-${testID}-LegacySelect`)).toBeDefined();
|
|
86
|
+
});
|
|
87
|
+
it("renders an accessibilityLabel if provided", () => {
|
|
88
|
+
const { getByLabelText } = render(React.createElement(LegacySelect, { onChange: onChange, label: "label", accessibilityLabel: "accessibilityLabel" },
|
|
89
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
90
|
+
React.createElement(LegacyOption, { value: "2" }, "2")));
|
|
91
|
+
expect(getByLabelText("accessibilityLabel")).toBeTruthy();
|
|
92
|
+
});
|
|
93
|
+
it("fires the onChange callback", () => {
|
|
94
|
+
const { getByTestId } = render(React.createElement(LegacySelect, { onChange: onChange, value: "2" },
|
|
95
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
96
|
+
React.createElement(LegacyOption, { value: "2" }, "2")));
|
|
97
|
+
const select = getByTestId("ATL-LegacySelect").findByType(LegacySelectInternalPicker);
|
|
98
|
+
expect(select).toBeTruthy();
|
|
99
|
+
fireEvent(select, "onChange", "1");
|
|
100
|
+
expect(onChange).toHaveBeenCalledWith("1");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe("when LegacySelect is invalid", () => {
|
|
104
|
+
const labelText = "labelText";
|
|
105
|
+
it("renders an invalid LegacySelect", () => {
|
|
106
|
+
const { getByText } = render(React.createElement(LegacySelect, { onChange: onChange, invalid: true, label: labelText },
|
|
107
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
108
|
+
React.createElement(LegacyOption, { value: "2" }, "2")));
|
|
109
|
+
expect(getByText(labelText, { includeHiddenElements: true }).props.style).toContainEqual({
|
|
110
|
+
color: tokens["color-critical"],
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
it("renders an invalid LegacySelect with placeholder", () => {
|
|
114
|
+
const placeholder = "Place me in the holder";
|
|
115
|
+
const { getByText } = render(React.createElement(LegacySelect, { label: labelText, onChange: onChange, invalid: true, placeholder: placeholder },
|
|
116
|
+
React.createElement(LegacyOption, { value: "1" }, "1"),
|
|
117
|
+
React.createElement(LegacyOption, { value: "2" }, "2")));
|
|
118
|
+
expect(getByText(placeholder, { includeHiddenElements: true })).toBeDefined();
|
|
119
|
+
expect(getByText(labelText, { includeHiddenElements: true }).props.style).toContainEqual({
|
|
120
|
+
color: tokens["color-critical"],
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe("when validations are passed to the component", () => {
|
|
125
|
+
describe("validations fail", () => {
|
|
126
|
+
let tree;
|
|
127
|
+
const labelText = "labelText";
|
|
128
|
+
const errorMsg = "Too short";
|
|
129
|
+
beforeEach(() => {
|
|
130
|
+
tree = render(React.createElement(LegacySelect, { label: labelText, onChange: onChange, value: "Watermelon", validations: {
|
|
131
|
+
minLength: { value: 60, message: errorMsg },
|
|
132
|
+
} },
|
|
133
|
+
React.createElement(LegacyOption, { value: "Apple" }, "Apple"),
|
|
134
|
+
React.createElement(LegacyOption, { value: "Watermelon" }, "Watermelon")));
|
|
135
|
+
});
|
|
136
|
+
it("renders the error message when there is an error", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
137
|
+
const select = tree
|
|
138
|
+
.getByTestId("ATL-LegacySelect")
|
|
139
|
+
.findByType(LegacySelectInternalPicker);
|
|
140
|
+
fireEvent(select, "onChange", "Apple");
|
|
141
|
+
expect(yield tree.findByText(errorMsg, { includeHiddenElements: true })).toBeTruthy();
|
|
142
|
+
}));
|
|
143
|
+
it("shows the invalid colours", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
+
const select = tree
|
|
145
|
+
.getByTestId("ATL-LegacySelect")
|
|
146
|
+
.findByType(LegacySelectInternalPicker);
|
|
147
|
+
fireEvent(select, "onChange", "Apple");
|
|
148
|
+
expect((yield tree.findByText(labelText, { includeHiddenElements: true }))
|
|
149
|
+
.props.style).toContainEqual({
|
|
150
|
+
color: tokens["color-critical"],
|
|
151
|
+
});
|
|
152
|
+
}));
|
|
153
|
+
});
|
|
154
|
+
describe("validations passes", () => {
|
|
155
|
+
let tree;
|
|
156
|
+
const labelText = "labelText";
|
|
157
|
+
const errorMsg = "Not too short";
|
|
158
|
+
beforeEach(() => {
|
|
159
|
+
tree = render(React.createElement(LegacySelect, { label: labelText, onChange: onChange, value: "Watermelon", validations: {
|
|
160
|
+
minLength: { value: 4, message: errorMsg },
|
|
161
|
+
} },
|
|
162
|
+
React.createElement(LegacyOption, { value: "Apple" }, "Apple"),
|
|
163
|
+
React.createElement(LegacyOption, { value: "Watermelon" }, "Watermelon")));
|
|
164
|
+
});
|
|
165
|
+
it("does not render any error messages", () => {
|
|
166
|
+
const select = tree
|
|
167
|
+
.getByTestId("ATL-LegacySelect")
|
|
168
|
+
.findByType(LegacySelectInternalPicker);
|
|
169
|
+
expect(select).toBeTruthy();
|
|
170
|
+
fireEvent(select, "onChange", "Apple");
|
|
171
|
+
expect(tree.queryByText(errorMsg)).toBeNull();
|
|
172
|
+
});
|
|
173
|
+
it("has non-critical colours", () => {
|
|
174
|
+
const select = tree
|
|
175
|
+
.getByTestId("ATL-LegacySelect")
|
|
176
|
+
.findByType(LegacySelectInternalPicker);
|
|
177
|
+
fireEvent(select, "onChange", "Apple");
|
|
178
|
+
expect(tree.getByText(labelText, { includeHiddenElements: true }).props.style).toContainEqual({
|
|
179
|
+
color: tokens["color-text--secondary"],
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -4,15 +4,15 @@ import {
|
|
|
4
4
|
Button, Modal, TouchableOpacity, View, } from "react-native";
|
|
5
5
|
import { Picker } from "@react-native-picker/picker";
|
|
6
6
|
import { SafeAreaView } from "react-native-safe-area-context";
|
|
7
|
-
import { styles } from "./
|
|
8
|
-
import {
|
|
7
|
+
import { styles } from "./LegacySelectDefaultPicker.style";
|
|
8
|
+
import { LegacySelectPressable } from "../LegacySelectPressable/LegacySelectPressable";
|
|
9
9
|
import { useAtlantisI18n } from "../../../hooks/useAtlantisI18n";
|
|
10
|
-
export function
|
|
10
|
+
export function LegacySelectDefaultPicker({ children, options, onChange, }) {
|
|
11
11
|
const [show, setShow] = useState(false);
|
|
12
12
|
const { t } = useAtlantisI18n();
|
|
13
13
|
const selectedLanguage = options.find(option => option.isActive);
|
|
14
14
|
return (React.createElement(React.Fragment, null,
|
|
15
|
-
React.createElement(
|
|
15
|
+
React.createElement(LegacySelectPressable, { onPress: showPicker }, children),
|
|
16
16
|
React.createElement(Modal, { visible: show, transparent: true, animationType: "slide", onRequestClose: hidePicker },
|
|
17
17
|
React.createElement(TouchableOpacity, { style: styles.overlay, onPress: hidePicker }),
|
|
18
18
|
React.createElement(View, { style: styles.actionBar },
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import React, { useRef } from "react";
|
|
2
2
|
import { Picker } from "@react-native-picker/picker";
|
|
3
|
-
import { styles } from "./
|
|
4
|
-
import {
|
|
3
|
+
import { styles } from "./LegacySelectDefaultPicker.style";
|
|
4
|
+
import { LegacySelectPressable } from "../LegacySelectPressable";
|
|
5
5
|
import { useAtlantisTheme } from "../../../AtlantisThemeContext";
|
|
6
|
-
export function
|
|
6
|
+
export function LegacySelectDefaultPicker({ children, options, disabled, onChange, }) {
|
|
7
7
|
var _a;
|
|
8
8
|
const selectedItem = options.find(option => option.isActive);
|
|
9
9
|
const pickerRef = useRef(null);
|
|
10
10
|
const { tokens } = useAtlantisTheme();
|
|
11
|
-
return (React.createElement(
|
|
11
|
+
return (React.createElement(LegacySelectPressable, { onPress: (_a = pickerRef.current) === null || _a === void 0 ? void 0 : _a.focus },
|
|
12
12
|
children,
|
|
13
13
|
React.createElement(Picker, { ref: pickerRef, selectedValue: selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value, onValueChange: onChange, mode: "dropdown", enabled: !disabled, style: styles.androidPickerContainer }, options.map(({ label, value, isActive }, i) => (React.createElement(Picker.Item, { key: i, label: label, value: value, color: isSelected(isActive) }))))));
|
|
14
14
|
function isSelected(isActive) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { fireEvent, render } from "@testing-library/react-native";
|
|
3
3
|
import { AccessibilityInfo, View } from "react-native";
|
|
4
|
-
import {
|
|
4
|
+
import { LegacySelectDefaultPicker } from "./LegacySelectDefaultPicker";
|
|
5
5
|
import { Text } from "../../../Text";
|
|
6
6
|
const A11yInfoSpy = jest.spyOn(AccessibilityInfo, "isScreenReaderEnabled");
|
|
7
7
|
const handleChange = jest.fn();
|
|
@@ -19,30 +19,30 @@ afterEach(() => {
|
|
|
19
19
|
});
|
|
20
20
|
const childText = "Click me";
|
|
21
21
|
function setup() {
|
|
22
|
-
return render(React.createElement(View, { testID: "
|
|
23
|
-
React.createElement(
|
|
22
|
+
return render(React.createElement(View, { testID: "LegacySelectDefaultPicker" },
|
|
23
|
+
React.createElement(LegacySelectDefaultPicker, { onChange: handleChange, options: [
|
|
24
24
|
{ value: "1", label: "First option" },
|
|
25
25
|
{ value: "2", label: "Second option" },
|
|
26
26
|
] },
|
|
27
27
|
React.createElement(Text, null, childText))));
|
|
28
28
|
}
|
|
29
|
-
describe("
|
|
29
|
+
describe("LegacySelectDefaultPicker", () => {
|
|
30
30
|
it("opens the picker", () => {
|
|
31
31
|
const screen = setup();
|
|
32
32
|
fireEvent.press(screen.getByText(childText));
|
|
33
|
-
expect(screen.getByTestId("
|
|
33
|
+
expect(screen.getByTestId("LegacySelectDefaultPicker").findByType(MockPicker)).toBeDefined();
|
|
34
34
|
});
|
|
35
35
|
it("closes the picker", () => {
|
|
36
36
|
const screen = setup();
|
|
37
37
|
fireEvent.press(screen.getByText(childText));
|
|
38
38
|
fireEvent.press(screen.getByText("Done"));
|
|
39
|
-
expect(screen.getByTestId("
|
|
39
|
+
expect(screen.getByTestId("LegacySelectDefaultPicker").findAllByType(MockPicker)).toEqual([]);
|
|
40
40
|
});
|
|
41
41
|
it("fires the onChange", () => {
|
|
42
42
|
const screen = setup();
|
|
43
43
|
fireEvent.press(screen.getByText(childText));
|
|
44
44
|
const menu = screen
|
|
45
|
-
.getByTestId("
|
|
45
|
+
.getByTestId("LegacySelectDefaultPicker")
|
|
46
46
|
.findByType(MockPicker);
|
|
47
47
|
expect(menu).toBeDefined();
|
|
48
48
|
fireEvent(menu, "onValueChange", "2");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./LegacySelectDefaultPicker";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./LegacySelectIOSPicker";
|
package/dist/src/LegacySelect/components/LegacySelectInternalPicker/LegacySelectInternalPicker.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { handlePress, isIOS14AndUp } from "./utils";
|
|
3
|
+
import { LegacySelectIOSPicker } from "../LegacySelectIOSPicker";
|
|
4
|
+
import { LegacySelectPressable } from "../LegacySelectPressable";
|
|
5
|
+
import { LegacySelectDefaultPicker } from "../LegacySelectDefaultPicker";
|
|
6
|
+
export function LegacySelectInternalPicker({ children, options, disabled, onChange, }) {
|
|
7
|
+
if (disabled)
|
|
8
|
+
return React.createElement(React.Fragment, null, children);
|
|
9
|
+
if (isIOS14AndUp()) {
|
|
10
|
+
return (React.createElement(LegacySelectPressable, null,
|
|
11
|
+
React.createElement(LegacySelectIOSPicker, { options: options, onOptionPress: handlePress(onChange) }, children)));
|
|
12
|
+
}
|
|
13
|
+
return (React.createElement(LegacySelectDefaultPicker, { options: options, onChange: onChange }, children));
|
|
14
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { fireEvent, render } from "@testing-library/react-native";
|
|
3
3
|
import { View } from "react-native";
|
|
4
|
-
import {
|
|
4
|
+
import { LegacySelectInternalPicker } from ".";
|
|
5
5
|
import { Text } from "../../../Text";
|
|
6
6
|
let Platform;
|
|
7
7
|
beforeEach(() => {
|
|
@@ -21,19 +21,19 @@ const RCTPicker = "RCTATLPicker";
|
|
|
21
21
|
const childText = "Click me";
|
|
22
22
|
const handleChange = jest.fn();
|
|
23
23
|
function setup(props) {
|
|
24
|
-
return render(React.createElement(View, { testID: "
|
|
25
|
-
React.createElement(
|
|
24
|
+
return render(React.createElement(View, { testID: "LegacySelectInternalPicker" },
|
|
25
|
+
React.createElement(LegacySelectInternalPicker, { onChange: handleChange, disabled: props === null || props === void 0 ? void 0 : props.disabled, options: [
|
|
26
26
|
{ value: "1", label: "First option" },
|
|
27
27
|
{ value: "2", label: "Second option" },
|
|
28
28
|
] },
|
|
29
29
|
React.createElement(Text, null, childText))));
|
|
30
30
|
}
|
|
31
|
-
describe("
|
|
31
|
+
describe("LegacySelectInternalPicker", () => {
|
|
32
32
|
it("fires the onChange", () => {
|
|
33
33
|
const screen = setup();
|
|
34
34
|
fireEvent.press(screen.getByText(childText));
|
|
35
35
|
const menu = screen
|
|
36
|
-
.getByTestId("
|
|
36
|
+
.getByTestId("LegacySelectInternalPicker")
|
|
37
37
|
.findByType(MockPicker);
|
|
38
38
|
expect(menu).toBeDefined();
|
|
39
39
|
fireEvent(menu, "onChange", "1");
|
|
@@ -45,7 +45,7 @@ describe("SelectInternalPicker", () => {
|
|
|
45
45
|
Object.defineProperty(Platform, "Version", { get: () => "14.1" });
|
|
46
46
|
const screen = setup();
|
|
47
47
|
const menu = screen
|
|
48
|
-
.getByTestId("
|
|
48
|
+
.getByTestId("LegacySelectInternalPicker")
|
|
49
49
|
.findByType(RCTPicker);
|
|
50
50
|
expect(menu).toBeDefined();
|
|
51
51
|
});
|
|
@@ -57,14 +57,14 @@ describe("SelectInternalPicker", () => {
|
|
|
57
57
|
Object.defineProperty(Platform, "Version", { get: () => version });
|
|
58
58
|
const screen = setup();
|
|
59
59
|
fireEvent.press(screen.getByText(childText));
|
|
60
|
-
expect(screen.getByTestId("
|
|
60
|
+
expect(screen.getByTestId("LegacySelectInternalPicker").findByType(MockPicker)).toBeDefined();
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
describe("Disabled", () => {
|
|
64
64
|
it("should not render the picker", () => {
|
|
65
65
|
const screen = setup({ disabled: true });
|
|
66
66
|
const menu = screen
|
|
67
|
-
.getByTestId("
|
|
67
|
+
.getByTestId("LegacySelectInternalPicker")
|
|
68
68
|
.findAllByType(RCTPicker);
|
|
69
69
|
expect(menu).toEqual([]);
|
|
70
70
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./LegacySelectInternalPicker";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Keyboard, Pressable } from "react-native";
|
|
3
|
-
import { useStyles } from "./
|
|
3
|
+
import { useStyles } from "./LegacySelectPressable.style";
|
|
4
4
|
import { useIsScreenReaderEnabled } from "../../../hooks";
|
|
5
5
|
/**
|
|
6
6
|
* Switches between Pressable with pressed styling and a fragment when a
|
|
7
7
|
* screen-reader is being used to avoid screen-readers from ignoring the press
|
|
8
8
|
* on the MenuView
|
|
9
9
|
*/
|
|
10
|
-
export function
|
|
10
|
+
export function LegacySelectPressable({ children, onPress, }) {
|
|
11
11
|
const isScreenReaderEnabled = useIsScreenReaderEnabled();
|
|
12
12
|
const styles = useStyles();
|
|
13
13
|
if (isScreenReaderEnabled)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./LegacySelectPressable";
|
package/dist/src/index.js
CHANGED
|
@@ -36,8 +36,8 @@ export * from "./InputPressable";
|
|
|
36
36
|
export * from "./InputSearch";
|
|
37
37
|
export * from "./InputText";
|
|
38
38
|
export * from "./InputTime";
|
|
39
|
+
export * from "./LegacySelect";
|
|
39
40
|
export * from "./ProgressBar";
|
|
40
|
-
export * from "./Select";
|
|
41
41
|
export * from "./StatusLabel";
|
|
42
42
|
export * from "./Switch";
|
|
43
43
|
export * from "./Text";
|