@atlaskit/form 8.8.3 → 8.8.4
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 +6 -0
- package/dist/cjs/checkbox-field.js +15 -29
- package/dist/cjs/entry-points/checkbox-field.js +0 -2
- package/dist/cjs/entry-points/field.js +0 -2
- package/dist/cjs/entry-points/fieldset.js +0 -2
- package/dist/cjs/entry-points/form-footer.js +0 -2
- package/dist/cjs/entry-points/form-header.js +0 -2
- package/dist/cjs/entry-points/form-section.js +0 -2
- package/dist/cjs/entry-points/form.js +0 -2
- package/dist/cjs/entry-points/label.js +0 -2
- package/dist/cjs/entry-points/messages.js +0 -1
- package/dist/cjs/entry-points/range-field.js +0 -2
- package/dist/cjs/field.js +49 -85
- package/dist/cjs/fieldset.js +9 -18
- package/dist/cjs/form-footer.js +4 -6
- package/dist/cjs/form-header.js +9 -23
- package/dist/cjs/form-section.js +9 -21
- package/dist/cjs/form.js +40 -63
- package/dist/cjs/index.js +0 -11
- package/dist/cjs/label.js +10 -17
- package/dist/cjs/messages.js +17 -37
- package/dist/cjs/range-field.js +8 -19
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/checkbox-field.js +6 -5
- package/dist/es2019/field.js +16 -31
- package/dist/es2019/fieldset.js +7 -8
- package/dist/es2019/form-footer.js +2 -1
- package/dist/es2019/form-header.js +6 -10
- package/dist/es2019/form-section.js +5 -9
- package/dist/es2019/form.js +4 -11
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/label.js +7 -6
- package/dist/es2019/messages.js +9 -11
- package/dist/es2019/range-field.js +2 -4
- package/dist/es2019/version.json +1 -1
- package/dist/esm/checkbox-field.js +15 -22
- package/dist/esm/field.js +49 -73
- package/dist/esm/fieldset.js +9 -12
- package/dist/esm/form-footer.js +4 -3
- package/dist/esm/form-header.js +9 -15
- package/dist/esm/form-section.js +8 -14
- package/dist/esm/form.js +40 -53
- package/dist/esm/index.js +2 -1
- package/dist/esm/label.js +10 -11
- package/dist/esm/messages.js +17 -21
- package/dist/esm/range-field.js +8 -15
- package/dist/esm/version.json +1 -1
- package/package.json +3 -3
- package/report.api.md +13 -0
package/dist/cjs/range-field.js
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
-
|
|
12
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
10
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
15
|
-
|
|
16
11
|
var _react = _interopRequireDefault(require("react"));
|
|
17
|
-
|
|
18
12
|
var _field = _interopRequireDefault(require("./field"));
|
|
19
|
-
|
|
20
13
|
var _excluded = ["children"],
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
_excluded2 = ["isInvalid", "isRequired"],
|
|
15
|
+
_excluded3 = ["fieldProps"];
|
|
24
16
|
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; }
|
|
25
|
-
|
|
26
17
|
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) { (0, _defineProperty2.default)(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; }
|
|
27
|
-
|
|
28
18
|
/**
|
|
29
19
|
* __Range field__
|
|
30
20
|
*
|
|
@@ -36,8 +26,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
36
26
|
*/
|
|
37
27
|
var RangeField = function RangeField(props) {
|
|
38
28
|
var children = props.children,
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
strippedProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
30
|
+
// isInvalid and isRequired are specifically invalid for range inputs
|
|
41
31
|
return (
|
|
42
32
|
/*#__PURE__*/
|
|
43
33
|
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
@@ -45,16 +35,15 @@ var RangeField = function RangeField(props) {
|
|
|
45
35
|
transform: Number
|
|
46
36
|
}), function (_ref) {
|
|
47
37
|
var _ref$fieldProps = _ref.fieldProps,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
isInvalid = _ref$fieldProps.isInvalid,
|
|
39
|
+
isRequired = _ref$fieldProps.isRequired,
|
|
40
|
+
fieldProps = (0, _objectWithoutProperties2.default)(_ref$fieldProps, _excluded2),
|
|
41
|
+
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded3);
|
|
52
42
|
return children(_objectSpread({
|
|
53
43
|
fieldProps: fieldProps
|
|
54
44
|
}, rest));
|
|
55
45
|
})
|
|
56
46
|
);
|
|
57
47
|
};
|
|
58
|
-
|
|
59
48
|
var _default = RangeField;
|
|
60
49
|
exports.default = _default;
|
package/dist/cjs/version.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React, { useCallback } from 'react';
|
|
3
3
|
import Field from './field';
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* __Checkbox field__
|
|
7
6
|
*
|
|
@@ -17,8 +16,9 @@ const CheckboxField = props => {
|
|
|
17
16
|
defaultIsChecked = false,
|
|
18
17
|
value,
|
|
19
18
|
...rest
|
|
20
|
-
} = props;
|
|
19
|
+
} = props;
|
|
21
20
|
|
|
21
|
+
// Maintains a memoised list of the default values
|
|
22
22
|
const defaultValue = useCallback((currentValue = []) => defaultIsChecked && value !== undefined ? [...currentValue, value] : currentValue, [value, defaultIsChecked]);
|
|
23
23
|
return value !== undefined ? /*#__PURE__*/React.createElement(Field, _extends({}, rest, {
|
|
24
24
|
defaultValue: defaultValue,
|
|
@@ -30,7 +30,8 @@ const CheckboxField = props => {
|
|
|
30
30
|
},
|
|
31
31
|
...others
|
|
32
32
|
}) => children({
|
|
33
|
-
fieldProps: {
|
|
33
|
+
fieldProps: {
|
|
34
|
+
...otherFieldProps,
|
|
34
35
|
isChecked: !!fieldValue.find(v => v === value),
|
|
35
36
|
value
|
|
36
37
|
},
|
|
@@ -45,14 +46,14 @@ const CheckboxField = props => {
|
|
|
45
46
|
},
|
|
46
47
|
...others
|
|
47
48
|
}) => children({
|
|
48
|
-
fieldProps: {
|
|
49
|
+
fieldProps: {
|
|
50
|
+
...otherFieldProps,
|
|
49
51
|
isChecked: fieldValue,
|
|
50
52
|
value
|
|
51
53
|
},
|
|
52
54
|
...others
|
|
53
55
|
}));
|
|
54
56
|
};
|
|
55
|
-
|
|
56
57
|
CheckboxField.defaultProps = {
|
|
57
58
|
defaultIsChecked: false
|
|
58
59
|
};
|
package/dist/es2019/field.js
CHANGED
|
@@ -17,56 +17,48 @@ const requiredIndicatorStyles = css({
|
|
|
17
17
|
color: `var(--ds-text-danger, ${R400})`,
|
|
18
18
|
fontFamily
|
|
19
19
|
});
|
|
20
|
-
|
|
21
20
|
function isEvent(event) {
|
|
22
21
|
return Boolean(event && event.target);
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
function isFunction(x) {
|
|
26
24
|
return typeof x === 'function';
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
/**
|
|
30
27
|
* __Field id__
|
|
31
28
|
*
|
|
32
29
|
* A field id uses the context API. It provides the id of the field to message components. This links the message with the field of screenreaders.
|
|
33
30
|
*/
|
|
34
31
|
export const FieldId = /*#__PURE__*/createContext(undefined);
|
|
35
|
-
|
|
36
32
|
function usePreviousRef(current) {
|
|
37
|
-
const ref = useRef(current);
|
|
33
|
+
const ref = useRef(current);
|
|
38
34
|
|
|
35
|
+
// will be updated on the next render
|
|
39
36
|
useEffect(() => {
|
|
40
37
|
ref.current = current;
|
|
41
|
-
});
|
|
38
|
+
});
|
|
42
39
|
|
|
40
|
+
// return the existing current (pre render)
|
|
43
41
|
return ref;
|
|
44
42
|
}
|
|
45
|
-
|
|
46
43
|
function isShallowEqual(previousValue, currentValue) {
|
|
47
44
|
if (previousValue === currentValue) {
|
|
48
45
|
return true;
|
|
49
|
-
}
|
|
50
|
-
|
|
46
|
+
}
|
|
51
47
|
|
|
48
|
+
// not checking functions
|
|
52
49
|
if (typeof previousValue === 'function' && typeof currentValue === 'function') {
|
|
53
50
|
return true;
|
|
54
51
|
}
|
|
55
|
-
|
|
56
52
|
if (Array.isArray(previousValue) && Array.isArray(currentValue)) {
|
|
57
53
|
return JSON.stringify(previousValue) === JSON.stringify(currentValue);
|
|
58
54
|
}
|
|
59
|
-
|
|
60
55
|
if (typeof previousValue === 'object' && typeof currentValue === 'object') {
|
|
61
56
|
return JSON.stringify(previousValue) === JSON.stringify(currentValue);
|
|
62
57
|
}
|
|
63
|
-
|
|
64
58
|
return false;
|
|
65
59
|
}
|
|
66
|
-
|
|
67
60
|
export default function Field(props) {
|
|
68
61
|
var _getCurrentValue;
|
|
69
|
-
|
|
70
62
|
const {
|
|
71
63
|
registerField,
|
|
72
64
|
getCurrentValue
|
|
@@ -74,19 +66,18 @@ export default function Field(props) {
|
|
|
74
66
|
const isDisabled = useContext(IsDisabledContext) || props.isDisabled || false;
|
|
75
67
|
const defaultValue = isFunction(props.defaultValue) ? props.defaultValue() : props.defaultValue;
|
|
76
68
|
const latestPropsRef = usePreviousRef(props);
|
|
69
|
+
|
|
77
70
|
/**
|
|
78
71
|
* HACK: defaultValue can potentially be an array or object which cannot be
|
|
79
72
|
* passed directly into a `useEffect` dependency array, since it will trigger
|
|
80
73
|
* the hook every time.
|
|
81
74
|
*/
|
|
82
|
-
|
|
83
75
|
const isDefaultValueChanged = !isShallowEqual(latestPropsRef.current.defaultValue, props.defaultValue);
|
|
84
76
|
const [state, setState] = useState({
|
|
85
77
|
fieldProps: {
|
|
86
78
|
onChange: () => {},
|
|
87
79
|
onBlur: () => {},
|
|
88
80
|
onFocus: () => {},
|
|
89
|
-
|
|
90
81
|
/* Previously, defaultValue was being set as undefined in Field.defaultProps, which
|
|
91
82
|
* effectively made it an optional prop to external consumers of Field. However the
|
|
92
83
|
* prop types defined defaultValue as required, so inside the component it was not
|
|
@@ -119,7 +110,6 @@ export default function Field(props) {
|
|
|
119
110
|
if (process.env.NODE_ENV !== 'production' && !process.env.CI) {
|
|
120
111
|
invariant(latestPropsRef.current.name, '@atlaskit/form: Field components have a required name prop');
|
|
121
112
|
}
|
|
122
|
-
|
|
123
113
|
function fieldStateToMeta(value = {}) {
|
|
124
114
|
return {
|
|
125
115
|
dirty: value.dirty || false,
|
|
@@ -133,7 +123,6 @@ export default function Field(props) {
|
|
|
133
123
|
validating: !!value.validating
|
|
134
124
|
};
|
|
135
125
|
}
|
|
136
|
-
|
|
137
126
|
const unregister = registerField(latestPropsRef.current.name,
|
|
138
127
|
/**
|
|
139
128
|
* Similar as for setting initial state value.
|
|
@@ -144,47 +133,44 @@ export default function Field(props) {
|
|
|
144
133
|
* the key prop to re-run validation.
|
|
145
134
|
*/
|
|
146
135
|
// @ts-ignore
|
|
147
|
-
isDefaultValueChanged ||
|
|
136
|
+
isDefaultValueChanged ||
|
|
137
|
+
// @ts-ignore
|
|
148
138
|
isFunction(latestPropsRef.current.defaultValue) ? latestPropsRef.current.defaultValue : latestStateRef.current.fieldProps.value, fieldState => {
|
|
149
139
|
/**
|
|
150
140
|
* Do not update dirtySinceLastSubmit until submission has finished.
|
|
151
141
|
*/
|
|
152
142
|
const modifiedDirtySinceLastSubmit = fieldState.submitting ? latestStateRef.current.meta.dirtySinceLastSubmit : fieldState.dirtySinceLastSubmit;
|
|
143
|
+
|
|
153
144
|
/**
|
|
154
145
|
* Do not update submitFailed until submission has finished.
|
|
155
146
|
*/
|
|
156
|
-
|
|
157
147
|
const modifiedSubmitFailed = fieldState.submitting ? latestStateRef.current.meta.submitFailed : fieldState.submitFailed;
|
|
148
|
+
|
|
158
149
|
/**
|
|
159
150
|
* Do not use submitError if the value has changed.
|
|
160
151
|
*/
|
|
161
|
-
|
|
162
152
|
const modifiedSubmitError = modifiedDirtySinceLastSubmit && latestPropsRef.current.validate ? undefined : fieldState.submitError;
|
|
163
153
|
const modifiedError = modifiedSubmitError || (fieldState.touched || fieldState.dirty) && fieldState.error;
|
|
154
|
+
|
|
164
155
|
/**
|
|
165
156
|
* If there has been a submit error, then use logic in modifiedError to determine validity,
|
|
166
157
|
* so we can determine when there is a submit error which we do not want to display
|
|
167
158
|
* because the value has been changed.
|
|
168
159
|
*/
|
|
169
|
-
|
|
170
160
|
const modifiedValid = modifiedSubmitFailed ? modifiedError === undefined : fieldState.valid;
|
|
171
|
-
|
|
172
161
|
function getTransform(eventOrValue, currentValue) {
|
|
173
162
|
if (latestPropsRef.current.transform) {
|
|
174
163
|
return latestPropsRef.current.transform(eventOrValue, currentValue);
|
|
175
164
|
}
|
|
176
|
-
|
|
177
165
|
if (isEvent(eventOrValue)) {
|
|
178
166
|
const {
|
|
179
167
|
currentTarget
|
|
180
168
|
} = eventOrValue;
|
|
181
|
-
|
|
182
169
|
if (currentTarget.type === 'checkbox') {
|
|
183
170
|
//@ts-expect-error TODO Fix legit TypeScript 3.9.6 improved inference error
|
|
184
171
|
if (currentTarget.checked) {
|
|
185
172
|
return currentTarget.value || true;
|
|
186
173
|
}
|
|
187
|
-
|
|
188
174
|
return currentTarget.value ? undefined : false;
|
|
189
175
|
} else if (currentTarget) {
|
|
190
176
|
return currentTarget.value;
|
|
@@ -193,7 +179,6 @@ export default function Field(props) {
|
|
|
193
179
|
return eventOrValue;
|
|
194
180
|
}
|
|
195
181
|
}
|
|
196
|
-
|
|
197
182
|
setState({
|
|
198
183
|
fieldProps: {
|
|
199
184
|
onChange: e => {
|
|
@@ -204,7 +189,6 @@ export default function Field(props) {
|
|
|
204
189
|
value: fieldState.value
|
|
205
190
|
},
|
|
206
191
|
error: modifiedError || undefined,
|
|
207
|
-
|
|
208
192
|
/**
|
|
209
193
|
* The following parameters are optionally typed in final-form to indicate that not all parameters need
|
|
210
194
|
* to be subscribed to. We cast them as booleans (using || false), since this is what they are semantically.
|
|
@@ -226,7 +210,6 @@ export default function Field(props) {
|
|
|
226
210
|
}, {
|
|
227
211
|
getValidator: () => function validate(value, formState, fieldState) {
|
|
228
212
|
const supplied = latestPropsRef.current.validate;
|
|
229
|
-
|
|
230
213
|
if (supplied && fieldState) {
|
|
231
214
|
return supplied(value, formState, fieldStateToMeta(fieldState));
|
|
232
215
|
}
|
|
@@ -234,11 +217,13 @@ export default function Field(props) {
|
|
|
234
217
|
});
|
|
235
218
|
return unregister;
|
|
236
219
|
}, [latestPropsRef, latestStateRef, registerField, props.name, isDefaultValueChanged]);
|
|
237
|
-
const fieldId = useMemo(
|
|
220
|
+
const fieldId = useMemo(
|
|
221
|
+
// eslint-disable-next-line @repo/internal/react/disallow-unstable-values
|
|
238
222
|
() => props.id ? props.id : `${props.name}-${uid({
|
|
239
223
|
id: props.name
|
|
240
224
|
})}`, [props.id, props.name]);
|
|
241
|
-
const extendedFieldProps = {
|
|
225
|
+
const extendedFieldProps = {
|
|
226
|
+
...state.fieldProps,
|
|
242
227
|
name: props.name,
|
|
243
228
|
isDisabled,
|
|
244
229
|
isInvalid: Boolean(state.error),
|
package/dist/es2019/fieldset.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
|
|
2
3
|
import { css, jsx } from '@emotion/react';
|
|
3
4
|
import { subtleHeading } from '@atlaskit/theme/colors';
|
|
4
5
|
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
@@ -15,11 +16,11 @@ const fieldsetLabelStyles = css({
|
|
|
15
16
|
const fieldSetStyles = css({
|
|
16
17
|
marginTop: `${gridSize}px`
|
|
17
18
|
});
|
|
19
|
+
|
|
18
20
|
/**
|
|
19
21
|
* TODO: Address duplication with packages/design-system/form/src/label.tsx
|
|
20
22
|
* in https://product-fabric.atlassian.net/browse/DSP-7731
|
|
21
23
|
*/
|
|
22
|
-
|
|
23
24
|
const getFieldsetLabelDynamicStyles = mode => css([h200({
|
|
24
25
|
theme: {
|
|
25
26
|
mode
|
|
@@ -30,13 +31,13 @@ const getFieldsetLabelDynamicStyles = mode => css([h200({
|
|
|
30
31
|
mode
|
|
31
32
|
}
|
|
32
33
|
})})`
|
|
33
|
-
}]);
|
|
34
|
+
}]);
|
|
34
35
|
|
|
36
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
37
|
+
const lightH200Styles = getFieldsetLabelDynamicStyles('light');
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
38
40
|
const darkH200Styles = getFieldsetLabelDynamicStyles('dark');
|
|
39
|
-
|
|
40
41
|
const FieldsetLabel = ({
|
|
41
42
|
children
|
|
42
43
|
}) => {
|
|
@@ -47,6 +48,7 @@ const FieldsetLabel = ({
|
|
|
47
48
|
css: [mode === 'light' ? lightH200Styles : darkH200Styles, fieldsetLabelStyles]
|
|
48
49
|
}, children);
|
|
49
50
|
};
|
|
51
|
+
|
|
50
52
|
/**
|
|
51
53
|
* __Fieldset__
|
|
52
54
|
*
|
|
@@ -57,8 +59,6 @@ const FieldsetLabel = ({
|
|
|
57
59
|
* - [Code](https://atlaskit.atlassian.com/packages/design-system/form/docs/fields)
|
|
58
60
|
* - [Usage](https://atlaskit.atlassian.com/packages/design-system/form/docs/fields)
|
|
59
61
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
62
|
const Fieldset = ({
|
|
63
63
|
children,
|
|
64
64
|
legend
|
|
@@ -67,5 +67,4 @@ const Fieldset = ({
|
|
|
67
67
|
css: fieldSetStyles
|
|
68
68
|
}, legend && jsx("legend", null, jsx(FieldsetLabel, null, legend)), children);
|
|
69
69
|
};
|
|
70
|
-
|
|
71
70
|
export default Fieldset;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
|
|
2
3
|
import { css, jsx } from '@emotion/react';
|
|
3
4
|
import { gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
4
5
|
const gridSize = getGridSize();
|
|
@@ -10,6 +11,7 @@ const formFooterWrapperStyles = css({
|
|
|
10
11
|
const justifyContentStyles = css({
|
|
11
12
|
justifyContent: 'flex-start'
|
|
12
13
|
});
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* __Form footer__
|
|
15
17
|
*
|
|
@@ -19,7 +21,6 @@ const justifyContentStyles = css({
|
|
|
19
21
|
* - [Code](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
20
22
|
* - [Usage](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
21
23
|
*/
|
|
22
|
-
|
|
23
24
|
export default function FormFooter({
|
|
24
25
|
align = 'end',
|
|
25
26
|
children
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
|
|
2
3
|
import { css, jsx } from '@emotion/react';
|
|
3
4
|
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
4
5
|
import { fontFamily as getFontFamily, gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
@@ -22,20 +23,20 @@ const formHeaderTitleStyles = css({
|
|
|
22
23
|
});
|
|
23
24
|
const formHeaderWrapperStyles = css({
|
|
24
25
|
fontFamily: `${fontFamily}`
|
|
25
|
-
});
|
|
26
|
+
});
|
|
26
27
|
|
|
28
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
27
29
|
const darkH700Styles = css(h700({
|
|
28
30
|
theme: {
|
|
29
31
|
mode: 'dark'
|
|
30
32
|
}
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
+
}));
|
|
34
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
33
35
|
const lightH700Styles = css(h700({
|
|
34
36
|
theme: {
|
|
35
37
|
mode: 'light'
|
|
36
38
|
}
|
|
37
39
|
}));
|
|
38
|
-
|
|
39
40
|
const FormHeaderContent = ({
|
|
40
41
|
children
|
|
41
42
|
}) => {
|
|
@@ -43,7 +44,6 @@ const FormHeaderContent = ({
|
|
|
43
44
|
css: formHeaderContentStyles
|
|
44
45
|
}, children);
|
|
45
46
|
};
|
|
46
|
-
|
|
47
47
|
const FormHeaderDescription = ({
|
|
48
48
|
children
|
|
49
49
|
}) => {
|
|
@@ -51,7 +51,6 @@ const FormHeaderDescription = ({
|
|
|
51
51
|
css: formHeaderDescriptionStyles
|
|
52
52
|
}, children);
|
|
53
53
|
};
|
|
54
|
-
|
|
55
54
|
const FormHeaderTitle = ({
|
|
56
55
|
children
|
|
57
56
|
}) => {
|
|
@@ -62,7 +61,6 @@ const FormHeaderTitle = ({
|
|
|
62
61
|
css: [mode === 'light' ? lightH700Styles : darkH700Styles, formHeaderTitleStyles]
|
|
63
62
|
}, children);
|
|
64
63
|
};
|
|
65
|
-
|
|
66
64
|
const FormHeaderWrapper = ({
|
|
67
65
|
children
|
|
68
66
|
}) => {
|
|
@@ -70,6 +68,7 @@ const FormHeaderWrapper = ({
|
|
|
70
68
|
css: formHeaderWrapperStyles
|
|
71
69
|
}, children);
|
|
72
70
|
};
|
|
71
|
+
|
|
73
72
|
/**
|
|
74
73
|
* __Form header__
|
|
75
74
|
*
|
|
@@ -80,8 +79,6 @@ const FormHeaderWrapper = ({
|
|
|
80
79
|
* - [Code](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
81
80
|
* - [Usage](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
82
81
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
82
|
const FormHeader = ({
|
|
86
83
|
children,
|
|
87
84
|
description,
|
|
@@ -89,6 +86,5 @@ const FormHeader = ({
|
|
|
89
86
|
}) => {
|
|
90
87
|
return jsx(FormHeaderWrapper, null, title && jsx(FormHeaderTitle, null, title), description && jsx(FormHeaderDescription, null, description), children && jsx(FormHeaderContent, null, children));
|
|
91
88
|
};
|
|
92
|
-
|
|
93
89
|
export default FormHeader;
|
|
94
90
|
export { FormHeaderContent, FormHeaderDescription, FormHeaderTitle };
|
|
@@ -18,20 +18,20 @@ const formSectionTitleStyles = css({
|
|
|
18
18
|
});
|
|
19
19
|
const formSectionWrapperStyles = css({
|
|
20
20
|
marginTop: `${gridSize * 3}px`
|
|
21
|
-
});
|
|
21
|
+
});
|
|
22
22
|
|
|
23
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
23
24
|
const lightH600Styles = css(h600({
|
|
24
25
|
theme: {
|
|
25
26
|
mode: 'light'
|
|
26
27
|
}
|
|
27
|
-
}));
|
|
28
|
-
|
|
28
|
+
}));
|
|
29
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
29
30
|
const darkH600Styles = css(h600({
|
|
30
31
|
theme: {
|
|
31
32
|
mode: 'dark'
|
|
32
33
|
}
|
|
33
34
|
}));
|
|
34
|
-
|
|
35
35
|
const FormSectionWrapper = ({
|
|
36
36
|
children
|
|
37
37
|
}) => {
|
|
@@ -39,7 +39,6 @@ const FormSectionWrapper = ({
|
|
|
39
39
|
css: formSectionWrapperStyles
|
|
40
40
|
}, children);
|
|
41
41
|
};
|
|
42
|
-
|
|
43
42
|
const FormSectionTitle = ({
|
|
44
43
|
children
|
|
45
44
|
}) => {
|
|
@@ -50,7 +49,6 @@ const FormSectionTitle = ({
|
|
|
50
49
|
css: [formSectionTitleStyles, mode === 'light' ? lightH600Styles : darkH600Styles]
|
|
51
50
|
}, children);
|
|
52
51
|
};
|
|
53
|
-
|
|
54
52
|
const FormSectionDescription = ({
|
|
55
53
|
children
|
|
56
54
|
}) => {
|
|
@@ -58,6 +56,7 @@ const FormSectionDescription = ({
|
|
|
58
56
|
css: formSectionDescriptionStyles
|
|
59
57
|
}, children);
|
|
60
58
|
};
|
|
59
|
+
|
|
61
60
|
/**
|
|
62
61
|
* __Form section__
|
|
63
62
|
*
|
|
@@ -68,8 +67,6 @@ const FormSectionDescription = ({
|
|
|
68
67
|
* - [Code](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
69
68
|
* - [Usage](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
70
69
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
70
|
const FormSection = ({
|
|
74
71
|
children,
|
|
75
72
|
description,
|
|
@@ -77,5 +74,4 @@ const FormSection = ({
|
|
|
77
74
|
}) => {
|
|
78
75
|
return jsx(FormSectionWrapper, null, title && jsx(FormSectionTitle, null, title), description && jsx(FormSectionDescription, null, description), children);
|
|
79
76
|
};
|
|
80
|
-
|
|
81
77
|
export default FormSection;
|
package/dist/es2019/form.js
CHANGED
|
@@ -2,7 +2,6 @@ import React, { createContext, useCallback, useEffect, useMemo, useRef, useState
|
|
|
2
2
|
import { createForm } from 'final-form';
|
|
3
3
|
import createDecorator from 'final-form-focus';
|
|
4
4
|
import set from 'lodash/set';
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* __Form context__
|
|
8
7
|
*
|
|
@@ -14,12 +13,12 @@ export const FormContext = /*#__PURE__*/createContext({
|
|
|
14
13
|
},
|
|
15
14
|
getCurrentValue: () => undefined
|
|
16
15
|
});
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* __Is disabled context__
|
|
19
19
|
*
|
|
20
20
|
* An is disabled context creates the context for when a value is disabled.
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
22
|
export const IsDisabledContext = /*#__PURE__*/createContext(false);
|
|
24
23
|
export default function Form(props) {
|
|
25
24
|
const formRef = useRef(null);
|
|
@@ -37,8 +36,8 @@ export default function Form(props) {
|
|
|
37
36
|
const initialValues = state.formState.initialValues;
|
|
38
37
|
const values = state.formState.values;
|
|
39
38
|
const value = name && typeof defaultValue === 'function' ? defaultValue(initialValues[name]) : defaultValue;
|
|
40
|
-
/* eslint-disable no-param-reassign */
|
|
41
39
|
|
|
40
|
+
/* eslint-disable no-param-reassign */
|
|
42
41
|
set(initialValues, name, value);
|
|
43
42
|
set(values, name, value);
|
|
44
43
|
/* eslint-enable */
|
|
@@ -46,6 +45,7 @@ export default function Form(props) {
|
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
});
|
|
48
|
+
|
|
49
49
|
createDecorator(() => formRef.current ? Array.from(formRef.current.querySelectorAll('input')) : [])(finalForm);
|
|
50
50
|
return finalForm;
|
|
51
51
|
});
|
|
@@ -75,31 +75,24 @@ export default function Form(props) {
|
|
|
75
75
|
form.resumeValidation();
|
|
76
76
|
return unsubscribe;
|
|
77
77
|
}, [form]);
|
|
78
|
-
|
|
79
78
|
const handleSubmit = e => {
|
|
80
79
|
if (e) {
|
|
81
80
|
e.preventDefault();
|
|
82
81
|
}
|
|
83
|
-
|
|
84
82
|
form.submit();
|
|
85
83
|
};
|
|
86
|
-
|
|
87
84
|
const handleReset = initialValues => {
|
|
88
85
|
form.reset(initialValues);
|
|
89
86
|
};
|
|
90
|
-
|
|
91
87
|
const handleKeyDown = e => {
|
|
92
88
|
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey) && formRef.current) {
|
|
93
89
|
const submitButton = formRef.current.querySelector('button:not([type]), button[type="submit"], input[type="submit"]');
|
|
94
|
-
|
|
95
90
|
if (submitButton) {
|
|
96
91
|
submitButton.click();
|
|
97
92
|
}
|
|
98
|
-
|
|
99
93
|
e.preventDefault();
|
|
100
94
|
}
|
|
101
95
|
};
|
|
102
|
-
|
|
103
96
|
const {
|
|
104
97
|
isDisabled = false,
|
|
105
98
|
children
|
|
@@ -108,11 +101,11 @@ export default function Form(props) {
|
|
|
108
101
|
dirty,
|
|
109
102
|
submitting
|
|
110
103
|
} = state;
|
|
104
|
+
|
|
111
105
|
/**
|
|
112
106
|
* This method is needed in FormContext to use it on the field level
|
|
113
107
|
* to check the current value of the field in case of the component re-mounting.
|
|
114
108
|
*/
|
|
115
|
-
|
|
116
109
|
const getCurrentValue = useCallback(name => {
|
|
117
110
|
const formState = form.getState();
|
|
118
111
|
return (formState === null || formState === void 0 ? void 0 : formState.values[name]) || undefined;
|
package/dist/es2019/index.js
CHANGED
|
@@ -7,4 +7,5 @@ export { default as CheckboxField } from './checkbox-field';
|
|
|
7
7
|
export { default as RangeField } from './range-field';
|
|
8
8
|
export { default as Label } from './label';
|
|
9
9
|
export { HelperMessage, ErrorMessage, ValidMessage } from './messages';
|
|
10
|
-
export { default as Fieldset } from './fieldset';
|
|
10
|
+
export { default as Fieldset } from './fieldset';
|
|
11
|
+
// eslint-disable-next-line import/no-unresolved
|
package/dist/es2019/label.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
+
|
|
2
3
|
import { css, jsx } from '@emotion/react';
|
|
3
4
|
import { subtleHeading } from '@atlaskit/theme/colors';
|
|
4
5
|
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
@@ -12,11 +13,11 @@ const labelStyles = css({
|
|
|
12
13
|
marginBottom: gridSize / 2,
|
|
13
14
|
fontFamily: fontFamily
|
|
14
15
|
});
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* TODO: Address duplication with packages/design-system/form/src/fieldset.tsx
|
|
17
19
|
* in https://product-fabric.atlassian.net/browse/DSP-7731
|
|
18
20
|
*/
|
|
19
|
-
|
|
20
21
|
const getFieldsetLabelDynamicStyles = mode => css([h200({
|
|
21
22
|
theme: {
|
|
22
23
|
mode
|
|
@@ -27,12 +28,14 @@ const getFieldsetLabelDynamicStyles = mode => css([h200({
|
|
|
27
28
|
mode
|
|
28
29
|
}
|
|
29
30
|
})})`
|
|
30
|
-
}]);
|
|
31
|
-
|
|
31
|
+
}]);
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
34
|
+
const lightH200Styles = getFieldsetLabelDynamicStyles('light');
|
|
34
35
|
|
|
36
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
35
37
|
const darkH200Styles = getFieldsetLabelDynamicStyles('dark');
|
|
38
|
+
|
|
36
39
|
/**
|
|
37
40
|
* __Label__
|
|
38
41
|
*
|
|
@@ -41,7 +44,6 @@ const darkH200Styles = getFieldsetLabelDynamicStyles('dark');
|
|
|
41
44
|
* It's recommended that a label has a `4px` spacing above its associated
|
|
42
45
|
* control element.
|
|
43
46
|
*/
|
|
44
|
-
|
|
45
47
|
const Label = ({
|
|
46
48
|
children,
|
|
47
49
|
htmlFor,
|
|
@@ -56,5 +58,4 @@ const Label = ({
|
|
|
56
58
|
htmlFor: htmlFor
|
|
57
59
|
}, children);
|
|
58
60
|
};
|
|
59
|
-
|
|
60
61
|
export default Label;
|