@pingux/astro 1.2.0-alpha.9 → 1.3.1
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/CHANGELOG.md +81 -0
- package/lib/cjs/components/AccordionGridGroup/AccordionGridGroup.js +35 -22
- package/lib/cjs/components/AccordionGridGroup/AccordionGridGroup.stories.js +148 -169
- package/lib/cjs/components/AccordionGridGroup/AccordionGridGroup.test.js +25 -30
- package/lib/cjs/components/AccordionGridItem/AccordionGridItem.js +29 -14
- package/lib/cjs/components/AccordionGridItem/AccordionGridItemBody.js +8 -5
- package/lib/cjs/components/AccordionGridItem/AccordionGridItemHeader.js +20 -17
- package/lib/cjs/components/AccordionGroup/AccordionGroup.js +2 -1
- package/lib/cjs/components/AccordionGroup/AccordionGroup.test.js +20 -1
- package/lib/cjs/components/ArrayField/ArrayField.js +213 -0
- package/lib/cjs/components/ArrayField/ArrayField.stories.js +223 -0
- package/lib/cjs/components/ArrayField/ArrayField.test.js +208 -0
- package/lib/cjs/components/ArrayField/ArrayFieldDeleteButton.js +61 -0
- package/lib/cjs/components/ArrayField/index.js +27 -0
- package/lib/cjs/components/Breadcrumbs/Breadcrumbs.stories.js +3 -3
- package/lib/cjs/components/Button/Button.js +14 -2
- package/lib/cjs/components/Button/Button.stories.js +33 -33
- package/lib/cjs/components/CheckboxField/CheckboxField.js +4 -1
- package/lib/cjs/components/CodeView/CodeView.js +3 -3
- package/lib/cjs/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.js +5 -3
- package/lib/cjs/components/Input/Input.js +3 -11
- package/lib/cjs/components/Input/Input.test.js +14 -2
- package/lib/cjs/components/Link/Link.js +2 -1
- package/lib/cjs/components/ListView/ListView.js +9 -13
- package/lib/cjs/components/ListView/ListView.stories.js +3 -0
- package/lib/cjs/components/ListViewItem/ListViewItem.js +15 -3
- package/lib/cjs/components/Loader/Loader.stories.js +3 -3
- package/lib/cjs/components/Modal/Modal.js +3 -0
- package/lib/cjs/components/Modal/Modal.stories.js +12 -67
- package/lib/cjs/components/MultivaluesField/MultivaluesField.js +10 -2
- package/lib/cjs/components/NavBar/NavBar.js +30 -4
- package/lib/cjs/components/NavBar/NavBar.stories.js +70 -463
- package/lib/cjs/components/NavBar/NavBar.test.js +51 -1
- package/lib/cjs/components/NavBarSection/NavBarItem.js +137 -0
- package/lib/cjs/components/NavBarSection/NavBarItemButton.js +96 -0
- package/lib/cjs/components/NavBarSection/NavBarItemHeader.js +1 -1
- package/lib/cjs/components/NavBarSection/NavBarItemLink.js +98 -0
- package/lib/cjs/components/NavBarSection/NavBarSection.js +10 -8
- package/lib/cjs/components/NavBarSection/index.js +28 -1
- package/lib/cjs/components/NumberField/NumberField.js +30 -10
- package/lib/cjs/components/NumberField/NumberField.test.js +7 -0
- package/lib/cjs/components/PageHeader/PageHeader.js +3 -0
- package/lib/cjs/components/PageHeader/PageHeader.stories.js +6 -1
- package/lib/cjs/components/RadioGroupField/RadioGroupField.js +9 -5
- package/lib/cjs/components/RockerButton/RockerButton.js +14 -22
- package/lib/cjs/components/RockerButtonGroup/RockerButtonGroup.js +5 -9
- package/lib/cjs/components/RockerButtonGroup/RockerButtonGroup.stories.js +4 -22
- package/lib/cjs/components/RockerButtonGroup/RockerButtonGroup.test.js +5 -14
- package/lib/cjs/components/SearchField/SearchField.stories.js +1 -15
- package/lib/cjs/components/SelectField/SelectField.stories.js +3 -55
- package/lib/cjs/components/SelectFieldBase/SelectFieldBase.js +8 -1
- package/lib/cjs/components/Tabs/Tabs.stories.js +1 -15
- package/lib/cjs/components/TextAreaField/TextAreaField.js +54 -9
- package/lib/cjs/components/TextAreaField/TextAreaField.stories.js +31 -52
- package/lib/cjs/components/TextAreaField/TextAreaField.test.js +12 -0
- package/lib/cjs/context/AccordionGridContext/index.js +20 -0
- package/lib/cjs/context/NavBarContext/index.js +20 -0
- package/lib/cjs/hooks/index.js +9 -0
- package/lib/cjs/hooks/useAriaLabelWarning/useAriaLabelWarning.js +2 -1
- package/lib/cjs/hooks/useField/useField.js +7 -2
- package/lib/cjs/{components/AccordionGridGroup/AccordionGridContext.js → hooks/useNavBarPress/index.js} +7 -6
- package/lib/cjs/hooks/useNavBarPress/useNavBarPress.js +38 -0
- package/lib/cjs/hooks/useNavBarPress/useNavBarPress.test.js +42 -0
- package/lib/cjs/hooks/useRockerButton/useRockerButton.js +4 -6
- package/lib/cjs/index.js +80 -58
- package/lib/cjs/recipes/ConditionalFilter.stories.js +7 -3
- package/lib/cjs/recipes/RadioButtonsWithLinks.stories.js +1 -1
- package/lib/cjs/styles/forms/checkbox.js +0 -1
- package/lib/cjs/styles/forms/input.js +1 -1
- package/lib/cjs/styles/forms/label.js +3 -0
- package/lib/cjs/styles/forms/radio.js +1 -1
- package/lib/cjs/styles/forms/switch.js +3 -1
- package/lib/cjs/styles/variants/accordion.js +39 -7
- package/lib/cjs/styles/variants/boxes.js +14 -25
- package/lib/cjs/styles/variants/buttons.js +27 -1
- package/lib/cjs/styles/variants/codeView.js +91 -0
- package/lib/cjs/styles/variants/navBar.js +68 -0
- package/lib/cjs/styles/variants/separator.js +2 -1
- package/lib/cjs/styles/variants/text.js +3 -1
- package/lib/cjs/styles/variants/variants.js +3 -0
- package/lib/components/AccordionGridGroup/AccordionGridGroup.js +35 -22
- package/lib/components/AccordionGridGroup/AccordionGridGroup.stories.js +143 -166
- package/lib/components/AccordionGridGroup/AccordionGridGroup.test.js +24 -25
- package/lib/components/AccordionGridItem/AccordionGridItem.js +29 -15
- package/lib/components/AccordionGridItem/AccordionGridItemBody.js +8 -6
- package/lib/components/AccordionGridItem/AccordionGridItemHeader.js +22 -18
- package/lib/components/AccordionGroup/AccordionGroup.js +2 -1
- package/lib/components/AccordionGroup/AccordionGroup.test.js +16 -2
- package/lib/components/ArrayField/ArrayField.js +179 -0
- package/lib/components/ArrayField/ArrayField.stories.js +196 -0
- package/lib/components/ArrayField/ArrayField.test.js +185 -0
- package/lib/components/ArrayField/ArrayFieldDeleteButton.js +43 -0
- package/lib/components/ArrayField/index.js +2 -0
- package/lib/components/Breadcrumbs/Breadcrumbs.stories.js +3 -3
- package/lib/components/Button/Button.js +15 -3
- package/lib/components/Button/Button.stories.js +17 -15
- package/lib/components/CheckboxField/CheckboxField.js +4 -1
- package/lib/components/CodeView/CodeView.js +2 -2
- package/lib/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.js +5 -3
- package/lib/components/Input/Input.js +2 -10
- package/lib/components/Input/Input.test.js +11 -2
- package/lib/components/Link/Link.js +2 -1
- package/lib/components/ListView/ListView.js +9 -12
- package/lib/components/ListView/ListView.stories.js +3 -0
- package/lib/components/ListViewItem/ListViewItem.js +14 -3
- package/lib/components/Loader/Loader.stories.js +1 -1
- package/lib/components/Modal/Modal.js +4 -1
- package/lib/components/Modal/Modal.stories.js +11 -60
- package/lib/components/MultivaluesField/MultivaluesField.js +9 -2
- package/lib/components/NavBar/NavBar.js +25 -4
- package/lib/components/NavBar/NavBar.stories.js +71 -462
- package/lib/components/NavBar/NavBar.test.js +39 -2
- package/lib/components/NavBarSection/NavBarItem.js +111 -0
- package/lib/components/NavBarSection/NavBarItemButton.js +69 -0
- package/lib/components/NavBarSection/NavBarItemHeader.js +1 -1
- package/lib/components/NavBarSection/NavBarItemLink.js +71 -0
- package/lib/components/NavBarSection/NavBarSection.js +9 -8
- package/lib/components/NavBarSection/index.js +4 -1
- package/lib/components/NumberField/NumberField.js +32 -12
- package/lib/components/NumberField/NumberField.test.js +5 -0
- package/lib/components/PageHeader/PageHeader.js +2 -0
- package/lib/components/PageHeader/PageHeader.stories.js +5 -1
- package/lib/components/RadioGroupField/RadioGroupField.js +9 -5
- package/lib/components/RockerButton/RockerButton.js +14 -21
- package/lib/components/RockerButtonGroup/RockerButtonGroup.js +5 -9
- package/lib/components/RockerButtonGroup/RockerButtonGroup.stories.js +2 -17
- package/lib/components/RockerButtonGroup/RockerButtonGroup.test.js +5 -11
- package/lib/components/SearchField/SearchField.stories.js +0 -11
- package/lib/components/SelectField/SelectField.stories.js +2 -50
- package/lib/components/SelectFieldBase/SelectFieldBase.js +8 -1
- package/lib/components/Tabs/Tabs.stories.js +0 -11
- package/lib/components/TextAreaField/TextAreaField.js +54 -10
- package/lib/components/TextAreaField/TextAreaField.stories.js +26 -42
- package/lib/components/TextAreaField/TextAreaField.test.js +13 -0
- package/lib/context/AccordionGridContext/index.js +5 -0
- package/lib/context/NavBarContext/index.js +5 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/useAriaLabelWarning/useAriaLabelWarning.js +2 -1
- package/lib/hooks/useField/useField.js +7 -2
- package/lib/hooks/useNavBarPress/index.js +1 -0
- package/lib/hooks/useNavBarPress/useNavBarPress.js +27 -0
- package/lib/hooks/useNavBarPress/useNavBarPress.test.js +36 -0
- package/lib/hooks/useRockerButton/useRockerButton.js +4 -6
- package/lib/index.js +2 -0
- package/lib/recipes/ConditionalFilter.stories.js +7 -3
- package/lib/recipes/RadioButtonsWithLinks.stories.js +1 -1
- package/lib/styles/forms/checkbox.js +0 -1
- package/lib/styles/forms/input.js +1 -1
- package/lib/styles/forms/label.js +3 -0
- package/lib/styles/forms/radio.js +1 -1
- package/lib/styles/forms/switch.js +3 -1
- package/lib/styles/variants/accordion.js +26 -5
- package/lib/styles/variants/boxes.js +14 -25
- package/lib/styles/variants/buttons.js +27 -1
- package/lib/styles/variants/codeView.js +91 -0
- package/lib/styles/variants/navBar.js +46 -0
- package/lib/styles/variants/separator.js +2 -1
- package/lib/styles/variants/text.js +3 -1
- package/lib/styles/variants/variants.js +2 -0
- package/package.json +4 -2
- package/lib/cjs/layouts/ListLayout.stories.js +0 -895
- package/lib/cjs/layouts/SchemaFormLayout.stories.js +0 -139
- package/lib/cjs/recipes/ArrayField.stories.js +0 -169
- package/lib/components/AccordionGridGroup/AccordionGridContext.js +0 -2
- package/lib/layouts/ListLayout.stories.js +0 -866
- package/lib/layouts/SchemaFormLayout.stories.js +0 -107
- package/lib/recipes/ArrayField.stories.js +0 -134
@@ -7,7 +7,7 @@ import axeTest from '../../utils/testUtils/testAxe';
|
|
7
7
|
import { act, fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
|
8
8
|
import Text from '../Text';
|
9
9
|
import AccordionGroup from '../AccordionGroup';
|
10
|
-
import { OverlayPanel } from '../../index';
|
10
|
+
import { OverlayPanel, TextField } from '../../index';
|
11
11
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
12
12
|
var testId = 'test-accordion';
|
13
13
|
var defaultProps = {
|
@@ -31,7 +31,11 @@ var getComponent = function getComponent() {
|
|
31
31
|
textValue: "Duplicate",
|
32
32
|
"data-id": "third",
|
33
33
|
label: "Accordion item"
|
34
|
-
}, ___EmotionJSX(
|
34
|
+
}, ___EmotionJSX(TextField, {
|
35
|
+
role: "form",
|
36
|
+
label: "Example Label",
|
37
|
+
"data-testid": "testField"
|
38
|
+
}))));
|
35
39
|
};
|
36
40
|
|
37
41
|
var getComponentInOverlayPanel = function getComponentInOverlayPanel() {
|
@@ -214,6 +218,16 @@ test('expanded keys expands an accordion item', function () {
|
|
214
218
|
var selectedItem = buttons[0];
|
215
219
|
expect(selectedItem).toHaveAttribute('aria-expanded', 'true');
|
216
220
|
});
|
221
|
+
test('able to click a textfield that is the rendered child of an accordion', function () {
|
222
|
+
getComponent({
|
223
|
+
expandedKeys: ['third']
|
224
|
+
});
|
225
|
+
var field = screen.getByTestId('testField');
|
226
|
+
var input = screen.getByRole('form');
|
227
|
+
userEvent.click(input);
|
228
|
+
userEvent.type(input, 'banana');
|
229
|
+
expect(field).toHaveClass('has-focus-within');
|
230
|
+
});
|
217
231
|
test('Item accepts a data-id and the data-id can be found in the DOM', function () {
|
218
232
|
getComponent();
|
219
233
|
var buttons = screen.getAllByRole('button');
|
@@ -0,0 +1,179 @@
|
|
1
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
2
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
3
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
4
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
5
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
6
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
7
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
8
|
+
import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
|
9
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
10
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
11
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
12
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
13
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
14
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
15
|
+
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
17
|
+
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
19
|
+
|
20
|
+
import React, { useCallback, useState } from 'react';
|
21
|
+
import PropTypes from 'prop-types';
|
22
|
+
import { v4 as uuid } from 'uuid';
|
23
|
+
import Box from '../Box';
|
24
|
+
import Button from '../Button';
|
25
|
+
import FieldHelperText from '../FieldHelperText';
|
26
|
+
import Text from '../Text';
|
27
|
+
import statuses from '../../utils/devUtils/constants/statuses';
|
28
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
29
|
+
|
30
|
+
var ArrayField = function ArrayField(_ref) {
|
31
|
+
var _context2;
|
32
|
+
|
33
|
+
var addButtonLabel = _ref.addButtonLabel,
|
34
|
+
defaultValue = _ref.defaultValue,
|
35
|
+
value = _ref.value,
|
36
|
+
label = _ref.label,
|
37
|
+
helperText = _ref.helperText,
|
38
|
+
status = _ref.status,
|
39
|
+
onAdd = _ref.onAdd,
|
40
|
+
onChange = _ref.onChange,
|
41
|
+
onDelete = _ref.onDelete,
|
42
|
+
renderField = _ref.renderField,
|
43
|
+
others = _objectWithoutProperties(_ref, ["addButtonLabel", "defaultValue", "value", "label", "helperText", "status", "onAdd", "onChange", "onDelete", "renderField"]);
|
44
|
+
|
45
|
+
var isControlled = value !== undefined;
|
46
|
+
var createEmptyField = useCallback(function () {
|
47
|
+
return {
|
48
|
+
id: uuid(),
|
49
|
+
value: ''
|
50
|
+
};
|
51
|
+
}, []);
|
52
|
+
|
53
|
+
var _useState = useState(defaultValue || [createEmptyField()]),
|
54
|
+
_useState2 = _slicedToArray(_useState, 2),
|
55
|
+
fieldValues = _useState2[0],
|
56
|
+
setFieldValues = _useState2[1];
|
57
|
+
|
58
|
+
var mapArrayFieldWithNewValue = useCallback(function (arrValues, newValue, fieldId) {
|
59
|
+
return _mapInstanceProperty(arrValues).call(arrValues, function (fieldValue) {
|
60
|
+
if (fieldValue.id === fieldId) {
|
61
|
+
return _objectSpread(_objectSpread({}, fieldValue), {}, {
|
62
|
+
value: newValue
|
63
|
+
});
|
64
|
+
}
|
65
|
+
|
66
|
+
return fieldValue;
|
67
|
+
});
|
68
|
+
}, []);
|
69
|
+
var onFieldValueChange = useCallback(function (event, fieldId) {
|
70
|
+
var tempValue = event; // Checks if value receieved is a key or event
|
71
|
+
|
72
|
+
if (typeof event !== 'string') {
|
73
|
+
tempValue = event.target.value;
|
74
|
+
}
|
75
|
+
|
76
|
+
if (isControlled) {
|
77
|
+
onChange(mapArrayFieldWithNewValue(value, tempValue, fieldId));
|
78
|
+
} else {
|
79
|
+
setFieldValues(function (oldValues) {
|
80
|
+
return mapArrayFieldWithNewValue(oldValues, tempValue, fieldId);
|
81
|
+
});
|
82
|
+
}
|
83
|
+
}, [isControlled, mapArrayFieldWithNewValue, onChange, value]);
|
84
|
+
var onFieldDelete = useCallback(function (fieldId) {
|
85
|
+
if (isControlled) {
|
86
|
+
onDelete(fieldId);
|
87
|
+
} else {
|
88
|
+
setFieldValues(function (oldValues) {
|
89
|
+
return _filterInstanceProperty(oldValues).call(oldValues, function (_ref2) {
|
90
|
+
var id = _ref2.id;
|
91
|
+
return id !== fieldId;
|
92
|
+
});
|
93
|
+
});
|
94
|
+
}
|
95
|
+
}, [isControlled, onDelete]);
|
96
|
+
var onFieldAdd = useCallback(function () {
|
97
|
+
if (onAdd) {
|
98
|
+
return onAdd();
|
99
|
+
}
|
100
|
+
|
101
|
+
return setFieldValues(function (oldValues) {
|
102
|
+
var _context;
|
103
|
+
|
104
|
+
return _concatInstanceProperty(_context = []).call(_context, oldValues, [createEmptyField()]);
|
105
|
+
});
|
106
|
+
}, [createEmptyField, onAdd]);
|
107
|
+
return ___EmotionJSX(Box, others, ___EmotionJSX(Text, {
|
108
|
+
variant: "label"
|
109
|
+
}, label), ___EmotionJSX(Box, {
|
110
|
+
as: "ul",
|
111
|
+
pl: "0"
|
112
|
+
}, _mapInstanceProperty(_context2 = value || fieldValues).call(_context2, function (_ref3) {
|
113
|
+
var id = _ref3.id,
|
114
|
+
onComponentRender = _ref3.onComponentRender,
|
115
|
+
fieldValue = _ref3.fieldValue,
|
116
|
+
otherFieldProps = _objectWithoutProperties(_ref3, ["id", "onComponentRender", "fieldValue"]);
|
117
|
+
|
118
|
+
var isDisabled = (value || fieldValues).length === 1;
|
119
|
+
return ___EmotionJSX(Box, {
|
120
|
+
as: "li",
|
121
|
+
mb: "xs",
|
122
|
+
key: id
|
123
|
+
}, onComponentRender ? onComponentRender(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) : renderField(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps));
|
124
|
+
})), helperText && ___EmotionJSX(FieldHelperText, {
|
125
|
+
status: status
|
126
|
+
}, helperText), ___EmotionJSX(Button, {
|
127
|
+
"aria-label": "Add field",
|
128
|
+
variant: "text",
|
129
|
+
onPress: onFieldAdd,
|
130
|
+
sx: {
|
131
|
+
width: 'fit-content'
|
132
|
+
}
|
133
|
+
}, ___EmotionJSX(Text, {
|
134
|
+
variant: "label",
|
135
|
+
color: "active"
|
136
|
+
}, addButtonLabel)));
|
137
|
+
};
|
138
|
+
|
139
|
+
ArrayField.propTypes = {
|
140
|
+
/** Label for add button */
|
141
|
+
addButtonLabel: PropTypes.string,
|
142
|
+
|
143
|
+
/** The default value for the array input field (uncontrolled). */
|
144
|
+
defaultValue: PropTypes.arrayOf(PropTypes.shape({
|
145
|
+
id: PropTypes.string,
|
146
|
+
value: PropTypes.string
|
147
|
+
})),
|
148
|
+
|
149
|
+
/** The default value of the array input field (controlled). */
|
150
|
+
value: PropTypes.arrayOf(PropTypes.shape({
|
151
|
+
id: PropTypes.string,
|
152
|
+
value: PropTypes.string
|
153
|
+
})),
|
154
|
+
|
155
|
+
/** The rendered label for the field. */
|
156
|
+
label: PropTypes.node,
|
157
|
+
|
158
|
+
/** Text to display before add button. Useful for errors or other info. */
|
159
|
+
helperText: PropTypes.node,
|
160
|
+
|
161
|
+
/** Callback for changing array field data */
|
162
|
+
onChange: PropTypes.func,
|
163
|
+
|
164
|
+
/** Callback for adding new empty field */
|
165
|
+
onAdd: PropTypes.func,
|
166
|
+
|
167
|
+
/** Callback for deleting a field */
|
168
|
+
onDelete: PropTypes.func,
|
169
|
+
|
170
|
+
/** Render prop to display an input field */
|
171
|
+
renderField: PropTypes.func,
|
172
|
+
|
173
|
+
/** Determines the helper text styling. */
|
174
|
+
status: PropTypes.oneOf(_Object$values(statuses))
|
175
|
+
};
|
176
|
+
ArrayField.defaultProps = {
|
177
|
+
addButtonLabel: '+ Add'
|
178
|
+
};
|
179
|
+
export default ArrayField;
|
@@ -0,0 +1,196 @@
|
|
1
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
2
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
3
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
4
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
5
|
+
import React from 'react';
|
6
|
+
import { OverlayProvider } from '@react-aria/overlays';
|
7
|
+
import { v4 as uuid } from 'uuid';
|
8
|
+
import { ArrayField, ArrayFieldDeleteButton, Item, SelectField, TextField } from '../../index';
|
9
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
10
|
+
export default {
|
11
|
+
title: 'Form/ArrayField',
|
12
|
+
parameters: {
|
13
|
+
actions: {
|
14
|
+
argTypesRegex: '^on.*'
|
15
|
+
},
|
16
|
+
docs: {
|
17
|
+
source: {
|
18
|
+
type: 'code'
|
19
|
+
}
|
20
|
+
}
|
21
|
+
},
|
22
|
+
argTypes: {
|
23
|
+
label: {
|
24
|
+
defaultValue: 'Array field label',
|
25
|
+
control: {
|
26
|
+
type: 'text'
|
27
|
+
}
|
28
|
+
},
|
29
|
+
helperText: {
|
30
|
+
defaultValue: 'Helper text info...',
|
31
|
+
control: {
|
32
|
+
type: 'text'
|
33
|
+
}
|
34
|
+
},
|
35
|
+
addButtonLabel: {
|
36
|
+
defaultValue: '+ Add field',
|
37
|
+
control: {
|
38
|
+
type: 'text'
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
};
|
43
|
+
var defaultData = [{
|
44
|
+
id: uuid(),
|
45
|
+
value: 'Hello'
|
46
|
+
}, {
|
47
|
+
id: uuid(),
|
48
|
+
value: 'World'
|
49
|
+
}];
|
50
|
+
export var Uncontrolled = function Uncontrolled(_ref) {
|
51
|
+
var args = _extends({}, _ref);
|
52
|
+
|
53
|
+
return ___EmotionJSX(ArrayField, _extends({
|
54
|
+
defaultValue: defaultData,
|
55
|
+
renderField: function renderField(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) {
|
56
|
+
return ___EmotionJSX(TextField, _extends({
|
57
|
+
"aria-label": "Text field",
|
58
|
+
value: fieldValue,
|
59
|
+
onChange: function onChange(e) {
|
60
|
+
return onFieldValueChange(e, id);
|
61
|
+
},
|
62
|
+
mr: "xs",
|
63
|
+
slots: {
|
64
|
+
inContainer: ___EmotionJSX(ArrayFieldDeleteButton, {
|
65
|
+
isDisabled: isDisabled,
|
66
|
+
onDelete: function onDelete() {
|
67
|
+
return onFieldDelete(id);
|
68
|
+
}
|
69
|
+
})
|
70
|
+
}
|
71
|
+
}, otherFieldProps));
|
72
|
+
},
|
73
|
+
sx: {
|
74
|
+
width: '400px'
|
75
|
+
}
|
76
|
+
}, args));
|
77
|
+
};
|
78
|
+
export var Controlled = function Controlled() {
|
79
|
+
var defaultDataSelectField = [{
|
80
|
+
id: uuid(),
|
81
|
+
fieldValue: 'red',
|
82
|
+
onComponentRender: function onComponentRender(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) {
|
83
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(SelectField, _extends({
|
84
|
+
defaultSelectedKey: fieldValue,
|
85
|
+
onSelectionChange: function onSelectionChange(e) {
|
86
|
+
return onFieldValueChange(e, id);
|
87
|
+
},
|
88
|
+
width: "100%",
|
89
|
+
slots: {
|
90
|
+
inContainer: ___EmotionJSX(ArrayFieldDeleteButton, {
|
91
|
+
isDisabled: isDisabled,
|
92
|
+
onDelete: function onDelete() {
|
93
|
+
return onFieldDelete(id);
|
94
|
+
}
|
95
|
+
})
|
96
|
+
}
|
97
|
+
}, otherFieldProps), ___EmotionJSX(Item, {
|
98
|
+
key: "red"
|
99
|
+
}, "Red"), ___EmotionJSX(Item, {
|
100
|
+
key: "blue"
|
101
|
+
}, "Blue"), ___EmotionJSX(Item, {
|
102
|
+
key: "yellow"
|
103
|
+
}, "Yellow")));
|
104
|
+
}
|
105
|
+
}, {
|
106
|
+
id: uuid(),
|
107
|
+
fieldValue: 'black',
|
108
|
+
onComponentRender: function onComponentRender(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) {
|
109
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(SelectField, _extends({
|
110
|
+
defaultSelectedKey: fieldValue,
|
111
|
+
onSelectionChange: function onSelectionChange(key) {
|
112
|
+
return onFieldValueChange(key, id);
|
113
|
+
},
|
114
|
+
width: "100%",
|
115
|
+
slots: {
|
116
|
+
inContainer: ___EmotionJSX(ArrayFieldDeleteButton, {
|
117
|
+
isDisabled: isDisabled,
|
118
|
+
onDelete: function onDelete() {
|
119
|
+
return onFieldDelete(id);
|
120
|
+
}
|
121
|
+
})
|
122
|
+
}
|
123
|
+
}, otherFieldProps), ___EmotionJSX(Item, {
|
124
|
+
key: "orange"
|
125
|
+
}, "Orange"), ___EmotionJSX(Item, {
|
126
|
+
key: "purple"
|
127
|
+
}, "Purple"), ___EmotionJSX(Item, {
|
128
|
+
key: "black"
|
129
|
+
}, "Black")));
|
130
|
+
}
|
131
|
+
}];
|
132
|
+
var defaultEmptyField = {
|
133
|
+
id: uuid(),
|
134
|
+
fieldValue: 'blue',
|
135
|
+
onComponentRender: function onComponentRender(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) {
|
136
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(SelectField, _extends({
|
137
|
+
defaultSelectedKey: fieldValue,
|
138
|
+
onSelectionChange: function onSelectionChange(e) {
|
139
|
+
return onFieldValueChange(e, id);
|
140
|
+
},
|
141
|
+
width: "100%",
|
142
|
+
slots: {
|
143
|
+
inContainer: ___EmotionJSX(ArrayFieldDeleteButton, {
|
144
|
+
isDisabled: isDisabled,
|
145
|
+
onDelete: function onDelete() {
|
146
|
+
return onFieldDelete(id);
|
147
|
+
}
|
148
|
+
})
|
149
|
+
}
|
150
|
+
}, otherFieldProps), ___EmotionJSX(Item, {
|
151
|
+
key: "blue"
|
152
|
+
}, "Blue"), ___EmotionJSX(Item, {
|
153
|
+
key: "teal"
|
154
|
+
}, "Teal"), ___EmotionJSX(Item, {
|
155
|
+
key: "turquoise"
|
156
|
+
}, "Turquoise")));
|
157
|
+
}
|
158
|
+
};
|
159
|
+
|
160
|
+
var _React$useState = React.useState(defaultDataSelectField),
|
161
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
162
|
+
fieldValues = _React$useState2[0],
|
163
|
+
setFieldValues = _React$useState2[1];
|
164
|
+
|
165
|
+
function handleOnChange(values) {
|
166
|
+
setFieldValues(values);
|
167
|
+
}
|
168
|
+
|
169
|
+
function handleOnAdd() {
|
170
|
+
setFieldValues(function (oldValues) {
|
171
|
+
var _context;
|
172
|
+
|
173
|
+
return _concatInstanceProperty(_context = []).call(_context, oldValues, [defaultEmptyField]);
|
174
|
+
});
|
175
|
+
}
|
176
|
+
|
177
|
+
function handleOnDelete(fieldId) {
|
178
|
+
setFieldValues(function (oldValues) {
|
179
|
+
return _filterInstanceProperty(oldValues).call(oldValues, function (_ref2) {
|
180
|
+
var id = _ref2.id;
|
181
|
+
return id !== fieldId;
|
182
|
+
});
|
183
|
+
});
|
184
|
+
}
|
185
|
+
|
186
|
+
return ___EmotionJSX(ArrayField, {
|
187
|
+
value: fieldValues,
|
188
|
+
helperText: "Here is some helpful text...",
|
189
|
+
onAdd: handleOnAdd,
|
190
|
+
onChange: handleOnChange,
|
191
|
+
onDelete: handleOnDelete,
|
192
|
+
sx: {
|
193
|
+
width: '400px'
|
194
|
+
}
|
195
|
+
});
|
196
|
+
};
|
@@ -0,0 +1,185 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import React from 'react';
|
3
|
+
import ArrayField from './ArrayField';
|
4
|
+
import ArrayFieldDeleteButton from './ArrayFieldDeleteButton';
|
5
|
+
import TextField from '../TextField';
|
6
|
+
import { fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
|
7
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
8
|
+
jest.mock('uuid', function () {
|
9
|
+
return {
|
10
|
+
v4: function v4() {
|
11
|
+
return 'testid';
|
12
|
+
}
|
13
|
+
};
|
14
|
+
});
|
15
|
+
var defaultData = [{
|
16
|
+
id: '1',
|
17
|
+
value: 'Hello'
|
18
|
+
}, {
|
19
|
+
id: '2',
|
20
|
+
value: 'World'
|
21
|
+
}];
|
22
|
+
var defaultProps = {
|
23
|
+
defaultValue: defaultData
|
24
|
+
};
|
25
|
+
|
26
|
+
var getComponent = function getComponent() {
|
27
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
28
|
+
return render(___EmotionJSX(ArrayField, _extends({}, defaultProps, props)));
|
29
|
+
};
|
30
|
+
|
31
|
+
var renderField = function renderField(id, value, onFieldValueChange, onFieldDelete, otherFieldProps) {
|
32
|
+
return ___EmotionJSX(TextField, _extends({
|
33
|
+
label: "Text field",
|
34
|
+
value: value,
|
35
|
+
onChange: function onChange(e) {
|
36
|
+
return onFieldValueChange(e, id);
|
37
|
+
},
|
38
|
+
mr: "xs",
|
39
|
+
slots: {
|
40
|
+
inContainer: ___EmotionJSX(ArrayFieldDeleteButton, {
|
41
|
+
isDisabled: false,
|
42
|
+
onDelete: function onDelete() {
|
43
|
+
return onFieldDelete(id);
|
44
|
+
}
|
45
|
+
})
|
46
|
+
}
|
47
|
+
}, otherFieldProps));
|
48
|
+
};
|
49
|
+
|
50
|
+
test('displays multiple text fields', function () {
|
51
|
+
var onChange = jest.fn();
|
52
|
+
getComponent({
|
53
|
+
onChange: onChange,
|
54
|
+
renderField: renderField
|
55
|
+
});
|
56
|
+
expect(screen.getAllByLabelText('Text field')).toHaveLength(2);
|
57
|
+
});
|
58
|
+
test('adds one text field and new empty field is added', function () {
|
59
|
+
getComponent({
|
60
|
+
renderField: renderField
|
61
|
+
});
|
62
|
+
fireEvent.click(screen.getByText('+ Add'));
|
63
|
+
expect(screen.getAllByLabelText('Text field')).toHaveLength(3);
|
64
|
+
});
|
65
|
+
test('onAdd callback is fired when adding field', function () {
|
66
|
+
var onAdd = jest.fn();
|
67
|
+
getComponent({
|
68
|
+
onAdd: onAdd,
|
69
|
+
renderField: renderField
|
70
|
+
});
|
71
|
+
fireEvent.click(screen.getByText('+ Add'));
|
72
|
+
expect(onAdd).toHaveBeenCalled();
|
73
|
+
});
|
74
|
+
test('deletes one text field and only one field is left', function () {
|
75
|
+
getComponent({
|
76
|
+
renderField: renderField
|
77
|
+
});
|
78
|
+
fireEvent.click(screen.getAllByRole('button')[0]);
|
79
|
+
expect(screen.getByLabelText('Text field')).toBeInTheDocument();
|
80
|
+
});
|
81
|
+
test('onDelete callback is fired when deleting field', function () {
|
82
|
+
var onDelete = jest.fn();
|
83
|
+
var value = defaultData;
|
84
|
+
var defaultValue = null;
|
85
|
+
getComponent({
|
86
|
+
value: value,
|
87
|
+
defaultValue: defaultValue,
|
88
|
+
onDelete: onDelete,
|
89
|
+
renderField: renderField
|
90
|
+
});
|
91
|
+
fireEvent.click(screen.getAllByRole('button')[0]);
|
92
|
+
expect(onDelete).toHaveBeenCalled();
|
93
|
+
});
|
94
|
+
test('Values are changed in text field', function () {
|
95
|
+
getComponent({
|
96
|
+
renderField: renderField
|
97
|
+
});
|
98
|
+
fireEvent.change(screen.getAllByLabelText('Text field')[0], {
|
99
|
+
target: {
|
100
|
+
value: '123'
|
101
|
+
}
|
102
|
+
});
|
103
|
+
expect(screen.getByDisplayValue('123')).toBeInTheDocument();
|
104
|
+
});
|
105
|
+
test('onChange gets called when field values are changed', function () {
|
106
|
+
var onChange = jest.fn();
|
107
|
+
var value = defaultData;
|
108
|
+
var defaultValue = null;
|
109
|
+
getComponent({
|
110
|
+
value: value,
|
111
|
+
onChange: onChange,
|
112
|
+
renderField: renderField,
|
113
|
+
defaultValue: defaultValue
|
114
|
+
});
|
115
|
+
fireEvent.change(screen.getAllByLabelText('Text field')[0], {
|
116
|
+
target: {
|
117
|
+
value: '123'
|
118
|
+
}
|
119
|
+
});
|
120
|
+
expect(onChange).toHaveBeenNthCalledWith(1, [{
|
121
|
+
id: '1',
|
122
|
+
value: '123'
|
123
|
+
}, {
|
124
|
+
id: '2',
|
125
|
+
value: 'World'
|
126
|
+
}]);
|
127
|
+
});
|
128
|
+
test('onComponentRender displays fields correctly', function () {
|
129
|
+
var onChange = jest.fn();
|
130
|
+
var componentRenderData = [{
|
131
|
+
id: '1',
|
132
|
+
value: 'Hello',
|
133
|
+
onComponentRender: function onComponentRender(id, value, onFieldValueChange, onFieldDelete, otherFieldProps) {
|
134
|
+
return ___EmotionJSX(TextField, _extends({
|
135
|
+
label: "Text field",
|
136
|
+
value: value,
|
137
|
+
onChange: function onChange(e) {
|
138
|
+
return onFieldValueChange(e, id);
|
139
|
+
},
|
140
|
+
mr: "xs",
|
141
|
+
slots: {
|
142
|
+
inContainer: ___EmotionJSX(ArrayFieldDeleteButton, {
|
143
|
+
isDisabled: false,
|
144
|
+
onDelete: function onDelete() {
|
145
|
+
return onFieldDelete(id);
|
146
|
+
}
|
147
|
+
})
|
148
|
+
}
|
149
|
+
}, otherFieldProps));
|
150
|
+
}
|
151
|
+
}, {
|
152
|
+
id: '2',
|
153
|
+
value: 'World',
|
154
|
+
onComponentRender: function onComponentRender(id, value, onFieldValueChange, onFieldDelete, otherFieldProps) {
|
155
|
+
return ___EmotionJSX(TextField, _extends({
|
156
|
+
label: "Text field 2",
|
157
|
+
value: value,
|
158
|
+
onChange: function onChange(e) {
|
159
|
+
return onFieldValueChange(e, id);
|
160
|
+
},
|
161
|
+
mr: "xs",
|
162
|
+
slots: {
|
163
|
+
inContainer: ___EmotionJSX(ArrayFieldDeleteButton, {
|
164
|
+
isDisabled: false,
|
165
|
+
onDelete: function onDelete() {
|
166
|
+
return onFieldDelete(id);
|
167
|
+
}
|
168
|
+
})
|
169
|
+
}
|
170
|
+
}, otherFieldProps));
|
171
|
+
}
|
172
|
+
}];
|
173
|
+
render(___EmotionJSX(ArrayField, {
|
174
|
+
defaultValue: componentRenderData,
|
175
|
+
onChange: onChange
|
176
|
+
}));
|
177
|
+
expect(screen.getByLabelText('Text field')).toBeInTheDocument();
|
178
|
+
expect(screen.getByLabelText('Text field 2')).toBeInTheDocument();
|
179
|
+
});
|
180
|
+
test('creates empty field when no data passed', function () {
|
181
|
+
render(___EmotionJSX(ArrayField, {
|
182
|
+
renderField: renderField
|
183
|
+
}));
|
184
|
+
expect(screen.getByLabelText('Text field')).toBeInTheDocument();
|
185
|
+
});
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import TrashIcon from 'mdi-react/TrashIcon';
|
4
|
+
import Icon from '../Icon';
|
5
|
+
import IconButton from '../IconButton';
|
6
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
7
|
+
|
8
|
+
var ArrayFieldDeleteButton = function ArrayFieldDeleteButton(_ref) {
|
9
|
+
var label = _ref.label,
|
10
|
+
isDisabled = _ref.isDisabled,
|
11
|
+
id = _ref.id,
|
12
|
+
onDelete = _ref.onDelete;
|
13
|
+
return ___EmotionJSX(IconButton, {
|
14
|
+
onPress: function onPress() {
|
15
|
+
return onDelete(id);
|
16
|
+
},
|
17
|
+
isDisabled: isDisabled,
|
18
|
+
sx: {
|
19
|
+
position: 'absolute',
|
20
|
+
right: -35,
|
21
|
+
width: 32,
|
22
|
+
height: 32,
|
23
|
+
top: 5,
|
24
|
+
cursor: 'pointer'
|
25
|
+
},
|
26
|
+
title: label
|
27
|
+
}, ___EmotionJSX(Icon, {
|
28
|
+
icon: TrashIcon,
|
29
|
+
size: 20,
|
30
|
+
color: "neutral.40"
|
31
|
+
}));
|
32
|
+
};
|
33
|
+
|
34
|
+
ArrayFieldDeleteButton.propTypes = {
|
35
|
+
label: PropTypes.string,
|
36
|
+
id: PropTypes.number,
|
37
|
+
isDisabled: PropTypes.bool,
|
38
|
+
onDelete: PropTypes.func
|
39
|
+
};
|
40
|
+
ArrayFieldDeleteButton.defaultProps = {
|
41
|
+
label: 'Delete field'
|
42
|
+
};
|
43
|
+
export default ArrayFieldDeleteButton;
|
@@ -41,15 +41,15 @@ export var Default = function Default(args) {
|
|
41
41
|
onAction: onAction
|
42
42
|
}, args), ___EmotionJSX(Item, {
|
43
43
|
key: "home",
|
44
|
-
variant: "
|
44
|
+
variant: "link",
|
45
45
|
"data-id": "home"
|
46
46
|
}, "Home"), ___EmotionJSX(Item, {
|
47
47
|
key: "trendy",
|
48
|
-
variant: "
|
48
|
+
variant: "link",
|
49
49
|
"data-id": "trendy"
|
50
50
|
}, "Trendy"), ___EmotionJSX(Item, {
|
51
51
|
key: "march 2020 assets",
|
52
|
-
variant: "
|
52
|
+
variant: "link",
|
53
53
|
"data-id": "march"
|
54
54
|
}, "March 2020 Assets"));
|
55
55
|
};
|