@atlaskit/link-create 0.10.0 → 1.0.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.
Files changed (87) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/controllers/create-field/index.js +12 -0
  3. package/dist/cjs/controllers/create-field/main.js +62 -0
  4. package/dist/cjs/index.js +12 -0
  5. package/dist/cjs/ui/create-form/async-select/main.js +117 -35
  6. package/dist/cjs/ui/create-form/form-footer/main.js +9 -2
  7. package/dist/cjs/ui/create-form/form-spy/index.js +27 -0
  8. package/dist/cjs/ui/create-form/index.js +15 -1
  9. package/dist/cjs/ui/create-form/main.js +20 -10
  10. package/dist/cjs/ui/create-form/select/index.js +12 -0
  11. package/dist/cjs/ui/create-form/select/main.js +50 -0
  12. package/dist/cjs/ui/create-form/select/types.js +5 -0
  13. package/dist/cjs/ui/create-form/textfield/main.js +26 -48
  14. package/dist/cjs/ui/index.js +15 -1
  15. package/dist/cjs/version.json +1 -1
  16. package/dist/es2019/controllers/create-field/index.js +1 -0
  17. package/dist/es2019/controllers/create-field/main.js +57 -0
  18. package/dist/es2019/index.js +1 -1
  19. package/dist/es2019/ui/create-form/async-select/main.js +75 -34
  20. package/dist/es2019/ui/create-form/form-footer/main.js +9 -2
  21. package/dist/es2019/ui/create-form/form-spy/index.js +18 -0
  22. package/dist/es2019/ui/create-form/index.js +3 -1
  23. package/dist/es2019/ui/create-form/main.js +25 -16
  24. package/dist/es2019/ui/create-form/select/index.js +1 -0
  25. package/dist/es2019/ui/create-form/select/main.js +40 -0
  26. package/dist/es2019/ui/create-form/textfield/main.js +24 -48
  27. package/dist/es2019/ui/index.js +3 -1
  28. package/dist/es2019/version.json +1 -1
  29. package/dist/esm/controllers/create-field/index.js +1 -0
  30. package/dist/esm/controllers/create-field/main.js +56 -0
  31. package/dist/esm/controllers/create-field/types.js +1 -0
  32. package/dist/esm/index.js +1 -1
  33. package/dist/esm/ui/create-form/async-select/main.js +118 -36
  34. package/dist/esm/ui/create-form/form-footer/main.js +9 -2
  35. package/dist/esm/ui/create-form/form-spy/index.js +19 -0
  36. package/dist/esm/ui/create-form/index.js +3 -1
  37. package/dist/esm/ui/create-form/main.js +19 -8
  38. package/dist/esm/ui/create-form/select/index.js +1 -0
  39. package/dist/esm/ui/create-form/select/main.js +42 -0
  40. package/dist/esm/ui/create-form/select/types.js +1 -0
  41. package/dist/esm/ui/create-form/textfield/main.js +25 -47
  42. package/dist/esm/ui/index.js +3 -1
  43. package/dist/esm/version.json +1 -1
  44. package/dist/types/common/utils/form/index.d.ts +2 -2
  45. package/dist/types/controllers/create-field/index.d.ts +1 -0
  46. package/dist/types/controllers/create-field/main.d.ts +3 -0
  47. package/dist/types/controllers/create-field/types.d.ts +24 -0
  48. package/dist/types/index.d.ts +1 -1
  49. package/dist/types/ui/create-form/async-select/main.d.ts +5 -5
  50. package/dist/types/ui/create-form/async-select/types.d.ts +9 -4
  51. package/dist/types/ui/create-form/form-spy/index.d.ts +12 -0
  52. package/dist/types/ui/create-form/index.d.ts +2 -0
  53. package/dist/types/ui/create-form/main.d.ts +2 -1
  54. package/dist/types/ui/create-form/select/index.d.ts +1 -0
  55. package/dist/types/ui/create-form/select/main.d.ts +12 -0
  56. package/dist/types/ui/create-form/select/types.d.ts +18 -0
  57. package/dist/types/ui/create-form/textfield/main.d.ts +2 -1
  58. package/dist/types/ui/index.d.ts +2 -0
  59. package/dist/types-ts4.5/common/utils/form/index.d.ts +2 -2
  60. package/dist/types-ts4.5/controllers/create-field/index.d.ts +1 -0
  61. package/dist/types-ts4.5/controllers/create-field/main.d.ts +3 -0
  62. package/dist/types-ts4.5/controllers/create-field/types.d.ts +24 -0
  63. package/dist/types-ts4.5/index.d.ts +1 -1
  64. package/dist/types-ts4.5/ui/create-form/async-select/main.d.ts +5 -5
  65. package/dist/types-ts4.5/ui/create-form/async-select/types.d.ts +9 -4
  66. package/dist/types-ts4.5/ui/create-form/form-spy/index.d.ts +12 -0
  67. package/dist/types-ts4.5/ui/create-form/index.d.ts +2 -0
  68. package/dist/types-ts4.5/ui/create-form/main.d.ts +2 -1
  69. package/dist/types-ts4.5/ui/create-form/select/index.d.ts +1 -0
  70. package/dist/types-ts4.5/ui/create-form/select/main.d.ts +12 -0
  71. package/dist/types-ts4.5/ui/create-form/select/types.d.ts +18 -0
  72. package/dist/types-ts4.5/ui/create-form/textfield/main.d.ts +2 -1
  73. package/dist/types-ts4.5/ui/index.d.ts +2 -0
  74. package/example-helpers/mock-plugin-form.tsx +1 -3
  75. package/package.json +7 -4
  76. package/report.api.md +54 -11
  77. package/tmp/api-report-tmp.d.ts +32 -4
  78. package/dist/cjs/ui/group-selection/index.js +0 -22
  79. package/dist/es2019/ui/group-selection/index.js +0 -16
  80. package/dist/esm/ui/group-selection/index.js +0 -15
  81. package/dist/types/ui/group-selection/index.d.ts +0 -4
  82. package/dist/types/ui/group-selection/types.d.ts +0 -12
  83. package/dist/types-ts4.5/ui/group-selection/index.d.ts +0 -4
  84. package/dist/types-ts4.5/ui/group-selection/types.d.ts +0 -12
  85. /package/dist/cjs/{ui/group-selection → controllers/create-field}/types.js +0 -0
  86. /package/dist/es2019/{ui/group-selection → controllers/create-field}/types.js +0 -0
  87. /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 = ["label", "name", "validationHelpText", "isRequired", "testId", "validators", "defaultValue"];
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 { Fragment, useEffect } from 'react';
9
+ import { useEffect, useMemo, useState } from 'react';
6
10
  import { jsx } from '@emotion/react';
