@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
@@ -0,0 +1,57 @@
1
+ /** @jsx jsx */
2
+ import { Fragment, useEffect, useMemo } from 'react';
3
+ import { css, jsx } from '@emotion/react';
4
+ import { Field } from 'react-final-form';
5
+ import { ErrorMessage, HelperMessage, Label, RequiredAsterisk } from '@atlaskit/form';
6
+ import { validateSubmitErrors } from '../../common/utils/form';
7
+ import { useFormContext } from '../form-context';
8
+ const fieldWrapperStyles = css({
9
+ marginTop: "var(--ds-space-100, 8px)"
10
+ });
11
+ export function CreateField({
12
+ id,
13
+ name,
14
+ label,
15
+ isRequired,
16
+ validators,
17
+ validationHelpText,
18
+ testId,
19
+ children
20
+ }) {
21
+ const {
22
+ assignValidator
23
+ } = useFormContext();
24
+ useEffect(() => {
25
+ if (validators) {
26
+ assignValidator(name, validators);
27
+ }
28
+ }, [name, validators, assignValidator]);
29
+ const fieldId = useMemo(() => id ? id : `link-create-field-${name}`, [id, name]);
30
+ return jsx("div", {
31
+ css: fieldWrapperStyles,
32
+ "data-testid": testId
33
+ }, jsx(Field, {
34
+ name: name
35
+ }, ({
36
+ input,
37
+ meta
38
+ }) => {
39
+ const isInvalid = validateSubmitErrors(meta);
40
+ const {
41
+ submitError
42
+ } = meta;
43
+ return jsx(Fragment, null, label && jsx(Label, {
44
+ htmlFor: fieldId,
45
+ id: `${fieldId}-label`,
46
+ testId: `${testId}-label`
47
+ }, label, isRequired && jsx(RequiredAsterisk, null)), children({
48
+ ...input,
49
+ fieldId,
50
+ isInvalid
51
+ }), !submitError && validationHelpText && jsx(HelperMessage, {
52
+ testId: `${testId}-helper-message`
53
+ }, validationHelpText), submitError && isInvalid && jsx(ErrorMessage, {
54
+ testId: `${testId}-error-message`
55
+ }, submitError));
56
+ }));
57
+ }
@@ -1,2 +1,2 @@
1
- export { default, TextField, CreateForm, AsyncSelect, CreateFormLoader } from './ui/index';
1
+ export { default, TextField, CreateForm, Select, AsyncSelect, CreateFormLoader, FormSpy } from './ui/index';
2
2
  export { useLinkCreateCallback, LinkCreateCallbackProvider } from './controllers/callback-context';
@@ -1,55 +1,96 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  /** @jsx jsx */
3
- import { Fragment, useEffect } from 'react';
3
+ import { useEffect, useMemo, useState } from 'react';
4
4
  import { jsx } from '@emotion/react';
5
- import { ErrorMessage, Field, HelperMessage } from '@atlaskit/form';
5
+ import debounce from 'debounce-promise';
6
+ import { useForm } from 'react-final-form';
6
7
  import { AsyncSelect as AkAsyncSelect } from '@atlaskit/select';
7
- import { validateSubmitErrors } from '../../../common/utils/form';
8
- import { useFormContext } from '../../../controllers/form-context';
8
+ import { CreateField } from '../../../controllers/create-field';
9
9
  export const TEST_ID = 'link-create-async-select';
10
+
10
11
  /**
11
- * An async select utilising the Atlaskit AsyncSelect and Field objects from `@atlaskit/form`.
12
- * Validation is handled by the form as it is on form submission. Any errors returned by
13
- * the handleSubmit function passed to the form <Form> that have a key matching the `name`
14
- * of this text field are shown above the field.
12
+ * An async select utilising the Atlaskit AsyncSelect 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.
15
16
  */
