@atlaskit/form 8.4.8 → 8.5.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,15 @@
1
1
  # @atlaskit/form
2
2
 
3
+ ## 8.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`c987bb60a89`](https://bitbucket.org/atlassian/atlassian-frontend/commits/c987bb60a89) - Exposes an additional Label component in `@atlaskit/form` - this component is designed to be wrapped by the Field component but there are certain use cases that require a Label on its own. This is to fulfill those use cases.
8
+
9
+ ### Patch Changes
10
+
11
+ - [`58884c2f6c1`](https://bitbucket.org/atlassian/atlassian-frontend/commits/58884c2f6c1) - Internal code change turning on a new linting rule.
12
+
3
13
  ## 8.4.8
4
14
 
5
15
  ### Patch Changes
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@atlaskit/form/Label",
3
+ "main": "../dist/cjs/entry-points/label.js",
4
+ "module": "../dist/esm/entry-points/label.js",
5
+ "module:es2019": "../dist/es2019/entry-points/label.js",
6
+ "types": "../dist/types/entry-points/label.d.ts"
7
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ Object.defineProperty(exports, "Label", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _label.default;
12
+ }
13
+ });
14
+
15
+ var _label = _interopRequireDefault(require("../label"));
package/dist/cjs/field.js CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- var _typeof3 = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
@@ -16,7 +14,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
16
14
 
17
15
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
18
16
 
19
- var _react = _interopRequireWildcard(require("react"));
17
+ var _react = require("react");
20
18
 
21
19
  var _core = require("@emotion/core");
22
20
 
@@ -26,17 +24,11 @@ var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
26
24
 
27
25
  var _colors = require("@atlaskit/theme/colors");
28
26
 
29
- var _components = require("@atlaskit/theme/components");
30
-
31
27
  var _constants = require("@atlaskit/theme/constants");
32
28
 
33
- var _typography = require("@atlaskit/theme/typography");
34
-
35
29
  var _form = require("./form");
36
30
 
37
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
38
-
39
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
+ var _label = _interopRequireDefault(require("./label"));
40
32
 
41
33
  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; }
42
34
 
@@ -45,45 +37,13 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
45
37
  var gridSize = (0, _constants.gridSize)();
46
38
  var fontFamily = (0, _constants.fontFamily)();
47
39
  var fieldWrapperStyles = (0, _core.css)({
48
- marginTop: "".concat(gridSize, "px")
49
- });
50
- var labelStyles = (0, _core.css)({
51
- display: 'inline-block',
52
- marginTop: 0,
53
- marginBottom: "".concat(gridSize * 0.5, "px"),
54
- fontFamily: "".concat(fontFamily)
40
+ marginTop: gridSize
55
41
  });
56
42
  var requiredIndicatorStyles = (0, _core.css)({
57
- paddingLeft: "".concat(gridSize * 0.25, "px"),
58
- color: "".concat("var(--ds-text-danger, ".concat(_colors.R400, ")")),
59
- fontFamily: "".concat(fontFamily)
60
- }); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
61
-
62
- var lightH200Styles = (0, _core.css)((0, _typography.h200)({
63
- theme: {
64
- mode: 'light'
65
- }
66
- })); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
67
-
68
- var darkH200Styles = (0, _core.css)((0, _typography.h200)({
69
- theme: {
70
- mode: 'dark'
71
- }
72
- }));
73
-
74
- var Label = function Label(_ref) {
75
- var children = _ref.children,
76
- fieldId = _ref.fieldId;
77
-
78
- var _useGlobalTheme = (0, _components.useGlobalTheme)(),
79
- mode = _useGlobalTheme.mode;
80
-
81
- return (0, _core.jsx)("label", {
82
- css: [mode === 'light' ? lightH200Styles : darkH200Styles, labelStyles],
83
- id: "".concat(fieldId, "-label"),
84
- htmlFor: fieldId
85
- }, children);
86
- };
43
+ paddingLeft: "".concat(gridSize / 4, "px"),
44
+ color: "var(--ds-text-danger, ".concat(_colors.R400, ")"),
45
+ fontFamily: fontFamily
46
+ });
87
47
 
