carbon-react 114.17.5 → 114.18.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.
Files changed (72) hide show
  1. package/esm/__internal__/checkable-input/checkable-input.component.js +5 -1
  2. package/esm/__internal__/fieldset/fieldset.component.js +27 -23
  3. package/esm/__internal__/form-field/form-field.component.js +2 -2
  4. package/esm/__internal__/form-spacing-provider/form-spacing-context.d.ts +5 -0
  5. package/esm/__internal__/form-spacing-provider/form-spacing-context.js +2 -0
  6. package/esm/__internal__/form-spacing-provider/form-spacing-provider.component.d.ts +7 -0
  7. package/esm/__internal__/form-spacing-provider/form-spacing-provider.component.js +18 -0
  8. package/esm/__internal__/form-spacing-provider/index.d.ts +3 -0
  9. package/esm/__internal__/form-spacing-provider/index.js +2 -0
  10. package/esm/components/checkbox/checkbox-group.component.js +4 -1
  11. package/esm/components/checkbox/checkbox.component.js +7 -5
  12. package/esm/components/date/date.component.js +5 -2
  13. package/esm/components/date-range/date-range.component.js +8 -2
  14. package/esm/components/fieldset/fieldset.component.js +7 -3
  15. package/esm/components/form/form.component.js +5 -1
  16. package/esm/components/form/form.config.d.ts +10 -0
  17. package/esm/components/form/form.config.js +11 -1
  18. package/esm/components/form/form.style.js +2 -35
  19. package/esm/components/inline-inputs/inline-inputs.component.d.ts +3 -2
  20. package/esm/components/inline-inputs/inline-inputs.component.js +166 -4
  21. package/esm/components/inline-inputs/inline-inputs.style.js +3 -0
  22. package/esm/components/multi-action-button/multi-action-button.component.js +2 -1
  23. package/esm/components/numeral-date/numeral-date.component.js +4 -1
  24. package/esm/components/select/filterable-select/filterable-select.component.js +4 -2
  25. package/esm/components/select/multi-select/multi-select.component.js +4 -2
  26. package/esm/components/select/select-textbox/select-textbox.component.js +4 -1
  27. package/esm/components/select/simple-select/simple-select.component.js +4 -2
  28. package/esm/components/split-button/split-button.component.js +2 -1
  29. package/esm/components/switch/switch.component.js +3 -2
  30. package/esm/components/textarea/textarea.component.js +7 -6
  31. package/esm/hooks/__internal__/useFormSpacing/add-form-spacing/index.d.ts +3 -0
  32. package/esm/hooks/__internal__/useFormSpacing/add-form-spacing/index.js +30 -0
  33. package/esm/hooks/__internal__/useFormSpacing/index.d.ts +3 -0
  34. package/esm/hooks/__internal__/useFormSpacing/index.js +11 -0
  35. package/lib/__internal__/checkable-input/checkable-input.component.js +5 -1
  36. package/lib/__internal__/fieldset/fieldset.component.js +28 -23
  37. package/lib/__internal__/form-field/form-field.component.js +3 -3
  38. package/lib/__internal__/form-spacing-provider/form-spacing-context.d.ts +5 -0
  39. package/lib/__internal__/form-spacing-provider/form-spacing-context.js +14 -0
  40. package/lib/__internal__/form-spacing-provider/form-spacing-provider.component.d.ts +7 -0
  41. package/lib/__internal__/form-spacing-provider/form-spacing-provider.component.js +30 -0
  42. package/lib/__internal__/form-spacing-provider/index.d.ts +3 -0
  43. package/lib/__internal__/form-spacing-provider/index.js +23 -0
  44. package/lib/__internal__/form-spacing-provider/package.json +6 -0
  45. package/lib/components/checkbox/checkbox-group.component.js +5 -1
  46. package/lib/components/checkbox/checkbox.component.js +8 -6
  47. package/lib/components/date/date.component.js +6 -2
  48. package/lib/components/date-range/date-range.component.js +8 -2
  49. package/lib/components/fieldset/fieldset.component.js +9 -4
  50. package/lib/components/form/form.component.js +7 -1
  51. package/lib/components/form/form.config.d.ts +10 -0
  52. package/lib/components/form/form.config.js +13 -2
  53. package/lib/components/form/form.style.js +2 -38
  54. package/lib/components/inline-inputs/inline-inputs.component.d.ts +3 -2
  55. package/lib/components/inline-inputs/inline-inputs.component.js +168 -4
  56. package/lib/components/inline-inputs/inline-inputs.style.js +4 -0
  57. package/lib/components/multi-action-button/multi-action-button.component.js +2 -1
  58. package/lib/components/numeral-date/numeral-date.component.js +5 -1
  59. package/lib/components/select/filterable-select/filterable-select.component.js +4 -1
  60. package/lib/components/select/multi-select/multi-select.component.js +4 -1
  61. package/lib/components/select/select-textbox/select-textbox.component.js +4 -1
  62. package/lib/components/select/simple-select/simple-select.component.js +4 -1
  63. package/lib/components/split-button/split-button.component.js +2 -1
  64. package/lib/components/switch/switch.component.js +4 -3
  65. package/lib/components/textarea/textarea.component.js +7 -6
  66. package/lib/hooks/__internal__/useFormSpacing/add-form-spacing/index.d.ts +3 -0
  67. package/lib/hooks/__internal__/useFormSpacing/add-form-spacing/index.js +39 -0
  68. package/lib/hooks/__internal__/useFormSpacing/add-form-spacing/package.json +6 -0
  69. package/lib/hooks/__internal__/useFormSpacing/index.d.ts +3 -0
  70. package/lib/hooks/__internal__/useFormSpacing/index.js +26 -0
  71. package/lib/hooks/__internal__/useFormSpacing/package.json +6 -0
  72. package/package.json +2 -2