16
17
  export function AsyncSelect({
17
- label,
18
+ id,
18
19
  name,
19
- validationHelpText,
20
+ label,
20
21
  isRequired,
21
- testId = TEST_ID,
22
22
  validators,
23
- defaultValue,
24
- ...rest
23
+ validationHelpText,
24
+ testId = TEST_ID,
25
+ defaultOption: propsDefaultValue,
26
+ loadOptions,
27
+ ...restProps
25
28
  }) {
26
29
  const {
27
- assignValidator
28
- } = useFormContext();
30
+ mutators
31
+ } = useForm();
32
+ const [defaultValue, setDefaultValue] = useState(propsDefaultValue);
33
+ const [isLoadingDefaultOptions, setIsLoadingDefaultOptions] = useState(false);
34
+ const [defaultOptions, setDefaultOptions] = useState([]);
35
+ useEffect(() => {
36
+ let current = true;
37
+ const fetch = async (query = '') => {
38
+ if (!loadOptions) {
39
+ return;
40
+ }
41
+ try {
42
+ /**
43
+ * If we are fetching default options, clear the
44
+ * value the user has set
45
+ */
46
+ mutators.setField(name, null);
47
+ setIsLoadingDefaultOptions(true);
48
+ setDefaultOptions([]);
49
+ const options = await loadOptions(query);
50
+ if (current) {
51
+ setDefaultOptions(options);
52
+ setIsLoadingDefaultOptions(false);
53
+ }
54
+ } catch (err) {
55
+ if (current) {
56
+ setIsLoadingDefaultOptions(false);
57
+ }
58
+ }
59
+ };
60
+ fetch();
61
+ return () => {
62
+ current = false;
63
+ };
64
+ }, [loadOptions, setIsLoadingDefaultOptions, setDefaultOptions, mutators, name]);
29
65
  useEffect(() => {
30
- if (validators) {
31
- assignValidator(name, validators);
66
+ /**
67
+ * Mutate the form state to set a default value for this field
68
+ * if `defaultOption` is a prop and we have not set a value for it yet
69
+ */
70
+ if (!defaultValue && propsDefaultValue) {
71
+ setDefaultValue(propsDefaultValue);
72
+ mutators.setField(name, propsDefaultValue);
32
73
  }
33
- }, [name, validators, assignValidator]);
34
- return jsx("div", {
35
- "data-testid": testId
36
- }, jsx(Field, {
74
+ }, [defaultValue, propsDefaultValue, name, mutators]);
75
+ const debouncedLoadOptions = useMemo(() => loadOptions ? debounce(loadOptions, 300) : undefined, [loadOptions]);
76
+ return jsx(CreateField, {
77
+ id: id,
37
78
  name: name,
38
79
  label: label,
39
80
  isRequired: isRequired,
40
- defaultValue: defaultValue
81
+ validators: validators,
82
+ validationHelpText: validationHelpText,
83
+ testId: testId
41
84
  }, ({
42
- fieldProps,
43
- meta,
44
- error
85
+ fieldId,
86
+ ...fieldProps
45
87
  }) => {
46
- const isInvalid = validateSubmitErrors(meta);
47
- return jsx(Fragment, null, jsx(AkAsyncSelect, _extends({}, fieldProps, rest, {
48
- isInvalid: isInvalid
49
- })), !error && validationHelpText && jsx(HelperMessage, {
50
- testId: `${testId}-helper-message`
51
- }, validationHelpText), isInvalid && jsx(ErrorMessage, {
52
- testId: `${testId}-error-message`
53
- }, error));
54
- }));
88
+ return jsx(AkAsyncSelect, _extends({
89
+ inputId: fieldId
90
+ }, fieldProps, restProps, {
91
+ loadOptions: debouncedLoadOptions,
92
+ defaultOptions: defaultOptions,
93
+ isLoading: isLoadingDefaultOptions
94
+ }));
95
+ });
55
96
  }
