@atlaskit/form 8.3.1 → 8.4.3
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 +29 -0
- package/CheckboxField/package.json +4 -4
- package/Field/package.json +4 -4
- package/Fieldset/package.json +4 -4
- package/Form/package.json +4 -4
- package/FormFooter/package.json +4 -4
- package/FormHeader/package.json +4 -4
- package/FormSection/package.json +4 -4
- package/Messages/package.json +4 -4
- package/RangeField/package.json +4 -4
- package/dist/cjs/{CheckboxField.js → checkbox-field.js} +12 -3
- package/dist/cjs/entry-points/checkbox-field.js +15 -0
- package/dist/cjs/entry-points/field.js +15 -0
- package/dist/cjs/entry-points/fieldset.js +15 -0
- package/dist/cjs/entry-points/form-footer.js +15 -0
- package/dist/cjs/entry-points/form-header.js +15 -0
- package/dist/cjs/entry-points/form-section.js +15 -0
- package/dist/cjs/entry-points/form.js +15 -0
- package/dist/cjs/entry-points/messages.js +25 -0
- package/dist/cjs/entry-points/range-field.js +15 -0
- package/dist/cjs/{Field.js → field.js} +80 -15
- package/dist/cjs/fieldset.js +72 -0
- package/dist/cjs/form-footer.js +39 -0
- package/dist/cjs/form-header.js +107 -0
- package/dist/cjs/form-section.js +93 -0
- package/dist/cjs/{Form.js → form.js} +11 -0
- package/dist/cjs/index.js +20 -20
- package/dist/cjs/messages.js +157 -0
- package/dist/cjs/{RangeField.js → range-field.js} +11 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/{CheckboxField.js → checkbox-field.js} +10 -1
- package/dist/es2019/entry-points/checkbox-field.js +1 -0
- package/dist/es2019/entry-points/field.js +1 -0
- package/dist/es2019/entry-points/fieldset.js +1 -0
- package/dist/es2019/entry-points/form-footer.js +1 -0
- package/dist/es2019/entry-points/form-header.js +1 -0
- package/dist/es2019/entry-points/form-section.js +1 -0
- package/dist/es2019/entry-points/form.js +1 -0
- package/dist/es2019/entry-points/messages.js +1 -0
- package/dist/es2019/entry-points/range-field.js +1 -0
- package/dist/es2019/{Field.js → field.js} +73 -13
- package/dist/es2019/fieldset.js +61 -0
- package/dist/es2019/form-footer.js +30 -0
- package/dist/es2019/form-header.js +94 -0
- package/dist/es2019/form-section.js +81 -0
- package/dist/es2019/{Form.js → form.js} +12 -0
- package/dist/es2019/index.js +9 -9
- package/dist/es2019/messages.js +122 -0
- package/dist/es2019/{RangeField.js → range-field.js} +10 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/{CheckboxField.js → checkbox-field.js} +10 -1
- package/dist/esm/entry-points/checkbox-field.js +1 -0
- package/dist/esm/entry-points/field.js +1 -0
- package/dist/esm/entry-points/fieldset.js +1 -0
- package/dist/esm/entry-points/form-footer.js +1 -0
- package/dist/esm/entry-points/form-header.js +1 -0
- package/dist/esm/entry-points/form-section.js +1 -0
- package/dist/esm/entry-points/form.js +1 -0
- package/dist/esm/entry-points/messages.js +1 -0
- package/dist/esm/entry-points/range-field.js +1 -0
- package/dist/esm/{Field.js → field.js} +73 -13
- package/dist/esm/fieldset.js +60 -0
- package/dist/esm/form-footer.js +30 -0
- package/dist/esm/form-header.js +90 -0
- package/dist/esm/form-section.js +78 -0
- package/dist/esm/{Form.js → form.js} +12 -0
- package/dist/esm/index.js +9 -9
- package/dist/esm/messages.js +130 -0
- package/dist/esm/{RangeField.js → range-field.js} +11 -2
- package/dist/esm/version.json +1 -1
- package/dist/types/checkbox-field.d.ts +51 -0
- package/dist/types/entry-points/checkbox-field.d.ts +2 -0
- package/dist/types/entry-points/field.d.ts +2 -0
- package/dist/types/entry-points/fieldset.d.ts +1 -0
- package/dist/types/entry-points/form-footer.d.ts +1 -0
- package/dist/types/entry-points/form-header.d.ts +1 -0
- package/dist/types/entry-points/form-section.d.ts +1 -0
- package/dist/types/entry-points/form.d.ts +1 -0
- package/dist/types/entry-points/messages.d.ts +1 -0
- package/dist/types/entry-points/range-field.d.ts +2 -0
- package/dist/types/field.d.ts +78 -0
- package/dist/types/fieldset.d.ts +24 -0
- package/dist/types/form-footer.d.ts +23 -0
- package/dist/types/form-header.d.ts +32 -0
- package/dist/types/form-section.d.ts +28 -0
- package/dist/types/{Form.d.ts → form.d.ts} +23 -1
- package/dist/types/index.d.ts +13 -13
- package/dist/types/messages.d.ts +48 -0
- package/dist/types/range-field.d.ts +41 -0
- package/extract-react-types/checkbox-field-props.tsx +1 -1
- package/extract-react-types/field-props.tsx +5 -0
- package/extract-react-types/fieldset-props.tsx +5 -0
- package/extract-react-types/form-footer-props.tsx +5 -0
- package/extract-react-types/form-header-props.tsx +5 -0
- package/extract-react-types/form-props.tsx +5 -0
- package/extract-react-types/form-section-props.tsx +5 -0
- package/extract-react-types/range-field-props.tsx +1 -1
- package/package.json +30 -13
- package/dist/cjs/Fieldset.js +0 -32
- package/dist/cjs/FormFooter.js +0 -63
- package/dist/cjs/FormHeader.js +0 -57
- package/dist/cjs/FormSection.js +0 -57
- package/dist/cjs/Messages.js +0 -91
- package/dist/cjs/styled/Field.js +0 -41
- package/dist/cjs/styled/FormFooter.js +0 -25
- package/dist/cjs/styled/FormHeader.js +0 -49
- package/dist/cjs/styled/FormSection.js +0 -41
- package/dist/es2019/Fieldset.js +0 -14
- package/dist/es2019/FormFooter.js +0 -19
- package/dist/es2019/FormHeader.js +0 -13
- package/dist/es2019/FormSection.js +0 -13
- package/dist/es2019/Messages.js +0 -60
- package/dist/es2019/styled/Field.js +0 -29
- package/dist/es2019/styled/FormFooter.js +0 -11
- package/dist/es2019/styled/FormHeader.js +0 -40
- package/dist/es2019/styled/FormSection.js +0 -32
- package/dist/esm/Fieldset.js +0 -15
- package/dist/esm/FormFooter.js +0 -45
- package/dist/esm/FormHeader.js +0 -39
- package/dist/esm/FormSection.js +0 -39
- package/dist/esm/Messages.js +0 -63
- package/dist/esm/styled/Field.js +0 -21
- package/dist/esm/styled/FormFooter.js +0 -13
- package/dist/esm/styled/FormHeader.js +0 -29
- package/dist/esm/styled/FormSection.js +0 -24
- package/dist/types/CheckboxField.d.ts +0 -21
- package/dist/types/Field.d.ts +0 -45
- package/dist/types/Fieldset.d.ts +0 -7
- package/dist/types/FormFooter.d.ts +0 -15
- package/dist/types/FormHeader.d.ts +0 -13
- package/dist/types/FormSection.d.ts +0 -13
- package/dist/types/Messages.d.ts +0 -14
- package/dist/types/RangeField.d.ts +0 -17
- package/dist/types/styled/Field.d.ts +0 -11
- package/dist/types/styled/FormFooter.d.ts +0 -9
- package/dist/types/styled/FormHeader.d.ts +0 -19
- package/dist/types/styled/FormSection.d.ts +0 -15
- package/types/package.json +0 -7
|
@@ -6,11 +6,59 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
6
6
|
|
|
7
7
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
8
|
|
|
9
|
+
/** @jsx jsx */
|
|
9
10
|
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
11
|
+
import { css, jsx } from '@emotion/core';
|
|
10
12
|
import { uid } from 'react-uid';
|
|
11
13
|
import invariant from 'tiny-invariant';
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
+
import { R400 } from '@atlaskit/theme/colors';
|
|
15
|
+
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
16
|
+
import { fontFamily as getFontFamily, gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
17
|
+
import { h200 } from '@atlaskit/theme/typography';
|
|
18
|
+
import { token } from '@atlaskit/tokens';
|
|
19
|
+
import { FormContext, IsDisabledContext } from './form';
|
|
20
|
+
var gridSize = getGridSize();
|
|
21
|
+
var fontFamily = getFontFamily();
|
|
22
|
+
var fieldWrapperStyles = css({
|
|
23
|
+
marginTop: "".concat(gridSize, "px")
|
|
24
|
+
});
|
|
25
|
+
var labelStyles = css({
|
|
26
|
+
display: 'inline-block',
|
|
27
|
+
marginTop: 0,
|
|
28
|
+
marginBottom: "".concat(gridSize * 0.5, "px"),
|
|
29
|
+
fontFamily: "".concat(fontFamily)
|
|
30
|
+
});
|
|
31
|
+
var requiredIndicatorStyles = css({
|
|
32
|
+
paddingLeft: "".concat(gridSize * 0.25, "px"),
|
|
33
|
+
color: "".concat(token('color.text.danger', R400)),
|
|
34
|
+
fontFamily: "".concat(fontFamily)
|
|
35
|
+
}); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
36
|
+
|
|
37
|
+
var lightH200Styles = css(h200({
|
|
38
|
+
theme: {
|
|
39
|
+
mode: 'light'
|
|
40
|
+
}
|
|
41
|
+
})); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
42
|
+
|
|
43
|
+
var darkH200Styles = css(h200({
|
|
44
|
+
theme: {
|
|
45
|
+
mode: 'dark'
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
var Label = function Label(_ref) {
|
|
50
|
+
var children = _ref.children,
|
|
51
|
+
fieldId = _ref.fieldId;
|
|
52
|
+
|
|
53
|
+
var _useGlobalTheme = useGlobalTheme(),
|
|
54
|
+
mode = _useGlobalTheme.mode;
|
|
55
|
+
|
|
56
|
+
return jsx("label", {
|
|
57
|
+
css: [mode === 'light' ? lightH200Styles : darkH200Styles, labelStyles],
|
|
58
|
+
id: "".concat(fieldId, "-label"),
|
|
59
|
+
htmlFor: fieldId
|
|
60
|
+
}, children);
|
|
61
|
+
};
|
|
14
62
|
|
|
15
63
|
function isEvent(event) {
|
|
16
64
|
return Boolean(event && event.target);
|
|
@@ -20,8 +68,11 @@ function isFunction(x) {
|
|
|
20
68
|
return typeof x === 'function';
|
|
21
69
|
}
|
|
22
70
|
|
|
23
|
-
|
|
24
|
-
|
|
71
|
+
/**
|
|
72
|
+
* __Field id__
|
|
73
|
+
*
|
|
74
|
+
* 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.
|
|
75
|
+
*/
|
|
25
76
|
export var FieldId = /*#__PURE__*/React.createContext(undefined);
|
|
26
77
|
|
|
27
78
|
function usePreviousRef(current) {
|
|
@@ -124,12 +175,18 @@ export default function Field(props) {
|
|
|
124
175
|
|
|
125
176
|
var unregister = registerField(latestPropsRef.current.name, // @ts-ignore
|
|
126
177
|
latestPropsRef.current.defaultValue, function (fieldState) {
|
|
127
|
-
/**
|
|
178
|
+
/**
|
|
179
|
+
* Do not update dirtySinceLastSubmit until submission has finished.
|
|
180
|
+
*/
|
|
128
181
|
var modifiedDirtySinceLastSubmit = fieldState.submitting ? latestStateRef.current.meta.dirtySinceLastSubmit : fieldState.dirtySinceLastSubmit;
|
|
129
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Do not update submitFailed until submission has finished.
|
|
184
|
+
*/
|
|
130
185
|
|
|
131
186
|
var modifiedSubmitFailed = fieldState.submitting ? latestStateRef.current.meta.submitFailed : fieldState.submitFailed;
|
|
132
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* Do not use submitError if the value has changed.
|
|
189
|
+
*/
|
|
133
190
|
|
|
134
191
|
var modifiedSubmitError = modifiedDirtySinceLastSubmit && latestPropsRef.current.validate ? undefined : fieldState.submitError;
|
|
135
192
|
var modifiedError = modifiedSubmitError || (fieldState.touched || fieldState.dirty) && fieldState.error;
|
|
@@ -206,7 +263,8 @@ export default function Field(props) {
|
|
|
206
263
|
});
|
|
207
264
|
return unregister;
|
|
208
265
|
}, [latestPropsRef, latestStateRef, registerField, props.name, hasDefaultValueChanged]);
|
|
209
|
-
var fieldId = useMemo(
|
|
266
|
+
var fieldId = useMemo( // eslint-disable-next-line @repo/internal/react/disallow-unstable-values
|
|
267
|
+
function () {
|
|
210
268
|
return props.id ? props.id : "".concat(props.name, "-").concat(uid({
|
|
211
269
|
id: props.name
|
|
212
270
|
}));
|
|
@@ -222,12 +280,14 @@ export default function Field(props) {
|
|
|
222
280
|
id: fieldId
|
|
223
281
|
});
|
|
224
282
|
|
|
225
|
-
return
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
283
|
+
return jsx("div", {
|
|
284
|
+
css: fieldWrapperStyles
|
|
285
|
+
}, props.label && jsx(Label, {
|
|
286
|
+
fieldId: fieldId
|
|
287
|
+
}, props.label, props.isRequired && jsx("span", {
|
|
288
|
+
css: requiredIndicatorStyles,
|
|
229
289
|
"aria-hidden": "true"
|
|
230
|
-
}, "*")),
|
|
290
|
+
}, "*")), jsx(FieldId.Provider, {
|
|
231
291
|
value: fieldId
|
|
232
292
|
}, props.children({
|
|
233
293
|
fieldProps: extendedFieldProps,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { css, jsx } from '@emotion/core';
|
|
3
|
+
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
4
|
+
import { fontFamily as getFontFamily, gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
5
|
+
import { h200 } from '@atlaskit/theme/typography';
|
|
6
|
+
var fontFamily = getFontFamily();
|
|
7
|
+
var gridSize = getGridSize();
|
|
8
|
+
var fieldsetLabelStyles = css({
|
|
9
|
+
display: 'inline-block',
|
|
10
|
+
marginTop: 0,
|
|
11
|
+
marginBottom: 0,
|
|
12
|
+
fontFamily: "".concat(fontFamily)
|
|
13
|
+
});
|
|
14
|
+
var fieldSetStyles = css({
|
|
15
|
+
marginTop: "".concat(gridSize, "px")
|
|
16
|
+
}); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
17
|
+
|
|
18
|
+
var lightH200Styles = css(h200({
|
|
19
|
+
theme: {
|
|
20
|
+
mode: 'light'
|
|
21
|
+
}
|
|
22
|
+
})); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
23
|
+
|
|
24
|
+
var darkH200Styles = css(h200({
|
|
25
|
+
theme: {
|
|
26
|
+
mode: 'dark'
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
var FieldsetLabel = function FieldsetLabel(_ref) {
|
|
31
|
+
var children = _ref.children;
|
|
32
|
+
|
|
33
|
+
var _useGlobalTheme = useGlobalTheme(),
|
|
34
|
+
mode = _useGlobalTheme.mode;
|
|
35
|
+
|
|
36
|
+
return jsx("label", {
|
|
37
|
+
css: [mode === 'light' ? lightH200Styles : darkH200Styles, fieldsetLabelStyles]
|
|
38
|
+
}, children);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* __Fieldset__
|
|
42
|
+
*
|
|
43
|
+
* A fieldset groups a number of fields together. For example, when multiple CheckboxFields share the same name,
|
|
44
|
+
* a fieldset can be used to group them together. This makes the form more accessible.
|
|
45
|
+
*
|
|
46
|
+
* - [Examples](https://atlaskit.atlassian.com/packages/design-system/form/docs/fields)
|
|
47
|
+
* - [Code](https://atlaskit.atlassian.com/packages/design-system/form/docs/fields)
|
|
48
|
+
* - [Usage](https://atlaskit.atlassian.com/packages/design-system/form/docs/fields)
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
var Fieldset = function Fieldset(_ref2) {
|
|
53
|
+
var children = _ref2.children,
|
|
54
|
+
legend = _ref2.legend;
|
|
55
|
+
return jsx("fieldset", {
|
|
56
|
+
css: fieldSetStyles
|
|
57
|
+
}, legend && jsx("legend", null, jsx(FieldsetLabel, null, legend)), children);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default Fieldset;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { css, jsx } from '@emotion/core';
|
|
3
|
+
import { gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
4
|
+
var gridSize = getGridSize();
|
|
5
|
+
var formFooterWrapperStyles = css({
|
|
6
|
+
display: 'flex',
|
|
7
|
+
marginTop: "".concat(gridSize * 3, "px"),
|
|
8
|
+
justifyContent: 'flex-end'
|
|
9
|
+
});
|
|
10
|
+
var justifyContentStyles = css({
|
|
11
|
+
justifyContent: 'flex-start'
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* __Form footer__
|
|
15
|
+
*
|
|
16
|
+
* A form footer has the content to be shown at the bottom of the form. This is usually the submit button.
|
|
17
|
+
*
|
|
18
|
+
* - [Examples](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
19
|
+
* - [Code](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
20
|
+
* - [Usage](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export default function FormFooter(_ref) {
|
|
24
|
+
var _ref$align = _ref.align,
|
|
25
|
+
align = _ref$align === void 0 ? 'end' : _ref$align,
|
|
26
|
+
children = _ref.children;
|
|
27
|
+
return jsx("footer", {
|
|
28
|
+
css: [formFooterWrapperStyles, align === 'start' && justifyContentStyles]
|
|
29
|
+
}, children);
|
|
30
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { css, jsx } from '@emotion/core';
|
|
3
|
+
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
4
|
+
import { fontFamily as getFontFamily, gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
5
|
+
import { h700 } from '@atlaskit/theme/typography';
|
|
6
|
+
var gridSize = getGridSize();
|
|
7
|
+
var fontFamily = getFontFamily();
|
|
8
|
+
var formHeaderContentStyles = css({
|
|
9
|
+
minWidth: '100%',
|
|
10
|
+
marginTop: "".concat(gridSize, "px")
|
|
11
|
+
});
|
|
12
|
+
var formHeaderDescriptionStyles = css({
|
|
13
|
+
marginTop: "".concat(gridSize, "px")
|
|
14
|
+
});
|
|
15
|
+
var formHeaderTitleStyles = css({
|
|
16
|
+
marginTop: 0,
|
|
17
|
+
marginRight: "".concat(gridSize * 4, "px"),
|
|
18
|
+
lineHeight: "".concat(gridSize * 4, "px"),
|
|
19
|
+
overflow: 'hidden',
|
|
20
|
+
textOverflow: 'ellipsis',
|
|
21
|
+
whiteSpace: 'nowrap'
|
|
22
|
+
});
|
|
23
|
+
var formHeaderWrapperStyles = css({
|
|
24
|
+
fontFamily: "".concat(fontFamily)
|
|
25
|
+
}); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
26
|
+
|
|
27
|
+
var darkH700Styles = css(h700({
|
|
28
|
+
theme: {
|
|
29
|
+
mode: 'dark'
|
|
30
|
+
}
|
|
31
|
+
})); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
32
|
+
|
|
33
|
+
var lightH700Styles = css(h700({
|
|
34
|
+
theme: {
|
|
35
|
+
mode: 'light'
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
var FormHeaderContent = function FormHeaderContent(_ref) {
|
|
40
|
+
var children = _ref.children;
|
|
41
|
+
return jsx("div", {
|
|
42
|
+
css: formHeaderContentStyles
|
|
43
|
+
}, children);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
var FormHeaderDescription = function FormHeaderDescription(_ref2) {
|
|
47
|
+
var children = _ref2.children;
|
|
48
|
+
return jsx("div", {
|
|
49
|
+
css: formHeaderDescriptionStyles
|
|
50
|
+
}, children);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var FormHeaderTitle = function FormHeaderTitle(_ref3) {
|
|
54
|
+
var children = _ref3.children;
|
|
55
|
+
|
|
56
|
+
var _useGlobalTheme = useGlobalTheme(),
|
|
57
|
+
mode = _useGlobalTheme.mode;
|
|
58
|
+
|
|
59
|
+
return jsx("h2", {
|
|
60
|
+
css: [mode === 'light' ? lightH700Styles : darkH700Styles, formHeaderTitleStyles]
|
|
61
|
+
}, children);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
var FormHeaderWrapper = function FormHeaderWrapper(_ref4) {
|
|
65
|
+
var children = _ref4.children;
|
|
66
|
+
return jsx("div", {
|
|
67
|
+
css: formHeaderWrapperStyles
|
|
68
|
+
}, children);
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* __Form header__
|
|
72
|
+
*
|
|
73
|
+
* A form header contains the form component's heading and subheadings. This provides the correct padding
|
|
74
|
+
* and styling for it.
|
|
75
|
+
*
|
|
76
|
+
* - [Examples](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
77
|
+
* - [Code](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
78
|
+
* - [Usage](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
var FormHeader = function FormHeader(_ref5) {
|
|
83
|
+
var children = _ref5.children,
|
|
84
|
+
description = _ref5.description,
|
|
85
|
+
title = _ref5.title;
|
|
86
|
+
return jsx(FormHeaderWrapper, null, title && jsx(FormHeaderTitle, null, title), description && jsx(FormHeaderDescription, null, description), jsx(FormHeaderContent, null, children));
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default FormHeader;
|
|
90
|
+
export { FormHeaderContent, FormHeaderDescription, FormHeaderTitle };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/core';
|
|
4
|
+
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
5
|
+
import { gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
6
|
+
import { h600 } from '@atlaskit/theme/typography';
|
|
7
|
+
var gridSize = getGridSize();
|
|
8
|
+
var formSectionDescriptionStyles = css({
|
|
9
|
+
marginTop: "".concat(gridSize, "px")
|
|
10
|
+
});
|
|
11
|
+
var formSectionTitleStyles = css({
|
|
12
|
+
marginTop: 0,
|
|
13
|
+
marginRight: "".concat(gridSize * 4, "px"),
|
|
14
|
+
lineHeight: "".concat(gridSize * 4, "px"),
|
|
15
|
+
overflow: 'hidden',
|
|
16
|
+
textOverflow: 'ellipsis',
|
|
17
|
+
whiteSpace: 'nowrap'
|
|
18
|
+
});
|
|
19
|
+
var formSectionWrapperStyles = css({
|
|
20
|
+
marginTop: "".concat(gridSize * 3, "px")
|
|
21
|
+
}); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
22
|
+
|
|
23
|
+
var lightH600Styles = css(h600({
|
|
24
|
+
theme: {
|
|
25
|
+
mode: 'light'
|
|
26
|
+
}
|
|
27
|
+
})); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
28
|
+
|
|
29
|
+
var darkH600Styles = css(h600({
|
|
30
|
+
theme: {
|
|
31
|
+
mode: 'dark'
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
var FormSectionWrapper = function FormSectionWrapper(_ref) {
|
|
36
|
+
var children = _ref.children;
|
|
37
|
+
return jsx("div", {
|
|
38
|
+
css: formSectionWrapperStyles
|
|
39
|
+
}, children);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var FormSectionTitle = function FormSectionTitle(_ref2) {
|
|
43
|
+
var children = _ref2.children;
|
|
44
|
+
|
|
45
|
+
var _useGlobalTheme = useGlobalTheme(),
|
|
46
|
+
mode = _useGlobalTheme.mode;
|
|
47
|
+
|
|
48
|
+
return jsx("h3", {
|
|
49
|
+
css: [formSectionTitleStyles, mode === 'light' ? lightH600Styles : darkH600Styles]
|
|
50
|
+
}, children);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var FormSectionDescription = function FormSectionDescription(_ref3) {
|
|
54
|
+
var children = _ref3.children;
|
|
55
|
+
return jsx("div", {
|
|
56
|
+
css: formSectionDescriptionStyles
|
|
57
|
+
}, children);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* __Form section__
|
|
61
|
+
*
|
|
62
|
+
* A form section is used to define a section of a form layout. This contains a section title, content
|
|
63
|
+
* and a description of the section.
|
|
64
|
+
*
|
|
65
|
+
* - [Examples](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
66
|
+
* - [Code](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
67
|
+
* - [Usage](https://atlaskit.atlassian.com/packages/design-system/form/docs/layout)
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
var FormSection = function FormSection(_ref4) {
|
|
72
|
+
var children = _ref4.children,
|
|
73
|
+
description = _ref4.description,
|
|
74
|
+
title = _ref4.title;
|
|
75
|
+
return jsx(FormSectionWrapper, null, title && jsx(FormSectionTitle, null, title), description && jsx(FormSectionDescription, null, description), children);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default FormSection;
|
|
@@ -3,9 +3,21 @@ import React, { createContext, useCallback, useEffect, useRef, useState } from '
|
|
|
3
3
|
import { createForm } from 'final-form';
|
|
4
4
|
import createDecorator from 'final-form-focus';
|
|
5
5
|
import set from 'lodash/set';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* __Form context__
|
|
9
|
+
*
|
|
10
|
+
* A form context creates a context for the field values and allows them to be accessed by the children.
|
|
11
|
+
*/
|
|
6
12
|
export var FormContext = /*#__PURE__*/createContext(function () {
|
|
7
13
|
return function () {};
|
|
8
14
|
});
|
|
15
|
+
/**
|
|
16
|
+
* __Is disabled context__
|
|
17
|
+
*
|
|
18
|
+
* An is disabled context creates the context for when a value is disabled.
|
|
19
|
+
*/
|
|
20
|
+
|
|
9
21
|
export var IsDisabledContext = /*#__PURE__*/createContext(false);
|
|
10
22
|
export default function Form(props) {
|
|
11
23
|
var formRef = useRef(null);
|
package/dist/esm/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { default } from './
|
|
2
|
-
export { default as FormHeader } from './
|
|
3
|
-
export { default as FormFooter } from './
|
|
4
|
-
export { default as FormSection } from './
|
|
5
|
-
export { default as Field } from './
|
|
6
|
-
export { default as CheckboxField } from './
|
|
7
|
-
export { default as RangeField } from './
|
|
8
|
-
export { HelperMessage, ErrorMessage, ValidMessage } from './
|
|
9
|
-
export { default as Fieldset } from './
|
|
1
|
+
export { default } from './form';
|
|
2
|
+
export { default as FormHeader } from './form-header';
|
|
3
|
+
export { default as FormFooter } from './form-footer';
|
|
4
|
+
export { default as FormSection } from './form-section';
|
|
5
|
+
export { default as Field } from './field';
|
|
6
|
+
export { default as CheckboxField } from './checkbox-field';
|
|
7
|
+
export { default as RangeField } from './range-field';
|
|
8
|
+
export { HelperMessage, ErrorMessage, ValidMessage } from './messages';
|
|
9
|
+
export { default as Fieldset } from './fieldset'; // eslint-disable-next-line import/no-unresolved
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/core';
|
|
4
|
+
import SuccessIcon from '@atlaskit/icon/glyph/editor/success';
|
|
5
|
+
import ErrorIcon from '@atlaskit/icon/glyph/error';
|
|
6
|
+
import { G400, N200, R400 } from '@atlaskit/theme/colors';
|
|
7
|
+
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
8
|
+
import { fontFamily as getFontFamily, gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
9
|
+
import { h200 } from '@atlaskit/theme/typography';
|
|
10
|
+
import { token } from '@atlaskit/tokens';
|
|
11
|
+
import { FieldId } from './field';
|
|
12
|
+
var gridSize = getGridSize();
|
|
13
|
+
var fontFamily = getFontFamily(); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
14
|
+
|
|
15
|
+
var lightH200Styles = css(h200({
|
|
16
|
+
theme: {
|
|
17
|
+
mode: 'light'
|
|
18
|
+
}
|
|
19
|
+
})); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
20
|
+
|
|
21
|
+
var darkH200Styles = css(h200({
|
|
22
|
+
theme: {
|
|
23
|
+
mode: 'dark'
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
var messageErrorColorStyles = css({
|
|
27
|
+
color: token('color.text.danger', R400)
|
|
28
|
+
});
|
|
29
|
+
var messageNeutralColorStyles = css({
|
|
30
|
+
color: token('color.text.lowEmphasis', N200)
|
|
31
|
+
});
|
|
32
|
+
var messageValidColorStyles = css({
|
|
33
|
+
color: token('color.text.success', G400)
|
|
34
|
+
});
|
|
35
|
+
var messageStyles = css({
|
|
36
|
+
display: 'flex',
|
|
37
|
+
marginTop: "".concat(gridSize * 0.5, "px"),
|
|
38
|
+
justifyContent: 'baseline',
|
|
39
|
+
fontFamily: "".concat(fontFamily),
|
|
40
|
+
fontWeight: 'normal'
|
|
41
|
+
});
|
|
42
|
+
var iconWrapperStyles = css({
|
|
43
|
+
display: 'flex'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var IconWrapper = function IconWrapper(_ref) {
|
|
47
|
+
var children = _ref.children;
|
|
48
|
+
return jsx("span", {
|
|
49
|
+
css: iconWrapperStyles
|
|
50
|
+
}, children);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var Message = function Message(_ref2) {
|
|
54
|
+
var children = _ref2.children,
|
|
55
|
+
error = _ref2.error,
|
|
56
|
+
valid = _ref2.valid,
|
|
57
|
+
fieldId = _ref2.fieldId,
|
|
58
|
+
testId = _ref2.testId;
|
|
59
|
+
|
|
60
|
+
var _useGlobalTheme = useGlobalTheme(),
|
|
61
|
+
mode = _useGlobalTheme.mode;
|
|
62
|
+
|
|
63
|
+
return jsx("div", {
|
|
64
|
+
css: [mode === 'light' ? lightH200Styles : darkH200Styles, messageStyles, error ? messageErrorColorStyles : valid ? messageValidColorStyles : messageNeutralColorStyles],
|
|
65
|
+
"data-testid": testId,
|
|
66
|
+
id: fieldId
|
|
67
|
+
}, children);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* __Helper message__
|
|
72
|
+
*
|
|
73
|
+
* A helper message tells the user what kind of input the field takes. For example, a helper message could be
|
|
74
|
+
* 'Password should be more than 4 characters'
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
export var HelperMessage = function HelperMessage(_ref3) {
|
|
78
|
+
var children = _ref3.children,
|
|
79
|
+
testId = _ref3.testId;
|
|
80
|
+
return jsx(FieldId.Consumer, null, function (fieldId) {
|
|
81
|
+
return jsx(Message, {
|
|
82
|
+
fieldId: fieldId ? "".concat(fieldId, "-helper") : undefined,
|
|
83
|
+
testId: testId
|
|
84
|
+
}, children);
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* __Error message__
|
|
89
|
+
*
|
|
90
|
+
* An error message is used to tell a user that the field input is invalid. For example, an error message could be
|
|
91
|
+
* 'Invalid username, needs to be more than 4 characters'.
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
export var ErrorMessage = function ErrorMessage(_ref4) {
|
|
96
|
+
var children = _ref4.children,
|
|
97
|
+
testId = _ref4.testId;
|
|
98
|
+
return jsx(FieldId.Consumer, null, function (fieldId) {
|
|
99
|
+
return jsx(Message, {
|
|
100
|
+
error: true,
|
|
101
|
+
fieldId: fieldId ? "".concat(fieldId, "-error") : undefined,
|
|
102
|
+
testId: testId
|
|
103
|
+
}, jsx(IconWrapper, null, jsx(ErrorIcon, {
|
|
104
|
+
size: "small",
|
|
105
|
+
label: "error"
|
|
106
|
+
})), children);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* __Valid message__
|
|
111
|
+
*
|
|
112
|
+
* A valid message is used to tell a user that the field input is valid. For example,
|
|
113
|
+
* a helper message could be 'Nice one, this username is available'.
|
|
114
|
+
*
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
export var ValidMessage = function ValidMessage(_ref5) {
|
|
118
|
+
var children = _ref5.children,
|
|
119
|
+
testId = _ref5.testId;
|
|
120
|
+
return jsx(FieldId.Consumer, null, function (fieldId) {
|
|
121
|
+
return jsx(Message, {
|
|
122
|
+
fieldId: fieldId ? "".concat(fieldId, "-valid") : undefined,
|
|
123
|
+
testId: testId,
|
|
124
|
+
valid: true
|
|
125
|
+
}, jsx(IconWrapper, null, jsx(SuccessIcon, {
|
|
126
|
+
size: "small",
|
|
127
|
+
label: "success"
|
|
128
|
+
})), children);
|
|
129
|
+
});
|
|
130
|
+
};
|
|
@@ -7,8 +7,17 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
7
7
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
8
|
|
|
9
9
|
import React from 'react';
|
|
10
|
-
import Field from './
|
|
11
|
-
|
|
10
|
+
import Field from './field';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* __Range field__
|
|
14
|
+
*
|
|
15
|
+
* A range field is where a user can submit a range input as a part of a form.
|
|
16
|
+
*
|
|
17
|
+
* - [Examples](https://atlaskit.atlassian.com/packages/design-system/form/docs/fields#rangefield-reference)
|
|
18
|
+
* - [Code](https://atlaskit.atlassian.com/packages/design-system/form/docs/fields#rangefield-reference)
|
|
19
|
+
* - [Usage](https://atlaskit.atlassian.com/packages/design-system/form/docs/fields#rangefield-reference)
|
|
20
|
+
*/
|
|
12
21
|
var RangeField = function RangeField(props) {
|
|
13
22
|
var children = props.children,
|
|
14
23
|
strippedProps = _objectWithoutProperties(props, ["children"]); // isInvalid and isRequired are specifically invalid for range inputs
|
package/dist/esm/version.json
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { FieldProps, Meta } from './field';
|
|
3
|
+
export interface CheckboxFieldProps extends FieldProps<string | undefined> {
|
|
4
|
+
isChecked: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface CheckboxProps {
|
|
7
|
+
/**
|
|
8
|
+
* Content to render in the checkbox field. This is a function that is called with information about the field.
|
|
9
|
+
*/
|
|
10
|
+
children: (args: {
|
|
11
|
+
fieldProps: CheckboxFieldProps;
|
|
12
|
+
error?: string;
|
|
13
|
+
valid: boolean;
|
|
14
|
+
meta: Meta;
|
|
15
|
+
}) => ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* Sets the default state of the checkbox as checked.
|
|
18
|
+
*/
|
|
19
|
+
defaultIsChecked?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Sets whether the field is required for submission. Required fields are marked with a red asterisk.
|
|
22
|
+
*/
|
|
23
|
+
isRequired?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Sets whether the field is disabled. Users cannot edit or focus on the fields. If the parent form component is disabled, then the field will always be disabled.
|
|
26
|
+
*/
|
|
27
|
+
isDisabled?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Label displayed beside the checkbox.
|
|
30
|
+
*/
|
|
31
|
+
label?: ReactNode;
|
|
32
|
+
/**
|
|
33
|
+
* Specifies the name of the field. This is important for referencing the form data.
|
|
34
|
+
*/
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
* The value of the checkbox. This is the value used in the form state when the checkbox is checked.
|
|
38
|
+
*/
|
|
39
|
+
value?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* __Checkbox field__
|
|
43
|
+
*
|
|
44
|
+
* A checkbox field is a form field that lets users select an item. Users can check or uncheck the checkbox.
|
|
45
|
+
*
|
|
46
|
+
* - [Examples] https://atlaskit.atlassian.com/packages/design-system/form/docs/fields#checkboxfield-reference
|
|
47
|
+
* - [Code] https://atlaskit.atlassian.com/packages/design-system/form/docs/fields#checkboxfield-reference
|
|
48
|
+
* - [Usage] https://atlaskit.atlassian.com/packages/design-system/form/docs/fields#checkboxfield-reference
|
|
49
|
+
*/
|
|
50
|
+
declare const CheckboxField: FC<CheckboxProps>;
|
|
51
|
+
export default CheckboxField;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Fieldset } from '../fieldset';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as FormFooter } from '../form-footer';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as FormHeader } from '../form-header';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as FormSection } from '../form-section';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../form';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HelperMessage, ErrorMessage, ValidMessage } from '../messages';
|