7
- import { ErrorMessage, Field, HelperMessage } from '@atlaskit/form';
11
+ import debounce from 'debounce-promise';
12
+ import { useForm } from 'react-final-form';
8
13
  import { AsyncSelect as AkAsyncSelect } from '@atlaskit/select';
9
- import { validateSubmitErrors } from '../../../common/utils/form';
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 objects from `@atlaskit/form`.
14
- * Validation is handled by the form as it is on form submission. Any errors returned by
15
- * the handleSubmit function passed to the form <Form> that have a key matching the `name`
16
- * of this text field are shown above the field.
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 label = _ref.label,
24
+ var id = _ref.id,
20
25
  name = _ref.name,
21
- validationHelpText = _ref.validationHelpText,
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
- validators = _ref.validators,
26
- defaultValue = _ref.defaultValue,
27
- rest = _objectWithoutProperties(_ref, _excluded);
28
- var _useFormContext = useFormContext(),
29
- assignValidator = _useFormContext.assignValidator;
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
- if (validators) {
32
- assignValidator(name, validators);
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
- }, [name, validators, assignValidator]);
35
- return jsx("div", {
36
- "data-testid": testId
37
- }, jsx(Field, {
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
- defaultValue: defaultValue
42
- }, function (_ref2) {
43
- var fieldProps = _ref2.fieldProps,
44
- meta = _ref2.meta,
45
- error = _ref2.error;
46
- var isInvalid = validateSubmitErrors(meta);
47
- return jsx(Fragment, null, jsx(AkAsyncSelect, _extends({}, fieldProps, rest, {
48
- isInvalid: isInvalid
49
- })), !error && validationHelpText && jsx(HelperMessage, {
50
- testId: "".concat(testId, "-helper-message")
51
- }, validationHelpText), isInvalid && jsx(ErrorMessage, {
52
- testId: "".concat(testId, "-error-message")
53
- }, error));
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(FormFooter, null, formErrorMessage && jsx("div", {
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 _extends from "@babel/runtime/helpers/extends";
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].toString(), function () {
78
+ return args[1];
79
+ });
80
+ }
81
+ }
72
82
  }, function (_ref3) {
73
- var formProps = _ref3.formProps,
74
- submitting = _ref3.submitting;
75
- return jsx("form", _extends({}, formProps, {
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
- }), jsx("div", null, children), !hideFooter && jsx(CreateFormFooter, {
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 = ["label", "name", "testId", "validationHelpText", "validators", "defaultValue", "isRequired"];
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 { validateSubmitErrors } from '../../../common/utils/form';
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 label = _ref.label,
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
- var _useFormContext = useFormContext(),
31
- assignValidator = _useFormContext.assignValidator;
32
- useEffect(function () {
33
- if (validators) {
34
- assignValidator(name, validators);
35
- }
36
- }, [name, validators, assignValidator]);
37
- return (
38
- /**
39
- * The defaultValue here should be '' when there is nothing passed in from the props.
40
- * This is because if we don't give it anything, the `fieldProps` wouldn't have a `value`
41
- * prop and make the TextField component uncontrolled. Later when user starts typing, the
42
- * `value` will be populated again in `fieldProps` which cause the TextField to be changed
43
- * to a controlled component and raise a warning from React.
44
- */
45
-
46
- jsx(Field, {
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
  }
@@ -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 { AsyncSelect } from './create-form/async-select';
5
+ export { Select } from './create-form/select';
6
+ export { AsyncSelect } from './create-form/async-select';
7
+ export { FormSpy } from './create-form/form-spy';
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-create",
3
- "version": "0.10.0",
3
+ "version": "1.0.1",
4
4
  "sideEffects": false
5
5
  }
@@ -1,7 +1,7 @@
1
- import { Meta } from '@atlaskit/form/Field';
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: Meta) => boolean;
7
+ export declare const validateSubmitErrors: (meta: FieldMetaState<any>) => boolean;
@@ -0,0 +1 @@
1
+ export { CreateField } from './main';
@@ -0,0 +1,3 @@
1
+ import { jsx } from '@emotion/react';
2
+ import { CreateFieldProps } from './types';
3
+ export declare function CreateField({ id, name, label, isRequired, validators, validationHelpText, testId, children, }: CreateFieldProps): jsx.JSX.Element;
@@ -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 {};
@@ -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 objects from `@atlaskit/form`.
7
- * Validation is handled by the form as it is on form submission. Any errors returned by
8
- * the handleSubmit function passed to the form <Form> that have a key matching the `name`
9
- * of this text field are shown above the field.
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>({ label, name, validationHelpText, isRequired, testId, validators, defaultValue, ...rest }: AsyncSelectProps<T>): jsx.JSX.Element;
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 textfield explaining any requirements for a valid value.
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;
@@ -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
5
  export { TextField } from './textfield';
6
+ export { FormSpy } from './form-spy';
@@ -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({ label, name, testId, validationHelpText, validators, defaultValue, isRequired, ...restProps }: TextFieldProps): jsx.JSX.Element;
11
+ export declare function TextField({ id, name, label, isRequired, validators, validationHelpText, testId, ...restProps }: TextFieldProps): jsx.JSX.Element;
@@ -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 { Meta } from '@atlaskit/form/Field';
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: Meta) => boolean;
7
+ export declare const validateSubmitErrors: (meta: FieldMetaState<any>) => boolean;
@@ -0,0 +1 @@
1
+ export { CreateField } from './main';