88
48
  function isEvent(event) {
89
49
  return Boolean(event && event.target);
@@ -98,8 +58,7 @@ function isFunction(x) {
98
58
  *
99
59
  * 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.
100
60
  */
101
- var FieldId = /*#__PURE__*/_react.default.createContext(undefined);
102
-
61
+ var FieldId = /*#__PURE__*/(0, _react.createContext)(undefined);
103
62
  exports.FieldId = FieldId;
104
63
 
105
64
  function usePreviousRef(current) {
@@ -309,8 +268,9 @@ function Field(props) {
309
268
 
310
269
  return (0, _core.jsx)("div", {
311
270
  css: fieldWrapperStyles
312
- }, props.label && (0, _core.jsx)(Label, {
313
- fieldId: fieldId
271
+ }, props.label && (0, _core.jsx)(_label.default, {
272
+ htmlFor: fieldId,
273
+ id: "".concat(fieldId, "-label")
314
274
  }, props.label, props.isRequired && (0, _core.jsx)("span", {
315
275
  css: requiredIndicatorStyles,
316
276
  "aria-hidden": "true"
@@ -100,7 +100,7 @@ var FormHeader = function FormHeader(_ref5) {
100
100
  var children = _ref5.children,
101
101
  description = _ref5.description,
102
102
  title = _ref5.title;
103
- return (0, _core.jsx)(FormHeaderWrapper, null, title && (0, _core.jsx)(FormHeaderTitle, null, title), description && (0, _core.jsx)(FormHeaderDescription, null, description), (0, _core.jsx)(FormHeaderContent, null, children));
103
+ return (0, _core.jsx)(FormHeaderWrapper, null, title && (0, _core.jsx)(FormHeaderTitle, null, title), description && (0, _core.jsx)(FormHeaderDescription, null, description), children && (0, _core.jsx)(FormHeaderContent, null, children));
104
104
  };
105
105
 
106
106
  var _default = FormHeader;
package/dist/cjs/index.js CHANGED
@@ -53,6 +53,12 @@ Object.defineProperty(exports, "HelperMessage", {
53
53
  return _messages.HelperMessage;
54
54
  }
55
55
  });
56
+ Object.defineProperty(exports, "Label", {
57
+ enumerable: true,
58
+ get: function get() {
59
+ return _label.default;
60
+ }
61
+ });
56
62
  Object.defineProperty(exports, "RangeField", {
57
63
  enumerable: true,
58
64
  get: function get() {
@@ -86,6 +92,8 @@ var _checkboxField = _interopRequireDefault(require("./checkbox-field"));
86
92
 
87
93
  var _rangeField = _interopRequireDefault(require("./range-field"));
88
94
 
95
+ var _label = _interopRequireDefault(require("./label"));
96
+
89
97
  var _messages = require("./messages");
90
98
 
91
99
  var _fieldset = _interopRequireDefault(require("./fieldset"));
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _core = require("@emotion/core");
9
+
10
+ var _components = require("@atlaskit/theme/components");
11
+
12
+ var _constants = require("@atlaskit/theme/constants");
13
+
14
+ var _typography = require("@atlaskit/theme/typography");
15
+
16
+ /** @jsx jsx */
17
+ var fontFamily = (0, _constants.fontFamily)();
18
+ var gridSize = (0, _constants.gridSize)();
19
+ var labelStyles = (0, _core.css)({
20
+ display: 'inline-block',
21
+ marginTop: 0,
22
+ marginBottom: gridSize / 2,
23
+ fontFamily: fontFamily
24
+ }); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
25
+
26
+ var lightH200Styles = (0, _core.css)((0, _typography.h200)({
27
+ theme: {
28
+ mode: 'light'
29
+ }
30
+ })); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
31
+
32
+ var darkH200Styles = (0, _core.css)((0, _typography.h200)({
33
+ theme: {
34
+ mode: 'dark'
35
+ }
36
+ }));
37
+ /**
38
+ * __Label__
39
+ *
40
+ * A label represents a caption for an item in a user interface.
41
+ *
42
+ * It's recommended that a label has a `4px` spacing above its associated
43
+ * control element.
44
+ */
45
+
46
+ var Label = function Label(_ref) {
47
+ var children = _ref.children,
48
+ htmlFor = _ref.htmlFor,
49
+ id = _ref.id;
50
+
51
+ var _useGlobalTheme = (0, _components.useGlobalTheme)(),
52
+ mode = _useGlobalTheme.mode;
53
+
54
+ return (0, _core.jsx)("label", {
55
+ css: [mode === 'light' ? lightH200Styles : darkH200Styles, labelStyles],
56
+ id: id,
57
+ htmlFor: htmlFor
58
+ }, children);
59
+ };
60
+
61
+ var _default = Label;
62
+ exports.default = _default;
@@ -38,18 +38,22 @@ var RangeField = function RangeField(props) {
38
38
  var children = props.children,
39
39
  strippedProps = (0, _objectWithoutProperties2.default)(props, _excluded); // isInvalid and isRequired are specifically invalid for range inputs
40
40
 
41
- return /*#__PURE__*/_react.default.createElement(_field.default, (0, _extends2.default)({}, strippedProps, {
42
- transform: Number
43
- }), function (_ref) {
44
- var _ref$fieldProps = _ref.fieldProps,
45
- isInvalid = _ref$fieldProps.isInvalid,
46
- isRequired = _ref$fieldProps.isRequired,
47
- fieldProps = (0, _objectWithoutProperties2.default)(_ref$fieldProps, _excluded2),
48
- rest = (0, _objectWithoutProperties2.default)(_ref, _excluded3);
49
- return children(_objectSpread({
50
- fieldProps: fieldProps
51
- }, rest));
52
- });
41
+ return (
42
+ /*#__PURE__*/
43
+ // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
44
+ _react.default.createElement(_field.default, (0, _extends2.default)({}, strippedProps, {
45
+ transform: Number
46
+ }), function (_ref) {
47
+ var _ref$fieldProps = _ref.fieldProps,
48
+ isInvalid = _ref$fieldProps.isInvalid,
49
+ isRequired = _ref$fieldProps.isRequired,
50
+ fieldProps = (0, _objectWithoutProperties2.default)(_ref$fieldProps, _excluded2),
51
+ rest = (0, _objectWithoutProperties2.default)(_ref, _excluded3);
52
+ return children(_objectSpread({
53
+ fieldProps: fieldProps
54
+ }, rest));
55
+ })
56
+ );
53
57
  };
54
58
 
55
59
  var _default = RangeField;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/form",
3
- "version": "8.4.8",
3
+ "version": "8.5.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1 @@
1
+ export { default as Label } from '../label';
@@ -1,55 +1,22 @@
1
1
  /** @jsx jsx */
2
- import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { css, jsx } from '@emotion/core';
4
4
  import { uid } from 'react-uid';
5
5
  import invariant from 'tiny-invariant';
6
6
  import { R400 } from '@atlaskit/theme/colors';
7
- import { useGlobalTheme } from '@atlaskit/theme/components';
8
7
  import { fontFamily as getFontFamily, gridSize as getGridSize } from '@atlaskit/theme/constants';
9
- import { h200 } from '@atlaskit/theme/typography';
10
8
  import { FormContext, IsDisabledContext } from './form';
9
+ import Label from './label';
11
10
  const gridSize = getGridSize();
12
11
  const fontFamily = getFontFamily();
13
12
  const fieldWrapperStyles = css({
14
- marginTop: `${gridSize}px`
15
- });
16
- const labelStyles = css({
17
- display: 'inline-block',
18
- marginTop: 0,
19
- marginBottom: `${gridSize * 0.5}px`,
20
- fontFamily: `${fontFamily}`
13
+ marginTop: gridSize
21
14
  });
22
15
  const requiredIndicatorStyles = css({
23
- paddingLeft: `${gridSize * 0.25}px`,
24
- color: `${`var(--ds-text-danger, ${R400})`}`,
25
- fontFamily: `${fontFamily}`
26
- }); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
27
-
28
- const lightH200Styles = css(h200({
29
- theme: {
30
- mode: 'light'
31
- }
32
- })); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
33
-
34
- const darkH200Styles = css(h200({
35
- theme: {
36
- mode: 'dark'
37
- }
38
- }));
39
-
40
- const Label = ({
41
- children,
42
- fieldId
43
- }) => {
44
- const {
45
- mode
46
- } = useGlobalTheme();
47
- return jsx("label", {
48
- css: [mode === 'light' ? lightH200Styles : darkH200Styles, labelStyles],
49
- id: `${fieldId}-label`,
50
- htmlFor: fieldId
51
- }, children);
52
- };
16
+ paddingLeft: `${gridSize / 4}px`,
17
+ color: `var(--ds-text-danger, ${R400})`,
18
+ fontFamily
19
+ });
53
20
 
54
21
  function isEvent(event) {
55
22
  return Boolean(event && event.target);
@@ -64,7 +31,7 @@ function isFunction(x) {
64
31
  *
65
32
  * 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.
66
33
  */
67
- export const FieldId = /*#__PURE__*/React.createContext(undefined);
34
+ export const FieldId = /*#__PURE__*/createContext(undefined);
68
35
 
69
36
  function usePreviousRef(current) {
70
37
  const ref = useRef(current); // will be updated on the next render
@@ -264,7 +231,8 @@ export default function Field(props) {
264
231
  return jsx("div", {
265
232
  css: fieldWrapperStyles
266
233
  }, props.label && jsx(Label, {
267
- fieldId: fieldId
234
+ htmlFor: fieldId,
235
+ id: `${fieldId}-label`
268
236
  }, props.label, props.isRequired && jsx("span", {
269
237
  css: requiredIndicatorStyles,
270
238
  "aria-hidden": "true"
@@ -87,7 +87,7 @@ const FormHeader = ({
87
87
  description,
88
88
  title
89
89
  }) => {
90
- return jsx(FormHeaderWrapper, null, title && jsx(FormHeaderTitle, null, title), description && jsx(FormHeaderDescription, null, description), jsx(FormHeaderContent, null, children));
90
+ return jsx(FormHeaderWrapper, null, title && jsx(FormHeaderTitle, null, title), description && jsx(FormHeaderDescription, null, description), children && jsx(FormHeaderContent, null, children));
91
91
  };
92
92
 
93
93
  export default FormHeader;
@@ -5,5 +5,6 @@ export { default as FormSection } from './form-section';
5
5
  export { default as Field } from './field';
6
6
  export { default as CheckboxField } from './checkbox-field';
7
7
  export { default as RangeField } from './range-field';
8
+ export { default as Label } from './label';
8
9
  export { HelperMessage, ErrorMessage, ValidMessage } from './messages';
9
10
  export { default as Fieldset } from './fieldset'; // eslint-disable-next-line import/no-unresolved
@@ -0,0 +1,50 @@
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
+ const fontFamily = getFontFamily();
7
+ const gridSize = getGridSize();
8
+ const labelStyles = css({
9
+ display: 'inline-block',
10
+ marginTop: 0,
11
+ marginBottom: gridSize / 2,
12
+ fontFamily: fontFamily
13
+ }); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
14
+
15
+ const lightH200Styles = css(h200({
16
+ theme: {
17
+ mode: 'light'
18
+ }
19
+ })); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
20
+
21
+ const darkH200Styles = css(h200({
22
+ theme: {
23
+ mode: 'dark'
24
+ }
25
+ }));
26
+ /**
27
+ * __Label__
28
+ *
29
+ * A label represents a caption for an item in a user interface.
30
+ *
31
+ * It's recommended that a label has a `4px` spacing above its associated
32
+ * control element.
33
+ */
34
+
35
+ const Label = ({
36
+ children,
37
+ htmlFor,
38
+ id
39
+ }) => {
40
+ const {
41
+ mode
42
+ } = useGlobalTheme();
43
+ return jsx("label", {
44
+ css: [mode === 'light' ? lightH200Styles : darkH200Styles, labelStyles],
45
+ id: id,
46
+ htmlFor: htmlFor
47
+ }, children);
48
+ };
49
+
50
+ export default Label;
@@ -17,19 +17,23 @@ const RangeField = props => {
17
17
  ...strippedProps
18
18
  } = props; // isInvalid and isRequired are specifically invalid for range inputs
19
19
 
20
- return /*#__PURE__*/React.createElement(Field, _extends({}, strippedProps, {
21
- transform: Number
22
- }), ({
23
- fieldProps: {
24
- isInvalid,
25
- isRequired,
26
- ...fieldProps
27
- },
28
- ...rest
29
- }) => children({
30
- fieldProps,
31
- ...rest
32
- }));
20
+ return (
21
+ /*#__PURE__*/
22
+ // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
23
+ React.createElement(Field, _extends({}, strippedProps, {
24
+ transform: Number
25
+ }), ({
26
+ fieldProps: {
27
+ isInvalid,
28
+ isRequired,
29
+ ...fieldProps
30
+ },
31
+ ...rest
32
+ }) => children({
33
+ fieldProps,
34
+ ...rest
35
+ }))
36
+ );
33
37
  };
34
38
 
35
39
  export default RangeField;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/form",
3
- "version": "8.4.8",
3
+ "version": "8.5.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1 @@
1
+ export { default as Label } from '../label';
package/dist/esm/field.js CHANGED
@@ -7,57 +7,24 @@ 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(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; }
8
8
 
9
9
  /** @jsx jsx */
10
- import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
10
+ import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
11
11
  import { css, jsx } from '@emotion/core';
12
12
  import { uid } from 'react-uid';
13
13
  import invariant from 'tiny-invariant';
14
14
  import { R400 } from '@atlaskit/theme/colors';
15
- import { useGlobalTheme } from '@atlaskit/theme/components';
16
15
  import { fontFamily as getFontFamily, gridSize as getGridSize } from '@atlaskit/theme/constants';
17
- import { h200 } from '@atlaskit/theme/typography';
18
16
  import { FormContext, IsDisabledContext } from './form';
17
+ import Label from './label';
19
18
  var gridSize = getGridSize();
20
19
  var fontFamily = getFontFamily();
21
20
  var fieldWrapperStyles = css({
22
- marginTop: "".concat(gridSize, "px")
23
- });
24
- var labelStyles = css({
25
- display: 'inline-block',
26
- marginTop: 0,
27
- marginBottom: "".concat(gridSize * 0.5, "px"),
28
- fontFamily: "".concat(fontFamily)
21
+ marginTop: gridSize
29
22
  });
30
23
  var requiredIndicatorStyles = css({
31
- paddingLeft: "".concat(gridSize * 0.25, "px"),
32
- color: "".concat("var(--ds-text-danger, ".concat(R400, ")")),
33
- fontFamily: "".concat(fontFamily)
34
- }); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
35
-
36
- var lightH200Styles = css(h200({
37
- theme: {
38
- mode: 'light'
39
- }
40
- })); // eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
41
-
42
- var darkH200Styles = css(h200({
43
- theme: {
44
- mode: 'dark'
45
- }
46
- }));
47
-
48
- var Label = function Label(_ref) {
49
- var children = _ref.children,
50
- fieldId = _ref.fieldId;
51
-
52
- var _useGlobalTheme = useGlobalTheme(),
53
- mode = _useGlobalTheme.mode;
54
-
55
- return jsx("label", {
56
- css: [mode === 'light' ? lightH200Styles : darkH200Styles, labelStyles],
57
- id: "".concat(fieldId, "-label"),
58
- htmlFor: fieldId
59
- }, children);
60
- };
24
+ paddingLeft: "".concat(gridSize / 4, "px"),
25
+ color: "var(--ds-text-danger, ".concat(R400, ")"),
26
+ fontFamily: fontFamily
27
+ });
61
28
 
62
29
  function isEvent(event) {
63
30
  return Boolean(event && event.target);
@@ -72,7 +39,7 @@ function isFunction(x) {
72
39
  *
73
40
  * 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.
74
41
  */
75
- export var FieldId = /*#__PURE__*/React.createContext(undefined);
42
+ export var FieldId = /*#__PURE__*/createContext(undefined);
76
43
 
77
44
  function usePreviousRef(current) {
78
45
  var ref = useRef(current); // will be updated on the next render
@@ -282,7 +249,8 @@ export default function Field(props) {
282
249
  return jsx("div", {
283
250
  css: fieldWrapperStyles
284
251
  }, props.label && jsx(Label, {
285
- fieldId: fieldId
252
+ htmlFor: fieldId,
253
+ id: "".concat(fieldId, "-label")
286
254
  }, props.label, props.isRequired && jsx("span", {
287
255
  css: requiredIndicatorStyles,
288
256
  "aria-hidden": "true"
@@ -83,7 +83,7 @@ var FormHeader = function FormHeader(_ref5) {
83
83
  var children = _ref5.children,
84
84
  description = _ref5.description,
85
85
  title = _ref5.title;
86
- return jsx(FormHeaderWrapper, null, title && jsx(FormHeaderTitle, null, title), description && jsx(FormHeaderDescription, null, description), jsx(FormHeaderContent, null, children));
86
+ return jsx(FormHeaderWrapper, null, title && jsx(FormHeaderTitle, null, title), description && jsx(FormHeaderDescription, null, description), children && jsx(FormHeaderContent, null, children));
87
87
  };
88
88
 
89
89
  export default FormHeader;
package/dist/esm/index.js CHANGED
@@ -5,5 +5,6 @@ export { default as FormSection } from './form-section';
5
5
  export { default as Field } from './field';
6
6
  export { default as CheckboxField } from './checkbox-field';
7
7
  export { default as RangeField } from './range-field';
8
+ export { default as Label } from './label';
8
9
  export { HelperMessage, ErrorMessage, ValidMessage } from './messages';
9
10
  export { default as Fieldset } from './fieldset'; // eslint-disable-next-line import/no-unresolved
@@ -0,0 +1,50 @@
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 labelStyles = css({
9
+ display: 'inline-block',
10
+ marginTop: 0,
11
+ marginBottom: gridSize / 2,
12
+ fontFamily: fontFamily
13
+ }); // 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
+ /**
27
+ * __Label__
28
+ *
29
+ * A label represents a caption for an item in a user interface.
30
+ *
31
+ * It's recommended that a label has a `4px` spacing above its associated
32
+ * control element.
33
+ */
34
+
35
+ var Label = function Label(_ref) {
36
+ var children = _ref.children,
37
+ htmlFor = _ref.htmlFor,
38
+ id = _ref.id;
39
+
40
+ var _useGlobalTheme = useGlobalTheme(),
41
+ mode = _useGlobalTheme.mode;
42
+
43
+ return jsx("label", {
44
+ css: [mode === 'light' ? lightH200Styles : darkH200Styles, labelStyles],
45
+ id: id,
46
+ htmlFor: htmlFor
47
+ }, children);
48
+ };
49
+
50
+ export default Label;
@@ -26,19 +26,23 @@ var RangeField = function RangeField(props) {
26
26
  strippedProps = _objectWithoutProperties(props, _excluded); // isInvalid and isRequired are specifically invalid for range inputs
27
27
 
28
28
 
29
- return /*#__PURE__*/React.createElement(Field, _extends({}, strippedProps, {
30
- transform: Number
31
- }), function (_ref) {
32
- var _ref$fieldProps = _ref.fieldProps,
33
- isInvalid = _ref$fieldProps.isInvalid,
34
- isRequired = _ref$fieldProps.isRequired,
35
- fieldProps = _objectWithoutProperties(_ref$fieldProps, _excluded2),
36
- rest = _objectWithoutProperties(_ref, _excluded3);
37
-
38
- return children(_objectSpread({
39
- fieldProps: fieldProps
40
- }, rest));
41
- });
29
+ return (
30
+ /*#__PURE__*/
31
+ // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
32
+ React.createElement(Field, _extends({}, strippedProps, {
33
+ transform: Number
34
+ }), function (_ref) {
35
+ var _ref$fieldProps = _ref.fieldProps,
36
+ isInvalid = _ref$fieldProps.isInvalid,
37
+ isRequired = _ref$fieldProps.isRequired,
38
+ fieldProps = _objectWithoutProperties(_ref$fieldProps, _excluded2),
39
+ rest = _objectWithoutProperties(_ref, _excluded3);
40
+
41
+ return children(_objectSpread({
42
+ fieldProps: fieldProps
43
+ }, rest));
44
+ })
45
+ );
42
46
  };
43
47
 
44
48
  export default RangeField;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/form",
3
- "version": "8.4.8",
3
+ "version": "8.5.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,2 @@
1
+ export { default as Label } from '../label';
2
+ export type { LabelProps } from '../label';
@@ -1,5 +1,5 @@
1
1
  /** @jsx jsx */
2
- import React, { FormEvent, ReactNode } from 'react';
2
+ import { FormEvent, ReactNode } from 'react';
3
3
  declare type SupportedElements = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
4
4
  export interface FieldProps<FieldValue, Element extends SupportedElements = HTMLInputElement> {
5
5
  id: string;
@@ -34,7 +34,7 @@ export interface FieldComponentProps<FieldValue, Element extends SupportedElemen
34
34
  error?: string;
35
35
  valid: boolean;
36
36
  meta: Meta;
37
- }) => React.ReactNode;
37
+ }) => ReactNode;
38
38
  /**
39
39
  * Sets the default value of the field. If a function is provided, it is called with the current default value of the field.
40
40
  */
@@ -73,6 +73,6 @@ export interface FieldComponentProps<FieldValue, Element extends SupportedElemen
73
73
  *
74
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
75
  */
76
- export declare const FieldId: React.Context<string | undefined>;
76
+ export declare const FieldId: import("react").Context<string | undefined>;
77
77
  export default function Field<FieldValue = string, Element extends SupportedElements = HTMLInputElement>(props: FieldComponentProps<FieldValue, Element>): JSX.Element;
78
78
  export {};
@@ -9,6 +9,8 @@ export { default as CheckboxField } from './checkbox-field';
9
9
  export type { CheckboxFieldProps } from './checkbox-field';
10
10
  export { default as RangeField } from './range-field';
11
11
  export type { RangeFieldProps } from './range-field';
12
+ export { default as Label } from './label';
13
+ export type { LabelProps } from './label';
12
14
  export { HelperMessage, ErrorMessage, ValidMessage } from './messages';
13
15
  export { default as Fieldset } from './fieldset';
14
16
  export type { OnSubmitHandler, FormApi } from './types';
@@ -0,0 +1,16 @@
1
+ /** @jsx jsx */
2
+ import { FC } from 'react';
3
+ export interface LabelProps {
4
+ id?: string;
5
+ htmlFor: string;
6
+ }
7
+ /**
8
+ * __Label__
9
+ *
10
+ * A label represents a caption for an item in a user interface.
11
+ *
12
+ * It's recommended that a label has a `4px` spacing above its associated
13
+ * control element.
14
+ */
15
+ declare const Label: FC<LabelProps>;
16
+ export default Label;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/form",
3
- "version": "8.4.8",
3
+ "version": "8.5.0",
4
4
  "description": "A form allows users to input information.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -25,6 +25,7 @@
25
25
  "./Form": "./src/entry-points/form.tsx",
26
26
  "./Messages": "./src/entry-points/messages.tsx",
27
27
  "./RangeField": "./src/entry-points/range-field.tsx",
28
+ "./Label": "./src/entry-points/label.tsx",
28
29
  ".": "./src/index.tsx"
29
30
  },
30
31
  "atlassian": {
@@ -56,15 +57,15 @@
56
57
  "@atlaskit/checkbox": "^12.3.0",
57
58
  "@atlaskit/datetime-picker": "^11.1.0",
58
59
  "@atlaskit/docs": "^9.0.0",
59
- "@atlaskit/dropdown-menu": "^11.0.0",
60
+ "@atlaskit/dropdown-menu": "^11.1.0",
60
61
  "@atlaskit/droplist": "^11.0.0",
61
62
  "@atlaskit/modal-dialog": "^12.2.0",
62
63
  "@atlaskit/radio": "^5.3.0",
63
- "@atlaskit/range": "^5.1.0",
64
+ "@atlaskit/range": "^6.0.0",
64
65
  "@atlaskit/section-message": "^6.1.0",
65
66
  "@atlaskit/select": "^15.2.0",
66
67
  "@atlaskit/ssr": "*",
67
- "@atlaskit/textarea": "^4.2.0",
68
+ "@atlaskit/textarea": "^4.3.0",
68
69
  "@atlaskit/textfield": "^5.1.0",
69
70
  "@atlaskit/toggle": "^12.4.0",
70
71
  "@atlaskit/tooltip": "^17.5.0",