@@ -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
+ const formFooterWrapperStyles = css({
9
+ display: 'flex',
10
+ marginTop: "var(--ds-space-300, 24px)",
11
+ justifyContent: 'flex-end'
12
+ });
9
13
  const errorStyles = css({
10
14
  display: 'flex',
11
15
  alignItems: 'center',
@@ -18,7 +22,10 @@ export function CreateFormFooter({
18
22
  testId
19
23
  }) {
20
24
  const intl = useIntl();
21
- return jsx(FormFooter, null, formErrorMessage && jsx("div", {
25
+ return jsx("footer", {
26
+ "data-testid": `${testId}-footer`,
27
+ css: formFooterWrapperStyles
28
+ }, formErrorMessage && jsx("div", {
22
29
  css: errorStyles,
23
30
  "data-testid": `${testId}-error`
24
31
  }, jsx(ErrorIcon, {
@@ -0,0 +1,18 @@
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 const FormSpy = ({
9
+ children
10
+ }) => {
11
+ return /*#__PURE__*/React.createElement(FinalFormSpy, {
12
+ subscription: {
13
+ values: true
14
+ }
15
+ }, props => children({
16
+ values: props.values
17
+ }));
18
+ };
@@ -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,9 +1,8 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
1
  /** @jsx jsx */
3
2
  import { useCallback } from 'react';
4
3
  import { css, jsx } from '@emotion/react';
4
+ import { Form } from 'react-final-form';
5
5
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
6
- import Form from '@atlaskit/form';
7
6
  import { ANALYTICS_CHANNEL, CREATE_FORM_MAX_WIDTH_IN_PX } from '../../common/constants';
8
7
  import createEventPayload from '../../common/utils/analytics/analytics.codegen';
9
8
  import { useFormContext } from '../../controllers/form-context';
@@ -22,7 +21,8 @@ export const CreateForm = ({
22
21
  onSubmit,
23
22
  onCancel,
24
23
  isLoading,
25
- hideFooter
24
+ hideFooter,
25
+ initialValues
26
26
  }) => {
27
27
  const {
28
28
  createAnalyticsEvent
@@ -51,18 +51,27 @@ export const CreateForm = ({
51
51
  return jsx(CreateFormLoader, null);
52
52
  }
53
53
  return jsx(Form, {
54
- onSubmit: handleSubmit
54
+ onSubmit: handleSubmit,
55
+ initialValues: initialValues,
56
+ mutators: {
57
+ setField: (args, state, tools) => {
58
+ tools.changeValue(state, args[0].toString(), () => args[1]);
59
+ }
60
+ }
55
61
  }, ({
56
- formProps,
57
- submitting
58
- }) => jsx("form", _extends({}, formProps, {
59
- name: "link-create-form",
60
- "data-testid": testId,
61
- css: formStyles
62
- }), jsx("div", null, children), !hideFooter && jsx(CreateFormFooter, {
63
- formErrorMessage: formErrorMessage,
64
- handleCancel: handleCancel,
65
- submitting: submitting,
66
- testId: testId
67
- })));
62
+ submitting,
63
+ ...formProps
64
+ }) => {
65
+ return jsx("form", {
66
+ onSubmit: formProps.handleSubmit,
67
+ name: "link-create-form",
68
+ "data-testid": testId,
69
+ css: formStyles
70
+ }, jsx("div", null, children), !hideFooter && jsx(CreateFormFooter, {
71
+ formErrorMessage: formErrorMessage,
72
+ handleCancel: handleCancel,
73
+ submitting: submitting,
74
+ testId: testId
75
+ }));
76
+ });
68
77
  };
@@ -0,0 +1 @@
1
+ export { Select } from './main';
@@ -0,0 +1,40 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ /** @jsx jsx */
3
+
4
+ import { jsx } from '@emotion/react';
5
+ import AkSelect from '@atlaskit/select';
6
+ import { CreateField } from '../../../controllers/create-field';
7
+ export const TEST_ID = 'link-create-select';
8
+ /**
9
+ * A select utilising the Atlaskit Select and Field components from
10
+ * `@atlaskit/form`. Validation is handled by the form on form submission. Any
11
+ * errors returned by the handleSubmit function passed to the form <Form> that
12
+ * have a key matching the `name` of this field are shown below the field.
13
+ */
14
+ export function Select({
15
+ id,
16
+ name,
17
+ label,
18
+ isRequired,
19
+ validators,
20
+ validationHelpText,
21
+ testId = TEST_ID,
22
+ ...restProps
23
+ }) {
24
+ return jsx(CreateField, {
25
+ id: id,
26
+ name: name,
27
+ label: label,
28
+ isRequired: isRequired,
29
+ validators: validators,
30
+ validationHelpText: validationHelpText,
31
+ testId: testId
32
+ }, ({
33
+ fieldId,
34
+ ...fieldProps
35
+ }) => {
36
+ return jsx(AkSelect, _extends({
37
+ inputId: fieldId
38
+ }, fieldProps, restProps));
39
+ });
40
+ }
@@ -1,11 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  /** @jsx jsx */
3
- import { Fragment, useEffect } from 'react';
4
3
  import { jsx } from '@emotion/react';
5
- import { ErrorMessage, Field, HelperMessage } from '@atlaskit/form';
6
4
  import AkTextfield from '@atlaskit/textfield';
7
- import { validateSubmitErrors } from '../../../common/utils/form';
8
- import { useFormContext } from '../../../controllers/form-context';
5
+ import { CreateField } from '../../../controllers/create-field';
9
6
  export const TEST_ID = 'link-create-text-field';
10
7
 
11
8
  /**
@@ -16,52 +13,31 @@ export const TEST_ID = 'link-create-text-field';
16
13
  */
17
14
 
18
15
  export function TextField({
19
- label,
16
+ id,
20
17
  name,
21
- testId = TEST_ID,
22
- validationHelpText,
23
- validators,
24
- defaultValue,
18
+ label,
25
19
  isRequired,
20
+ validators,
21
+ validationHelpText,
22
+ testId = TEST_ID,
26
23
  ...restProps
27
24
  }) {
28
- const {
29
- assignValidator
30
- } = useFormContext();
31
- useEffect(() => {
32
- if (validators) {
33
- assignValidator(name, validators);
34
- }
35
- }, [name, validators, assignValidator]);
36
- return (
37
- /**
38
- * The defaultValue here should be '' when there is nothing passed in from the props.
39
- * This is because if we don't give it anything, the `fieldProps` wouldn't have a `value`
40
- * prop and make the TextField component uncontrolled. Later when user starts typing, the
41
- * `value` will be populated again in `fieldProps` which cause the TextField to be changed
42
- * to a controlled component and raise a warning from React.
43
- */
44
-
45
- jsx(Field, {
46
- name: name,
47
- label: label,
48
- isRequired: isRequired,
49
- defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : ''
50
- }, ({
51
- fieldProps,
52
- meta,
53
- error
54
- }) => {
55
- const 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: `${testId}-helper-message`
62
- }, validationHelpText), error && isInvalid && jsx(ErrorMessage, {
63
- testId: `${testId}-error-message`
64
- }, error));
65
- })
66
- );
25
+ return jsx(CreateField, {
26
+ id: id,
27
+ name: name,
28
+ label: label,
29
+ isRequired: isRequired,
30
+ validators: validators,
31
+ validationHelpText: validationHelpText,
32
+ testId: testId
33
+ }, ({
34
+ fieldId,
35
+ ...fieldProps
36
+ }) => {
37
+ return jsx(AkTextfield, _extends({
38
+ id: fieldId
39
+ }, fieldProps, restProps, {
40
+ isRequired: false // Remove the default browser validation
41
+ }));
42
+ });
67
43
  }
@@ -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
  }
@@ -0,0 +1 @@
1
+ export { CreateField } from './main';
@@ -0,0 +1,56 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ /** @jsx jsx */
5
+ import { Fragment, useEffect, useMemo } from 'react';
6
+ import { css, jsx } from '@emotion/react';
7
+ import { Field } from 'react-final-form';
8
+ import { ErrorMessage, HelperMessage, Label, RequiredAsterisk } from '@atlaskit/form';
9
+ import { validateSubmitErrors } from '../../common/utils/form';
10
+ import { useFormContext } from '../form-context';
11
+ var fieldWrapperStyles = css({
12
+ marginTop: "var(--ds-space-100, 8px)"
13
+ });
14
+ export function CreateField(_ref) {
15
+ var id = _ref.id,
16
+ name = _ref.name,
17
+ label = _ref.label,
18
+ isRequired = _ref.isRequired,
19
+ validators = _ref.validators,
20
+ validationHelpText = _ref.validationHelpText,
21
+ testId = _ref.testId,
22
+ children = _ref.children;
23
+ var _useFormContext = useFormContext(),
24
+ assignValidator = _useFormContext.assignValidator;
25
+ useEffect(function () {
26
+ if (validators) {
27
+ assignValidator(name, validators);
28
+ }
29
+ }, [name, validators, assignValidator]);
30
+ var fieldId = useMemo(function () {
31
+ return id ? id : "link-create-field-".concat(name);
32
+ }, [id, name]);
33
+ return jsx("div", {
34
+ css: fieldWrapperStyles,
35
+ "data-testid": testId
36
+ }, jsx(Field, {
37
+ name: name
38
+ }, function (_ref2) {
39
+ var input = _ref2.input,
40
+ meta = _ref2.meta;
41
+ var isInvalid = validateSubmitErrors(meta);
42
+ var submitError = meta.submitError;
43
+ return jsx(Fragment, null, label && jsx(Label, {
44
+ htmlFor: fieldId,
45
+ id: "".concat(fieldId, "-label"),
46
+ testId: "".concat(testId, "-label")
47
+ }, label, isRequired && jsx(RequiredAsterisk, null)), children(_objectSpread(_objectSpread({}, input), {}, {
48
+ fieldId: fieldId,
49
+ isInvalid: isInvalid
50
+ })), !submitError && validationHelpText && jsx(HelperMessage, {
51
+ testId: "".concat(testId, "-helper-message")
52
+ }, validationHelpText), submitError && isInvalid && jsx(ErrorMessage, {
53
+ testId: "".concat(testId, "-error-message")
54
+ }, submitError));
55
+ }));
56
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { default, TextField, CreateForm, AsyncSelect, CreateFormLoader } from './ui/index';
1
+ export { default, TextField, CreateForm, Select, AsyncSelect, CreateFormLoader, FormSpy } from './ui/index';
2
2
  export { useLinkCreateCallback, LinkCreateCallbackProvider } from './controllers/callback-context';