@atlaskit/link-create 0.10.0 → 1.0.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/CHANGELOG.md +6 -0
- package/dist/cjs/controllers/create-field/index.js +12 -0
- package/dist/cjs/controllers/create-field/main.js +62 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/ui/create-form/async-select/main.js +117 -35
- package/dist/cjs/ui/create-form/form-footer/main.js +9 -2
- package/dist/cjs/ui/create-form/form-spy/index.js +27 -0
- package/dist/cjs/ui/create-form/index.js +15 -1
- package/dist/cjs/ui/create-form/main.js +20 -10
- package/dist/cjs/ui/create-form/select/index.js +12 -0
- package/dist/cjs/ui/create-form/select/main.js +50 -0
- package/dist/cjs/ui/create-form/select/types.js +5 -0
- package/dist/cjs/ui/create-form/textfield/main.js +26 -48
- package/dist/cjs/ui/index.js +15 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/controllers/create-field/index.js +1 -0
- package/dist/es2019/controllers/create-field/main.js +57 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/ui/create-form/async-select/main.js +75 -34
- package/dist/es2019/ui/create-form/form-footer/main.js +9 -2
- package/dist/es2019/ui/create-form/form-spy/index.js +18 -0
- package/dist/es2019/ui/create-form/index.js +3 -1
- package/dist/es2019/ui/create-form/main.js +25 -16
- package/dist/es2019/ui/create-form/select/index.js +1 -0
- package/dist/es2019/ui/create-form/select/main.js +40 -0
- package/dist/es2019/ui/create-form/textfield/main.js +24 -48
- package/dist/es2019/ui/index.js +3 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/controllers/create-field/index.js +1 -0
- package/dist/esm/controllers/create-field/main.js +56 -0
- package/dist/esm/controllers/create-field/types.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/ui/create-form/async-select/main.js +118 -36
- package/dist/esm/ui/create-form/form-footer/main.js +9 -2
- package/dist/esm/ui/create-form/form-spy/index.js +19 -0
- package/dist/esm/ui/create-form/index.js +3 -1
- package/dist/esm/ui/create-form/main.js +19 -8
- package/dist/esm/ui/create-form/select/index.js +1 -0
- package/dist/esm/ui/create-form/select/main.js +42 -0
- package/dist/esm/ui/create-form/select/types.js +1 -0
- package/dist/esm/ui/create-form/textfield/main.js +25 -47
- package/dist/esm/ui/index.js +3 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/common/utils/form/index.d.ts +2 -2
- package/dist/types/controllers/create-field/index.d.ts +1 -0
- package/dist/types/controllers/create-field/main.d.ts +3 -0
- package/dist/types/controllers/create-field/types.d.ts +24 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/ui/create-form/async-select/main.d.ts +5 -5
- package/dist/types/ui/create-form/async-select/types.d.ts +9 -4
- package/dist/types/ui/create-form/form-spy/index.d.ts +12 -0
- package/dist/types/ui/create-form/index.d.ts +2 -0
- package/dist/types/ui/create-form/main.d.ts +2 -1
- package/dist/types/ui/create-form/select/index.d.ts +1 -0
- package/dist/types/ui/create-form/select/main.d.ts +12 -0
- package/dist/types/ui/create-form/select/types.d.ts +18 -0
- package/dist/types/ui/create-form/textfield/main.d.ts +2 -1
- package/dist/types/ui/index.d.ts +2 -0
- package/dist/types-ts4.5/common/utils/form/index.d.ts +2 -2
- package/dist/types-ts4.5/controllers/create-field/index.d.ts +1 -0
- package/dist/types-ts4.5/controllers/create-field/main.d.ts +3 -0
- package/dist/types-ts4.5/controllers/create-field/types.d.ts +24 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/create-form/async-select/main.d.ts +5 -5
- package/dist/types-ts4.5/ui/create-form/async-select/types.d.ts +9 -4
- package/dist/types-ts4.5/ui/create-form/form-spy/index.d.ts +12 -0
- package/dist/types-ts4.5/ui/create-form/index.d.ts +2 -0
- package/dist/types-ts4.5/ui/create-form/main.d.ts +2 -1
- package/dist/types-ts4.5/ui/create-form/select/index.d.ts +1 -0
- package/dist/types-ts4.5/ui/create-form/select/main.d.ts +12 -0
- package/dist/types-ts4.5/ui/create-form/select/types.d.ts +18 -0
- package/dist/types-ts4.5/ui/create-form/textfield/main.d.ts +2 -1
- package/dist/types-ts4.5/ui/index.d.ts +2 -0
- package/example-helpers/mock-plugin-form.tsx +1 -3
- package/package.json +6 -3
- package/report.api.md +54 -11
- package/tmp/api-report-tmp.d.ts +32 -4
- package/dist/cjs/ui/group-selection/index.js +0 -22
- package/dist/es2019/ui/group-selection/index.js +0 -16
- package/dist/esm/ui/group-selection/index.js +0 -15
- package/dist/types/ui/group-selection/index.d.ts +0 -4
- package/dist/types/ui/group-selection/types.d.ts +0 -12
- package/dist/types-ts4.5/ui/group-selection/index.d.ts +0 -4
- package/dist/types-ts4.5/ui/group-selection/types.d.ts +0 -12
- /package/dist/cjs/{ui/group-selection → controllers/create-field}/types.js +0 -0
- /package/dist/es2019/{ui/group-selection → controllers/create-field}/types.js +0 -0
- /package/dist/{esm/ui/group-selection → es2019/ui/create-form/select}/types.js +0 -0
|
@@ -1,55 +1,137 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["
|
|
5
|
+
var _excluded = ["id", "name", "label", "isRequired", "validators", "validationHelpText", "testId", "defaultOption", "loadOptions"],
|
|
6
|
+
_excluded2 = ["fieldId"];
|
|
7
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
8
|
/** @jsx jsx */
|
|
5
|
-
import {
|
|
9
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
6
10
|
import { jsx } from '@emotion/react';
|
|
7
|
-
import
|
|
11
|
+
import debounce from 'debounce-promise';
|
|
12
|
+
import { useForm } from 'react-final-form';
|
|
8
13
|
import { AsyncSelect as AkAsyncSelect } from '@atlaskit/select';
|
|
9
|
-
import {
|
|
10
|
-
import { useFormContext } from '../../../controllers/form-context';
|
|
14
|
+
import { CreateField } from '../../../controllers/create-field';
|
|
11
15
|
export var TEST_ID = 'link-create-async-select';
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
|
-
* An async select utilising the Atlaskit AsyncSelect and Field
|
|
14
|
-
* Validation is handled by the form
|
|
15
|
-
* the handleSubmit function passed to the form <Form> that
|
|
16
|
-
* of this
|
|
18
|
+
* An async select utilising the Atlaskit AsyncSelect and Field components from
|
|
19
|
+
* `@atlaskit/form`. Validation is handled by the form on form submission. Any
|
|
20
|
+
* errors returned by the handleSubmit function passed to the form <Form> that
|
|
21
|
+
* have a key matching the `name` of this field are shown below the field.
|
|
17
22
|
*/
|
|
18
23
|
export function AsyncSelect(_ref) {
|
|
19
|
-
var
|
|
24
|
+
var id = _ref.id,
|
|
20
25
|
name = _ref.name,
|
|
21
|
-
|
|
26
|
+
label = _ref.label,
|
|
22
27
|
isRequired = _ref.isRequired,
|
|
28
|
+
validators = _ref.validators,
|
|
29
|
+
validationHelpText = _ref.validationHelpText,
|
|
23
30
|
_ref$testId = _ref.testId,
|
|
24
31
|
testId = _ref$testId === void 0 ? TEST_ID : _ref$testId,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
|
|
32
|
+
propsDefaultValue = _ref.defaultOption,
|
|
33
|
+
loadOptions = _ref.loadOptions,
|
|
34
|
+
restProps = _objectWithoutProperties(_ref, _excluded);
|
|
35
|
+
var _useForm = useForm(),
|
|
36
|
+
mutators = _useForm.mutators;
|
|
37
|
+
var _useState = useState(propsDefaultValue),
|
|
38
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
+
defaultValue = _useState2[0],
|
|
40
|
+
setDefaultValue = _useState2[1];
|
|
41
|
+
var _useState3 = useState(false),
|
|
42
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
43
|
+
isLoadingDefaultOptions = _useState4[0],
|
|
44
|
+
setIsLoadingDefaultOptions = _useState4[1];
|
|
45
|
+
var _useState5 = useState([]),
|
|
46
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
47
|
+
defaultOptions = _useState6[0],
|
|
48
|
+
setDefaultOptions = _useState6[1];
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
var current = true;
|
|
51
|
+
var fetch = /*#__PURE__*/function () {
|
|
52
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
53
|
+
var query,
|
|
54
|
+
options,
|
|
55
|
+
_args = arguments;
|
|
56
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
57
|
+
while (1) switch (_context.prev = _context.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
query = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
|
|
60
|
+
if (loadOptions) {
|
|
61
|
+
_context.next = 3;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
return _context.abrupt("return");
|
|
65
|
+
case 3:
|
|
66
|
+
_context.prev = 3;
|
|
67
|
+
/**
|
|
68
|
+
* If we are fetching default options, clear the
|
|
69
|
+
* value the user has set
|
|
70
|
+
*/
|
|
71
|
+
mutators.setField(name, null);
|
|
72
|
+
setIsLoadingDefaultOptions(true);
|
|
73
|
+
setDefaultOptions([]);
|
|
74
|
+
_context.next = 9;
|
|
75
|
+
return loadOptions(query);
|
|
76
|
+
case 9:
|
|
77
|
+
options = _context.sent;
|
|
78
|
+
if (current) {
|
|
79
|
+
setDefaultOptions(options);
|
|
80
|
+
setIsLoadingDefaultOptions(false);
|
|
81
|
+
}
|
|
82
|
+
_context.next = 16;
|
|
83
|
+
break;
|
|
84
|
+
case 13:
|
|
85
|
+
_context.prev = 13;
|
|
86
|
+
_context.t0 = _context["catch"](3);
|
|
87
|
+
if (current) {
|
|
88
|
+
setIsLoadingDefaultOptions(false);
|
|
89
|
+
}
|
|
90
|
+
case 16:
|
|
91
|
+
case "end":
|
|
92
|
+
return _context.stop();
|
|
93
|
+
}
|
|
94
|
+
}, _callee, null, [[3, 13]]);
|
|
95
|
+
}));
|
|
96
|
+
return function fetch() {
|
|
97
|
+
return _ref2.apply(this, arguments);
|
|
98
|
+
};
|
|
99
|
+
}();
|
|
100
|
+
fetch();
|
|
101
|
+
return function () {
|
|
102
|
+
current = false;
|
|
103
|
+
};
|
|
104
|
+
}, [loadOptions, setIsLoadingDefaultOptions, setDefaultOptions, mutators, name]);
|
|
30
105
|
useEffect(function () {
|
|
31
|
-
|
|
32
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Mutate the form state to set a default value for this field
|
|
108
|
+
* if `defaultOption` is a prop and we have not set a value for it yet
|
|
109
|
+
*/
|
|
110
|
+
if (!defaultValue && propsDefaultValue) {
|
|
111
|
+
setDefaultValue(propsDefaultValue);
|
|
112
|
+
mutators.setField(name, propsDefaultValue);
|
|
33
113
|
}
|
|
34
|
-
}, [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
114
|
+
}, [defaultValue, propsDefaultValue, name, mutators]);
|
|
115
|
+
var debouncedLoadOptions = useMemo(function () {
|
|
116
|
+
return loadOptions ? debounce(loadOptions, 300) : undefined;
|
|
117
|
+
}, [loadOptions]);
|
|
118
|
+
return jsx(CreateField, {
|
|
119
|
+
id: id,
|
|
38
120
|
name: name,
|
|
39
121
|
label: label,
|
|
40
122
|
isRequired: isRequired,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return jsx(
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
})
|
|
123
|
+
validators: validators,
|
|
124
|
+
validationHelpText: validationHelpText,
|
|
125
|
+
testId: testId
|
|
126
|
+
}, function (_ref3) {
|
|
127
|
+
var fieldId = _ref3.fieldId,
|
|
128
|
+
fieldProps = _objectWithoutProperties(_ref3, _excluded2);
|
|
129
|
+
return jsx(AkAsyncSelect, _extends({
|
|
130
|
+
inputId: fieldId
|
|
131
|
+
}, fieldProps, restProps, {
|
|
132
|
+
loadOptions: debouncedLoadOptions,
|
|
133
|
+
defaultOptions: defaultOptions,
|
|
134
|
+
isLoading: isLoadingDefaultOptions
|
|
135
|
+
}));
|
|
136
|
+
});
|
|
55
137
|
}
|
|
@@ -3,9 +3,13 @@ import { css, jsx } from '@emotion/react';
|
|
|
3
3
|
import { useIntl } from 'react-intl-next';
|
|
4
4
|
import Button, { ButtonGroup } from '@atlaskit/button';
|
|
5
5
|
import LoadingButton from '@atlaskit/button/loading-button';
|
|
6
|
-
import { FormFooter } from '@atlaskit/form';
|
|
7
6
|
import ErrorIcon from '@atlaskit/icon/glyph/error';
|
|
8
7
|
import { messages } from './messages';
|
|
8
|
+
var formFooterWrapperStyles = css({
|
|
9
|
+
display: 'flex',
|
|
10
|
+
marginTop: "var(--ds-space-300, 24px)",
|
|
11
|
+
justifyContent: 'flex-end'
|
|
12
|
+
});
|
|
9
13
|
var errorStyles = css({
|
|
10
14
|
display: 'flex',
|
|
11
15
|
alignItems: 'center',
|
|
@@ -17,7 +21,10 @@ export function CreateFormFooter(_ref) {
|
|
|
17
21
|
submitting = _ref.submitting,
|
|
18
22
|
testId = _ref.testId;
|
|
19
23
|
var intl = useIntl();
|
|
20
|
-
return jsx(
|
|
24
|
+
return jsx("footer", {
|
|
25
|
+
"data-testid": "".concat(testId, "-footer"),
|
|
26
|
+
css: formFooterWrapperStyles
|
|
27
|
+
}, formErrorMessage && jsx("div", {
|
|
21
28
|
css: errorStyles,
|
|
22
29
|
"data-testid": "".concat(testId, "-error")
|
|
23
30
|
}, jsx(ErrorIcon, {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormSpy as FinalFormSpy } from 'react-final-form';
|
|
3
|
+
/**
|
|
4
|
+
* Lightweight wrapper around the react-final-form
|
|
5
|
+
* FormSpy component so that we can control selectively
|
|
6
|
+
* how much of the API we are commited to.
|
|
7
|
+
*/
|
|
8
|
+
export var FormSpy = function FormSpy(_ref) {
|
|
9
|
+
var children = _ref.children;
|
|
10
|
+
return /*#__PURE__*/React.createElement(FinalFormSpy, {
|
|
11
|
+
subscription: {
|
|
12
|
+
values: true
|
|
13
|
+
}
|
|
14
|
+
}, function (props) {
|
|
15
|
+
return children({
|
|
16
|
+
values: props.values
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { CreateForm } from './main';
|
|
2
|
+
export { Select } from './select';
|
|
2
3
|
export { AsyncSelect } from './async-select';
|
|
3
4
|
export { CreateFormLoader } from './form-loader';
|
|
4
|
-
export { TextField } from './textfield';
|
|
5
|
+
export { TextField } from './textfield';
|
|
6
|
+
export { FormSpy } from './form-spy';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
var _excluded = ["submitting"];
|
|
3
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
5
|
/** @jsx jsx */
|
|
5
6
|
import { useCallback } from 'react';
|
|
6
7
|
import { css, jsx } from '@emotion/react';
|
|
8
|
+
import { Form } from 'react-final-form';
|
|
7
9
|
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
8
|
-
import Form from '@atlaskit/form';
|
|
9
10
|
import { ANALYTICS_CHANNEL, CREATE_FORM_MAX_WIDTH_IN_PX } from '../../common/constants';
|
|
10
11
|
import createEventPayload from '../../common/utils/analytics/analytics.codegen';
|
|
11
12
|
import { useFormContext } from '../../controllers/form-context';
|
|
@@ -25,7 +26,8 @@ export var CreateForm = function CreateForm(_ref) {
|
|
|
25
26
|
onSubmit = _ref.onSubmit,
|
|
26
27
|
onCancel = _ref.onCancel,
|
|
27
28
|
isLoading = _ref.isLoading,
|
|
28
|
-
hideFooter = _ref.hideFooter
|
|
29
|
+
hideFooter = _ref.hideFooter,
|
|
30
|
+
initialValues = _ref.initialValues;
|
|
29
31
|
var _useAnalyticsEvents = useAnalyticsEvents(),
|
|
30
32
|
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
31
33
|
var _useFormContext = useFormContext(),
|
|
@@ -68,15 +70,24 @@ export var CreateForm = function CreateForm(_ref) {
|
|
|
68
70
|
return jsx(CreateFormLoader, null);
|
|
69
71
|
}
|
|
70
72
|
return jsx(Form, {
|
|
71
|
-
onSubmit: handleSubmit
|
|
73
|
+
onSubmit: handleSubmit,
|
|
74
|
+
initialValues: initialValues,
|
|
75
|
+
mutators: {
|
|
76
|
+
setField: function setField(args, state, tools) {
|
|
77
|
+
tools.changeValue(state, args[0], function () {
|
|
78
|
+
return args[1];
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
72
82
|
}, function (_ref3) {
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
return jsx("form",
|
|
83
|
+
var submitting = _ref3.submitting,
|
|
84
|
+
formProps = _objectWithoutProperties(_ref3, _excluded);
|
|
85
|
+
return jsx("form", {
|
|
86
|
+
onSubmit: formProps.handleSubmit,
|
|
76
87
|
name: "link-create-form",
|
|
77
88
|
"data-testid": testId,
|
|
78
89
|
css: formStyles
|
|
79
|
-
}
|
|
90
|
+
}, jsx("div", null, children), !hideFooter && jsx(CreateFormFooter, {
|
|
80
91
|
formErrorMessage: formErrorMessage,
|
|
81
92
|
handleCancel: handleCancel,
|
|
82
93
|
submitting: submitting,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Select } from './main';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["id", "name", "label", "isRequired", "validators", "validationHelpText", "testId"],
|
|
4
|
+
_excluded2 = ["fieldId"];
|
|
5
|
+
/** @jsx jsx */
|
|
6
|
+
|
|
7
|
+
import { jsx } from '@emotion/react';
|
|
8
|
+
import AkSelect from '@atlaskit/select';
|
|
9
|
+
import { CreateField } from '../../../controllers/create-field';
|
|
10
|
+
export var TEST_ID = 'link-create-select';
|
|
11
|
+
/**
|
|
12
|
+
* A select utilising the Atlaskit Select and Field components from
|
|
13
|
+
* `@atlaskit/form`. Validation is handled by the form on form submission. Any
|
|
14
|
+
* errors returned by the handleSubmit function passed to the form <Form> that
|
|
15
|
+
* have a key matching the `name` of this field are shown below the field.
|
|
16
|
+
*/
|
|
17
|
+
export function Select(_ref) {
|
|
18
|
+
var id = _ref.id,
|
|
19
|
+
name = _ref.name,
|
|
20
|
+
label = _ref.label,
|
|
21
|
+
isRequired = _ref.isRequired,
|
|
22
|
+
validators = _ref.validators,
|
|
23
|
+
validationHelpText = _ref.validationHelpText,
|
|
24
|
+
_ref$testId = _ref.testId,
|
|
25
|
+
testId = _ref$testId === void 0 ? TEST_ID : _ref$testId,
|
|
26
|
+
restProps = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
+
return jsx(CreateField, {
|
|
28
|
+
id: id,
|
|
29
|
+
name: name,
|
|
30
|
+
label: label,
|
|
31
|
+
isRequired: isRequired,
|
|
32
|
+
validators: validators,
|
|
33
|
+
validationHelpText: validationHelpText,
|
|
34
|
+
testId: testId
|
|
35
|
+
}, function (_ref2) {
|
|
36
|
+
var fieldId = _ref2.fieldId,
|
|
37
|
+
fieldProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
38
|
+
return jsx(AkSelect, _extends({
|
|
39
|
+
inputId: fieldId
|
|
40
|
+
}, fieldProps, restProps));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["
|
|
3
|
+
var _excluded = ["id", "name", "label", "isRequired", "validators", "validationHelpText", "testId"],
|
|
4
|
+
_excluded2 = ["fieldId"];
|
|
4
5
|
/** @jsx jsx */
|
|
5
|
-
import { Fragment, useEffect } from 'react';
|
|
6
6
|
import { jsx } from '@emotion/react';
|
|
7
|
-
import { ErrorMessage, Field, HelperMessage } from '@atlaskit/form';
|
|
8
7
|
import AkTextfield from '@atlaskit/textfield';
|
|
9
|
-
import {
|
|
10
|
-
import { useFormContext } from '../../../controllers/form-context';
|
|
8
|
+
import { CreateField } from '../../../controllers/create-field';
|
|
11
9
|
export var TEST_ID = 'link-create-text-field';
|
|
12
10
|
|
|
13
11
|
/**
|
|
@@ -18,50 +16,30 @@ export var TEST_ID = 'link-create-text-field';
|
|
|
18
16
|
*/
|
|
19
17
|
|
|
20
18
|
export function TextField(_ref) {
|
|
21
|
-
var
|
|
19
|
+
var id = _ref.id,
|
|
22
20
|
name = _ref.name,
|
|
21
|
+
label = _ref.label,
|
|
22
|
+
isRequired = _ref.isRequired,
|
|
23
|
+
validators = _ref.validators,
|
|
24
|
+
validationHelpText = _ref.validationHelpText,
|
|
23
25
|
_ref$testId = _ref.testId,
|
|
24
26
|
testId = _ref$testId === void 0 ? TEST_ID : _ref$testId,
|
|
25
|
-
validationHelpText = _ref.validationHelpText,
|
|
26
|
-
validators = _ref.validators,
|
|
27
|
-
defaultValue = _ref.defaultValue,
|
|
28
|
-
isRequired = _ref.isRequired,
|
|
29
27
|
restProps = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
name: name,
|
|
48
|
-
label: label,
|
|
49
|
-
isRequired: isRequired,
|
|
50
|
-
defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : ''
|
|
51
|
-
}, function (_ref2) {
|
|
52
|
-
var fieldProps = _ref2.fieldProps,
|
|
53
|
-
meta = _ref2.meta,
|
|
54
|
-
error = _ref2.error;
|
|
55
|
-
var isInvalid = validateSubmitErrors(meta);
|
|
56
|
-
return jsx(Fragment, null, jsx(AkTextfield, _extends({}, fieldProps, restProps, {
|
|
57
|
-
testId: testId,
|
|
58
|
-
isInvalid: isInvalid,
|
|
59
|
-
isRequired: false // Remove the default browser validation
|
|
60
|
-
})), !error && validationHelpText && jsx(HelperMessage, {
|
|
61
|
-
testId: "".concat(testId, "-helper-message")
|
|
62
|
-
}, validationHelpText), error && isInvalid && jsx(ErrorMessage, {
|
|
63
|
-
testId: "".concat(testId, "-error-message")
|
|
64
|
-
}, error));
|
|
65
|
-
})
|
|
66
|
-
);
|
|
28
|
+
return jsx(CreateField, {
|
|
29
|
+
id: id,
|
|
30
|
+
name: name,
|
|
31
|
+
label: label,
|
|
32
|
+
isRequired: isRequired,
|
|
33
|
+
validators: validators,
|
|
34
|
+
validationHelpText: validationHelpText,
|
|
35
|
+
testId: testId
|
|
36
|
+
}, function (_ref2) {
|
|
37
|
+
var fieldId = _ref2.fieldId,
|
|
38
|
+
fieldProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
39
|
+
return jsx(AkTextfield, _extends({
|
|
40
|
+
id: fieldId
|
|
41
|
+
}, fieldProps, restProps, {
|
|
42
|
+
isRequired: false // Remove the default browser validation
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
67
45
|
}
|
package/dist/esm/ui/index.js
CHANGED
|
@@ -2,4 +2,6 @@ export { default } from './main';
|
|
|
2
2
|
export { TextField } from './create-form/textfield';
|
|
3
3
|
export { CreateForm } from './create-form/main';
|
|
4
4
|
export { CreateFormLoader } from './create-form/form-loader';
|
|
5
|
-
export {
|
|
5
|
+
export { Select } from './create-form/select';
|
|
6
|
+
export { AsyncSelect } from './create-form/async-select';
|
|
7
|
+
export { FormSpy } from './create-form/form-spy';
|
package/dist/esm/version.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FieldMetaState } from 'react-final-form';
|
|
2
2
|
/**
|
|
3
3
|
* This function checks if there have been changes since last submit
|
|
4
4
|
* to let a Field know if it should hide the error message until
|
|
5
5
|
* the next submit, or if it returns to the previous error state
|
|
6
6
|
*/
|
|
7
|
-
export declare const validateSubmitErrors: (meta:
|
|
7
|
+
export declare const validateSubmitErrors: (meta: FieldMetaState<any>) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CreateField } from './main';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FieldInputProps } from 'react-final-form';
|
|
3
|
+
import { Validator } from '../../common/types';
|
|
4
|
+
type FieldProps = FieldInputProps<any, HTMLElement> & {
|
|
5
|
+
fieldId: string;
|
|
6
|
+
isInvalid: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type CreateFieldProps = {
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Name passed to the <Field>.*/
|
|
11
|
+
name: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Optional text below the textfield explaining any requirements for a valid value.
|
|
15
|
+
* eg. "Must be 4 or more letters"
|
|
16
|
+
*/
|
|
17
|
+
validationHelpText?: string;
|
|
18
|
+
/** Validators for this field */
|
|
19
|
+
validators?: Validator[];
|
|
20
|
+
isRequired?: boolean;
|
|
21
|
+
testId: string;
|
|
22
|
+
children: (fieldProps: FieldProps) => React.ReactNode;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { CreateFormProps } from './ui/index';
|
|
2
2
|
export type { LinkCreateProps, LinkCreatePlugin, LinkCreateWithModalProps, CreatePayload, } from './common/types';
|
|
3
|
-
export { default, TextField, CreateForm, AsyncSelect, CreateFormLoader, } from './ui/index';
|
|
3
|
+
export { default, TextField, CreateForm, Select, AsyncSelect, CreateFormLoader, FormSpy, } from './ui/index';
|
|
4
4
|
export { useLinkCreateCallback, LinkCreateCallbackProvider, } from './controllers/callback-context';
|
|
5
5
|
export type { Validator, ValidatorMap } from './common/types';
|
|
@@ -3,9 +3,9 @@ import { OptionType } from '@atlaskit/select';
|
|
|
3
3
|
import { AsyncSelectProps } from './types';
|
|
4
4
|
export declare const TEST_ID = "link-create-async-select";
|
|
5
5
|
/**
|
|
6
|
-
* An async select utilising the Atlaskit AsyncSelect and Field
|
|
7
|
-
* Validation is handled by the form
|
|
8
|
-
* the handleSubmit function passed to the form <Form> that
|
|
9
|
-
* of this
|
|
6
|
+
* An async select utilising the Atlaskit AsyncSelect and Field components from
|
|
7
|
+
* `@atlaskit/form`. Validation is handled by the form on form submission. Any
|
|
8
|
+
* errors returned by the handleSubmit function passed to the form <Form> that
|
|
9
|
+
* have a key matching the `name` of this field are shown below the field.
|
|
10
10
|
*/
|
|
11
|
-
export declare function AsyncSelect<T = OptionType>({
|
|
11
|
+
export declare function AsyncSelect<T = OptionType>({ id, name, label, isRequired, validators, validationHelpText, testId, defaultOption: propsDefaultValue, loadOptions, ...restProps }: AsyncSelectProps<T>): jsx.JSX.Element;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { AsyncSelectProps as AKAsyncSelectProps, OptionType } from '@atlaskit/select';
|
|
1
|
+
import { AsyncSelectProps as AKAsyncSelectProps, GroupType, OptionType } from '@atlaskit/select';
|
|
2
2
|
import { Validator } from '../../../common/types';
|
|
3
|
-
export type AsyncSelectProps<T = OptionType> = AKAsyncSelectProps<T> & {
|
|
4
|
-
/** Name passed to the <Field
|
|
3
|
+
export type AsyncSelectProps<T = OptionType> = Omit<AKAsyncSelectProps<T>, 'loadOptions'> & {
|
|
4
|
+
/** Name passed to the <Field> */
|
|
5
5
|
name: string;
|
|
6
6
|
/** This should be properly internationalization-ed */
|
|
7
7
|
label: string;
|
|
8
8
|
/**
|
|
9
|
-
* Optional text below the
|
|
9
|
+
* Optional text below the field explaining any requirements for a valid value.
|
|
10
10
|
* eg. "Must be 4 or more letters"
|
|
11
11
|
*/
|
|
12
12
|
validationHelpText?: string;
|
|
@@ -15,4 +15,9 @@ export type AsyncSelectProps<T = OptionType> = AKAsyncSelectProps<T> & {
|
|
|
15
15
|
isRequired?: boolean;
|
|
16
16
|
/** Validators for this field */
|
|
17
17
|
validators?: Validator[];
|
|
18
|
+
/**
|
|
19
|
+
* Function to options to display in async select.
|
|
20
|
+
* **WARNING** Will refetch if function changes.
|
|
21
|
+
*/
|
|
22
|
+
loadOptions?: (inputValue: string) => Promise<T[] | GroupType<T>[]>;
|
|
18
23
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type FormSpyProps<T> = {
|
|
3
|
+
children: ({ values }: {
|
|
4
|
+
values: T;
|
|
5
|
+
}) => React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Lightweight wrapper around the react-final-form
|
|
9
|
+
* FormSpy component so that we can control selectively
|
|
10
|
+
* how much of the API we are commited to.
|
|
11
|
+
*/
|
|
12
|
+
export declare const FormSpy: <T extends Record<string, unknown>>({ children, }: FormSpyProps<T>) => JSX.Element;
|
|
@@ -8,6 +8,7 @@ export interface CreateFormProps<FormData> {
|
|
|
8
8
|
onCancel?: () => void;
|
|
9
9
|
isLoading?: boolean;
|
|
10
10
|
hideFooter?: boolean;
|
|
11
|
+
initialValues?: FormData;
|
|
11
12
|
}
|
|
12
13
|
export declare const TEST_ID = "link-create-form";
|
|
13
|
-
export declare const CreateForm: <FormData_1 extends Record<string, any> = {}>({ children, testId, onSubmit, onCancel, isLoading, hideFooter, }: CreateFormProps<FormData_1>) => jsx.JSX.Element;
|
|
14
|
+
export declare const CreateForm: <FormData_1 extends Record<string, any> = {}>({ children, testId, onSubmit, onCancel, isLoading, hideFooter, initialValues, }: CreateFormProps<FormData_1>) => jsx.JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Select } from './main';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react';
|
|
3
|
+
import { OptionType } from '@atlaskit/select';
|
|
4
|
+
import { SelectProps } from './types';
|
|
5
|
+
export declare const TEST_ID = "link-create-select";
|
|
6
|
+
/**
|
|
7
|
+
* A select utilising the Atlaskit Select and Field components from
|
|
8
|
+
* `@atlaskit/form`. Validation is handled by the form on form submission. Any
|
|
9
|
+
* errors returned by the handleSubmit function passed to the form <Form> that
|
|
10
|
+
* have a key matching the `name` of this field are shown below the field.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Select<T = OptionType>({ id, name, label, isRequired, validators, validationHelpText, testId, ...restProps }: SelectProps<T>): jsx.JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SelectProps as AKSelectProps, OptionType } from '@atlaskit/select';
|
|
2
|
+
import { Validator } from '../../../common/types';
|
|
3
|
+
export type SelectProps<T = OptionType> = AKSelectProps<T> & {
|
|
4
|
+
/** Name passed to the <Field> */
|
|
5
|
+
name: string;
|
|
6
|
+
/** This should be properly internationalization-ed */
|
|
7
|
+
label: string;
|
|
8
|
+
/**
|
|
9
|
+
* Optional text below the field explaining any requirements for a valid value.
|
|
10
|
+
* eg. "Must be 4 or more letters"
|
|
11
|
+
*/
|
|
12
|
+
validationHelpText?: string;
|
|
13
|
+
testId?: string;
|
|
14
|
+
/** Will display a red astrix next to the field title if true */
|
|
15
|
+
isRequired?: boolean;
|
|
16
|
+
/** Validators for this field */
|
|
17
|
+
validators?: Validator[];
|
|
18
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
1
2
|
import { jsx } from '@emotion/react';
|
|
2
3
|
import { TextFieldProps } from './types';
|
|
3
4
|
export declare const TEST_ID = "link-create-text-field";
|
|
@@ -7,4 +8,4 @@ export declare const TEST_ID = "link-create-text-field";
|
|
|
7
8
|
* the handleSubmit function passed to the form <Form> that have a key matching the `name`
|
|
8
9
|
* of this text field are shown above the field.
|
|
9
10
|
*/
|
|
10
|
-
export declare function TextField({
|
|
11
|
+
export declare function TextField({ id, name, label, isRequired, validators, validationHelpText, testId, ...restProps }: TextFieldProps): jsx.JSX.Element;
|
package/dist/types/ui/index.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export { TextField } from './create-form/textfield';
|
|
|
3
3
|
export { CreateForm } from './create-form/main';
|
|
4
4
|
export { CreateFormLoader } from './create-form/form-loader';
|
|
5
5
|
export type { CreateFormProps } from './create-form/main';
|
|
6
|
+
export { Select } from './create-form/select';
|
|
6
7
|
export { AsyncSelect } from './create-form/async-select';
|
|
8
|
+
export { FormSpy } from './create-form/form-spy';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FieldMetaState } from 'react-final-form';
|
|
2
2
|
/**
|
|
3
3
|
* This function checks if there have been changes since last submit
|
|
4
4
|
* to let a Field know if it should hide the error message until
|
|
5
5
|
* the next submit, or if it returns to the previous error state
|
|
6
6
|
*/
|
|
7
|
-
export declare const validateSubmitErrors: (meta:
|
|
7
|
+
export declare const validateSubmitErrors: (meta: FieldMetaState<any>) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CreateField } from './main';
|