@pingux/astro 2.92.1 → 2.93.0-alpha.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/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/components/SelectField/Select.styles.d.ts +2 -0
- package/lib/cjs/components/SelectField/SelectField.d.ts +4 -0
- package/lib/cjs/components/SelectField/SelectField.js +18 -91
- package/lib/cjs/components/SelectField/SelectField.stories.d.ts +50 -0
- package/lib/cjs/components/SelectField/SelectField.stories.js +4 -1
- package/lib/cjs/components/SelectField/SelectField.test.d.ts +1 -0
- package/lib/cjs/components/SelectField/SelectField.test.js +20 -4
- package/lib/cjs/components/SelectField/index.d.ts +1 -0
- package/lib/cjs/components/SelectFieldBase/SelectFieldBase.d.ts +11 -0
- package/lib/cjs/components/SelectFieldBase/SelectFieldBase.js +26 -83
- package/lib/cjs/components/SelectFieldBase/SelectFieldBase.test.d.ts +1 -0
- package/lib/cjs/components/SelectFieldBase/SelectFieldBase.test.js +10 -4
- package/lib/cjs/components/SelectFieldBase/index.d.ts +1 -0
- package/lib/cjs/components/TextAreaField/TextAreaField.test.js +10 -9
- package/lib/cjs/hooks/useSelectField/useSelectField.d.ts +12 -7
- package/lib/cjs/types/TextAreaField.d.ts +2 -13
- package/lib/cjs/types/arrayField.d.ts +7 -3
- package/lib/cjs/types/selectField.d.ts +23 -0
- package/lib/cjs/types/selectField.js +6 -0
- package/lib/cjs/types/shared/dom.d.ts +1 -0
- package/lib/cjs/types/shared/fieldProps.d.ts +12 -0
- package/lib/cjs/types/shared/fieldProps.js +6 -0
- package/lib/cjs/types/textField.d.ts +2 -11
- 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/lib/components/SelectField/Select.styles.js +1 -0
- package/lib/components/SelectField/SelectField.js +19 -92
- package/lib/components/SelectField/SelectField.stories.js +4 -1
- package/lib/components/SelectField/SelectField.test.js +20 -4
- package/lib/components/SelectFieldBase/SelectFieldBase.js +27 -84
- package/lib/components/SelectFieldBase/SelectFieldBase.test.js +10 -4
- package/lib/components/TextAreaField/TextAreaField.test.js +10 -9
- package/lib/types/selectField.js +1 -0
- package/lib/types/shared/fieldProps.js +1 -0
- package/package.json +1 -2
@@ -18,6 +18,7 @@ var defaultProps = {
|
|
18
18
|
'data-testid': testId,
|
19
19
|
label: 'testLabel'
|
20
20
|
};
|
21
|
+
var label = defaultProps.label;
|
21
22
|
var getComponent = function getComponent() {
|
22
23
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
23
24
|
return (0, _testWrapper.render)((0, _react3.jsx)(_["default"], (0, _extends2["default"])({}, defaultProps, props)));
|
@@ -34,12 +35,12 @@ test('disabled prop disables input', function () {
|
|
34
35
|
getComponent({
|
35
36
|
isDisabled: true
|
36
37
|
});
|
37
|
-
var textArea = _testWrapper.screen.getByLabelText(
|
38
|
+
var textArea = _testWrapper.screen.getByLabelText(label);
|
38
39
|
expect(textArea).toBeDisabled();
|
39
40
|
});
|
40
41
|
test('text area field has focus', function () {
|
41
42
|
getComponent();
|
42
|
-
var textArea = _testWrapper.screen.getByLabelText(
|
43
|
+
var textArea = _testWrapper.screen.getByLabelText(label);
|
43
44
|
_userEvent["default"].tab();
|
44
45
|
expect(textArea).toHaveFocus();
|
45
46
|
expect(textArea).toHaveClass('is-focused');
|
@@ -48,8 +49,8 @@ test('disabled prop disables text field label', function () {
|
|
48
49
|
getComponent({
|
49
50
|
isDisabled: true
|
50
51
|
});
|
51
|
-
var
|
52
|
-
expect(
|
52
|
+
var labelDom = _testWrapper.screen.getByText(label);
|
53
|
+
expect(labelDom).toHaveClass('is-disabled');
|
53
54
|
});
|
54
55
|
test('text area field with helper text', function () {
|
55
56
|
var helperText = 'helper text';
|
@@ -66,8 +67,8 @@ test('float label prop adds float label class', function () {
|
|
66
67
|
helperText: helperText,
|
67
68
|
labelMode: labelMode
|
68
69
|
});
|
69
|
-
var
|
70
|
-
expect(
|
70
|
+
var labelDom = _testWrapper.screen.getByText(label);
|
71
|
+
expect(labelDom).toHaveClass('is-float-label');
|
71
72
|
});
|
72
73
|
test('mousemove calls resize event', function () {
|
73
74
|
var labelMode = 'float';
|
@@ -77,7 +78,7 @@ test('mousemove calls resize event', function () {
|
|
77
78
|
labelMode: labelMode,
|
78
79
|
resizeCallback: mockfunction
|
79
80
|
});
|
80
|
-
var textArea = _testWrapper.screen.getByLabelText(
|
81
|
+
var textArea = _testWrapper.screen.getByLabelText(label);
|
81
82
|
_react2.fireEvent.mouseMove(textArea);
|
82
83
|
_react2.fireEvent.mouseMove(textArea);
|
83
84
|
expect(mockfunction).toHaveBeenCalledTimes(2);
|
@@ -92,7 +93,7 @@ test('label will receive gridRow attribute if it will be higher than textarea',
|
|
92
93
|
}
|
93
94
|
});
|
94
95
|
getComponent();
|
95
|
-
expect(_testWrapper.screen.getByText(
|
96
|
+
expect(_testWrapper.screen.getByText(label)).toHaveStyle('grid-row: 1/5');
|
96
97
|
(0, _defineProperty["default"])(HTMLElement.prototype, 'offsetHeight', originalOffsetHeight);
|
97
98
|
});
|
98
99
|
test('form wrapper will have default max label column width when no custom width set', function () {
|
@@ -108,7 +109,7 @@ test('passing read only prop applys the is-read-only class to the textarea', fun
|
|
108
109
|
getComponent({
|
109
110
|
isReadOnly: isReadOnly
|
110
111
|
});
|
111
|
-
var textArea = _testWrapper.screen.getByLabelText(
|
112
|
+
var textArea = _testWrapper.screen.getByLabelText(label);
|
112
113
|
expect(textArea).toHaveClass('is-read-only');
|
113
114
|
});
|
114
115
|
test('form wrapper will have a max label column width when custom width set', function () {
|
@@ -4,16 +4,18 @@ import { AriaSelectOptions } from '@react-aria/select';
|
|
4
4
|
import { SelectState } from '@react-stately/select';
|
5
5
|
import type { CollectionChildren } from '@react-types/shared';
|
6
6
|
import { LabelProps as ThemeUILabelProps } from 'theme-ui';
|
7
|
-
import { Axis, BoxProps, FocusableElement, LabelModeProps, ListBoxProps, PlacementAxis, ReactRef, StyleProps } from '../../types';
|
7
|
+
import { Axis, BoxProps, FocusableElement, LabelModeProps, ListBoxProps, PlacementAxis, ReactButtonRef, ReactRef, StyleProps } from '../../types';
|
8
8
|
import { FieldControlInputProps } from '../useField/useField';
|
9
|
-
interface UseSelectFieldProps<T> extends AriaSelectOptions<T> {
|
10
|
-
children
|
9
|
+
export interface UseSelectFieldProps<T> extends AriaSelectOptions<T> {
|
10
|
+
children?: CollectionChildren<T>;
|
11
11
|
align?: PlacementAxis;
|
12
12
|
defaultSelectedKey?: string;
|
13
13
|
defaultText?: string;
|
14
14
|
direction?: Axis;
|
15
15
|
disabledKeys?: Iterable<Key>;
|
16
16
|
hasNoEmptySelection?: boolean;
|
17
|
+
hasNoStatusIndicator?: boolean;
|
18
|
+
helperText?: string;
|
17
19
|
isDefaultOpen?: boolean;
|
18
20
|
isDisabled?: boolean;
|
19
21
|
isLoading?: boolean;
|
@@ -30,14 +32,17 @@ interface UseSelectFieldProps<T> extends AriaSelectOptions<T> {
|
|
30
32
|
onLoadMore?: () => unknown;
|
31
33
|
onOpenChange?: (isOpen: boolean) => unknown;
|
32
34
|
onSelectionChange?: (key: Key) => unknown;
|
33
|
-
controlProps?:
|
35
|
+
controlProps?: ControlProps;
|
34
36
|
scrollBoxProps?: BoxProps;
|
35
37
|
listBoxProps?: ListBoxProps;
|
36
38
|
labelProps?: ThemeUILabelProps;
|
37
39
|
containerProps?: BoxProps;
|
38
|
-
labelMode
|
40
|
+
labelMode?: LabelModeProps;
|
39
41
|
}
|
40
|
-
interface
|
42
|
+
interface ControlProps extends React.HTMLAttributes<Element> {
|
43
|
+
'data-testid'?: string;
|
44
|
+
}
|
45
|
+
export interface UseSelectFieldReturnProps<T> {
|
41
46
|
columnStyleProps: StyleProps;
|
42
47
|
fieldContainerProps: BoxProps;
|
43
48
|
fieldControlInputProps: FieldControlInputProps;
|
@@ -49,7 +54,7 @@ interface UseSelectFieldReturnProps<T> {
|
|
49
54
|
popoverRef: ReactRef;
|
50
55
|
state: SelectState<T>;
|
51
56
|
triggerProps: AriaButtonProps<'button'>;
|
52
|
-
triggerRef:
|
57
|
+
triggerRef: ReactButtonRef;
|
53
58
|
valueProps: DOMAttributes<FocusableElement>;
|
54
59
|
}
|
55
60
|
declare const useSelectField: <T extends object>(props: UseSelectFieldProps<T>, ref: ReactRef) => UseSelectFieldReturnProps<T>;
|
@@ -1,17 +1,8 @@
|
|
1
1
|
import { ReactNode } from 'react';
|
2
|
+
import { SharedFieldProps } from './shared/fieldProps';
|
2
3
|
import { TestingAttributes } from './shared/test';
|
3
|
-
import { Status } from './item';
|
4
|
-
import { LabelModeProps } from './label';
|
5
4
|
import { ValidPositiveInteger } from './shared';
|
6
|
-
export interface TextAreaFieldProps extends TestingAttributes {
|
7
|
-
/** The rendered label for the field. */
|
8
|
-
label: string;
|
9
|
-
/** Text rendered below the textarea. */
|
10
|
-
helperText?: string;
|
11
|
-
/** If present this prop will cause a help hint to render in the label of the field. */
|
12
|
-
hintText?: string;
|
13
|
-
/** A string designating whether or not the label is a float label. */
|
14
|
-
labelMode?: LabelModeProps;
|
5
|
+
export interface TextAreaFieldProps extends TestingAttributes, SharedFieldProps {
|
15
6
|
/** Whether the textarea is unable to be resized. */
|
16
7
|
isUnresizable?: boolean;
|
17
8
|
/**
|
@@ -52,6 +43,4 @@ export interface TextAreaFieldProps extends TestingAttributes {
|
|
52
43
|
/** The given node will be inserted into the field container. */
|
53
44
|
inContainer: ReactNode;
|
54
45
|
};
|
55
|
-
/** Status of the textarea field */
|
56
|
-
status?: Status;
|
57
46
|
}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
import React from 'react';
|
2
2
|
import { ThemeUICSSObject } from 'theme-ui';
|
3
3
|
import { LabelProps, Status, ValidPositiveInteger } from '.';
|
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;
|
4
|
+
export 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;
|
5
5
|
export interface FieldValue {
|
6
6
|
id: string;
|
7
7
|
value?: string;
|
@@ -37,10 +37,14 @@ 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;
|
43
48
|
isDisabled?: boolean;
|
44
49
|
onDelete?: (id?: number) => void;
|
45
50
|
}
|
46
|
-
export {};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { UseSelectFieldProps, UseSelectFieldReturnProps } from '../hooks/useSelectField/useSelectField';
|
3
|
+
import { SharedFieldProps } from './shared/fieldProps';
|
4
|
+
import { Status } from './item';
|
5
|
+
import { StyleProps } from './shared';
|
6
|
+
export interface SelectFieldProps<T> extends Omit<StyleProps, 'direction'>, UseSelectFieldProps<T> {
|
7
|
+
status?: Status;
|
8
|
+
slots?: {
|
9
|
+
leftOfData?: React.ReactNode;
|
10
|
+
inContainer?: React.ReactNode;
|
11
|
+
};
|
12
|
+
'data-testid'?: string;
|
13
|
+
}
|
14
|
+
export interface SelectFieldBaseProps extends UseSelectFieldReturnProps<object>, SharedFieldProps {
|
15
|
+
slots?: {
|
16
|
+
inContainer?: React.ReactNode;
|
17
|
+
leftOfData?: React.ReactNode;
|
18
|
+
};
|
19
|
+
name?: string;
|
20
|
+
placeholder?: string;
|
21
|
+
trigger?: React.ReactNode;
|
22
|
+
defaultText?: string;
|
23
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Status } from '../item';
|
2
|
+
import { LabelModeProps } from '../label';
|
3
|
+
export interface SharedFieldProps {
|
4
|
+
status?: Status;
|
5
|
+
label?: string;
|
6
|
+
/** Text rendered below the textarea. */
|
7
|
+
helperText?: string;
|
8
|
+
/** If present this prop will cause a help hint to render in the label of the field. */
|
9
|
+
hintText?: string;
|
10
|
+
/** A string designating whether or not the label is a float label. */
|
11
|
+
labelMode?: LabelModeProps;
|
12
|
+
}
|
@@ -1,16 +1,10 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { ThemeUICSSObject } from 'theme-ui';
|
3
3
|
import { ContainerProps, ControlProps } from '../hooks/useField/useField';
|
4
|
+
import { SharedFieldProps } from './shared/fieldProps';
|
4
5
|
import { HelpHintProps } from './helpHint';
|
5
|
-
import { Status } from './item';
|
6
|
-
import { LabelModeProps } from './label';
|
7
6
|
import { AriaRole, StyleProps, ValidPositiveInteger } from './shared';
|
8
|
-
export interface TextFieldProps extends StyleProps {
|
9
|
-
helperText?: string;
|
10
|
-
/** The rendered label for the field. */
|
11
|
-
label?: React.ReactNode;
|
12
|
-
/** A string designating whether or not the label is a float label. */
|
13
|
-
labelMode?: LabelModeProps;
|
7
|
+
export interface TextFieldProps extends StyleProps, SharedFieldProps {
|
14
8
|
/** The unique identifier for the input element. */
|
15
9
|
id?: string;
|
16
10
|
/** The name for the input element. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). */
|
@@ -21,8 +15,6 @@ export interface TextFieldProps extends StyleProps {
|
|
21
15
|
defaultValue?: string;
|
22
16
|
/** Whether the input element is automatically focused when loaded onto the page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautofocus). */
|
23
17
|
hasAutoFocus?: boolean;
|
24
|
-
/** If present this prop will cause a help hint to render in the label of the field. */
|
25
|
-
hintText?: string;
|
26
18
|
/** Whether the field has a status indicator. */
|
27
19
|
hasNoStatusIndicator?: boolean;
|
28
20
|
helpHintProps?: HelpHintProps;
|
@@ -54,7 +46,6 @@ export interface TextFieldProps extends StyleProps {
|
|
54
46
|
type?: string;
|
55
47
|
/** Props object that is spread directly into the input wrapper element. */
|
56
48
|
wrapperProps?: Record<string, unknown>;
|
57
|
-
status?: Status;
|
58
49
|
variant?: string;
|
59
50
|
controlProps?: ControlProps;
|
60
51
|
containerProps?: ContainerProps;
|
@@ -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
|
});
|
@@ -10,6 +10,7 @@ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
10
10
|
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; }
|
11
11
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
12
12
|
// Styles for default select and variants go here.
|
13
|
+
|
13
14
|
import { text } from '../../styles/variants';
|
14
15
|
import { defaultFocus, input } from '../Input/Input.styles';
|
15
16
|
var activeFloatLabel = {
|
@@ -12,108 +12,35 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
12
12
|
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; }
|
13
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
14
14
|
import React, { forwardRef } from 'react';
|
15
|
-
import PropTypes from 'prop-types';
|
16
15
|
import { usePropWarning, useSelectField } from '../../hooks';
|
17
|
-
import {
|
18
|
-
import { inputFieldAttributesBasePropTypes } from '../../utils/docUtils/fieldAttributes';
|
19
|
-
import { statusDefaultProp, statusPropTypes } from '../../utils/docUtils/statusProp';
|
16
|
+
import { statusDefaultProp } from '../../utils/docUtils/statusProp';
|
20
17
|
import SelectFieldBase from '../SelectFieldBase';
|
21
18
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
22
19
|
var SelectField = /*#__PURE__*/forwardRef(function (props, ref) {
|
23
|
-
|
20
|
+
/* istanbul ignore next */
|
21
|
+
var status = props.status,
|
22
|
+
_props$placeholder = props.placeholder,
|
23
|
+
placeholder = _props$placeholder === void 0 ? 'Select' : _props$placeholder,
|
24
|
+
_props$align = props.align,
|
25
|
+
align = _props$align === void 0 ? 'start' : _props$align,
|
26
|
+
_props$direction = props.direction,
|
27
|
+
direction = _props$direction === void 0 ? 'bottom' : _props$direction,
|
28
|
+
_props$scrollBoxProps = props.scrollBoxProps,
|
29
|
+
scrollBoxProps = _props$scrollBoxProps === void 0 ? {
|
30
|
+
margin: '300px'
|
31
|
+
} : _props$scrollBoxProps;
|
24
32
|
usePropWarning(props, 'disabled', 'isDisabled');
|
25
33
|
var _useSelectField = useSelectField(props, ref),
|
26
34
|
selectFieldProps = _extends({}, (_objectDestructuringEmpty(_useSelectField), _useSelectField));
|
27
|
-
return ___EmotionJSX(SelectFieldBase, _extends({
|
35
|
+
return ___EmotionJSX(SelectFieldBase, _extends({
|
36
|
+
placeholder: placeholder,
|
37
|
+
align: align,
|
38
|
+
direction: direction,
|
39
|
+
scrollBoxProps: scrollBoxProps
|
40
|
+
}, props, selectFieldProps, {
|
28
41
|
"aria-invalid": status === 'error' && true
|
29
42
|
}));
|
30
43
|
});
|
31
|
-
SelectField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
32
|
-
/** Alignment of the popover menu relative to the trigger. */
|
33
|
-
align: PropTypes.oneOf(['start', 'end', 'middle']),
|
34
|
-
/** Where the popover menu opens relative to its trigger. */
|
35
|
-
direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
|
36
|
-
/** The initial selected key in the collection (uncontrolled). */
|
37
|
-
defaultSelectedKey: PropTypes.string,
|
38
|
-
/** Default text rendered if no option is selected. Deprecated. */
|
39
|
-
defaultText: PropTypes.string,
|
40
|
-
/** Array of keys to disable within the options list. */
|
41
|
-
disabledKeys: PropTypes.arrayOf(PropTypes.string),
|
42
|
-
/** Whether the collection allows empty selection. */
|
43
|
-
hasNoEmptySelection: PropTypes.bool,
|
44
|
-
/** Whether the field has a status indicator. */
|
45
|
-
hasNoStatusIndicator: PropTypes.bool,
|
46
|
-
/** Text rendered below the input. */
|
47
|
-
helperText: PropTypes.node,
|
48
|
-
/** If present this prop will cause a help hint to render in the label of the field. */
|
49
|
-
hintText: PropTypes.string,
|
50
|
-
/** Sets the default open state of the menu. */
|
51
|
-
isDefaultOpen: PropTypes.bool,
|
52
|
-
/** Whether the input is disabled. */
|
53
|
-
isDisabled: PropTypes.bool,
|
54
|
-
/** Whether the items are currently loading. */
|
55
|
-
isLoading: PropTypes.bool,
|
56
|
-
/** @ignore Whether the menu should automatically flip direction when space is limited. */
|
57
|
-
isNotFlippable: PropTypes.bool,
|
58
|
-
/** Sets the open state of the menu. */
|
59
|
-
isOpen: PropTypes.bool,
|
60
|
-
/** @ignore Whether the input can be selected but not changed by the user. */
|
61
|
-
isReadOnly: PropTypes.bool,
|
62
|
-
/** Whether user input is required on the input before form submission. */
|
63
|
-
isRequired: PropTypes.bool,
|
64
|
-
/**
|
65
|
-
* *For performance reasons, use this prop instead of Array.map when iteratively rendering Items*.
|
66
|
-
* For use with [dynamic collections](https://react-spectrum.adobe.com/react-stately/collections.html#dynamic-collections).
|
67
|
-
*/
|
68
|
-
items: PropTypes.arrayOf(PropTypes.shape({})),
|
69
|
-
/** The label for the select element. */
|
70
|
-
label: PropTypes.node,
|
71
|
-
/** The name for the select element, used when submitting a form. */
|
72
|
-
name: PropTypes.string,
|
73
|
-
/** Temporary text that occupies the text input when it is empty. */
|
74
|
-
placeholder: PropTypes.string,
|
75
|
-
/** The currently selected key in the collection (controlled). */
|
76
|
-
selectedKey: PropTypes.string,
|
77
|
-
/** Determines the textarea status indicator and helper text styling. Eg. float. */
|
78
|
-
labelMode: PropTypes.string,
|
79
|
-
/**
|
80
|
-
* Handler that is called when more items should be loaded, e.g. while scrolling near the bottom.
|
81
|
-
*
|
82
|
-
* () => any
|
83
|
-
*/
|
84
|
-
onLoadMore: PropTypes.func,
|
85
|
-
/**
|
86
|
-
* Method that is called when the open state of the menu changes.
|
87
|
-
*
|
88
|
-
* (isOpen: boolean) => void
|
89
|
-
*/
|
90
|
-
onOpenChange: PropTypes.func,
|
91
|
-
/**
|
92
|
-
* Handler that is called when the selection changes.
|
93
|
-
*
|
94
|
-
* (key: Key) => any
|
95
|
-
*/
|
96
|
-
onSelectionChange: PropTypes.func
|
97
|
-
}, inputFieldAttributesBasePropTypes), {}, {
|
98
|
-
/** Provides a way to insert markup in specified places. */
|
99
|
-
slots: PropTypes.shape({
|
100
|
-
/** The given node will be inserted before the text in field container. */
|
101
|
-
leftOfData: PropTypes.node,
|
102
|
-
/** The given node will be inserted into the field container. */
|
103
|
-
inContainer: PropTypes.node
|
104
|
-
}),
|
105
|
-
/**
|
106
|
-
* Props object passed along to `useSelect` from React Aria, `useSelectState` from React Stately,
|
107
|
-
* and/or the visible button representation for the select input.
|
108
|
-
*/
|
109
|
-
controlProps: PropTypes.shape({}),
|
110
|
-
/** Props object that is spread directly into the ScrollBox element. */
|
111
|
-
// /** Props object that is spread directly into the ScrollBox element. */
|
112
|
-
/** @ignore */
|
113
|
-
scrollBoxProps: PropTypes.shape({
|
114
|
-
maxHeight: PropTypes.string
|
115
|
-
})
|
116
|
-
}, statusPropTypes), ariaAttributesBasePropTypes);
|
117
44
|
SelectField.defaultProps = _objectSpread({
|
118
45
|
placeholder: 'Select',
|
119
46
|
align: 'start',
|
@@ -328,7 +328,10 @@ export var HelperText = function HelperText() {
|
|
328
328
|
key: "yellow"
|
329
329
|
}, "Yellow"));
|
330
330
|
};
|
331
|
-
var options = _mapInstanceProperty(_context = _fillInstanceProperty(_context2 = new Array(200)).call(_context2
|
331
|
+
var options = _mapInstanceProperty(_context = _fillInstanceProperty(_context2 = new Array(200)).call(_context2, {
|
332
|
+
key: 'string',
|
333
|
+
name: 'string'
|
334
|
+
})).call(_context, function (_, i) {
|
332
335
|
return {
|
333
336
|
key: "option-".concat(i),
|
334
337
|
name: "Option ".concat(i)
|
@@ -17,7 +17,7 @@ var items = [{
|
|
17
17
|
var withSection = [{
|
18
18
|
name: 'Animals',
|
19
19
|
key: 'Animals',
|
20
|
-
|
20
|
+
children: [{
|
21
21
|
name: 'Aardvark'
|
22
22
|
}, {
|
23
23
|
name: 'Kangaroo'
|
@@ -27,7 +27,7 @@ var withSection = [{
|
|
27
27
|
}, {
|
28
28
|
name: 'People',
|
29
29
|
key: 'People',
|
30
|
-
|
30
|
+
children: [{
|
31
31
|
name: 'Michael'
|
32
32
|
}, {
|
33
33
|
name: 'Dwight'
|
@@ -37,7 +37,7 @@ var withSection = [{
|
|
37
37
|
}, {
|
38
38
|
name: null,
|
39
39
|
key: 'Fruit',
|
40
|
-
|
40
|
+
children: [{
|
41
41
|
name: 'Apple'
|
42
42
|
}, {
|
43
43
|
name: 'Strawberry'
|
@@ -78,7 +78,7 @@ var getComponentWithSections = function getComponentWithSections() {
|
|
78
78
|
}), function (section) {
|
79
79
|
return ___EmotionJSX(Section, {
|
80
80
|
key: section.key,
|
81
|
-
items: section.
|
81
|
+
items: section.children,
|
82
82
|
title: section.name
|
83
83
|
}, function (item) {
|
84
84
|
return ___EmotionJSX(Item, {
|
@@ -152,4 +152,20 @@ test('a blank title does not render', function () {
|
|
152
152
|
var button = screen.getByRole('button');
|
153
153
|
userEvent.click(button);
|
154
154
|
expect(screen.queryByText('Fruit')).not.toBeInTheDocument();
|
155
|
+
});
|
156
|
+
test('renders placeholder text', function () {
|
157
|
+
var placeholderText = 'Select an option';
|
158
|
+
getComponent({
|
159
|
+
placeholder: placeholderText
|
160
|
+
});
|
161
|
+
var placeholder = screen.getByText(placeholderText);
|
162
|
+
expect(placeholder).toBeInTheDocument();
|
163
|
+
});
|
164
|
+
test('renders default placeholder text', function () {
|
165
|
+
var placeholderText = 'Select';
|
166
|
+
getComponent({
|
167
|
+
placeholder: placeholderText
|
168
|
+
});
|
169
|
+
var placeholder = screen.getByText(placeholderText);
|
170
|
+
expect(placeholder).toBeInTheDocument();
|
155
171
|
});
|