@@ -1,9 +1,13 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
1
3
  import React, { useRef } from "react";
2
4
  import PropTypes from "prop-types";
3
5
  import Label from "../../__internal__/label";
4
6
  import StyledInlineInputs, { StyledContentContainer, StyledInlineInput } from "./inline-inputs.style";
7
+ import FormSpacingProvider from "../../__internal__/form-spacing-provider";
5
8
  import createGuid from "../../__internal__/utils/helpers/guid";
6
9
  import useIsAboveBreakpoint from "../../hooks/__internal__/useIsAboveBreakpoint";
10
+ import useFormSpacing from "../../hooks/__internal__/useFormSpacing";
7
11
  export const InlineInputsContext = /*#__PURE__*/React.createContext({});
8
12
 
9
13
  const columnWrapper = (children, gutter, labelId) => {
@@ -29,7 +33,8 @@ const InlineInputs = ({
29
33
  inputWidth,
30
34
  labelInline = true,
31
35
  labelWidth,
32
- required
36
+ required,
37
+ ...rest
33
38
  }) => {
34
39
  const labelId = useRef(createGuid());
35
40
  const largeScreen = useIsAboveBreakpoint(adaptiveLabelBreakpoint);
@@ -49,17 +54,20 @@ const InlineInputs = ({
49
54
  }, label);
50
55
  }
51
56
 
52
- return /*#__PURE__*/React.createElement(StyledInlineInputs, {
57
+ const marginProps = useFormSpacing(rest);
58
+ return /*#__PURE__*/React.createElement(StyledInlineInputs, _extends({
53
59
  gutter: gutter,
54
60
  "data-component": "inline-inputs",
55
61
  className: className,
56
62
  labelWidth: labelWidth,
57
63
  labelInline: inlineLabel
58
- }, renderLabel(), /*#__PURE__*/React.createElement(StyledContentContainer, {
64
+ }, marginProps), renderLabel(), /*#__PURE__*/React.createElement(StyledContentContainer, {
59
65
  gutter: gutter,
60
66
  "data-element": "inline-inputs-container",
61
67
  inputWidth: inputWidth
62
- }, columnWrapper(children, gutter, label ? labelId.current : undefined)));
68
+ }, /*#__PURE__*/React.createElement(FormSpacingProvider, {
69
+ marginBottom: undefined
70
+ }, columnWrapper(children, gutter, label ? labelId.current : undefined))));
63
71
  };
64
72
 
