@atlaskit/form 12.2.1 → 12.3.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,20 @@
1
1
  # @atlaskit/form
2
2
 
3
+ ## 12.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`c247b696ec62a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c247b696ec62a) -
8
+ We are testing removing spread props for checkbox field behind a feature flag. If this fix is
9
+ successful it will be implemented in a later release.
10
+
11
+ ## 12.2.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [`543068f818b30`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/543068f818b30) -
16
+ Remove unused internal invariant for the field component.
17
+
3
18
  ## 12.2.1
4
19
 
5
20
  ### Patch Changes
@@ -502,6 +502,204 @@ const formElement = (
502
502
  `,
503
503
  'should convert from function with multiple props on form',
504
504
  );
505
+ defineInlineTest(
506
+ { default: transformer, parser: 'tsx' },
507
+ {},
508
+ `
509
+ import React from 'react';
510
+ import Form from '@atlaskit/form';
511
+
512
+ const FormComponent1 = () => (
513
+ <Form onSubmit={() => {}}>
514
+ {({ formProps }) => (
515
+ <form {...formProps} foo={'bar'} baz={{ qux: 'qux' }}>
516
+ <input />
517
+ </form>
518
+ )}
519
+ </Form>
520
+ );
521
+
522
+ const FormComponent2 = () => (
523
+ <>
524
+ <Form onSubmit={() => {}}>
525
+ {({ formProps }) => (
526
+ <form {...formProps} foo={'bar'} baz={{ qux: 'qux' }}>
527
+ <input />
528
+ </form>
529
+ )}
530
+ </Form>
531
+ </>
532
+ );
533
+
534
+ class FormComponent3 extends React.Component {
535
+ render() {
536
+ return (
537
+ <Form onSubmit={() => {}}>
538
+ {({ formProps }) => (
539
+ <form {...formProps} foo={'bar'} baz={{ qux: 'qux' }}>
540
+ <input />
541
+ </form>
542
+ )}
543
+ </Form>
544
+ );
545
+ }
546
+ }
547
+
548
+ const formElement = (
549
+ <Form onSubmit={() => {}}>
550
+ {({ formProps }) => (
551
+ <form {...formProps} foo={'bar'} baz={{ qux: 'qux' }}>
552
+ <input />
553
+ </form>
554
+ )}
555
+ </Form>
556
+ );
557
+ `,
558
+ `
559
+ import React from 'react';
560
+ import Form from '@atlaskit/form';
561
+
562
+ const FormComponent1 = () => (
563
+ <Form
564
+ onSubmit={() => {}}
565
+ formProps={{
566
+ foo: 'bar',
567
+ baz: { qux: 'qux' }
568
+ }}><input /></Form>
569
+ );
570
+
571
+ const FormComponent2 = () => (
572
+ <>
573
+ <Form
574
+ onSubmit={() => {}}
575
+ formProps={{
576
+ foo: 'bar',
577
+ baz: { qux: 'qux' }
578
+ }}><input /></Form>
579
+ </>
580
+ );
581
+
582
+ class FormComponent3 extends React.Component {
583
+ render() {
584
+ return (
585
+ <Form
586
+ onSubmit={() => {}}
587
+ formProps={{
588
+ foo: 'bar',
589
+ baz: { qux: 'qux' }
590
+ }}><input /></Form>
591
+ );
592
+ }
593
+ }
594
+
595
+ const formElement = (
596
+ <Form
597
+ onSubmit={() => {}}
598
+ formProps={{
599
+ foo: 'bar',
600
+ baz: { qux: 'qux' }
601
+ }}><input /></Form>
602
+ );
603
+ `,
604
+ 'should convert from function with multiple expression container props on form',
605
+ );
606
+ defineInlineTest(
607
+ { default: transformer, parser: 'tsx' },
608
+ {},
609
+ `
610
+ import React from 'react';
611
+ import Form from '@atlaskit/form';
612
+
613
+ const FormComponent1 = () => (
614
+ <Form onSubmit={() => {}}>
615
+ {({ formProps }) => (
616
+ <form {...formProps} foo>
617
+ <input />
618
+ </form>
619
+ )}
620
+ </Form>
621
+ );
622
+
623
+ const FormComponent2 = () => (
624
+ <>
625
+ <Form onSubmit={() => {}}>
626
+ {({ formProps }) => (
627
+ <form {...formProps} foo>
628
+ <input />
629
+ </form>
630
+ )}
631
+ </Form>
632
+ </>
633
+ );
634
+
635
+ class FormComponent3 extends React.Component {
636
+ render() {
637
+ return (
638
+ <Form onSubmit={() => {}}>
639
+ {({ formProps }) => (
640
+ <form {...formProps} foo>
641
+ <input />
642
+ </form>
643
+ )}
644
+ </Form>
645
+ );
646
+ }
647
+ }
648
+
649
+ const formElement = (
650
+ <Form onSubmit={() => {}}>
651
+ {({ formProps }) => (
652
+ <form {...formProps} foo>
653
+ <input />
654
+ </form>
655
+ )}
656
+ </Form>
657
+ );
658
+ `,
659
+ `
660
+ import React from 'react';
661
+ import Form from '@atlaskit/form';
662
+
663
+ const FormComponent1 = () => (
664
+ <Form
665
+ onSubmit={() => {}}
666
+ formProps={{
667
+ foo: true
668
+ }}><input /></Form>
669
+ );
670
+
671
+ const FormComponent2 = () => (
672
+ <>
673
+ <Form
674
+ onSubmit={() => {}}
675
+ formProps={{
676
+ foo: true
677
+ }}><input /></Form>
678
+ </>
679
+ );
680
+
681
+ class FormComponent3 extends React.Component {
682
+ render() {
683
+ return (
684
+ <Form
685
+ onSubmit={() => {}}
686
+ formProps={{
687
+ foo: true
688
+ }}><input /></Form>
689
+ );
690
+ }
691
+ }
692
+
693
+ const formElement = (
694
+ <Form
695
+ onSubmit={() => {}}
696
+ formProps={{
697
+ foo: true
698
+ }}><input /></Form>
699
+ );
700
+ `,
701
+ 'should convert from function with boolean props on form',
702
+ );
505
703
  });
506
704
 
507
705
  describe('Do not migrate Form when anything more than `formProps` in child arg', () => {
@@ -4,7 +4,6 @@ import {
4
4
  type JSCodeshift,
5
5
  type JSXElement,
6
6
  type Options,
7
- type Property,
8
7
  } from 'jscodeshift';
9
8
  import { type Collection } from 'jscodeshift/src/Collection';
10
9
 
@@ -97,7 +96,8 @@ const convertToSimpleForm = (j: JSCodeshift, collection: Collection<any>) => {
97
96
  // make new object and add each attribute on HTML `form` that is not a spread of `formProps` to new object
98
97
  let otherSpreadPropsSeen = false;
99
98
  // We are required to do it this way instead of a map to make the types work correctly.
100
- const nonFormPropsAttributes: Property[] = [];
99
+ // We also have to use `any` here and below because typing in this SUCKS.
100
+ const nonFormPropsAttributes: any[] = [];
101
101
  htmlForm?.openingElement?.attributes?.forEach((attr) => {
102
102
  if (otherSpreadPropsSeen) {
103
103
  return;
@@ -120,11 +120,13 @@ const convertToSimpleForm = (j: JSCodeshift, collection: Collection<any>) => {
120
120
  return;
121
121
  }
122
122
 
123
- let value;
123
+ let value: any;
124
124
  if (attr.value === null) {
125
- value = j.nullLiteral();
125
+ value = j.booleanLiteral(true) as any;
126
+ } else if (attr.value.type === 'JSXExpressionContainer') {
127
+ value = attr.value.expression as any;
126
128
  } else {
127
- value = attr.value;
129
+ value = attr.value as any;
128
130
  }
129
131
 
130
132
  nonFormPropsAttributes.push(j.property('init', attr.name, value));
@@ -11,6 +11,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
11
11
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
13
  var _react = _interopRequireWildcard(require("react"));
14
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
15
  var _field = _interopRequireDefault(require("./field"));
15
16
  var _excluded = ["children", "defaultIsChecked", "isDisabled", "isRequired", "label", "name", "value"],
16
17
  _excluded2 = ["value"],
@@ -44,7 +45,7 @@ var CheckboxField = function CheckboxField(_ref) {
44
45
  var currentValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
45
46
  return defaultIsChecked && value !== undefined ? [].concat((0, _toConsumableArray2.default)(currentValue), [value]) : currentValue;
46
47
  }, [value, defaultIsChecked]);
47
- return value !== undefined ? /*#__PURE__*/_react.default.createElement(_field.default, (0, _extends2.default)({}, rest, {
48
+ return value !== undefined ? /*#__PURE__*/_react.default.createElement(_field.default, (0, _extends2.default)({}, (0, _platformFeatureFlags.fg)('platform_design-system-team_checkbox-field-spread') ? {} : _objectSpread({}, rest), {
48
49
  defaultValue: defaultValue,
49
50
  isDisabled: isDisabled,
50
51
  isRequired: isRequired,
@@ -68,7 +69,7 @@ var CheckboxField = function CheckboxField(_ref) {
68
69
  value: value
69
70
  })
70
71
  }, others));
71
- }) : /*#__PURE__*/_react.default.createElement(_field.default, (0, _extends2.default)({}, rest, {
72
+ }) : /*#__PURE__*/_react.default.createElement(_field.default, (0, _extends2.default)({}, (0, _platformFeatureFlags.fg)('platform_design-system-team_checkbox-field-spread') ? {} : _objectSpread({}, rest), {
72
73
  defaultValue: defaultIsChecked,
73
74
  isDisabled: isDisabled,
74
75
  isRequired: isRequired,
package/dist/cjs/field.js CHANGED
@@ -14,7 +14,6 @@ var _runtime = require("@compiled/react/runtime");
14
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
15
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
16
16
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
17
- var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
18
17
  var _useId = require("@atlaskit/ds-lib/use-id");
19
18
  var _fieldIdContext = require("./field-id-context");
20
19
  var _form = require("./form");
@@ -118,9 +117,6 @@ function Field(props) {
118
117
  setState = _useState2[1];
119
118
  var latestStateRef = usePreviousRef(state);
120
119
  (0, _react.useEffect)(function () {
121
- if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production' && !process.env.CI) {
122
- (0, _tinyInvariant.default)(latestPropsRef.current.name, '@atlaskit/form: Field components have a required name prop');
123
- }
124
120
  function fieldStateToMeta() {
125
121
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
126
122
  return {
@@ -1,5 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { useCallback } from 'react';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import Field from './field';
4
5
  /**
5
6
  * __Checkbox field__
@@ -22,7 +23,9 @@ const CheckboxField = ({
22
23
  }) => {
23
24
  // Maintains a memoised list of the default values
24
25
  const defaultValue = useCallback((currentValue = []) => defaultIsChecked && value !== undefined ? [...currentValue, value] : currentValue, [value, defaultIsChecked]);
25
- return value !== undefined ? /*#__PURE__*/React.createElement(Field, _extends({}, rest, {
26
+ return value !== undefined ? /*#__PURE__*/React.createElement(Field, _extends({}, fg('platform_design-system-team_checkbox-field-spread') ? {} : {
27
+ ...rest
28
+ }, {
26
29
  defaultValue: defaultValue,
27
30
  isDisabled: isDisabled,
28
31
  isRequired: isRequired,
@@ -42,7 +45,9 @@ const CheckboxField = ({
42
45
  value
43
46
  },
44
47
  ...others
45
- })) : /*#__PURE__*/React.createElement(Field, _extends({}, rest, {
48
+ })) : /*#__PURE__*/React.createElement(Field, _extends({}, fg('platform_design-system-team_checkbox-field-spread') ? {} : {
49
+ ...rest
50
+ }, {
46
51
  defaultValue: defaultIsChecked,
47
52
  isDisabled: isDisabled,
48
53
  isRequired: isRequired,
@@ -3,7 +3,6 @@ import "./field.compiled.css";
3
3
  import * as React from 'react';
4
4
  import { ax, ix } from "@compiled/react/runtime";
5
5
  import { useContext, useEffect, useMemo, useRef, useState } from 'react';
6
- import invariant from 'tiny-invariant';
7
6
  import { useId } from '@atlaskit/ds-lib/use-id';
8
7
  import { FieldId } from './field-id-context';
9
8
  import { FormContext, IsDisabledContext } from './form';
@@ -102,9 +101,6 @@ export default function Field(props) {
102
101
  });
103
102
  const latestStateRef = usePreviousRef(state);
104
103
  useEffect(() => {
105
- if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production' && !process.env.CI) {
106
- invariant(latestPropsRef.current.name, '@atlaskit/form: Field components have a required name prop');
107
- }
108
104
  function fieldStateToMeta(value = {}) {
109
105
  return {
110
106
  dirty: value.dirty || false,
@@ -10,6 +10,7 @@ var _excluded = ["children", "defaultIsChecked", "isDisabled", "isRequired", "la
10
10
  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; }
11
11
  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; }
12
12
  import React, { useCallback } from 'react';
13
+ import { fg } from '@atlaskit/platform-feature-flags';
13
14
  import Field from './field';
14
15
  /**
15
16
  * __Checkbox field__
@@ -35,7 +36,7 @@ var CheckboxField = function CheckboxField(_ref) {
35
36
  var currentValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
36
37
  return defaultIsChecked && value !== undefined ? [].concat(_toConsumableArray(currentValue), [value]) : currentValue;
37
38
  }, [value, defaultIsChecked]);
38
- return value !== undefined ? /*#__PURE__*/React.createElement(Field, _extends({}, rest, {
39
+ return value !== undefined ? /*#__PURE__*/React.createElement(Field, _extends({}, fg('platform_design-system-team_checkbox-field-spread') ? {} : _objectSpread({}, rest), {
39
40
  defaultValue: defaultValue,
40
41
  isDisabled: isDisabled,
41
42
  isRequired: isRequired,
@@ -59,7 +60,7 @@ var CheckboxField = function CheckboxField(_ref) {
59
60
  value: value
60
61
  })
61
62
  }, others));
62
- }) : /*#__PURE__*/React.createElement(Field, _extends({}, rest, {
63
+ }) : /*#__PURE__*/React.createElement(Field, _extends({}, fg('platform_design-system-team_checkbox-field-spread') ? {} : _objectSpread({}, rest), {
63
64
  defaultValue: defaultIsChecked,
64
65
  isDisabled: isDisabled,
65
66
  isRequired: isRequired,
package/dist/esm/field.js CHANGED
@@ -8,7 +8,6 @@ import { ax, ix } from "@compiled/react/runtime";
8
8
  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
9
  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
10
  import { useContext, useEffect, useMemo, useRef, useState } from 'react';
11
- import invariant from 'tiny-invariant';
12
11
  import { useId } from '@atlaskit/ds-lib/use-id';
13
12
  import { FieldId } from './field-id-context';
14
13
  import { FormContext, IsDisabledContext } from './form';
@@ -109,9 +108,6 @@ export default function Field(props) {
109
108
  setState = _useState2[1];
110
109
  var latestStateRef = usePreviousRef(state);
111
110
  useEffect(function () {
112
- if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production' && !process.env.CI) {
113
- invariant(latestPropsRef.current.name, '@atlaskit/form: Field components have a required name prop');
114
- }
115
111
  function fieldStateToMeta() {
116
112
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
117
113
  return {
@@ -2,6 +2,9 @@ import React, { type ReactNode } from 'react';
2
2
  import { type FieldProps, type Meta } from './field';
3
3
  type RangeProps = Omit<FieldProps<number>, 'isInvalid' | 'isRequired'>;
4
4
  export interface RangeFieldProps {
5
+ /**
6
+ * Content to render in the range field. This function is called with props for the field component and other information about the field.
7
+ */
5
8
  children: (args: {
6
9
  fieldProps: RangeProps;
7
10
  error?: string;
@@ -2,6 +2,9 @@ import React, { type ReactNode } from 'react';
2
2
  import { type FieldProps, type Meta } from './field';
3
3
  type RangeProps = Omit<FieldProps<number>, 'isInvalid' | 'isRequired'>;
4
4
  export interface RangeFieldProps {
5
+ /**
6
+ * Content to render in the range field. This function is called with props for the field component and other information about the field.
7
+ */
5
8
  children: (args: {
6
9
  fieldProps: RangeProps;
7
10
  error?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/form",
3
- "version": "12.2.1",
3
+ "version": "12.3.0",
4
4
  "description": "A form allows users to input information.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -36,8 +36,7 @@
36
36
  "@babel/runtime": "^7.0.0",
37
37
  "final-form": "^4.20.3",
38
38
  "final-form-focus": "^1.1.2",
39
- "lodash": "^4.17.21",
40
- "tiny-invariant": "^1.2.0"
39
+ "lodash": "^4.17.21"
41
40
  },
42
41
  "peerDependencies": {
43
42
  "react": "^18.2.0"
@@ -55,7 +54,7 @@
55
54
  "@atlaskit/link": "^3.2.0",
56
55
  "@atlaskit/lozenge": "^13.0.0",
57
56
  "@atlaskit/modal-dialog": "^14.3.0",
58
- "@atlaskit/radio": "^8.2.0",
57
+ "@atlaskit/radio": "^8.3.0",
59
58
  "@atlaskit/range": "^9.2.0",
60
59
  "@atlaskit/section-message": "^8.6.0",
61
60
  "@atlaskit/select": "^21.2.0",
@@ -127,6 +126,9 @@
127
126
  },
128
127
  "platform_design-system-team_form-upgrade": {
129
128
  "type": "boolean"
129
+ },
130
+ "platform_design-system-team_checkbox-field-spread": {
131
+ "type": "boolean"
130
132
  }
131
133
  }
132
134
  }