@atlaskit/form 12.6.2 → 12.7.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/form
2
2
 
3
+ ## 12.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`edef4ab21e5c5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/edef4ab21e5c5) -
8
+ We are testing a new streamlined implementation of the field component behind a feature flag. If
9
+ this fix is successful it will be available in a later release.
10
+
3
11
  ## 12.6.2
4
12
 
5
13
  ### Patch Changes
package/dist/cjs/field.js CHANGED
@@ -8,16 +8,17 @@ Object.defineProperty(exports, "__esModule", {
8
8
  });
9
9
  exports.default = Field;
10
10
  require("./field.compiled.css");
11
- var _react = _interopRequireWildcard(require("react"));
12
- var React = _react;
13
11
  var _runtime = require("@compiled/react/runtime");
14
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
13
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
16
14
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
15
+ var _react = _interopRequireWildcard(require("react"));
17
16
  var _useId = require("@atlaskit/ds-lib/use-id");
17
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
18
  var _fieldIdContext = require("./field-id-context");
19
19
  var _form = require("./form");
20
20
  var _label = require("./label");
21
+ var _messages = require("./messages");
21
22
  var _requiredAsterisk = _interopRequireDefault(require("./required-asterisk"));
22
23
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
23
24
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -67,6 +68,11 @@ function isShallowEqual(previousValue, currentValue) {
67
68
  }
68
69
  function Field(props) {
69
70
  var _getCurrentValue;
71
+ var _props$children = props.children,
72
+ children = _props$children === void 0 ? function () {
73
+ return null;
74
+ } : _props$children,
75
+ component = props.component;
70
76
  var _useContext = (0, _react.useContext)(_form.FormContext),
71
77
  registerField = _useContext.registerField,
72
78
  getCurrentValue = _useContext.getCurrentValue;
@@ -248,16 +254,18 @@ function Field(props) {
248
254
  'aria-labelledby': "".concat(fieldId, "-label"),
249
255
  id: fieldId
250
256
  });