65
73
  InlineInputs.propTypes = {
@@ -72,6 +80,160 @@ InlineInputs.propTypes = {
72
80
  "label": PropTypes.string,
73
81
  "labelInline": PropTypes.bool,
74
82
  "labelWidth": PropTypes.number,
83
+ "m": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
84
+ "__@toStringTag": PropTypes.string.isRequired,
85
+ "description": PropTypes.string,
86
+ "toString": PropTypes.func.isRequired,
87
+ "valueOf": PropTypes.func.isRequired
88
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
89
+ "__@toStringTag": PropTypes.string.isRequired,
90
+ "description": PropTypes.string,
91
+ "toString": PropTypes.func.isRequired,
92
+ "valueOf": PropTypes.func.isRequired
93
+ }), PropTypes.string]),
94
+ "margin": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
95
+ "__@toStringTag": PropTypes.string.isRequired,
96
+ "description": PropTypes.string,
97
+ "toString": PropTypes.func.isRequired,
98
+ "valueOf": PropTypes.func.isRequired
99
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
100
+ "__@toStringTag": PropTypes.string.isRequired,
101
+ "description": PropTypes.string,
102
+ "toString": PropTypes.func.isRequired,
103
+ "valueOf": PropTypes.func.isRequired
104
+ }), PropTypes.string]),
105
+ "marginBottom": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
106
+ "__@toStringTag": PropTypes.string.isRequired,
107
+ "description": PropTypes.string,
108
+ "toString": PropTypes.func.isRequired,
109
+ "valueOf": PropTypes.func.isRequired
110
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
111
+ "__@toStringTag": PropTypes.string.isRequired,
112
+ "description": PropTypes.string,
113
+ "toString": PropTypes.func.isRequired,
114
+ "valueOf": PropTypes.func.isRequired
115
+ }), PropTypes.string]),
116
+ "marginLeft": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
117
+ "__@toStringTag": PropTypes.string.isRequired,
118
+ "description": PropTypes.string,
119
+ "toString": PropTypes.func.isRequired,
120
+ "valueOf": PropTypes.func.isRequired
121
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
122
+ "__@toStringTag": PropTypes.string.isRequired,
123
+ "description": PropTypes.string,
124
+ "toString": PropTypes.func.isRequired,
125
+ "valueOf": PropTypes.func.isRequired
126
+ }), PropTypes.string]),
127
+ "marginRight": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
128
+ "__@toStringTag": PropTypes.string.isRequired,
129
+ "description": PropTypes.string,
130
+ "toString": PropTypes.func.isRequired,
131
+ "valueOf": PropTypes.func.isRequired
132
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
133
+ "__@toStringTag": PropTypes.string.isRequired,
134
+ "description": PropTypes.string,
135
+ "toString": PropTypes.func.isRequired,
136
+ "valueOf": PropTypes.func.isRequired
137
+ }), PropTypes.string]),
138
+ "marginTop": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
139
+ "__@toStringTag": PropTypes.string.isRequired,
140
+ "description": PropTypes.string,
141
+ "toString": PropTypes.func.isRequired,
142
+ "valueOf": PropTypes.func.isRequired
143
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
144
+ "__@toStringTag": PropTypes.string.isRequired,
145
+ "description": PropTypes.string,
146
+ "toString": PropTypes.func.isRequired,
147
+ "valueOf": PropTypes.func.isRequired
148
+ }), PropTypes.string]),
149
+ "marginX": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
150
+ "__@toStringTag": PropTypes.string.isRequired,
151
+ "description": PropTypes.string,
152
+ "toString": PropTypes.func.isRequired,
153
+ "valueOf": PropTypes.func.isRequired
154
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
155
+ "__@toStringTag": PropTypes.string.isRequired,
156
+ "description": PropTypes.string,
157
+ "toString": PropTypes.func.isRequired,
158
+ "valueOf": PropTypes.func.isRequired
159
+ }), PropTypes.string]),
160
+ "marginY": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
161
+ "__@toStringTag": PropTypes.string.isRequired,
162
+ "description": PropTypes.string,
163
+ "toString": PropTypes.func.isRequired,
164
+ "valueOf": PropTypes.func.isRequired
165
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
166
+ "__@toStringTag": PropTypes.string.isRequired,
167
+ "description": PropTypes.string,
168
+ "toString": PropTypes.func.isRequired,
169
+ "valueOf": PropTypes.func.isRequired
170
+ }), PropTypes.string]),
171
+ "mb": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
172
+ "__@toStringTag": PropTypes.string.isRequired,
173
+ "description": PropTypes.string,
174
+ "toString": PropTypes.func.isRequired,
175
+ "valueOf": PropTypes.func.isRequired
176
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
177
+ "__@toStringTag": PropTypes.string.isRequired,
178
+ "description": PropTypes.string,
179
+ "toString": PropTypes.func.isRequired,
180
+ "valueOf": PropTypes.func.isRequired
181
+ }), PropTypes.string]),
182
+ "ml": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
183
+ "__@toStringTag": PropTypes.string.isRequired,
184
+ "description": PropTypes.string,
185
+ "toString": PropTypes.func.isRequired,
186
+ "valueOf": PropTypes.func.isRequired
187
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
188
+ "__@toStringTag": PropTypes.string.isRequired,
189
+ "description": PropTypes.string,
190
+ "toString": PropTypes.func.isRequired,
191
+ "valueOf": PropTypes.func.isRequired
192
+ }), PropTypes.string]),
193
+ "mr": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
194
+ "__@toStringTag": PropTypes.string.isRequired,
195
+ "description": PropTypes.string,
196
+ "toString": PropTypes.func.isRequired,
197
+ "valueOf": PropTypes.func.isRequired
198
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
199
+ "__@toStringTag": PropTypes.string.isRequired,
200
+ "description": PropTypes.string,
201
+ "toString": PropTypes.func.isRequired,
202
+ "valueOf": PropTypes.func.isRequired
203
+ }), PropTypes.string]),
204
+ "mt": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
205
+ "__@toStringTag": PropTypes.string.isRequired,
206
+ "description": PropTypes.string,
207
+ "toString": PropTypes.func.isRequired,
208
+ "valueOf": PropTypes.func.isRequired
209
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
210
+ "__@toStringTag": PropTypes.string.isRequired,
211
+ "description": PropTypes.string,
212
+ "toString": PropTypes.func.isRequired,
213
+ "valueOf": PropTypes.func.isRequired
214
+ }), PropTypes.string]),
215
+ "mx": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
216
+ "__@toStringTag": PropTypes.string.isRequired,
217
+ "description": PropTypes.string,
218
+ "toString": PropTypes.func.isRequired,
219
+ "valueOf": PropTypes.func.isRequired
220
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
221
+ "__@toStringTag": PropTypes.string.isRequired,
222
+ "description": PropTypes.string,
223
+ "toString": PropTypes.func.isRequired,
224
+ "valueOf": PropTypes.func.isRequired
225
+ }), PropTypes.string]),
226
+ "my": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
227
+ "__@toStringTag": PropTypes.string.isRequired,
228
+ "description": PropTypes.string,
229
+ "toString": PropTypes.func.isRequired,
230
+ "valueOf": PropTypes.func.isRequired
231
+ }), PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.shape({
232
+ "__@toStringTag": PropTypes.string.isRequired,
233
+ "description": PropTypes.string,
234
+ "toString": PropTypes.func.isRequired,
235
+ "valueOf": PropTypes.func.isRequired
236
+ }), PropTypes.string]),
75
237
  "required": PropTypes.bool
