@atlaskit/form 12.2.2 → 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 +8 -0
- package/codemods/__tests__/not-yet-migrate-to-simplified-form.test.tsx +198 -0
- package/codemods/not-yet-migrate-to-simplified-form.tsx +7 -5
- package/dist/cjs/checkbox-field.js +3 -2
- package/dist/es2019/checkbox-field.js +7 -2
- package/dist/esm/checkbox-field.js +3 -2
- package/dist/types/range-field.d.ts +3 -0
- package/dist/types-ts4.5/range-field.d.ts +3 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
3
11
|
## 12.2.2
|
|
4
12
|
|
|
5
13
|
### 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
|
-
|
|
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.
|
|
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,
|
|
@@ -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({},
|
|
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({},
|
|
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,
|
|
@@ -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,
|
|
@@ -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.
|
|
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/"
|
|
@@ -126,6 +126,9 @@
|
|
|
126
126
|
},
|
|
127
127
|
"platform_design-system-team_form-upgrade": {
|
|
128
128
|
"type": "boolean"
|
|
129
|
+
},
|
|
130
|
+
"platform_design-system-team_checkbox-field-spread": {
|
|
131
|
+
"type": "boolean"
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
}
|