@pingux/astro 1.10.0-alpha.0 → 1.10.0-alpha.3
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/AccordionGridGroup/AccordionGridGroup.stories.js +55 -2
- package/lib/cjs/components/AccordionGridGroup/AccordionGridGroup.test.js +32 -0
- package/lib/cjs/components/AccordionGridItem/AccordionGridItem.js +1 -0
- package/lib/cjs/components/AccordionGridItem/AccordionGridItemBody.js +8 -2
- package/lib/cjs/components/ArrayField/ArrayField.js +16 -3
- package/lib/cjs/components/ArrayField/ArrayField.stories.js +43 -2
- package/lib/cjs/components/ArrayField/ArrayField.test.js +23 -0
- package/lib/cjs/recipes/Slider.stories.js +239 -0
- package/lib/cjs/styles/variants/accordion.js +10 -1
- package/lib/components/AccordionGridGroup/AccordionGridGroup.stories.js +51 -1
- package/lib/components/AccordionGridGroup/AccordionGridGroup.test.js +26 -1
- package/lib/components/AccordionGridItem/AccordionGridItem.js +1 -0
- package/lib/components/AccordionGridItem/AccordionGridItemBody.js +8 -2
- package/lib/components/ArrayField/ArrayField.js +15 -3
- package/lib/components/ArrayField/ArrayField.stories.js +39 -0
- package/lib/components/ArrayField/ArrayField.test.js +21 -0
- package/lib/recipes/Slider.stories.js +204 -0
- package/lib/styles/variants/accordion.js +10 -1
- package/package.json +3 -1
@@ -14,7 +14,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
14
14
|
value: true
|
15
15
|
});
|
16
16
|
|
17
|
-
exports["default"] = exports.Default = exports.Controlled = void 0;
|
17
|
+
exports["default"] = exports.Default = exports.Controlled = exports.AccordionWithInputs = void 0;
|
18
18
|
|
19
19
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
20
20
|
|
@@ -295,6 +295,59 @@ var Controlled = function Controlled() {
|
|
295
295
|
}) : null);
|
296
296
|
}))
|
297
297
|
);
|
298
|
+
}; // const items = [
|
299
|
+
// { id: 1, name: "Aardvark", key: "Aardvark" },
|
300
|
+
// { id: 2, name: "Kangaroo", key: "Kangaroo" },
|
301
|
+
// { id: 3, name: "Snake", key: "Snake" },
|
302
|
+
// { id: 4, name: "Frog", key: "Frog" },
|
303
|
+
// { id: 5, name: "Seal", key: "Seal" },
|
304
|
+
// { id: 6, name: "Orangutan", key: "Orangutan" },
|
305
|
+
// { id: 7, name: "Shark", key: "Shark" }
|
306
|
+
// ];
|
307
|
+
// const data = [
|
308
|
+
// {
|
309
|
+
// name: "Client Application Developer",
|
310
|
+
// key: "Client"
|
311
|
+
// },
|
312
|
+
// {
|
313
|
+
// name: "Environment Admin",
|
314
|
+
// key: "Environment"
|
315
|
+
// },
|
316
|
+
// {
|
317
|
+
// name: "Organization Admin",
|
318
|
+
// key: "Organization"
|
319
|
+
// }
|
320
|
+
// ];
|
321
|
+
|
322
|
+
|
323
|
+
exports.Controlled = Controlled;
|
324
|
+
|
325
|
+
var AccordionWithInputs = function AccordionWithInputs() {
|
326
|
+
return (0, _react2.jsx)(_AccordionGridGroup["default"], {
|
327
|
+
items: data
|
328
|
+
}, function (item) {
|
329
|
+
return (0, _react2.jsx)(_collections.Item, {
|
330
|
+
key: item.key,
|
331
|
+
textValue: item.name
|
332
|
+
}, (0, _react2.jsx)(_index.Text, {
|
333
|
+
sx: {
|
334
|
+
fontWeight: 3,
|
335
|
+
textOverflow: 'ellipsis',
|
336
|
+
whiteSpace: 'nowrap',
|
337
|
+
overflow: 'hidden'
|
338
|
+
},
|
339
|
+
variant: "itemTitle",
|
340
|
+
alignSelf: "center"
|
341
|
+
}, item.name), (0, _react2.jsx)(_index.Box, {
|
342
|
+
gap: "md"
|
343
|
+
}, (0, _react2.jsx)(_index.TextField, {
|
344
|
+
label: "label 1"
|
345
|
+
}), (0, _react2.jsx)(_index.TextField, {
|
346
|
+
label: "label 2"
|
347
|
+
}), (0, _react2.jsx)(_index.TextField, {
|
348
|
+
label: "label 3"
|
349
|
+
})));
|
350
|
+
});
|
298
351
|
};
|
299
352
|
|
300
|
-
exports.
|
353
|
+
exports.AccordionWithInputs = AccordionWithInputs;
|
@@ -59,6 +59,18 @@ var getComponentInOverlayPanel = function getComponentInOverlayPanel() {
|
|
59
59
|
}, (0, _react2.jsx)(_index.Box, null, (0, _react2.jsx)(_index.Link, null, "Header Button"), (0, _react2.jsx)(_index.Link, null, "Second Header Button")), (0, _react2.jsx)(_index.Box, null, (0, _react2.jsx)(_index.Link, null, "Body Button"), (0, _react2.jsx)(_index.Link, null, "Second Body Button"))))));
|
60
60
|
};
|
61
61
|
|
62
|
+
var getComponentWithTextFields = function getComponentWithTextFields() {
|
63
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
64
|
+
return (0, _testWrapper.render)((0, _react2.jsx)(_AccordionGridGroup["default"], (0, _extends2["default"])({}, defaultProps, props), (0, _react2.jsx)(_collections.Item, {
|
65
|
+
key: "first",
|
66
|
+
textValue: "Duplicate"
|
67
|
+
}, (0, _react2.jsx)(_index.Text, null, "Header"), (0, _react2.jsx)(_index.Box, null, (0, _react2.jsx)(_index.TextField, {
|
68
|
+
label: "label 1"
|
69
|
+
}), (0, _react2.jsx)(_index.TextField, {
|
70
|
+
label: "label 2"
|
71
|
+
})))));
|
72
|
+
};
|
73
|
+
|
62
74
|
(0, _testAxe["default"])(getComponent, {
|
63
75
|
// landmark-unique rule conflicts with react-aria role definition
|
64
76
|
rules: {
|
@@ -249,4 +261,24 @@ test('items do not automatically expand if wrapped in an open OverlayPanel', fun
|
|
249
261
|
|
250
262
|
var selectedRow = row[0];
|
251
263
|
expect(selectedRow).not.toHaveAttribute('aria-selected', 'true');
|
264
|
+
});
|
265
|
+
test('adds focus to inputs', function () {
|
266
|
+
getComponentWithTextFields();
|
267
|
+
|
268
|
+
var firstInput = _testWrapper.screen.getAllByRole('gridcell')[0];
|
269
|
+
|
270
|
+
var secondInput = _testWrapper.screen.getAllByRole('gridcell')[1];
|
271
|
+
|
272
|
+
expect(firstInput).not.toHaveFocus();
|
273
|
+
expect(secondInput).not.toHaveFocus();
|
274
|
+
|
275
|
+
_userEvent["default"].click(firstInput);
|
276
|
+
|
277
|
+
expect(firstInput).toHaveFocus();
|
278
|
+
expect(secondInput).not.toHaveFocus();
|
279
|
+
|
280
|
+
_userEvent["default"].click(secondInput);
|
281
|
+
|
282
|
+
expect(firstInput).not.toHaveFocus();
|
283
|
+
expect(secondInput).toHaveFocus();
|
252
284
|
});
|
@@ -105,6 +105,7 @@ var AccordionGridItem = function AccordionGridItem(props) {
|
|
105
105
|
}, (0, _utils.mergeProps)(rowProps, others), {
|
106
106
|
"aria-selected": isSelected,
|
107
107
|
className: classNames,
|
108
|
+
variant: "accordion.accordionGridItem",
|
108
109
|
ref: rowRef
|
109
110
|
}), (0, _react2.jsx)(_AccordionGridItemHeader["default"], (0, _extends2["default"])({
|
110
111
|
item: item,
|
@@ -62,10 +62,16 @@ var AccordionGridItemBody = /*#__PURE__*/(0, _react.forwardRef)(function (props,
|
|
62
62
|
|
63
63
|
var _useGridCell = (0, _grid.useGridCell)({
|
64
64
|
node: cellNode,
|
65
|
-
focusMode: '
|
65
|
+
focusMode: 'cell',
|
66
66
|
shouldSelectOnPressUp: true
|
67
67
|
}, state, ref),
|
68
|
-
gridCellProps = _useGridCell.gridCellProps;
|
68
|
+
gridCellProps = _useGridCell.gridCellProps;
|
69
|
+
/* istanbul ignore next */
|
70
|
+
|
71
|
+
|
72
|
+
gridCellProps.onClick = function (e) {
|
73
|
+
e.target.focus();
|
74
|
+
}; // Add the cell's key to the disabled keys array,
|
69
75
|
// so that clicking this cell does not close the accordion.
|
70
76
|
|
71
77
|
|
@@ -58,9 +58,11 @@ var _Text = _interopRequireDefault(require("../Text"));
|
|
58
58
|
|
59
59
|
var _statuses = _interopRequireDefault(require("../../utils/devUtils/constants/statuses"));
|
60
60
|
|
61
|
+
var _isValidPositiveInt = _interopRequireDefault(require("../../utils/devUtils/props/isValidPositiveInt"));
|
62
|
+
|
61
63
|
var _react2 = require("@emotion/react");
|
62
64
|
|
63
|
-
var _excluded = ["addButtonLabel", "defaultValue", "value", "label", "helperText", "status", "onAdd", "onChange", "onDelete", "renderField"],
|
65
|
+
var _excluded = ["addButtonLabel", "defaultValue", "value", "label", "helperText", "status", "onAdd", "onChange", "onDelete", "renderField", "maxSize", "maxSizeText"],
|
64
66
|
_excluded2 = ["id", "onComponentRender", "fieldValue"];
|
65
67
|
|
66
68
|
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); }
|
@@ -84,6 +86,8 @@ var ArrayField = function ArrayField(_ref) {
|
|
84
86
|
onChange = _ref.onChange,
|
85
87
|
onDelete = _ref.onDelete,
|
86
88
|
renderField = _ref.renderField,
|
89
|
+
maxSize = _ref.maxSize,
|
90
|
+
maxSizeText = _ref.maxSizeText,
|
87
91
|
others = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
88
92
|
var isControlled = value !== undefined;
|
89
93
|
var createEmptyField = (0, _react.useCallback)(function () {
|
@@ -147,6 +151,7 @@ var ArrayField = function ArrayField(_ref) {
|
|
147
151
|
return (0, _concat["default"])(_context = []).call(_context, oldValues, [createEmptyField()]);
|
148
152
|
});
|
149
153
|
}, [createEmptyField, onAdd]);
|
154
|
+
var isLimitReached = !!maxSize && (value || fieldValues).length >= maxSize;
|
150
155
|
return (0, _react2.jsx)(_Box["default"], others, (0, _react2.jsx)(_Text["default"], {
|
151
156
|
variant: "label"
|
152
157
|
}, label), (0, _react2.jsx)(_Box["default"], {
|
@@ -165,7 +170,9 @@ var ArrayField = function ArrayField(_ref) {
|
|
165
170
|
}, onComponentRender ? onComponentRender(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) : renderField(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps));
|
166
171
|
})), helperText && (0, _react2.jsx)(_FieldHelperText["default"], {
|
167
172
|
status: status
|
168
|
-
}, helperText), (0, _react2.jsx)(
|
173
|
+
}, helperText), isLimitReached && (0, _react2.jsx)(_FieldHelperText["default"], {
|
174
|
+
status: _statuses["default"].DEFAULT
|
175
|
+
}, maxSizeText || "Maximum ".concat(maxSize, " items.")), !isLimitReached && (0, _react2.jsx)(_Button["default"], {
|
169
176
|
"aria-label": "Add field",
|
170
177
|
variant: "text",
|
171
178
|
onPress: onFieldAdd,
|
@@ -213,7 +220,13 @@ ArrayField.propTypes = {
|
|
213
220
|
renderField: _propTypes["default"].func,
|
214
221
|
|
215
222
|
/** Determines the helper text styling. */
|
216
|
-
status: _propTypes["default"].oneOf((0, _values["default"])(_statuses["default"]))
|
223
|
+
status: _propTypes["default"].oneOf((0, _values["default"])(_statuses["default"])),
|
224
|
+
|
225
|
+
/** Determines the maximum number of items */
|
226
|
+
maxSize: _isValidPositiveInt["default"],
|
227
|
+
|
228
|
+
/** Text to display when the maximum number of items is reached */
|
229
|
+
maxSizeText: _propTypes["default"].node
|
217
230
|
};
|
218
231
|
ArrayField.defaultProps = {
|
219
232
|
addButtonLabel: '+ Add'
|
@@ -8,7 +8,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
9
9
|
});
|
10
10
|
|
11
|
-
exports["default"] = exports.Uncontrolled = exports.Controlled = void 0;
|
11
|
+
exports["default"] = exports.WithLimitedItemsNumber = exports.Uncontrolled = exports.Controlled = void 0;
|
12
12
|
|
13
13
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
14
14
|
|
@@ -58,6 +58,16 @@ var _default = {
|
|
58
58
|
control: {
|
59
59
|
type: 'text'
|
60
60
|
}
|
61
|
+
},
|
62
|
+
maxSize: {
|
63
|
+
control: {
|
64
|
+
type: 'number'
|
65
|
+
}
|
66
|
+
},
|
67
|
+
maxSizeText: {
|
68
|
+
control: {
|
69
|
+
type: 'text'
|
70
|
+
}
|
61
71
|
}
|
62
72
|
}
|
63
73
|
};
|
@@ -220,4 +230,35 @@ var Controlled = function Controlled() {
|
|
220
230
|
});
|
221
231
|
};
|
222
232
|
|
223
|
-
exports.Controlled = Controlled;
|
233
|
+
exports.Controlled = Controlled;
|
234
|
+
|
235
|
+
var WithLimitedItemsNumber = function WithLimitedItemsNumber(_ref3) {
|
236
|
+
var args = (0, _extends2["default"])({}, _ref3);
|
237
|
+
return (0, _react2.jsx)(_index.ArrayField, (0, _extends2["default"])({
|
238
|
+
defaultValue: defaultData,
|
239
|
+
renderField: function renderField(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) {
|
240
|
+
return (0, _react2.jsx)(_index.TextField, (0, _extends2["default"])({
|
241
|
+
"aria-label": "Text field",
|
242
|
+
value: fieldValue,
|
243
|
+
onChange: function onChange(e) {
|
244
|
+
return onFieldValueChange(e, id);
|
245
|
+
},
|
246
|
+
mr: "xs",
|
247
|
+
slots: {
|
248
|
+
inContainer: (0, _react2.jsx)(_index.ArrayFieldDeleteButton, {
|
249
|
+
isDisabled: isDisabled,
|
250
|
+
onDelete: function onDelete() {
|
251
|
+
return onFieldDelete(id);
|
252
|
+
}
|
253
|
+
})
|
254
|
+
}
|
255
|
+
}, otherFieldProps));
|
256
|
+
},
|
257
|
+
sx: {
|
258
|
+
width: '400px'
|
259
|
+
},
|
260
|
+
maxSize: 3
|
261
|
+
}, args));
|
262
|
+
};
|
263
|
+
|
264
|
+
exports.WithLimitedItemsNumber = WithLimitedItemsNumber;
|
@@ -218,4 +218,27 @@ test('check if tooltip on delete button renders on hover', function () {
|
|
218
218
|
_testWrapper.fireEvent.mouseEnter(button);
|
219
219
|
|
220
220
|
expect(_testWrapper.screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
221
|
+
});
|
222
|
+
test('removes add button if max number of fields is reached', function () {
|
223
|
+
getComponent({
|
224
|
+
renderField: renderField,
|
225
|
+
maxSize: 3
|
226
|
+
});
|
227
|
+
expect(_testWrapper.screen.getAllByLabelText('Text field')).toHaveLength(2);
|
228
|
+
|
229
|
+
_testWrapper.fireEvent.click(_testWrapper.screen.getByText('+ Add'));
|
230
|
+
|
231
|
+
expect(_testWrapper.screen.getAllByLabelText('Text field')).toHaveLength(3);
|
232
|
+
expect(_testWrapper.screen.queryByText('+ Add')).not.toBeInTheDocument();
|
233
|
+
expect(_testWrapper.screen.getByText('Maximum 3 items.')).toBeInTheDocument();
|
234
|
+
});
|
235
|
+
test('displays max size label if provided', function () {
|
236
|
+
var maxSizeText = 'Too many fields';
|
237
|
+
getComponent({
|
238
|
+
renderField: renderField,
|
239
|
+
maxSize: 1,
|
240
|
+
maxSizeText: maxSizeText
|
241
|
+
});
|
242
|
+
expect(_testWrapper.screen.queryByText('+ Add')).not.toBeInTheDocument();
|
243
|
+
expect(_testWrapper.screen.getByText(maxSizeText)).toBeInTheDocument();
|
221
244
|
});
|
@@ -0,0 +1,239 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
|
7
|
+
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
8
|
+
|
9
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
10
|
+
|
11
|
+
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
12
|
+
|
13
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
14
|
+
|
15
|
+
var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
16
|
+
|
17
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
18
|
+
|
19
|
+
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
20
|
+
|
21
|
+
_Object$defineProperty(exports, "__esModule", {
|
22
|
+
value: true
|
23
|
+
});
|
24
|
+
|
25
|
+
exports["default"] = exports.Default = void 0;
|
26
|
+
|
27
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
28
|
+
|
29
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
30
|
+
|
31
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
32
|
+
|
33
|
+
var _react = _interopRequireDefault(require("react"));
|
34
|
+
|
35
|
+
var _slider = require("@react-aria/slider");
|
36
|
+
|
37
|
+
var _slider2 = require("@react-stately/slider");
|
38
|
+
|
39
|
+
var _focus = require("@react-aria/focus");
|
40
|
+
|
41
|
+
var _visuallyHidden = require("@react-aria/visually-hidden");
|
42
|
+
|
43
|
+
var _utils = require("@react-aria/utils");
|
44
|
+
|
45
|
+
var _i18n = require("@react-aria/i18n");
|
46
|
+
|
47
|
+
var _index = require("../index");
|
48
|
+
|
49
|
+
var _react2 = require("@emotion/react");
|
50
|
+
|
51
|
+
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; }
|
52
|
+
|
53
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context6 = ownKeys(Object(source), !0)).call(_context6, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context7 = ownKeys(Object(source))).call(_context7, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
54
|
+
|
55
|
+
var _default = {
|
56
|
+
title: 'Recipes/Slider'
|
57
|
+
};
|
58
|
+
/*
|
59
|
+
* The slider value can be formatted by using the `formatOptions` prop.
|
60
|
+
`* formatOptions` is compatible with the option parameter of
|
61
|
+
* [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
|
62
|
+
* and is applied based on the current locale.
|
63
|
+
* https://react-spectrum.adobe.com/react-aria/useSlider.html
|
64
|
+
*/
|
65
|
+
|
66
|
+
exports["default"] = _default;
|
67
|
+
|
68
|
+
var Default = function Default() {
|
69
|
+
return (0, _react2.jsx)(_react["default"].Fragment, null, (0, _react2.jsx)(_index.Box, {
|
70
|
+
mb: "xl"
|
71
|
+
}, (0, _react2.jsx)(Slider, {
|
72
|
+
label: "Single with solid lower background",
|
73
|
+
maxValue: 100,
|
74
|
+
step: 1
|
75
|
+
})), (0, _react2.jsx)(_index.Box, null, (0, _react2.jsx)(RangeSlider, {
|
76
|
+
label: "Multiple with gradient background and custom point values",
|
77
|
+
maxValue: 100,
|
78
|
+
defaultValue: [0, 1],
|
79
|
+
step: 1
|
80
|
+
})));
|
81
|
+
};
|
82
|
+
|
83
|
+
exports.Default = Default;
|
84
|
+
|
85
|
+
var Slider = function Slider(props) {
|
86
|
+
var _context, _context2, _context3, _context4;
|
87
|
+
|
88
|
+
var trackRef = _react["default"].useRef(null);
|
89
|
+
|
90
|
+
var numberFormatter = (0, _i18n.useNumberFormatter)(props.formatOptions);
|
91
|
+
var state = (0, _slider2.useSliderState)(_objectSpread(_objectSpread({}, props), {}, {
|
92
|
+
numberFormatter: numberFormatter
|
93
|
+
}));
|
94
|
+
|
95
|
+
var _useSlider = (0, _slider.useSlider)(props, state, trackRef),
|
96
|
+
groupProps = _useSlider.groupProps,
|
97
|
+
trackProps = _useSlider.trackProps,
|
98
|
+
labelProps = _useSlider.labelProps,
|
99
|
+
outputProps = _useSlider.outputProps;
|
100
|
+
|
101
|
+
var thumbPosition = state.getThumbPercent(0) * 100;
|
102
|
+
return (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, groupProps, {
|
103
|
+
sx: {
|
104
|
+
position: 'relative',
|
105
|
+
alignItems: 'center',
|
106
|
+
width: '100%',
|
107
|
+
touchAction: 'none'
|
108
|
+
}
|
109
|
+
}), (0, _react2.jsx)(_index.Box, {
|
110
|
+
sx: {
|
111
|
+
alignSelf: 'stretch'
|
112
|
+
}
|
113
|
+
}, props.label && (0, _react2.jsx)("label", labelProps, props.label), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, outputProps, {
|
114
|
+
sx: {
|
115
|
+
flex: '1 0 auto',
|
116
|
+
textAlign: 'end'
|
117
|
+
}
|
118
|
+
}), "(", state.getThumbValueLabel(0), ")")), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, trackProps, {
|
119
|
+
ref: trackRef,
|
120
|
+
sx: {
|
121
|
+
position: 'relative',
|
122
|
+
height: 30,
|
123
|
+
width: ' 100%'
|
124
|
+
}
|
125
|
+
}), (0, _react2.jsx)(_index.Box, {
|
126
|
+
sx: {
|
127
|
+
position: 'absolute',
|
128
|
+
backgroundImage: thumbPosition < 25 ? (0, _concat["default"])(_context = "linear-gradient(to right, rgb(169, 215, 50) 0%, rgb(169, 215, 50) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context, thumbPosition, "%, rgb(242, 242, 242) 100%)") : thumbPosition >= 25 && thumbPosition <= 49 ? (0, _concat["default"])(_context2 = "linear-gradient(to right, rgb(226, 215, 20) 0%, rgb(226, 215, 20) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context2, thumbPosition, "%, rgb(242, 242, 242) 100%)") : thumbPosition >= 50 && thumbPosition <= 74 ? (0, _concat["default"])(_context3 = "linear-gradient(to right, rgb(231, 135, 38) 0%, rgb(231, 135, 38) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context3, thumbPosition, "%, rgb(242, 242, 242) 100%)") : (0, _concat["default"])(_context4 = "linear-gradient(to right, rgb(235, 44, 56) 0%, rgb(235, 44, 56) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context4, thumbPosition, "%, rgb(242, 242, 242) 100%)"),
|
129
|
+
height: 10,
|
130
|
+
borderRadius: '5px',
|
131
|
+
top: 13,
|
132
|
+
width: '100%'
|
133
|
+
}
|
134
|
+
}), (0, _react2.jsx)(Thumb, {
|
135
|
+
index: 0,
|
136
|
+
state: state,
|
137
|
+
trackRef: trackRef
|
138
|
+
})));
|
139
|
+
};
|
140
|
+
|
141
|
+
var RangeSlider = function RangeSlider(props) {
|
142
|
+
var _context5;
|
143
|
+
|
144
|
+
var trackRef = _react["default"].useRef(null);
|
145
|
+
|
146
|
+
var numberFormatter = (0, _i18n.useNumberFormatter)(props.formatOptions);
|
147
|
+
var state = (0, _slider2.useSliderState)(_objectSpread(_objectSpread({}, props), {}, {
|
148
|
+
numberFormatter: numberFormatter
|
149
|
+
}));
|
150
|
+
|
151
|
+
var _useSlider2 = (0, _slider.useSlider)(props, state, trackRef),
|
152
|
+
groupProps = _useSlider2.groupProps,
|
153
|
+
trackProps = _useSlider2.trackProps,
|
154
|
+
labelProps = _useSlider2.labelProps,
|
155
|
+
outputProps = _useSlider2.outputProps;
|
156
|
+
|
157
|
+
return (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, groupProps, {
|
158
|
+
sx: {
|
159
|
+
position: 'relative',
|
160
|
+
alignItems: 'center',
|
161
|
+
width: '100%',
|
162
|
+
touchAction: 'none'
|
163
|
+
}
|
164
|
+
}), (0, _react2.jsx)(_index.Box, {
|
165
|
+
sx: {
|
166
|
+
alignSelf: 'stretch'
|
167
|
+
}
|
168
|
+
}, props.label && (0, _react2.jsx)("label", labelProps, props.label), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, outputProps, {
|
169
|
+
sx: {
|
170
|
+
flex: '1 0 auto',
|
171
|
+
textAlign: 'end'
|
172
|
+
}
|
173
|
+
}), "(", (0, _concat["default"])(_context5 = "".concat(state.getThumbValueLabel(0), ", ")).call(_context5, state.getThumbValueLabel(1)), ")")), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, trackProps, {
|
174
|
+
ref: trackRef,
|
175
|
+
sx: {
|
176
|
+
position: 'relative',
|
177
|
+
height: 30,
|
178
|
+
width: ' 100%'
|
179
|
+
}
|
180
|
+
}), (0, _react2.jsx)(_index.Box, {
|
181
|
+
sx: {
|
182
|
+
position: 'absolute',
|
183
|
+
backgroundImage: 'linear-gradient(to right, rgb(169, 215, 50) 10%, rgb(226, 215, 20) 50%, rgb(235, 44, 56) 90%)',
|
184
|
+
height: 10,
|
185
|
+
borderRadius: '5px',
|
186
|
+
top: 13,
|
187
|
+
width: '100%'
|
188
|
+
}
|
189
|
+
}), (0, _react2.jsx)(Thumb, {
|
190
|
+
index: 0,
|
191
|
+
state: state,
|
192
|
+
trackRef: trackRef
|
193
|
+
}), (0, _react2.jsx)(Thumb, {
|
194
|
+
index: 1,
|
195
|
+
state: state,
|
196
|
+
trackRef: trackRef
|
197
|
+
})));
|
198
|
+
};
|
199
|
+
|
200
|
+
var Thumb = function Thumb(props) {
|
201
|
+
var state = props.state,
|
202
|
+
trackRef = props.trackRef,
|
203
|
+
index = props.index;
|
204
|
+
|
205
|
+
var inputRef = _react["default"].useRef(null);
|
206
|
+
|
207
|
+
var _useSliderThumb = (0, _slider.useSliderThumb)({
|
208
|
+
index: index,
|
209
|
+
trackRef: trackRef,
|
210
|
+
inputRef: inputRef
|
211
|
+
}, state),
|
212
|
+
thumbProps = _useSliderThumb.thumbProps,
|
213
|
+
inputProps = _useSliderThumb.inputProps;
|
214
|
+
|
215
|
+
var _useFocusRing = (0, _focus.useFocusRing)(),
|
216
|
+
focusProps = _useFocusRing.focusProps,
|
217
|
+
isFocusVisible = _useFocusRing.isFocusVisible;
|
218
|
+
|
219
|
+
return (0, _react2.jsx)(_index.Box, {
|
220
|
+
sx: {
|
221
|
+
position: 'absolute',
|
222
|
+
top: 5,
|
223
|
+
transform: 'translateX(-50%)',
|
224
|
+
left: "".concat(state.getThumbPercent(index) * 100, "%")
|
225
|
+
}
|
226
|
+
}, (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({}, thumbProps, {
|
227
|
+
sx: {
|
228
|
+
width: 25,
|
229
|
+
height: 25,
|
230
|
+
borderRadius: '50%',
|
231
|
+
backgroundColor: 'white',
|
232
|
+
border: '1px solid #C1C5C8',
|
233
|
+
boxShadow: '0 2px 2px 0 #CACACA',
|
234
|
+
outline: isFocusVisible ? '5px solid rgba(41,150,204,0.5)' : 'none'
|
235
|
+
}
|
236
|
+
}), (0, _react2.jsx)(_visuallyHidden.VisuallyHidden, null, (0, _react2.jsx)("input", (0, _extends2["default"])({
|
237
|
+
ref: inputRef
|
238
|
+
}, (0, _utils.mergeProps)(inputProps, focusProps))))));
|
239
|
+
};
|
@@ -130,6 +130,14 @@ var accordionGridBody = {
|
|
130
130
|
width: '100%',
|
131
131
|
'&.is-selected': {
|
132
132
|
display: 'flex !important'
|
133
|
+
},
|
134
|
+
':focus': {
|
135
|
+
outline: 'none'
|
136
|
+
}
|
137
|
+
};
|
138
|
+
var accordionGridItem = {
|
139
|
+
':focus': {
|
140
|
+
outline: 'none'
|
133
141
|
}
|
134
142
|
};
|
135
143
|
var _default = {
|
@@ -139,6 +147,7 @@ var _default = {
|
|
139
147
|
accordion: accordion,
|
140
148
|
accordionBody: accordionBody,
|
141
149
|
accordionGridHeaderNav: accordionGridHeaderNav,
|
142
|
-
accordionGridNavItem: accordionGridNavItem
|
150
|
+
accordionGridNavItem: accordionGridNavItem,
|
151
|
+
accordionGridItem: accordionGridItem
|
143
152
|
};
|
144
153
|
exports["default"] = _default;
|
@@ -4,7 +4,7 @@ import React, { useState } from 'react';
|
|
4
4
|
import { Item } from '@react-stately/collections';
|
5
5
|
import CreateIcon from 'mdi-react/CreateIcon';
|
6
6
|
import MoreVertIcon from 'mdi-react/MoreVertIcon';
|
7
|
-
import { Box, IconButton, Text, Separator, Link } from '../../index';
|
7
|
+
import { Box, IconButton, Text, Separator, Link, TextField } from '../../index';
|
8
8
|
import AccordionGridGroup from './AccordionGridGroup';
|
9
9
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
10
10
|
var data = [{
|
@@ -260,4 +260,54 @@ export var Controlled = function Controlled() {
|
|
260
260
|
}) : null);
|
261
261
|
}))
|
262
262
|
);
|
263
|
+
}; // const items = [
|
264
|
+
// { id: 1, name: "Aardvark", key: "Aardvark" },
|
265
|
+
// { id: 2, name: "Kangaroo", key: "Kangaroo" },
|
266
|
+
// { id: 3, name: "Snake", key: "Snake" },
|
267
|
+
// { id: 4, name: "Frog", key: "Frog" },
|
268
|
+
// { id: 5, name: "Seal", key: "Seal" },
|
269
|
+
// { id: 6, name: "Orangutan", key: "Orangutan" },
|
270
|
+
// { id: 7, name: "Shark", key: "Shark" }
|
271
|
+
// ];
|
272
|
+
// const data = [
|
273
|
+
// {
|
274
|
+
// name: "Client Application Developer",
|
275
|
+
// key: "Client"
|
276
|
+
// },
|
277
|
+
// {
|
278
|
+
// name: "Environment Admin",
|
279
|
+
// key: "Environment"
|
280
|
+
// },
|
281
|
+
// {
|
282
|
+
// name: "Organization Admin",
|
283
|
+
// key: "Organization"
|
284
|
+
// }
|
285
|
+
// ];
|
286
|
+
|
287
|
+
export var AccordionWithInputs = function AccordionWithInputs() {
|
288
|
+
return ___EmotionJSX(AccordionGridGroup, {
|
289
|
+
items: data
|
290
|
+
}, function (item) {
|
291
|
+
return ___EmotionJSX(Item, {
|
292
|
+
key: item.key,
|
293
|
+
textValue: item.name
|
294
|
+
}, ___EmotionJSX(Text, {
|
295
|
+
sx: {
|
296
|
+
fontWeight: 3,
|
297
|
+
textOverflow: 'ellipsis',
|
298
|
+
whiteSpace: 'nowrap',
|
299
|
+
overflow: 'hidden'
|
300
|
+
},
|
301
|
+
variant: "itemTitle",
|
302
|
+
alignSelf: "center"
|
303
|
+
}, item.name), ___EmotionJSX(Box, {
|
304
|
+
gap: "md"
|
305
|
+
}, ___EmotionJSX(TextField, {
|
306
|
+
label: "label 1"
|
307
|
+
}), ___EmotionJSX(TextField, {
|
308
|
+
label: "label 2"
|
309
|
+
}), ___EmotionJSX(TextField, {
|
310
|
+
label: "label 3"
|
311
|
+
})));
|
312
|
+
});
|
263
313
|
};
|
@@ -6,7 +6,7 @@ import { Item } from '@react-stately/collections';
|
|
6
6
|
import userEvent from '@testing-library/user-event';
|
7
7
|
import axeTest from '../../utils/testUtils/testAxe';
|
8
8
|
import { act, fireEvent, render, screen, waitFor } from '../../utils/testUtils/testWrapper';
|
9
|
-
import { Link, Box, OverlayPanel } from '../../index';
|
9
|
+
import { Link, Box, OverlayPanel, TextField, Text } from '../../index';
|
10
10
|
import AccordionGridGroup from '../AccordionGridGroup';
|
11
11
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
12
12
|
var testId = 'test-accordion';
|
@@ -44,6 +44,18 @@ var getComponentInOverlayPanel = function getComponentInOverlayPanel() {
|
|
44
44
|
}, ___EmotionJSX(Box, null, ___EmotionJSX(Link, null, "Header Button"), ___EmotionJSX(Link, null, "Second Header Button")), ___EmotionJSX(Box, null, ___EmotionJSX(Link, null, "Body Button"), ___EmotionJSX(Link, null, "Second Body Button"))))));
|
45
45
|
};
|
46
46
|
|
47
|
+
var getComponentWithTextFields = function getComponentWithTextFields() {
|
48
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
49
|
+
return render(___EmotionJSX(AccordionGridGroup, _extends({}, defaultProps, props), ___EmotionJSX(Item, {
|
50
|
+
key: "first",
|
51
|
+
textValue: "Duplicate"
|
52
|
+
}, ___EmotionJSX(Text, null, "Header"), ___EmotionJSX(Box, null, ___EmotionJSX(TextField, {
|
53
|
+
label: "label 1"
|
54
|
+
}), ___EmotionJSX(TextField, {
|
55
|
+
label: "label 2"
|
56
|
+
})))));
|
57
|
+
};
|
58
|
+
|
47
59
|
axeTest(getComponent, {
|
48
60
|
// landmark-unique rule conflicts with react-aria role definition
|
49
61
|
rules: {
|
@@ -187,4 +199,17 @@ test('items do not automatically expand if wrapped in an open OverlayPanel', fun
|
|
187
199
|
var row = screen.getAllByRole('row');
|
188
200
|
var selectedRow = row[0];
|
189
201
|
expect(selectedRow).not.toHaveAttribute('aria-selected', 'true');
|
202
|
+
});
|
203
|
+
test('adds focus to inputs', function () {
|
204
|
+
getComponentWithTextFields();
|
205
|
+
var firstInput = screen.getAllByRole('gridcell')[0];
|
206
|
+
var secondInput = screen.getAllByRole('gridcell')[1];
|
207
|
+
expect(firstInput).not.toHaveFocus();
|
208
|
+
expect(secondInput).not.toHaveFocus();
|
209
|
+
userEvent.click(firstInput);
|
210
|
+
expect(firstInput).toHaveFocus();
|
211
|
+
expect(secondInput).not.toHaveFocus();
|
212
|
+
userEvent.click(secondInput);
|
213
|
+
expect(firstInput).not.toHaveFocus();
|
214
|
+
expect(secondInput).toHaveFocus();
|
190
215
|
});
|
@@ -68,6 +68,7 @@ var AccordionGridItem = function AccordionGridItem(props) {
|
|
68
68
|
}, mergeProps(rowProps, others), {
|
69
69
|
"aria-selected": isSelected,
|
70
70
|
className: classNames,
|
71
|
+
variant: "accordion.accordionGridItem",
|
71
72
|
ref: rowRef
|
72
73
|
}), ___EmotionJSX(AccordionGridItemHeader, _extends({
|
73
74
|
item: item,
|
@@ -27,10 +27,16 @@ var AccordionGridItemBody = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
27
27
|
|
28
28
|
var _useGridCell = useGridCell({
|
29
29
|
node: cellNode,
|
30
|
-
focusMode: '
|
30
|
+
focusMode: 'cell',
|
31
31
|
shouldSelectOnPressUp: true
|
32
32
|
}, state, ref),
|
33
|
-
gridCellProps = _useGridCell.gridCellProps;
|
33
|
+
gridCellProps = _useGridCell.gridCellProps;
|
34
|
+
/* istanbul ignore next */
|
35
|
+
|
36
|
+
|
37
|
+
gridCellProps.onClick = function (e) {
|
38
|
+
e.target.focus();
|
39
|
+
}; // Add the cell's key to the disabled keys array,
|
34
40
|
// so that clicking this cell does not close the accordion.
|
35
41
|
|
36
42
|
|
@@ -12,7 +12,7 @@ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
12
12
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
13
13
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
14
14
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
15
|
-
var _excluded = ["addButtonLabel", "defaultValue", "value", "label", "helperText", "status", "onAdd", "onChange", "onDelete", "renderField"],
|
15
|
+
var _excluded = ["addButtonLabel", "defaultValue", "value", "label", "helperText", "status", "onAdd", "onChange", "onDelete", "renderField", "maxSize", "maxSizeText"],
|
16
16
|
_excluded2 = ["id", "onComponentRender", "fieldValue"];
|
17
17
|
|
18
18
|
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; }
|
@@ -27,6 +27,7 @@ import Button from '../Button';
|
|
27
27
|
import FieldHelperText from '../FieldHelperText';
|
28
28
|
import Text from '../Text';
|
29
29
|
import statuses from '../../utils/devUtils/constants/statuses';
|
30
|
+
import isValidPositiveInt from '../../utils/devUtils/props/isValidPositiveInt';
|
30
31
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
31
32
|
|
32
33
|
var ArrayField = function ArrayField(_ref) {
|
@@ -42,6 +43,8 @@ var ArrayField = function ArrayField(_ref) {
|
|
42
43
|
onChange = _ref.onChange,
|
43
44
|
onDelete = _ref.onDelete,
|
44
45
|
renderField = _ref.renderField,
|
46
|
+
maxSize = _ref.maxSize,
|
47
|
+
maxSizeText = _ref.maxSizeText,
|
45
48
|
others = _objectWithoutProperties(_ref, _excluded);
|
46
49
|
|
47
50
|
var isControlled = value !== undefined;
|
@@ -106,6 +109,7 @@ var ArrayField = function ArrayField(_ref) {
|
|
106
109
|
return _concatInstanceProperty(_context = []).call(_context, oldValues, [createEmptyField()]);
|
107
110
|
});
|
108
111
|
}, [createEmptyField, onAdd]);
|
112
|
+
var isLimitReached = !!maxSize && (value || fieldValues).length >= maxSize;
|
109
113
|
return ___EmotionJSX(Box, others, ___EmotionJSX(Text, {
|
110
114
|
variant: "label"
|
111
115
|
}, label), ___EmotionJSX(Box, {
|
@@ -125,7 +129,9 @@ var ArrayField = function ArrayField(_ref) {
|
|
125
129
|
}, onComponentRender ? onComponentRender(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) : renderField(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps));
|
126
130
|
})), helperText && ___EmotionJSX(FieldHelperText, {
|
127
131
|
status: status
|
128
|
-
}, helperText), ___EmotionJSX(
|
132
|
+
}, helperText), isLimitReached && ___EmotionJSX(FieldHelperText, {
|
133
|
+
status: statuses.DEFAULT
|
134
|
+
}, maxSizeText || "Maximum ".concat(maxSize, " items.")), !isLimitReached && ___EmotionJSX(Button, {
|
129
135
|
"aria-label": "Add field",
|
130
136
|
variant: "text",
|
131
137
|
onPress: onFieldAdd,
|
@@ -173,7 +179,13 @@ ArrayField.propTypes = {
|
|
173
179
|
renderField: PropTypes.func,
|
174
180
|
|
175
181
|
/** Determines the helper text styling. */
|
176
|
-
status: PropTypes.oneOf(_Object$values(statuses))
|
182
|
+
status: PropTypes.oneOf(_Object$values(statuses)),
|
183
|
+
|
184
|
+
/** Determines the maximum number of items */
|
185
|
+
maxSize: isValidPositiveInt,
|
186
|
+
|
187
|
+
/** Text to display when the maximum number of items is reached */
|
188
|
+
maxSizeText: PropTypes.node
|
177
189
|
};
|
178
190
|
ArrayField.defaultProps = {
|
179
191
|
addButtonLabel: '+ Add'
|
@@ -37,6 +37,16 @@ export default {
|
|
37
37
|
control: {
|
38
38
|
type: 'text'
|
39
39
|
}
|
40
|
+
},
|
41
|
+
maxSize: {
|
42
|
+
control: {
|
43
|
+
type: 'number'
|
44
|
+
}
|
45
|
+
},
|
46
|
+
maxSizeText: {
|
47
|
+
control: {
|
48
|
+
type: 'text'
|
49
|
+
}
|
40
50
|
}
|
41
51
|
}
|
42
52
|
};
|
@@ -193,4 +203,33 @@ export var Controlled = function Controlled() {
|
|
193
203
|
width: '400px'
|
194
204
|
}
|
195
205
|
});
|
206
|
+
};
|
207
|
+
export var WithLimitedItemsNumber = function WithLimitedItemsNumber(_ref3) {
|
208
|
+
var args = _extends({}, _ref3);
|
209
|
+
|
210
|
+
return ___EmotionJSX(ArrayField, _extends({
|
211
|
+
defaultValue: defaultData,
|
212
|
+
renderField: function renderField(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) {
|
213
|
+
return ___EmotionJSX(TextField, _extends({
|
214
|
+
"aria-label": "Text field",
|
215
|
+
value: fieldValue,
|
216
|
+
onChange: function onChange(e) {
|
217
|
+
return onFieldValueChange(e, id);
|
218
|
+
},
|
219
|
+
mr: "xs",
|
220
|
+
slots: {
|
221
|
+
inContainer: ___EmotionJSX(ArrayFieldDeleteButton, {
|
222
|
+
isDisabled: isDisabled,
|
223
|
+
onDelete: function onDelete() {
|
224
|
+
return onFieldDelete(id);
|
225
|
+
}
|
226
|
+
})
|
227
|
+
}
|
228
|
+
}, otherFieldProps));
|
229
|
+
},
|
230
|
+
sx: {
|
231
|
+
width: '400px'
|
232
|
+
},
|
233
|
+
maxSize: 3
|
234
|
+
}, args));
|
196
235
|
};
|
@@ -191,4 +191,25 @@ test('check if tooltip on delete button renders on hover', function () {
|
|
191
191
|
fireEvent.mouseMove(button);
|
192
192
|
fireEvent.mouseEnter(button);
|
193
193
|
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
194
|
+
});
|
195
|
+
test('removes add button if max number of fields is reached', function () {
|
196
|
+
getComponent({
|
197
|
+
renderField: renderField,
|
198
|
+
maxSize: 3
|
199
|
+
});
|
200
|
+
expect(screen.getAllByLabelText('Text field')).toHaveLength(2);
|
201
|
+
fireEvent.click(screen.getByText('+ Add'));
|
202
|
+
expect(screen.getAllByLabelText('Text field')).toHaveLength(3);
|
203
|
+
expect(screen.queryByText('+ Add')).not.toBeInTheDocument();
|
204
|
+
expect(screen.getByText('Maximum 3 items.')).toBeInTheDocument();
|
205
|
+
});
|
206
|
+
test('displays max size label if provided', function () {
|
207
|
+
var maxSizeText = 'Too many fields';
|
208
|
+
getComponent({
|
209
|
+
renderField: renderField,
|
210
|
+
maxSize: 1,
|
211
|
+
maxSizeText: maxSizeText
|
212
|
+
});
|
213
|
+
expect(screen.queryByText('+ Add')).not.toBeInTheDocument();
|
214
|
+
expect(screen.getByText(maxSizeText)).toBeInTheDocument();
|
194
215
|
});
|
@@ -0,0 +1,204 @@
|
|
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 _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
7
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
8
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
9
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
10
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
11
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
12
|
+
|
13
|
+
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; }
|
14
|
+
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context6 = ownKeys(Object(source), !0)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context7 = ownKeys(Object(source))).call(_context7, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
16
|
+
|
17
|
+
/* eslint-disable no-nested-ternary */
|
18
|
+
import React from 'react';
|
19
|
+
import { useSlider, useSliderThumb } from '@react-aria/slider';
|
20
|
+
import { useSliderState } from '@react-stately/slider';
|
21
|
+
import { useFocusRing } from '@react-aria/focus';
|
22
|
+
import { VisuallyHidden } from '@react-aria/visually-hidden';
|
23
|
+
import { mergeProps } from '@react-aria/utils';
|
24
|
+
import { useNumberFormatter } from '@react-aria/i18n';
|
25
|
+
import { Box } from '../index';
|
26
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
27
|
+
export default {
|
28
|
+
title: 'Recipes/Slider'
|
29
|
+
};
|
30
|
+
/*
|
31
|
+
* The slider value can be formatted by using the `formatOptions` prop.
|
32
|
+
`* formatOptions` is compatible with the option parameter of
|
33
|
+
* [Intl.NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
|
34
|
+
* and is applied based on the current locale.
|
35
|
+
* https://react-spectrum.adobe.com/react-aria/useSlider.html
|
36
|
+
*/
|
37
|
+
|
38
|
+
export var Default = function Default() {
|
39
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(Box, {
|
40
|
+
mb: "xl"
|
41
|
+
}, ___EmotionJSX(Slider, {
|
42
|
+
label: "Single with solid lower background",
|
43
|
+
maxValue: 100,
|
44
|
+
step: 1
|
45
|
+
})), ___EmotionJSX(Box, null, ___EmotionJSX(RangeSlider, {
|
46
|
+
label: "Multiple with gradient background and custom point values",
|
47
|
+
maxValue: 100,
|
48
|
+
defaultValue: [0, 1],
|
49
|
+
step: 1
|
50
|
+
})));
|
51
|
+
};
|
52
|
+
|
53
|
+
var Slider = function Slider(props) {
|
54
|
+
var _context, _context2, _context3, _context4;
|
55
|
+
|
56
|
+
var trackRef = React.useRef(null);
|
57
|
+
var numberFormatter = useNumberFormatter(props.formatOptions);
|
58
|
+
var state = useSliderState(_objectSpread(_objectSpread({}, props), {}, {
|
59
|
+
numberFormatter: numberFormatter
|
60
|
+
}));
|
61
|
+
|
62
|
+
var _useSlider = useSlider(props, state, trackRef),
|
63
|
+
groupProps = _useSlider.groupProps,
|
64
|
+
trackProps = _useSlider.trackProps,
|
65
|
+
labelProps = _useSlider.labelProps,
|
66
|
+
outputProps = _useSlider.outputProps;
|
67
|
+
|
68
|
+
var thumbPosition = state.getThumbPercent(0) * 100;
|
69
|
+
return ___EmotionJSX(Box, _extends({}, groupProps, {
|
70
|
+
sx: {
|
71
|
+
position: 'relative',
|
72
|
+
alignItems: 'center',
|
73
|
+
width: '100%',
|
74
|
+
touchAction: 'none'
|
75
|
+
}
|
76
|
+
}), ___EmotionJSX(Box, {
|
77
|
+
sx: {
|
78
|
+
alignSelf: 'stretch'
|
79
|
+
}
|
80
|
+
}, props.label && ___EmotionJSX("label", labelProps, props.label), ___EmotionJSX(Box, _extends({}, outputProps, {
|
81
|
+
sx: {
|
82
|
+
flex: '1 0 auto',
|
83
|
+
textAlign: 'end'
|
84
|
+
}
|
85
|
+
}), "(", state.getThumbValueLabel(0), ")")), ___EmotionJSX(Box, _extends({}, trackProps, {
|
86
|
+
ref: trackRef,
|
87
|
+
sx: {
|
88
|
+
position: 'relative',
|
89
|
+
height: 30,
|
90
|
+
width: ' 100%'
|
91
|
+
}
|
92
|
+
}), ___EmotionJSX(Box, {
|
93
|
+
sx: {
|
94
|
+
position: 'absolute',
|
95
|
+
backgroundImage: thumbPosition < 25 ? _concatInstanceProperty(_context = "linear-gradient(to right, rgb(169, 215, 50) 0%, rgb(169, 215, 50) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context, thumbPosition, "%, rgb(242, 242, 242) 100%)") : thumbPosition >= 25 && thumbPosition <= 49 ? _concatInstanceProperty(_context2 = "linear-gradient(to right, rgb(226, 215, 20) 0%, rgb(226, 215, 20) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context2, thumbPosition, "%, rgb(242, 242, 242) 100%)") : thumbPosition >= 50 && thumbPosition <= 74 ? _concatInstanceProperty(_context3 = "linear-gradient(to right, rgb(231, 135, 38) 0%, rgb(231, 135, 38) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context3, thumbPosition, "%, rgb(242, 242, 242) 100%)") : _concatInstanceProperty(_context4 = "linear-gradient(to right, rgb(235, 44, 56) 0%, rgb(235, 44, 56) ".concat(thumbPosition, "%, rgb(242, 242, 242) ")).call(_context4, thumbPosition, "%, rgb(242, 242, 242) 100%)"),
|
96
|
+
height: 10,
|
97
|
+
borderRadius: '5px',
|
98
|
+
top: 13,
|
99
|
+
width: '100%'
|
100
|
+
}
|
101
|
+
}), ___EmotionJSX(Thumb, {
|
102
|
+
index: 0,
|
103
|
+
state: state,
|
104
|
+
trackRef: trackRef
|
105
|
+
})));
|
106
|
+
};
|
107
|
+
|
108
|
+
var RangeSlider = function RangeSlider(props) {
|
109
|
+
var _context5;
|
110
|
+
|
111
|
+
var trackRef = React.useRef(null);
|
112
|
+
var numberFormatter = useNumberFormatter(props.formatOptions);
|
113
|
+
var state = useSliderState(_objectSpread(_objectSpread({}, props), {}, {
|
114
|
+
numberFormatter: numberFormatter
|
115
|
+
}));
|
116
|
+
|
117
|
+
var _useSlider2 = useSlider(props, state, trackRef),
|
118
|
+
groupProps = _useSlider2.groupProps,
|
119
|
+
trackProps = _useSlider2.trackProps,
|
120
|
+
labelProps = _useSlider2.labelProps,
|
121
|
+
outputProps = _useSlider2.outputProps;
|
122
|
+
|
123
|
+
return ___EmotionJSX(Box, _extends({}, groupProps, {
|
124
|
+
sx: {
|
125
|
+
position: 'relative',
|
126
|
+
alignItems: 'center',
|
127
|
+
width: '100%',
|
128
|
+
touchAction: 'none'
|
129
|
+
}
|
130
|
+
}), ___EmotionJSX(Box, {
|
131
|
+
sx: {
|
132
|
+
alignSelf: 'stretch'
|
133
|
+
}
|
134
|
+
}, props.label && ___EmotionJSX("label", labelProps, props.label), ___EmotionJSX(Box, _extends({}, outputProps, {
|
135
|
+
sx: {
|
136
|
+
flex: '1 0 auto',
|
137
|
+
textAlign: 'end'
|
138
|
+
}
|
139
|
+
}), "(", _concatInstanceProperty(_context5 = "".concat(state.getThumbValueLabel(0), ", ")).call(_context5, state.getThumbValueLabel(1)), ")")), ___EmotionJSX(Box, _extends({}, trackProps, {
|
140
|
+
ref: trackRef,
|
141
|
+
sx: {
|
142
|
+
position: 'relative',
|
143
|
+
height: 30,
|
144
|
+
width: ' 100%'
|
145
|
+
}
|
146
|
+
}), ___EmotionJSX(Box, {
|
147
|
+
sx: {
|
148
|
+
position: 'absolute',
|
149
|
+
backgroundImage: 'linear-gradient(to right, rgb(169, 215, 50) 10%, rgb(226, 215, 20) 50%, rgb(235, 44, 56) 90%)',
|
150
|
+
height: 10,
|
151
|
+
borderRadius: '5px',
|
152
|
+
top: 13,
|
153
|
+
width: '100%'
|
154
|
+
}
|
155
|
+
}), ___EmotionJSX(Thumb, {
|
156
|
+
index: 0,
|
157
|
+
state: state,
|
158
|
+
trackRef: trackRef
|
159
|
+
}), ___EmotionJSX(Thumb, {
|
160
|
+
index: 1,
|
161
|
+
state: state,
|
162
|
+
trackRef: trackRef
|
163
|
+
})));
|
164
|
+
};
|
165
|
+
|
166
|
+
var Thumb = function Thumb(props) {
|
167
|
+
var state = props.state,
|
168
|
+
trackRef = props.trackRef,
|
169
|
+
index = props.index;
|
170
|
+
var inputRef = React.useRef(null);
|
171
|
+
|
172
|
+
var _useSliderThumb = useSliderThumb({
|
173
|
+
index: index,
|
174
|
+
trackRef: trackRef,
|
175
|
+
inputRef: inputRef
|
176
|
+
}, state),
|
177
|
+
thumbProps = _useSliderThumb.thumbProps,
|
178
|
+
inputProps = _useSliderThumb.inputProps;
|
179
|
+
|
180
|
+
var _useFocusRing = useFocusRing(),
|
181
|
+
focusProps = _useFocusRing.focusProps,
|
182
|
+
isFocusVisible = _useFocusRing.isFocusVisible;
|
183
|
+
|
184
|
+
return ___EmotionJSX(Box, {
|
185
|
+
sx: {
|
186
|
+
position: 'absolute',
|
187
|
+
top: 5,
|
188
|
+
transform: 'translateX(-50%)',
|
189
|
+
left: "".concat(state.getThumbPercent(index) * 100, "%")
|
190
|
+
}
|
191
|
+
}, ___EmotionJSX(Box, _extends({}, thumbProps, {
|
192
|
+
sx: {
|
193
|
+
width: 25,
|
194
|
+
height: 25,
|
195
|
+
borderRadius: '50%',
|
196
|
+
backgroundColor: 'white',
|
197
|
+
border: '1px solid #C1C5C8',
|
198
|
+
boxShadow: '0 2px 2px 0 #CACACA',
|
199
|
+
outline: isFocusVisible ? '5px solid rgba(41,150,204,0.5)' : 'none'
|
200
|
+
}
|
201
|
+
}), ___EmotionJSX(VisuallyHidden, null, ___EmotionJSX("input", _extends({
|
202
|
+
ref: inputRef
|
203
|
+
}, mergeProps(inputProps, focusProps))))));
|
204
|
+
};
|
@@ -112,6 +112,14 @@ var accordionGridBody = {
|
|
112
112
|
width: '100%',
|
113
113
|
'&.is-selected': {
|
114
114
|
display: 'flex !important'
|
115
|
+
},
|
116
|
+
':focus': {
|
117
|
+
outline: 'none'
|
118
|
+
}
|
119
|
+
};
|
120
|
+
var accordionGridItem = {
|
121
|
+
':focus': {
|
122
|
+
outline: 'none'
|
115
123
|
}
|
116
124
|
};
|
117
125
|
export default {
|
@@ -121,5 +129,6 @@ export default {
|
|
121
129
|
accordion: accordion,
|
122
130
|
accordionBody: accordionBody,
|
123
131
|
accordionGridHeaderNav: accordionGridHeaderNav,
|
124
|
-
accordionGridNavItem: accordionGridNavItem
|
132
|
+
accordionGridNavItem: accordionGridNavItem,
|
133
|
+
accordionGridItem: accordionGridItem
|
125
134
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pingux/astro",
|
3
|
-
"version": "1.10.0-alpha.
|
3
|
+
"version": "1.10.0-alpha.3",
|
4
4
|
"description": "PingUX themeable React component library",
|
5
5
|
"author": "ux-development@pingidentity.com",
|
6
6
|
"license": "Apache-2.0",
|
@@ -98,6 +98,7 @@
|
|
98
98
|
"@react-aria/select": "^3.2.3",
|
99
99
|
"@react-aria/selection": "^3.3.1",
|
100
100
|
"@react-aria/separator": "^3.1.1",
|
101
|
+
"@react-aria/slider": "^3.0.7",
|
101
102
|
"@react-aria/switch": "3.1.1",
|
102
103
|
"@react-aria/tabs": "^3.0.1",
|
103
104
|
"@react-aria/tooltip": "^3.1.2",
|
@@ -119,6 +120,7 @@
|
|
119
120
|
"@react-stately/radio": "^3.2.0",
|
120
121
|
"@react-stately/searchfield": "^3.1.1",
|
121
122
|
"@react-stately/select": "^3.1.1",
|
123
|
+
"@react-stately/slider": "^3.0.7",
|
122
124
|
"@react-stately/tabs": "^3.0.1",
|
123
125
|
"@react-stately/toggle": "^3.2.0",
|
124
126
|
"@react-stately/tooltip": "^3.0.4",
|