76
238
  };
77
239
  InlineInputs.displayName = "InlineInputs";
@@ -1,4 +1,5 @@
1
1
  import styled, { css } from "styled-components";
2
+ import { margin } from "styled-system";
2
3
  import InputPresentation from "../../__internal__/input/input-presentation.style";
3
4
  import { StyledLabelContainer } from "../../__internal__/label/label.style";
4
5
  import baseTheme from "../../style/themes/base";
@@ -42,6 +43,8 @@ const StyledContentContainer = styled.div`
42
43
  `}
43
44
  `;
44
45
  const StyledInlineInputs = styled.div`
46
+ ${margin}
47
+
45
48
  display: ${({
46
49
  labelInline
47
50
  }) => labelInline ? `flex` : `block`};
@@ -117,6 +117,7 @@ const MultiActionButton = ({
117
117
  if (buttonRef.current === document.activeElement) return;
118
118
  setShowAdditionalButtons(false);
119
119
  }, []);
120
+ const marginProps = filterStyledSystemMarginProps(rest);
120
121
  return /*#__PURE__*/React.createElement(StyledMultiActionButton, _extends({
121
122
  "aria-haspopup": "true",
122
123
  onMouseLeave: hideButtonsIfTriggerNotFocused,
@@ -127,7 +128,7 @@ const MultiActionButton = ({
127
128
  "data-role": dataRole,
128
129
  displayed: showAdditionalButtons,
129
130
  width: width
130
- }, filterStyledSystemMarginProps(rest)), /*#__PURE__*/React.createElement(Button, _extends({
131
+ }, marginProps), /*#__PURE__*/React.createElement(Button, _extends({
131
132
  "aria-haspopup": "true",
132
133
  "aria-expanded": showAdditionalButtons,
133
134
  "aria-label": "Show more",
@@ -16,6 +16,7 @@ import { InputGroupBehaviour } from "../../__internal__/input-behaviour";
16
16
  import { TooltipProvider } from "../../__internal__/tooltip-provider";
17
17
  import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
18
18
  import NumeralDateContext from "./numeral-date-context";
19
+ import FormSpacingProvider from "../../__internal__/form-spacing-provider";
19
20
  export const ALLOWED_DATE_FORMATS = [["dd", "mm", "yyyy"], ["mm", "dd", "yyyy"], ["dd", "mm"], ["mm", "dd"], ["mm", "yyyy"]];
20
21
  const incorrectDateFormatMessage = "Forbidden prop dateFormat supplied to NumeralDate. " + "Only one of these date formats is allowed: " + "['dd', 'mm', 'yyyy'], " + "['mm', 'dd', 'yyyy'], " + "['dd', 'mm'], " + "['mm', 'dd'], " + "['mm', 'yyyy']";
21
22
 
@@ -222,6 +223,8 @@ const NumeralDate = ({
222
223
  isMiddle: isMiddle,
223
224
  isEnd: isEnd,
224
225
  hasValidationIcon: hasValidationIcon
226
+ }, /*#__PURE__*/React.createElement(FormSpacingProvider, {
227
+ marginBottom: undefined
225
228
  }, /*#__PURE__*/React.createElement(Textbox, _extends({}, index === 0 && {
226
229
  id: uniqueId
227
230
  }, {
@@ -256,7 +259,7 @@ const NumeralDate = ({
256
259
  }, {
257
260
  size: size,
258
261
  tooltipPosition: tooltipPosition
259
- }))));
262
+ })))));
260
263
  })))));
261
264
  };
262
265
 
@@ -3,7 +3,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
3
3
  import React, { useState, useEffect, useRef, useCallback } from "react";
4
4
  import PropTypes from "prop-types";
5
5
  import invariant from "invariant";