251
- return /*#__PURE__*/React.createElement("div", {
257
+ return /*#__PURE__*/_react.default.createElement("div", {
252
258
  "data-testid": props.testId,
253
259
  className: (0, _runtime.ax)(["_1pfhu2gc"])
254
- }, props.label && /*#__PURE__*/React.createElement(_label.Label, {
260
+ }, props.label && /*#__PURE__*/_react.default.createElement(_label.Label, {
255
261
  htmlFor: fieldId,
256
262
  id: "".concat(fieldId, "-label"),
257
263
  testId: props.testId && "".concat(props.testId, "--label")
258
- }, props.label, props.isRequired && /*#__PURE__*/React.createElement(_requiredAsterisk.default, null), props.elementAfterLabel), /*#__PURE__*/React.createElement(_fieldIdContext.FieldId.Provider, {
264
+ }, props.label, props.isRequired && /*#__PURE__*/_react.default.createElement(_requiredAsterisk.default, null), props.elementAfterLabel), /*#__PURE__*/_react.default.createElement(_fieldIdContext.FieldId.Provider, {
259
265
  value: fieldId
260
- }, props.children({
266
+ }, component && (0, _platformFeatureFlags.fg)('platform_design-system-team_field-upgrade') ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, component && component({
267
+ fieldProps: extendedFieldProps
268
+ }), /*#__PURE__*/_react.default.createElement(_messages.MessageWrapper, null, props.helperMessage && /*#__PURE__*/_react.default.createElement(_messages.HelperMessage, null, props.helperMessage), state.error && /*#__PURE__*/_react.default.createElement(_messages.ErrorMessage, null, props.errorMessage || state.error), state.meta.touched && state.valid && props.validMessage && /*#__PURE__*/_react.default.createElement(_messages.ValidMessage, null, props.validMessage))) : children({
261
269
  fieldProps: extendedFieldProps,
262
270
  error: state.error,
263
271
  valid: state.valid,
@@ -1,12 +1,13 @@
1
1
  /* field.tsx generated by @compiled/babel-plugin v0.36.1 */
2
2
  import "./field.compiled.css";
3
- import * as React from 'react';
4
3
  import { ax, ix } from "@compiled/react/runtime";
5
- import { useContext, useEffect, useMemo, useRef, useState } from 'react';
4
+ import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
6
5
  import { useId } from '@atlaskit/ds-lib/use-id';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
7
7
  import { FieldId } from './field-id-context';
8
8
  import { FormContext, IsDisabledContext } from './form';
9
9
  import { Label } from './label';
10
+ import { ErrorMessage, HelperMessage, MessageWrapper, ValidMessage } from './messages';
10
11
  import RequiredAsterisk from './required-asterisk';
11
12
  const fieldWrapperStyles = null;
12
13
  function isEvent(event) {
@@ -53,6 +54,10 @@ function isShallowEqual(previousValue, currentValue) {
53
54
  }
54
55
  export default function Field(props) {
55
56
  var _getCurrentValue;
57
+ const {
58
+ children = () => null,
59
+ component
60
+ } = props;
56
61
  const {
57
62
  registerField,
58
63
  getCurrentValue
@@ -241,7 +246,9 @@ export default function Field(props) {
241
246
  testId: props.testId && `${props.testId}--label`
242
247
  }, props.label, props.isRequired && /*#__PURE__*/React.createElement(RequiredAsterisk, null), props.elementAfterLabel), /*#__PURE__*/React.createElement(FieldId.Provider, {
243
248
  value: fieldId
244
- }, props.children({
249
+ }, component && fg('platform_design-system-team_field-upgrade') ? /*#__PURE__*/React.createElement(React.Fragment, null, component && component({
250
+ fieldProps: extendedFieldProps
251
+ }), /*#__PURE__*/React.createElement(MessageWrapper, null, props.helperMessage && /*#__PURE__*/React.createElement(HelperMessage, null, props.helperMessage), state.error && /*#__PURE__*/React.createElement(ErrorMessage, null, props.errorMessage || state.error), state.meta.touched && state.valid && props.validMessage && /*#__PURE__*/React.createElement(ValidMessage, null, props.validMessage))) : children({
245
252
  fieldProps: extendedFieldProps,
246
253
  error: state.error,
247
254
  valid: state.valid,
package/dist/esm/field.js CHANGED
@@ -3,15 +3,16 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  import _typeof from "@babel/runtime/helpers/typeof";
5
5
  import "./field.compiled.css";
6
- import * as React from 'react';
7
6
  import { ax, ix } from "@compiled/react/runtime";
8
7
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
8
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
- import { useContext, useEffect, useMemo, useRef, useState } from 'react';
9
+ import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
11
10
  import { useId } from '@atlaskit/ds-lib/use-id';
11
+ import { fg } from '@atlaskit/platform-feature-flags';
12
12
  import { FieldId } from './field-id-context';
13
13
  import { FormContext, IsDisabledContext } from './form';
14
14
  import { Label } from './label';
15
+ import { ErrorMessage, HelperMessage, MessageWrapper, ValidMessage } from './messages';
15
16
  import RequiredAsterisk from './required-asterisk';
16
17
  var fieldWrapperStyles = null;
17
18
  function isEvent(event) {
@@ -58,6 +59,11 @@ function isShallowEqual(previousValue, currentValue) {
58
59
  }
59
60
  export default function Field(props) {
60
61
  var _getCurrentValue;
62
+ var _props$children = props.children,
63
+ children = _props$children === void 0 ? function () {
64
+ return null;
65
+ } : _props$children,
66
+ component = props.component;
61
67
  var _useContext = useContext(FormContext),
62
68
  registerField = _useContext.registerField,
63
69
  getCurrentValue = _useContext.getCurrentValue;
@@ -248,7 +254,9 @@ export default function Field(props) {
248
254
  testId: props.testId && "".concat(props.testId, "--label")
249
255
  }, props.label, props.isRequired && /*#__PURE__*/React.createElement(RequiredAsterisk, null), props.elementAfterLabel), /*#__PURE__*/React.createElement(FieldId.Provider, {
250
256
  value: fieldId
251
- }, props.children({
257
+ }, component && fg('platform_design-system-team_field-upgrade') ? /*#__PURE__*/React.createElement(React.Fragment, null, component && component({
258
+ fieldProps: extendedFieldProps
259
+ }), /*#__PURE__*/React.createElement(MessageWrapper, null, props.helperMessage && /*#__PURE__*/React.createElement(HelperMessage, null, props.helperMessage), state.error && /*#__PURE__*/React.createElement(ErrorMessage, null, props.errorMessage || state.error), state.meta.touched && state.valid && props.validMessage && /*#__PURE__*/React.createElement(ValidMessage, null, props.validMessage))) : children({
252
260
  fieldProps: extendedFieldProps,
253
261
  error: state.error,
254
262
  valid: state.valid,
@@ -29,16 +29,34 @@ export interface Meta {
29
29
  submitError?: boolean;
30
30
  validating?: boolean;
31
31
  }
32
- export interface FieldComponentProps<FieldValue, Element extends SupportedElements> {
32
+ export type FieldComponentProps<FieldValue, Element extends SupportedElements> = {
33
33
  /**
34
- * Content to render in the field. This is a function that is called with props for the field component and other information about the field.
34
+ * Content to render in the field. This is a function that is called with props for the field component and other information about the field. This cannot be used at the same time as the `component` prop.
35
35
  */
36
- children: (args: {
36
+ children?: (args: {
37
37
  fieldProps: FieldProps<FieldValue, Element>;
38
38
  error?: string;
39
39
  valid: boolean;
40
40
  meta: Meta;
41
41
  }) => ReactNode;
42
+ /**
43
+ * Content to render in the field. This will be rendered with the `*Message` props. This cannot be used at the same time as the `children` prop.
44
+ */
45
+ component?: (args: {
46
+ fieldProps: FieldProps<FieldValue, Element>;
47
+ }) => ReactNode;
48
+ /**
49
+ * Renders a `HelperMessage` with the provided content when using the `component` prop.
50
+ */
51
+ helperMessage?: ReactNode;
52
+ /**
53
+ * Renders an `ErrorMessage` with the provided content when using the `component` prop.
54
+ */
55
+ errorMessage?: ReactNode;
56
+ /**
57
+ * Renders a `ValidMessage` with the provided content when using the `component` prop.
58
+ */
59
+ validMessage?: ReactNode;
42
60
  /**
43
61
  * Sets the default value of the field. If a function is provided, it is called with the current default value of the field.
44
62
  */
@@ -79,6 +97,6 @@ export interface FieldComponentProps<FieldValue, Element extends SupportedElemen
79
97
  * A `testId` prop is provided for specified elements, which is a unique string that appears as a data attribute `data-testid` in the rendered code, serving as a hook for automated tests
80
98
  */
81
99
  testId?: string;
82
- }
100
+ };
83
101
  export default function Field<FieldValue = string, Element extends SupportedElements = HTMLInputElement>(props: FieldComponentProps<FieldValue, Element>): JSX.Element;
84
102
  export {};
@@ -29,16 +29,34 @@ export interface Meta {
29
29
  submitError?: boolean;
30
30
  validating?: boolean;
31
31
  }
32
- export interface FieldComponentProps<FieldValue, Element extends SupportedElements> {
32
+ export type FieldComponentProps<FieldValue, Element extends SupportedElements> = {
33
33
  /**
34
- * Content to render in the field. This is a function that is called with props for the field component and other information about the field.
34
+ * Content to render in the field. This is a function that is called with props for the field component and other information about the field. This cannot be used at the same time as the `component` prop.
35
35
  */
36
- children: (args: {
36
+ children?: (args: {
37
37
  fieldProps: FieldProps<FieldValue, Element>;
38
38
  error?: string;
39
39
  valid: boolean;
40
40
  meta: Meta;
41
41
  }) => ReactNode;
42
+ /**
43
+ * Content to render in the field. This will be rendered with the `*Message` props. This cannot be used at the same time as the `children` prop.
44
+ */
45
+ component?: (args: {
46
+ fieldProps: FieldProps<FieldValue, Element>;
47
+ }) => ReactNode;
48
+ /**
49
+ * Renders a `HelperMessage` with the provided content when using the `component` prop.
50
+ */
51
+ helperMessage?: ReactNode;
52
+ /**
53
+ * Renders an `ErrorMessage` with the provided content when using the `component` prop.
54
+ */
55
+ errorMessage?: ReactNode;
56
+ /**
57
+ * Renders a `ValidMessage` with the provided content when using the `component` prop.
58
+ */
59
+ validMessage?: ReactNode;
42
60
  /**
43
61
  * Sets the default value of the field. If a function is provided, it is called with the current default value of the field.
44
62
  */
@@ -79,6 +97,6 @@ export interface FieldComponentProps<FieldValue, Element extends SupportedElemen
79
97
  * A `testId` prop is provided for specified elements, which is a unique string that appears as a data attribute `data-testid` in the rendered code, serving as a hook for automated tests
80
98
  */
81
99
  testId?: string;
82
- }
100
+ };
83
101
  export default function Field<FieldValue = string, Element extends SupportedElements = HTMLInputElement>(props: FieldComponentProps<FieldValue, Element>): JSX.Element;
84
102
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/form",
3
- "version": "12.6.2",
3
+ "version": "12.7.0",
4
4
  "description": "A form allows users to input information.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -116,6 +116,9 @@
116
116
  "platform_design-system-team_form-upgrade": {
117
117
  "type": "boolean"
118
118
  },
119
+ "platform_design-system-team_field-upgrade": {
120
+ "type": "boolean"
121
+ },
119
122
  "platform_design-system-team_checkbox-field-spread": {
120
123
  "type": "boolean"
121
124
  },