@pingux/astro 2.92.0 → 2.93.0-alpha.0
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/lib/cjs/components/ArrayField/ArrayField.js +10 -3
- package/lib/cjs/components/ArrayField/ArrayField.stories.d.ts +3 -0
- package/lib/cjs/components/ArrayField/ArrayField.stories.js +65 -2
- package/lib/cjs/components/ArrayField/ArrayField.test.js +26 -0
- package/lib/cjs/types/arrayField.d.ts +6 -1
- package/lib/components/ArrayField/ArrayField.js +10 -3
- package/lib/components/ArrayField/ArrayField.stories.js +63 -1
- package/lib/components/ArrayField/ArrayField.test.js +26 -0
- package/package.json +1 -1
@@ -30,7 +30,7 @@ var _pendoID = require("../../utils/devUtils/constants/pendoID");
|
|
30
30
|
var _statuses = _interopRequireDefault(require("../../utils/devUtils/constants/statuses"));
|
31
31
|
var _ariaAttributes = require("../../utils/docUtils/ariaAttributes");
|
32
32
|
var _react2 = require("@emotion/react");
|
33
|
-
var _excluded = ["addButtonLabel", "defaultValue", "fieldControlWrapperProps", "value", "label", "helperText", "status", "onAdd", "onChange", "onDelete", "renderField", "labelProps", "maxSize", "maxSizeText"],
|
33
|
+
var _excluded = ["addButtonLabel", "defaultValue", "fieldControlWrapperProps", "value", "label", "helperText", "status", "onAdd", "onChange", "onDelete", "renderField", "labelProps", "maxSize", "maxSizeText", "slots"],
|
34
34
|
_excluded2 = ["id", "onComponentRender", "fieldValue"];
|
35
35
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
36
36
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -52,6 +52,7 @@ var ArrayField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
52
52
|
labelProps = props.labelProps,
|
53
53
|
maxSize = props.maxSize,
|
54
54
|
maxSizeText = props.maxSizeText,
|
55
|
+
slots = props.slots,
|
55
56
|
others = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
56
57
|
var valueRef = _react["default"].useRef(value);
|
57
58
|
valueRef.current = value;
|
@@ -121,6 +122,9 @@ var ArrayField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
121
122
|
raLabelProps = _useLabel.labelProps;
|
122
123
|
var isLimitReached = !!maxSize && (value || fieldValues).length >= maxSize;
|
123
124
|
var isDisabled = (value || fieldValues).length === 1;
|
125
|
+
|
126
|
+
// renders of the bottom bar if one or more of the components within it should render
|
127
|
+
var shouldShowBottomBar = !isLimitReached || (slots === null || slots === void 0 ? void 0 : slots.left) || (slots === null || slots === void 0 ? void 0 : slots.right);
|
124
128
|
var renderedItem = (0, _react.useCallback)(function (id, fieldValue, otherFieldProps, onComponentRender, labelId) {
|
125
129
|
if (onComponentRender) {
|
126
130
|
return onComponentRender(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, labelId, otherFieldProps);
|
@@ -154,7 +158,10 @@ var ArrayField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
154
158
|
status: status
|
155
159
|
}, helperText), isLimitReached && (0, _react2.jsx)(_.FieldHelperText, {
|
156
160
|
status: _statuses["default"].DEFAULT
|
157
|
-
}, maxSizeText || "Maximum ".concat(maxSize, " items.")),
|
161
|
+
}, maxSizeText || "Maximum ".concat(maxSize, " items.")), shouldShowBottomBar && (0, _react2.jsx)(_.Box, {
|
162
|
+
isRow: true,
|
163
|
+
gap: "md"
|
164
|
+
}, (slots === null || slots === void 0 ? void 0 : slots.left) && (slots === null || slots === void 0 ? void 0 : slots.left), !isLimitReached && (0, _react2.jsx)(_.Button, {
|
158
165
|
"aria-label": "Add field",
|
159
166
|
variant: "link",
|
160
167
|
onPress: onFieldAdd,
|
@@ -165,7 +172,7 @@ var ArrayField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
165
172
|
}, (0, _react2.jsx)(_.Text, {
|
166
173
|
variant: "label",
|
167
174
|
color: "active"
|
168
|
-
}, addButtonLabel)));
|
175
|
+
}, addButtonLabel)), (slots === null || slots === void 0 ? void 0 : slots.right) && (slots === null || slots === void 0 ? void 0 : slots.right)));
|
169
176
|
});
|
170
177
|
ArrayField.defaultProps = {
|
171
178
|
addButtonLabel: '+ Add',
|
@@ -9,3 +9,6 @@ export declare const WithLimitedItemsNumber: StoryFn<ArrayFieldProps>;
|
|
9
9
|
export declare const Customizations: ({ ...args }: {
|
10
10
|
[x: string]: any;
|
11
11
|
}) => React.JSX.Element;
|
12
|
+
export declare const WithBothSlots: ({ ...args }: {
|
13
|
+
[x: string]: any;
|
14
|
+
}) => React.JSX.Element;
|
@@ -12,7 +12,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
12
12
|
_Object$defineProperty(exports, "__esModule", {
|
13
13
|
value: true
|
14
14
|
});
|
15
|
-
exports["default"] = exports.WithLimitedItemsNumber = exports.Uncontrolled = exports.Customizations = exports.Controlled = void 0;
|
15
|
+
exports["default"] = exports.WithLimitedItemsNumber = exports.WithBothSlots = exports.Uncontrolled = exports.Customizations = exports.Controlled = void 0;
|
16
16
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
17
17
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
18
18
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
@@ -318,4 +318,67 @@ var Customizations = function Customizations(_ref5) {
|
|
318
318
|
}
|
319
319
|
}, args));
|
320
320
|
};
|
321
|
-
exports.Customizations = Customizations;
|
321
|
+
exports.Customizations = Customizations;
|
322
|
+
var WithBothSlots = function WithBothSlots(_ref6) {
|
323
|
+
var args = (0, _extends2["default"])({}, ((0, _objectDestructuringEmpty2["default"])(_ref6), _ref6));
|
324
|
+
var LeftSlot = (0, _react2.jsx)(_index.Button, {
|
325
|
+
"aria-label": "Add field",
|
326
|
+
variant: "link",
|
327
|
+
sx: {
|
328
|
+
width: 'fit-content',
|
329
|
+
mt: 'xs'
|
330
|
+
}
|
331
|
+
}, (0, _react2.jsx)(_index.Text, {
|
332
|
+
variant: "label",
|
333
|
+
color: "active"
|
334
|
+
}, "Left slot"));
|
335
|
+
var RightSlot = (0, _react2.jsx)(_index.Button, {
|
336
|
+
"aria-label": "Add field",
|
337
|
+
variant: "link",
|
338
|
+
sx: {
|
339
|
+
width: 'fit-content',
|
340
|
+
mt: 'xs'
|
341
|
+
}
|
342
|
+
}, (0, _react2.jsx)(_index.Text, {
|
343
|
+
variant: "label",
|
344
|
+
color: "active"
|
345
|
+
}, "Right slot"));
|
346
|
+
return (0, _react2.jsx)(_index.ArrayField, (0, _extends2["default"])({
|
347
|
+
defaultValue: defaultData,
|
348
|
+
sx: {
|
349
|
+
width: '450px'
|
350
|
+
},
|
351
|
+
labelProps: {
|
352
|
+
hintText: 'Example Hint',
|
353
|
+
isRequired: true,
|
354
|
+
helpHintProps: {
|
355
|
+
direction: 'top'
|
356
|
+
}
|
357
|
+
},
|
358
|
+
slots: {
|
359
|
+
left: LeftSlot,
|
360
|
+
right: RightSlot
|
361
|
+
},
|
362
|
+
renderField: function renderField(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) {
|
363
|
+
return (0, _react2.jsx)(_index.Box, {
|
364
|
+
width: "400px"
|
365
|
+
}, (0, _react2.jsx)(_index.TextField, (0, _extends2["default"])({
|
366
|
+
"aria-label": "Text field",
|
367
|
+
value: fieldValue,
|
368
|
+
onChange: function onChange(e) {
|
369
|
+
return onFieldValueChange(e, id);
|
370
|
+
},
|
371
|
+
mr: "xs",
|
372
|
+
slots: {
|
373
|
+
inContainer: (0, _react2.jsx)(_index.ArrayFieldDeleteButton, {
|
374
|
+
isDisabled: isDisabled,
|
375
|
+
onDelete: function onDelete() {
|
376
|
+
return onFieldDelete(id);
|
377
|
+
}
|
378
|
+
})
|
379
|
+
}
|
380
|
+
}, otherFieldProps)));
|
381
|
+
}
|
382
|
+
}, args));
|
383
|
+
};
|
384
|
+
exports.WithBothSlots = WithBothSlots;
|
@@ -227,4 +227,30 @@ test('displays max size label if provided', function () {
|
|
227
227
|
});
|
228
228
|
expect(_testWrapper.screen.queryByText('+ Add')).not.toBeInTheDocument();
|
229
229
|
expect(_testWrapper.screen.getByText(maxSizeText)).toBeInTheDocument();
|
230
|
+
});
|
231
|
+
test('renders left slot content', function () {
|
232
|
+
var leftSlotContent = (0, _react2.jsx)("div", {
|
233
|
+
"data-testid": "left-slot"
|
234
|
+
}, "Left Slot Content");
|
235
|
+
getComponent({
|
236
|
+
slots: {
|
237
|
+
left: leftSlotContent
|
238
|
+
}
|
239
|
+
});
|
240
|
+
var leftSlot = _testWrapper.screen.getByTestId('left-slot');
|
241
|
+
expect(leftSlot).toBeInTheDocument();
|
242
|
+
expect(leftSlot).toHaveTextContent('Left Slot Content');
|
243
|
+
});
|
244
|
+
test('renders right slot content', function () {
|
245
|
+
var rightSlotContent = (0, _react2.jsx)("div", {
|
246
|
+
"data-testid": "right-slot"
|
247
|
+
}, "Right Slot Content");
|
248
|
+
getComponent({
|
249
|
+
slots: {
|
250
|
+
right: rightSlotContent
|
251
|
+
}
|
252
|
+
});
|
253
|
+
var rightSlot = _testWrapper.screen.getByTestId('right-slot');
|
254
|
+
expect(rightSlot).toBeInTheDocument();
|
255
|
+
expect(rightSlot).toHaveTextContent('Right Slot Content');
|
230
256
|
});
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
import React from 'react';
|
2
2
|
import { ThemeUICSSObject } from 'theme-ui';
|
3
3
|
import { LabelProps, Status, ValidPositiveInteger } from '.';
|
4
4
|
type RenderFieldFunction = (id: string, fieldValue: string, onFieldValueChange: (e: React.ChangeEvent, fieldId: string) => void, onFieldDelete: (fieldId: string) => void, isDisabled: boolean, otherFieldProps?: Record<string, string>) => React.ReactNode;
|
@@ -37,6 +37,11 @@ export interface ArrayFieldProps {
|
|
37
37
|
status?: Status;
|
38
38
|
/** Props object that is spread directly into the wrapper rendering the fields. */
|
39
39
|
fieldControlWrapperProps?: Record<string, string>;
|
40
|
+
/** slots that render on either the left or right side of the add more button */
|
41
|
+
slots?: {
|
42
|
+
right?: React.ReactNode;
|
43
|
+
left?: React.ReactNode;
|
44
|
+
};
|
40
45
|
}
|
41
46
|
export interface ArrayFieldDeleteButtonProps {
|
42
47
|
id?: number;
|
@@ -9,7 +9,7 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
9
9
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
10
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["addButtonLabel", "defaultValue", "fieldControlWrapperProps", "value", "label", "helperText", "status", "onAdd", "onChange", "onDelete", "renderField", "labelProps", "maxSize", "maxSizeText"],
|
12
|
+
var _excluded = ["addButtonLabel", "defaultValue", "fieldControlWrapperProps", "value", "label", "helperText", "status", "onAdd", "onChange", "onDelete", "renderField", "labelProps", "maxSize", "maxSizeText", "slots"],
|
13
13
|
_excluded2 = ["id", "onComponentRender", "fieldValue"];
|
14
14
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
15
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
@@ -40,6 +40,7 @@ var ArrayField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
40
40
|
labelProps = props.labelProps,
|
41
41
|
maxSize = props.maxSize,
|
42
42
|
maxSizeText = props.maxSizeText,
|
43
|
+
slots = props.slots,
|
43
44
|
others = _objectWithoutProperties(props, _excluded);
|
44
45
|
var valueRef = React.useRef(value);
|
45
46
|
valueRef.current = value;
|
@@ -109,6 +110,9 @@ var ArrayField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
109
110
|
raLabelProps = _useLabel.labelProps;
|
110
111
|
var isLimitReached = !!maxSize && (value || fieldValues).length >= maxSize;
|
111
112
|
var isDisabled = (value || fieldValues).length === 1;
|
113
|
+
|
114
|
+
// renders of the bottom bar if one or more of the components within it should render
|
115
|
+
var shouldShowBottomBar = !isLimitReached || (slots === null || slots === void 0 ? void 0 : slots.left) || (slots === null || slots === void 0 ? void 0 : slots.right);
|
112
116
|
var renderedItem = useCallback(function (id, fieldValue, otherFieldProps, onComponentRender, labelId) {
|
113
117
|
if (onComponentRender) {
|
114
118
|
return onComponentRender(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, labelId, otherFieldProps);
|
@@ -142,7 +146,10 @@ var ArrayField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
142
146
|
status: status
|
143
147
|
}, helperText), isLimitReached && ___EmotionJSX(FieldHelperText, {
|
144
148
|
status: statuses.DEFAULT
|
145
|
-
}, maxSizeText || "Maximum ".concat(maxSize, " items.")),
|
149
|
+
}, maxSizeText || "Maximum ".concat(maxSize, " items.")), shouldShowBottomBar && ___EmotionJSX(Box, {
|
150
|
+
isRow: true,
|
151
|
+
gap: "md"
|
152
|
+
}, (slots === null || slots === void 0 ? void 0 : slots.left) && (slots === null || slots === void 0 ? void 0 : slots.left), !isLimitReached && ___EmotionJSX(Button, {
|
146
153
|
"aria-label": "Add field",
|
147
154
|
variant: "link",
|
148
155
|
onPress: onFieldAdd,
|
@@ -153,7 +160,7 @@ var ArrayField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
153
160
|
}, ___EmotionJSX(Text, {
|
154
161
|
variant: "label",
|
155
162
|
color: "active"
|
156
|
-
}, addButtonLabel)));
|
163
|
+
}, addButtonLabel)), (slots === null || slots === void 0 ? void 0 : slots.right) && (slots === null || slots === void 0 ? void 0 : slots.right)));
|
157
164
|
});
|
158
165
|
ArrayField.defaultProps = {
|
159
166
|
addButtonLabel: '+ Add',
|
@@ -17,7 +17,7 @@ import React from 'react';
|
|
17
17
|
import { OverlayProvider } from 'react-aria';
|
18
18
|
import { v4 as uuid } from 'uuid';
|
19
19
|
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
20
|
-
import { ArrayField, ArrayFieldDeleteButton, Box, Item, SelectField, TextField } from '../../index';
|
20
|
+
import { ArrayField, ArrayFieldDeleteButton, Box, Button, Item, SelectField, Text, TextField } from '../../index';
|
21
21
|
import { ariaAttributeBaseArgTypes } from '../../utils/docUtils/ariaAttributes';
|
22
22
|
import ArrayFieldReadme from './ArrayField.mdx';
|
23
23
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
@@ -305,4 +305,66 @@ export var Customizations = function Customizations(_ref5) {
|
|
305
305
|
}, otherFieldProps)));
|
306
306
|
}
|
307
307
|
}, args));
|
308
|
+
};
|
309
|
+
export var WithBothSlots = function WithBothSlots(_ref6) {
|
310
|
+
var args = _extends({}, (_objectDestructuringEmpty(_ref6), _ref6));
|
311
|
+
var LeftSlot = ___EmotionJSX(Button, {
|
312
|
+
"aria-label": "Add field",
|
313
|
+
variant: "link",
|
314
|
+
sx: {
|
315
|
+
width: 'fit-content',
|
316
|
+
mt: 'xs'
|
317
|
+
}
|
318
|
+
}, ___EmotionJSX(Text, {
|
319
|
+
variant: "label",
|
320
|
+
color: "active"
|
321
|
+
}, "Left slot"));
|
322
|
+
var RightSlot = ___EmotionJSX(Button, {
|
323
|
+
"aria-label": "Add field",
|
324
|
+
variant: "link",
|
325
|
+
sx: {
|
326
|
+
width: 'fit-content',
|
327
|
+
mt: 'xs'
|
328
|
+
}
|
329
|
+
}, ___EmotionJSX(Text, {
|
330
|
+
variant: "label",
|
331
|
+
color: "active"
|
332
|
+
}, "Right slot"));
|
333
|
+
return ___EmotionJSX(ArrayField, _extends({
|
334
|
+
defaultValue: defaultData,
|
335
|
+
sx: {
|
336
|
+
width: '450px'
|
337
|
+
},
|
338
|
+
labelProps: {
|
339
|
+
hintText: 'Example Hint',
|
340
|
+
isRequired: true,
|
341
|
+
helpHintProps: {
|
342
|
+
direction: 'top'
|
343
|
+
}
|
344
|
+
},
|
345
|
+
slots: {
|
346
|
+
left: LeftSlot,
|
347
|
+
right: RightSlot
|
348
|
+
},
|
349
|
+
renderField: function renderField(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) {
|
350
|
+
return ___EmotionJSX(Box, {
|
351
|
+
width: "400px"
|
352
|
+
}, ___EmotionJSX(TextField, _extends({
|
353
|
+
"aria-label": "Text field",
|
354
|
+
value: fieldValue,
|
355
|
+
onChange: function onChange(e) {
|
356
|
+
return onFieldValueChange(e, id);
|
357
|
+
},
|
358
|
+
mr: "xs",
|
359
|
+
slots: {
|
360
|
+
inContainer: ___EmotionJSX(ArrayFieldDeleteButton, {
|
361
|
+
isDisabled: isDisabled,
|
362
|
+
onDelete: function onDelete() {
|
363
|
+
return onFieldDelete(id);
|
364
|
+
}
|
365
|
+
})
|
366
|
+
}
|
367
|
+
}, otherFieldProps)));
|
368
|
+
}
|
369
|
+
}, args));
|
308
370
|
};
|
@@ -224,4 +224,30 @@ test('displays max size label if provided', function () {
|
|
224
224
|
});
|
225
225
|
expect(screen.queryByText('+ Add')).not.toBeInTheDocument();
|
226
226
|
expect(screen.getByText(maxSizeText)).toBeInTheDocument();
|
227
|
+
});
|
228
|
+
test('renders left slot content', function () {
|
229
|
+
var leftSlotContent = ___EmotionJSX("div", {
|
230
|
+
"data-testid": "left-slot"
|
231
|
+
}, "Left Slot Content");
|
232
|
+
getComponent({
|
233
|
+
slots: {
|
234
|
+
left: leftSlotContent
|
235
|
+
}
|
236
|
+
});
|
237
|
+
var leftSlot = screen.getByTestId('left-slot');
|
238
|
+
expect(leftSlot).toBeInTheDocument();
|
239
|
+
expect(leftSlot).toHaveTextContent('Left Slot Content');
|
240
|
+
});
|
241
|
+
test('renders right slot content', function () {
|
242
|
+
var rightSlotContent = ___EmotionJSX("div", {
|
243
|
+
"data-testid": "right-slot"
|
244
|
+
}, "Right Slot Content");
|
245
|
+
getComponent({
|
246
|
+
slots: {
|
247
|
+
right: rightSlotContent
|
248
|
+
}
|
249
|
+
});
|
250
|
+
var rightSlot = screen.getByTestId('right-slot');
|
251
|
+
expect(rightSlot).toBeInTheDocument();
|
252
|
+
expect(rightSlot).toHaveTextContent('Right Slot Content');
|
227
253
|
});
|