6
- import { filterStyledSystemMarginProps, filterOutStyledSystemSpacingProps } from "../../../style/utils";
6
+ import { filterOutStyledSystemSpacingProps } from "../../../style/utils";
7
7
  import SelectTextbox, { formInputPropTypes } from "../select-textbox/select-textbox.component";
8
8
  import guid from "../../../__internal__/utils/helpers/guid";
9
9
  import withFilter from "../utils/with-filter.hoc";
@@ -13,6 +13,7 @@ import isExpectedOption from "../utils/is-expected-option";
13
13
  import isNavigationKey from "../utils/is-navigation-key";
14
14
  import Logger from "../../../__internal__/utils/logger";
15
15
  import useStableCallback from "../../../hooks/__internal__/useStableCallback";
16
+ import useFormSpacing from "../../../hooks/__internal__/useFormSpacing";
16
17
  let deprecateInputRefWarnTriggered = false;
17
18
  const FilterableSelectList = withFilter(SelectList);
18
19
  const FilterableSelect = /*#__PURE__*/React.forwardRef(({
@@ -437,6 +438,7 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
437
438
  enableVirtualScroll: enableVirtualScroll,
438
439
  virtualScrollOverscan: virtualScrollOverscan
439
440
  }, children);
441
+ const marginProps = useFormSpacing(textboxProps);
440
442
  return /*#__PURE__*/React.createElement(StyledSelect, _extends({
441
443
  hasTextCursor: true,
442
444
  readOnly: readOnly,
@@ -445,7 +447,7 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
445
447
  "data-role": dataRole,
446
448
  "data-element": dataElement,
447
449
  isOpen: isOpen
448
- }, filterStyledSystemMarginProps(textboxProps)), /*#__PURE__*/React.createElement("div", {
450
+ }, marginProps), /*#__PURE__*/React.createElement("div", {
449
451
  ref: containerRef
450
452
  }, /*#__PURE__*/React.createElement(SelectTextbox, _extends({
451
453
  activeDescendantId: activeDescendantId,
@@ -3,7 +3,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
3
3
  import React, { useState, useEffect, useRef, useCallback, useMemo } from "react";
4
4
  import PropTypes from "prop-types";
5
5
  import invariant from "invariant";
6
- import { filterStyledSystemMarginProps, filterOutStyledSystemSpacingProps } from "../../../style/utils";
6
+ import { filterOutStyledSystemSpacingProps } from "../../../style/utils";
7
7
  import SelectTextbox, { formInputPropTypes } from "../select-textbox/select-textbox.component";
8
8
  import guid from "../../../__internal__/utils/helpers/guid";
9
9
  import withFilter from "../utils/with-filter.hoc";
@@ -15,6 +15,7 @@ import isExpectedValue from "../utils/is-expected-value";
15
15
  import isNavigationKey from "../utils/is-navigation-key";
16
16
  import Logger from "../../../__internal__/utils/logger";
17
17
  import useStableCallback from "../../../hooks/__internal__/useStableCallback";
18
+ import useFormSpacing from "../../../hooks/__internal__/useFormSpacing";
18
19
  let deprecateInputRefWarnTriggered = false;
19
20
  const FilterableSelectList = withFilter(SelectList);
20
21
  const MultiSelect = /*#__PURE__*/React.forwardRef(({
@@ -449,6 +450,7 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
449
450
  enableVirtualScroll: enableVirtualScroll,
450
451
  virtualScrollOverscan: virtualScrollOverscan
451
452
  }, children);
453
+ const marginProps = useFormSpacing(textboxProps);
452
454
  return /*#__PURE__*/React.createElement(StyledSelectMultiSelect, _extends({
453
455
  disabled: disabled,
454
456
  readOnly: readOnly,
@@ -458,7 +460,7 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
458
460
  "data-role": dataRole,
459
461
  "data-element": dataElement,
460
462
  isOpen: isOpen
461
- }, filterStyledSystemMarginProps(textboxProps)), /*#__PURE__*/React.createElement("div", {
463
+ }, marginProps), /*#__PURE__*/React.createElement("div", {
462
464
  ref: containerRef
463
465
  }, /*#__PURE__*/React.createElement(StyledAccessibilityLabelContainer, {
464
466
  "data-element": "accessibility-label",
@@ -145,7 +145,10 @@ const SelectTextbox = /*#__PURE__*/React.forwardRef(({
145
145
  onChange: onChange,
146
146
  value: selectedValue,
147
147
  placeholder: hasTextCursor ? placeholder || l.select.placeholder() : undefined
148
- }, getInputAriaAttributes(), getTextboxProps()), !hasTextCursor && renderSelectText());
148
+ }, getInputAriaAttributes(), getTextboxProps(), {
149
+ my: 0 // prevents any form spacing being applied
150
+
151
+ }), !hasTextCursor && renderSelectText());
149
152
  });
150
153
  const formInputPropTypes = {
151
154
  /**
@@ -4,7 +4,7 @@ import React, { useState, useEffect, useRef, useCallback, useMemo } from "react"
4
4
  import PropTypes from "prop-types";
5
5
  import propTypes from "@styled-system/prop-types";
6
6
  import invariant from "invariant";
7
- import { filterStyledSystemMarginProps, filterOutStyledSystemSpacingProps } from "../../../style/utils";
7
+ import { filterOutStyledSystemSpacingProps } from "../../../style/utils";
8
8
  import StyledSelect from "../select.style";
9
9
  import SelectTextbox, { formInputPropTypes } from "../select-textbox/select-textbox.component";
10
10
  import SelectList from "../select-list/select-list.component";
@@ -13,6 +13,7 @@ import getNextChildByText from "../utils/get-next-child-by-text";
13
13
  import isExpectedOption from "../utils/is-expected-option";
14
14
  import isNavigationKey from "../utils/is-navigation-key";
15
15
  import Logger from "../../../__internal__/utils/logger";
16
+ import useFormSpacing from "../../../hooks/__internal__/useFormSpacing";
16
17
  let deprecateInputRefWarnTriggered = false;
17
18
  const SimpleSelect = /*#__PURE__*/React.forwardRef(({
18
19
  value,
@@ -355,6 +356,7 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
355
356
  enableVirtualScroll: enableVirtualScroll,
356
357
  virtualScrollOverscan: virtualScrollOverscan
357
358
  }, children);
359
+ const marginProps = useFormSpacing(props);
358
360
  return /*#__PURE__*/React.createElement(StyledSelect, _extends({
359
361
  transparent: transparent,
360
362
  disabled: disabled,
@@ -363,7 +365,7 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
363
365
  "data-role": dataRole,
364
366
  "data-element": dataElement,
365
367
  isOpen: isOpen
366
- }, filterStyledSystemMarginProps(props)), /*#__PURE__*/React.createElement("div", {
368
+ }, marginProps), /*#__PURE__*/React.createElement("div", {
367
369
  ref: containerRef
368
370
  }, /*#__PURE__*/React.createElement(SelectTextbox, _extends({
369
371
  "aria-controls": selectListId.current,
@@ -173,12 +173,13 @@ const SplitButton = ({
173
173
  }
174
174
 
175
175
  const handleClick = useClickAwayListener(hideButtons);
176
+ const marginProps = filterStyledSystemMarginProps(rest);
176
177
  return /*#__PURE__*/React.createElement(StyledSplitButton, _extends({
177
178
  "aria-haspopup": "true",
178
179
  onMouseLeave: hideButtonsIfTriggerNotFocused,
179
180
  onClick: handleClick,
180
181
  ref: splitButtonNode
181
- }, componentTags(), filterStyledSystemMarginProps(rest)), renderMainButton(), renderAdditionalButtons());
182
+ }, componentTags(), marginProps), renderMainButton(), renderAdditionalButtons());
182
183
  };
183
184
 
184
185
  SplitButton.propTypes = {
@@ -5,8 +5,8 @@ import CheckableInput from "../../__internal__/checkable-input";
5
5
  import SwitchSlider from "./__internal__/switch-slider.component";
6
6
  import useIsAboveBreakpoint from "../../hooks/__internal__/useIsAboveBreakpoint";
7
7
  import { TooltipProvider } from "../../__internal__/tooltip-provider";
8
- import { filterStyledSystemMarginProps } from "../../style/utils";
9
8
  import Logger from "../../__internal__/utils/logger";
9
+ import useFormSpacing from "../../hooks/__internal__/useFormSpacing";
10
10
  let deprecateInputRefWarnTriggered = false;
11
11
  const Switch = /*#__PURE__*/React.forwardRef(({
12
12
  autoFocus,
@@ -60,6 +60,7 @@ const Switch = /*#__PURE__*/React.forwardRef(({
60
60
  }
61
61
 
62
62
  const shouldValidationBeOnLabel = labelInline && !reverse ? true : validationOnLabel;
63
+ const marginProps = useFormSpacing(rest);
63
64
  const switchStyleProps = {
64
65
  "data-component": dataComponent,
65
66
  "data-role": dataRole,
@@ -71,7 +72,7 @@ const Switch = /*#__PURE__*/React.forwardRef(({
71
72
  reverse: !reverse,
72
73
  // switched to preserve backward compatibility
73
74
  size,
74
- ...filterStyledSystemMarginProps(rest)
75
+ ...marginProps
75
76
  };
76
77
  const switchSliderProps = {
77
78
  checked: isControlled ? checked : checkedInternal,
@@ -7,7 +7,6 @@ import FormField from "../../__internal__/form-field";
7
7
  import useCharacterCount from "../../hooks/__internal__/useCharacterCount";
8
8
  import Input from "../../__internal__/input/input.component";
9
9
  import { InputBehaviour } from "../../__internal__/input-behaviour";
10
- import { filterStyledSystemMarginProps } from "../../style/utils";
11
10
  import InputIconToggle from "../../__internal__/input-icon-toggle";
12
11
  import guid from "../../__internal__/utils/helpers/guid";
13
12
  import StyledTextarea, { MIN_HEIGHT } from "./textarea.style";
@@ -17,7 +16,8 @@ import { NewValidationContext } from "../carbon-provider/carbon-provider.compone
17
16
  import { ErrorBorder, StyledHintText } from "../textbox/textbox.style";
18
17
  import ValidationMessage from "../../__internal__/validation-message";
19
18
  import Box from "../box";
20
- import Logger from "../../__internal__/utils/logger"; // TODO: Change characterLimit type to number - batch with other breaking changes
19
+ import Logger from "../../__internal__/utils/logger";
20
+ import useFormSpacing from "../../hooks/__internal__/useFormSpacing"; // TODO: Change characterLimit type to number - batch with other breaking changes
21
21
 
22
22
  let deprecateInputRefWarnTriggered = false;
23
23
  const Textarea = /*#__PURE__*/React.forwardRef(({
@@ -58,7 +58,7 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
58
58
  "data-role": dataRole,
59
59
  helpAriaLabel,
60
60
  inputRef,
61
- ...props
61
+ ...rest
62
62
  }, ref) => {
63
63
  const {
64
64
  validationRedesignOptIn
@@ -171,7 +171,7 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
171
171
  id: id,
172
172
  as: "textarea",
173
173
  inputRef: inputRef
174
- }, props)), children, /*#__PURE__*/React.createElement(InputIconToggle, {
174
+ }, rest)), children, /*#__PURE__*/React.createElement(InputIconToggle, {
175
175
  disabled: disabled,
176
176
  readOnly: readOnly,
177
177
  inputIcon: inputIcon,
@@ -182,6 +182,7 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
182
182
  validationIconId: validationRedesignOptIn ? undefined : validationIconId,
183
183
  useValidationIcon: !(validationRedesignOptIn || validationOnLabel)
184
184
  }));
185
+ const marginProps = useFormSpacing(rest);
185
186
  return /*#__PURE__*/React.createElement(TooltipProvider, {
186
187
  tooltipPosition: tooltipPosition,
187
188
  helpAriaLabel: helpAriaLabel
@@ -191,7 +192,7 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
191
192
  "data-role": dataRole,
192
193
  "data-element": dataElement,
193
194
  hasIcon: hasIconInside
194
- }, filterStyledSystemMarginProps(props)), /*#__PURE__*/React.createElement(FormField, {
195
+ }, marginProps), /*#__PURE__*/React.createElement(FormField, {
195
196
  fieldHelp: computeLabelPropValues(fieldHelp),
196
197
  fieldHelpId: fieldHelpId,
197
198
  error: error,
@@ -206,7 +207,7 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
206
207
  labelWidth: computeLabelPropValues(labelWidth),
207
208
  labelHelp: computeLabelPropValues(labelHelp),
208
209
  labelSpacing: labelSpacing,
209
- isRequired: props.required,
210
+ isRequired: rest.required,
210
211
  useValidationIcon: computeLabelPropValues(validationOnLabel),
211
212
  adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
212
213
  validationRedesignOptIn: validationRedesignOptIn
@@ -0,0 +1,3 @@
1
+ import { MarginProps } from "styled-system";
2
+ declare const _default: (marginProps: MarginProps, formMarginBottom?: string | undefined) => MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>>;
3
+ export default _default;
@@ -0,0 +1,30 @@
1
+ export default ((marginProps, formMarginBottom) => {
2
+ if (!formMarginBottom) {
3
+ return marginProps;
4
+ }
5
+
6
+ const copiedProps = { ...marginProps
7
+ };
8
+ const {
9
+ mb,
10
+ marginBottom,
11
+ mt,
12
+ marginTop,
13
+ my,
14
+ marginY,
15
+ m,
16
+ margin
17
+ } = copiedProps;
18
+ const hasCustomMarginBottom = [mb, marginBottom, my, marginY, m, margin].some(prop => prop !== undefined);
19
+ const hasCustomMarginTop = [mt, marginTop, my, marginY, m, margin].some(prop => prop !== undefined);
20
+
21
+ if (!hasCustomMarginBottom) {
22
+ copiedProps.mb = formMarginBottom;
23
+ }
24
+
25
+ if (!hasCustomMarginTop) {
26
+ copiedProps.mt = 0;
27
+ }
28
+
29
+ return copiedProps;
30
+ });
@@ -0,0 +1,3 @@
1
+ import { MarginProps } from "styled-system";
2
+ declare const _default: (props: Record<string, unknown> | MarginProps) => MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>>;
3
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { useContext } from "react";
2
+ import { filterStyledSystemMarginProps } from "../../../style/utils";
3
+ import { FormSpacingContext } from "../../../__internal__/form-spacing-provider";
4
+ import addFormSpacing from "./add-form-spacing";
5
+ export default (props => {
6
+ const {
7
+ marginBottom
8
+ } = useContext(FormSpacingContext);
9
+ const marginProps = addFormSpacing(filterStyledSystemMarginProps(props), marginBottom);
10
+ return marginProps;
11
+ });
@@ -27,6 +27,8 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
27
27
 
28
28
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
29
29
 
30
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
31
+
30
32
  const CheckableInput = /*#__PURE__*/_react.default.forwardRef(({
31
33
  ariaLabelledBy: externalAriaLabelledBy,
32
34
  autoFocus,
@@ -124,7 +126,9 @@ const CheckableInput = /*#__PURE__*/_react.default.forwardRef(({
124
126
  labelWidth: labelWidth,
125
127
  labelInline: labelInline,
126
128
  reverse: reverse
127
- }, /*#__PURE__*/_react.default.createElement(_inputBehaviour.InputBehaviour, null, /*#__PURE__*/_react.default.createElement(_formField.default, formFieldProps, /*#__PURE__*/_react.default.createElement(_checkableInput.StyledCheckableInput, null, /*#__PURE__*/_react.default.createElement(_hiddenCheckableInput.default, inputProps), children))));
129
+ }, /*#__PURE__*/_react.default.createElement(_inputBehaviour.InputBehaviour, null, /*#__PURE__*/_react.default.createElement(_formField.default, _extends({}, formFieldProps, {
130
+ my: 0
131
+ }), /*#__PURE__*/_react.default.createElement(_checkableInput.StyledCheckableInput, null, /*#__PURE__*/_react.default.createElement(_hiddenCheckableInput.default, inputProps), children))));
128
132
  });
129
133
 
130
134
  CheckableInput.propTypes = {
@@ -15,6 +15,8 @@ var _validationIcon = _interopRequireDefault(require("../validations/validation-
15
15
 
16
16
  var _inputBehaviour = require("../input-behaviour");
17
17
 
18
+ var _useFormSpacing = _interopRequireDefault(require("../../hooks/__internal__/useFormSpacing"));
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
21
 
20
22
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
@@ -32,29 +34,32 @@ const Fieldset = ({
32
34
  isRequired,
33
35
  blockGroupBehaviour,
34
36
  ...rest
35
- }) => /*#__PURE__*/_react.default.createElement(_inputBehaviour.InputGroupBehaviour, {
36
- blockGroupBehaviour: blockGroupBehaviour
37
- }, /*#__PURE__*/_react.default.createElement(_fieldset.StyledFieldset, _extends({
38
- "data-component": "fieldset",
39
- m: 0
40
- }, rest), legend && /*#__PURE__*/_react.default.createElement(_inputBehaviour.InputGroupContext.Consumer, null, ({
41
- onMouseEnter,
42
- onMouseLeave
43
- }) => /*#__PURE__*/_react.default.createElement(_fieldset.StyledLegend, {
44
- onMouseEnter: onMouseEnter,
45
- onMouseLeave: onMouseLeave,
46
- inline: inline,
47
- width: legendWidth,
48
- align: legendAlign,
49
- rightPadding: legendSpacing
50
- }, /*#__PURE__*/_react.default.createElement(_fieldset.StyledLegendContent, {
51
- isRequired: isRequired
52
- }, legend, /*#__PURE__*/_react.default.createElement(_validationIcon.default, {
53
- error: error,
54
- warning: warning,
55
- info: info,
56
- tooltipFlipOverrides: ["top", "bottom"]
57
- })))), children));
37
+ }) => {
38
+ const marginProps = (0, _useFormSpacing.default)(rest);
39
+ return /*#__PURE__*/_react.default.createElement(_inputBehaviour.InputGroupBehaviour, {
40
+ blockGroupBehaviour: blockGroupBehaviour
41
+ }, /*#__PURE__*/_react.default.createElement(_fieldset.StyledFieldset, _extends({
42
+ "data-component": "fieldset",
43
+ m: 0
44
+ }, marginProps, rest), legend && /*#__PURE__*/_react.default.createElement(_inputBehaviour.InputGroupContext.Consumer, null, ({
45
+ onMouseEnter,
46
+ onMouseLeave
47
+ }) => /*#__PURE__*/_react.default.createElement(_fieldset.StyledLegend, {
48
+ onMouseEnter: onMouseEnter,
49
+ onMouseLeave: onMouseLeave,
50
+ inline: inline,
51
+ width: legendWidth,
52
+ align: legendAlign,
53
+ rightPadding: legendSpacing
54
+ }, /*#__PURE__*/_react.default.createElement(_fieldset.StyledLegendContent, {
55
+ isRequired: isRequired
56
+ }, legend, /*#__PURE__*/_react.default.createElement(_validationIcon.default, {
57
+ error: error,
58
+ warning: warning,
59
+ info: info,
60
+ tooltipFlipOverrides: ["top", "bottom"]
61
+ })))), children));
62
+ };
58
63
 
59
64
  Fieldset.propTypes = {
60
65
  "blockGroupBehaviour": _propTypes.default.bool,