carbon-react 144.9.11 → 144.11.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 (47) hide show
  1. package/esm/__internal__/fieldset/fieldset.component.d.ts +5 -1
  2. package/esm/__internal__/fieldset/fieldset.component.js +27 -7
  3. package/esm/__internal__/fieldset/fieldset.style.d.ts +2 -1
  4. package/esm/__internal__/fieldset/fieldset.style.js +4 -1
  5. package/esm/components/date/date.component.js +1 -0
  6. package/esm/components/decimal/decimal.component.js +1 -0
  7. package/esm/components/draggable/draggable-container.component.d.ts +6 -1
  8. package/esm/components/draggable/draggable-container.component.js +4 -1
  9. package/esm/components/draggable/draggable-item/draggable-item.component.d.ts +6 -1
  10. package/esm/components/draggable/draggable-item/draggable-item.component.js +7 -3
  11. package/esm/components/draggable/draggable-item/draggable-item.style.d.ts +2 -3
  12. package/esm/components/draggable/draggable-item/draggable-item.style.js +5 -6
  13. package/esm/components/grouped-character/grouped-character.component.js +1 -0
  14. package/esm/components/number/number.component.js +1 -0
  15. package/esm/components/numeral-date/numeral-date.component.js +142 -105
  16. package/esm/components/numeral-date/numeral-date.style.d.ts +4 -2
  17. package/esm/components/numeral-date/numeral-date.style.js +46 -38
  18. package/esm/components/select/__internal__/select-textbox/select-textbox.component.js +1 -0
  19. package/esm/components/select/filterable-select/filterable-select.component.js +1 -0
  20. package/esm/components/select/multi-select/multi-select.component.js +1 -0
  21. package/esm/components/select/simple-select/simple-select.component.js +1 -0
  22. package/esm/components/textbox/textbox.component.d.ts +2 -0
  23. package/esm/components/textbox/textbox.component.js +4 -2
  24. package/lib/__internal__/fieldset/fieldset.component.d.ts +5 -1
  25. package/lib/__internal__/fieldset/fieldset.component.js +26 -6
  26. package/lib/__internal__/fieldset/fieldset.style.d.ts +2 -1
  27. package/lib/__internal__/fieldset/fieldset.style.js +4 -1
  28. package/lib/components/date/date.component.js +1 -0
  29. package/lib/components/decimal/decimal.component.js +1 -0
  30. package/lib/components/draggable/draggable-container.component.d.ts +6 -1
  31. package/lib/components/draggable/draggable-container.component.js +4 -1
  32. package/lib/components/draggable/draggable-item/draggable-item.component.d.ts +6 -1
  33. package/lib/components/draggable/draggable-item/draggable-item.component.js +6 -2
  34. package/lib/components/draggable/draggable-item/draggable-item.style.d.ts +2 -3
  35. package/lib/components/draggable/draggable-item/draggable-item.style.js +5 -6
  36. package/lib/components/grouped-character/grouped-character.component.js +1 -0
  37. package/lib/components/number/number.component.js +1 -0
  38. package/lib/components/numeral-date/numeral-date.component.js +141 -104
  39. package/lib/components/numeral-date/numeral-date.style.d.ts +4 -2
  40. package/lib/components/numeral-date/numeral-date.style.js +47 -39
  41. package/lib/components/select/__internal__/select-textbox/select-textbox.component.js +1 -0
  42. package/lib/components/select/filterable-select/filterable-select.component.js +1 -0
  43. package/lib/components/select/multi-select/multi-select.component.js +1 -0
  44. package/lib/components/select/simple-select/simple-select.component.js +1 -0
  45. package/lib/components/textbox/textbox.component.d.ts +2 -0
  46. package/lib/components/textbox/textbox.component.js +4 -2
  47. package/package.json +1 -1
@@ -34,6 +34,10 @@ export interface FieldsetProps extends MarginProps {
34
34
  name?: string;
35
35
  /** Set an id value on the component */
36
36
  id?: string;
37
+ /** Content for the Help tooltip */
38
+ labelHelp?: React.ReactNode;
39
+ /** Id for the validation icon tooltip */
40
+ validationId?: string;
37
41
  }
38
- declare const Fieldset: ({ legend, children, inline, legendWidth, legendAlign, legendSpacing, error, warning, info, isRequired, blockGroupBehaviour, legendMargin, isDisabled, isOptional, ...rest }: FieldsetProps) => React.JSX.Element;
42
+ declare const Fieldset: ({ legend, children, inline, legendWidth, legendAlign, legendSpacing, error, warning, info, isRequired, blockGroupBehaviour, legendMargin, isDisabled, isOptional, labelHelp, validationId, ...rest }: FieldsetProps) => React.JSX.Element;
39
43
  export default Fieldset;
@@ -1,11 +1,12 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
2
  import React, { useContext, useEffect, useState } from "react";
3
3
  import PropTypes from "prop-types";
4
- import { StyledFieldset, StyledLegend, StyledLegendContent } from "./fieldset.style";
4
+ import { StyledFieldset, StyledLegend, StyledLegendContent, StyledIconWrapper } from "./fieldset.style";
5
5
  import ValidationIcon from "../validations/validation-icon.component";
6
6
  import NewValidationContext from "../../components/carbon-provider/__internal__/new-validation.context";
7
7
  import { InputGroupBehaviour, InputGroupContext } from "../input-behaviour";
8
8
  import useFormSpacing from "../../hooks/__internal__/useFormSpacing";
9
+ import Help from "../../components/help";
9
10
  const Fieldset = ({
10
11
  legend,
11
12
  children,
@@ -21,6 +22,8 @@ const Fieldset = ({
21
22
  legendMargin = {},
22
23
  isDisabled,
23
24
  isOptional,
25
+ labelHelp,
26
+ validationId,
24
27
  ...rest
25
28
  }) => {
26
29
  const {
@@ -28,6 +31,7 @@ const Fieldset = ({
28
31
  } = useContext(NewValidationContext);
29
32
  const marginProps = useFormSpacing(rest);
30
33
  const [ref, setRef] = useState(null);
34
+ const [isFocused, setFocus] = useState(false);
31
35
  useEffect(() => {
32
36
  if (ref && isRequired) {
33
37
  Array.from(ref.querySelectorAll("input") || /* istanbul ignore next */[]).forEach(el => {
@@ -35,6 +39,27 @@ const Fieldset = ({
35
39
  });
36
40
  }
37
41
  }, [ref, isRequired]);
42
+ const tooltipIcon = () => {
43
+ if (error || warning || info) {
44
+ return /*#__PURE__*/React.createElement(StyledIconWrapper, null, /*#__PURE__*/React.createElement(ValidationIcon, {
45
+ error: error,
46
+ warning: warning,
47
+ info: info,
48
+ tooltipFlipOverrides: ["top", "bottom"],
49
+ tooltipId: validationId
50
+ }));
51
+ }
52
+ const helpProps = {
53
+ onFocus: () => setFocus(true),
54
+ onBlur: () => setFocus(false)
55
+ };
56
+ if (labelHelp) {
57
+ return /*#__PURE__*/React.createElement(StyledIconWrapper, helpProps, /*#__PURE__*/React.createElement(Help, {
58
+ isFocused: isFocused
59
+ }, labelHelp));
60
+ }
61
+ return null;
62
+ };
38
63
  return /*#__PURE__*/React.createElement(InputGroupBehaviour, {
39
64
  blockGroupBehaviour: blockGroupBehaviour
40
65
  }, /*#__PURE__*/React.createElement(StyledFieldset, _extends({
@@ -57,11 +82,6 @@ const Fieldset = ({
57
82
  isRequired: isRequired,
58
83
  isOptional: isOptional,
59
84
  isDisabled: isDisabled
60
- }, legend, !validationRedesignOptIn && /*#__PURE__*/React.createElement(ValidationIcon, {
61
- error: error,
62
- warning: warning,
63
- info: info,
64
- tooltipFlipOverrides: ["top", "bottom"]
65
- })))), children));
85
+ }, legend, !validationRedesignOptIn && tooltipIcon()))), children));
66
86
  };
67
87
  export default Fieldset;
@@ -15,4 +15,5 @@ declare type StyledLegendProps = {
15
15
  rightPadding?: 1 | 2;
16
16
  };
17
17
  declare const StyledLegend: import("styled-components").StyledComponent<"legend", any, StyledLegendProps, never>;
18
- export { StyledFieldset, StyledLegend, StyledLegendContent };
18
+ declare const StyledIconWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
19
+ export { StyledFieldset, StyledLegend, StyledLegendContent, StyledIconWrapper };
@@ -75,4 +75,7 @@ const StyledLegend = styled.legend`
75
75
  `}
76
76
  ${margin}
77
77
  `;
78
- export { StyledFieldset, StyledLegend, StyledLegendContent };
78
+ const StyledIconWrapper = styled.div`
79
+ margin-left: var(--spacing050);
80
+ `;
81
+ export { StyledFieldset, StyledLegend, StyledLegendContent, StyledIconWrapper };
@@ -1131,6 +1131,7 @@ if (process.env.NODE_ENV !== "production") {
1131
1131
  "suppressHydrationWarning": PropTypes.bool,
1132
1132
  "tabIndex": PropTypes.number,
1133
1133
  "title": PropTypes.string,
1134
+ "tooltipId": PropTypes.string,
1134
1135
  "tooltipPosition": PropTypes.oneOf(["bottom", "left", "right", "top"]),
1135
1136
  "translate": PropTypes.oneOf(["no", "yes"]),
1136
1137
  "typeof": PropTypes.string,
@@ -758,6 +758,7 @@ if (process.env.NODE_ENV !== "production") {
758
758
  "suppressHydrationWarning": PropTypes.bool,
759
759
  "tabIndex": PropTypes.number,
760
760
  "title": PropTypes.string,
761
+ "tooltipId": PropTypes.string,
761
762
  "tooltipPosition": PropTypes.oneOf(["bottom", "left", "right", "top"]),
762
763
  "translate": PropTypes.oneOf(["no", "yes"]),
763
764
  "typeof": PropTypes.string,
@@ -10,9 +10,14 @@ export interface DraggableContainerProps extends MarginProps, Omit<TagProps, "da
10
10
  * `<DraggableItem />` is required to make `Draggable` works
11
11
  */
12
12
  children?: React.ReactNode;
13
+ /**
14
+ * Defines the direction in which the draggable items contents are placed.
15
+ * Can be either "row" or "row-reverse".
16
+ */
17
+ flexDirection?: "row" | "row-reverse";
13
18
  }
14
19
  declare const DraggableContainer: {
15
- ({ "data-element": dataElement, "data-role": dataRole, children, getOrder, ...rest }: DraggableContainerProps): JSX.Element;
20
+ ({ "data-element": dataElement, "data-role": dataRole, children, getOrder, flexDirection, ...rest }: DraggableContainerProps): JSX.Element;
16
21
  displayName: string;
17
22
  };
18
23
  export default DraggableContainer;
@@ -12,6 +12,7 @@ const DraggableContainer = ({
12
12
  "data-role": dataRole = "draggable-container",
13
13
  children,
14
14
  getOrder,
15
+ flexDirection = "row",
15
16
  ...rest
16
17
  }) => {
17
18
  const [draggableItems, setDraggableItems] = useState(React.Children.toArray(children));
@@ -67,7 +68,8 @@ const DraggableContainer = ({
67
68
  return /*#__PURE__*/React.isValidElement(item) && /*#__PURE__*/React.cloneElement(item, {
68
69
  id: `${item.props.id}`,
69
70
  findItem,
70
- moveItem
71
+ moveItem,
72
+ flexDirection
71
73
  }, [item.props.children]);
72
74
  })));
73
75
  };
@@ -76,6 +78,7 @@ if (process.env.NODE_ENV !== "production") {
76
78
  "children": PropTypes.node,
77
79
  "data-element": PropTypes.string,
78
80
  "data-role": PropTypes.string,
81
+ "flexDirection": PropTypes.oneOf(["row-reverse", "row"]),
79
82
  "getOrder": PropTypes.func,
80
83
  "m": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
81
84
  "__@toStringTag": PropTypes.string.isRequired,
@@ -22,9 +22,14 @@ export interface DraggableItemProps extends PaddingProps {
22
22
  * @ignore
23
23
  */
24
24
  moveItem?: (droppedId: string | number, overIndex: number | undefined) => void;
25
+ /**
26
+ * @private
27
+ * @ignore
28
+ */
29
+ flexDirection?: "row" | "row-reverse";
25
30
  }
26
31
  declare const DraggableItem: {
27
- ({ id, findItem, moveItem, children, py, ...rest }: DraggableItemProps): JSX.Element;
32
+ ({ id, findItem, moveItem, children, py, flexDirection, ...rest }: DraggableItemProps): JSX.Element;
28
33
  displayName: string;
29
34
  };
30
35
  export default DraggableItem;
@@ -3,13 +3,15 @@ import React from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import { useDrop, useDrag } from "react-dnd";
5
5
  import { filterStyledSystemPaddingProps } from "../../../style/utils";
6
- import { StyledDraggableItem, StyledIcon } from "./draggable-item.style";
6
+ import { StyledDraggableItem } from "./draggable-item.style";
7
+ import Icon from "../../icon";
7
8
  const DraggableItem = ({
8
9
  id,
9
10
  findItem,
10
11
  moveItem,
11
12
  children,
12
13
  py = 1,
14
+ flexDirection,
13
15
  ...rest
14
16
  }) => {
15
17
  let originalIndex;
@@ -60,8 +62,9 @@ const DraggableItem = ({
60
62
  "data-role": "draggable-item",
61
63
  isDragging: isDragging,
62
64
  ref: node => drag(drop(node)),
63
- py: py
64
- }, paddingProps), children, /*#__PURE__*/React.createElement(StyledIcon, {
65
+ py: py,
66
+ flexDirection: flexDirection
67
+ }, paddingProps), children, /*#__PURE__*/React.createElement(Icon, {
65
68
  type: "drag"
66
69
  }));
67
70
  };
@@ -69,6 +72,7 @@ if (process.env.NODE_ENV !== "production") {
69
72
  DraggableItem.propTypes = {
70
73
  "children": PropTypes.node,
71
74
  "findItem": PropTypes.func,
75
+ "flexDirection": PropTypes.oneOf(["row-reverse", "row"]),
72
76
  "id": PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
73
77
  "moveItem": PropTypes.func,
74
78
  "p": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
@@ -1,9 +1,8 @@
1
- /// <reference types="react" />
2
1
  import { PaddingProps } from "styled-system";
3
2
  declare const StyledDraggableContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
4
3
  interface StyledDraggableItemProps extends PaddingProps {
5
4
  isDragging?: boolean;
5
+ flexDirection?: "row" | "row-reverse";
6
6
  }
7
7
  declare const StyledDraggableItem: import("styled-components").StyledComponent<"div", any, StyledDraggableItemProps, never>;
8
- declare const StyledIcon: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../../icon").IconProps & import("react").RefAttributes<HTMLSpanElement>>, any, {}, never>;
9
- export { StyledDraggableContainer, StyledDraggableItem, StyledIcon };
8
+ export { StyledDraggableContainer, StyledDraggableItem };
@@ -1,7 +1,6 @@
1
1
  import styled from "styled-components";
2
2
  import { padding, margin } from "styled-system";
3
3
  import { baseTheme } from "../../../style/themes";
4
- import Icon from "../../icon";
5
4
  const StyledDraggableContainer = styled.div`
6
5
  ${margin}
7
6
  `;
@@ -11,18 +10,18 @@ const StyledDraggableItem = styled.div`
11
10
  border-bottom: 1px solid var(--colorsUtilityMajor050);
12
11
  ${padding}
13
12
  cursor: move;
14
-
13
+ justify-content: space-between;
14
+ flex-direction: ${({
15
+ flexDirection
16
+ }) => flexDirection};
15
17
  opacity: ${({
16
18
  isDragging
17
19
  }) => isDragging ? "0" : "1"};
18
20
  `;
19
- const StyledIcon = styled(Icon)`
20
- margin-left: auto;
21
- `;
22
21
  StyledDraggableContainer.defaultProps = {
23
22
  theme: baseTheme
24
23
  };
25
24
  StyledDraggableItem.defaultProps = {
26
25
  theme: baseTheme
27
26
  };
28
- export { StyledDraggableContainer, StyledDraggableItem, StyledIcon };
27
+ export { StyledDraggableContainer, StyledDraggableItem };
@@ -685,6 +685,7 @@ if (process.env.NODE_ENV !== "production") {
685
685
  "suppressHydrationWarning": PropTypes.bool,
686
686
  "tabIndex": PropTypes.number,
687
687
  "title": PropTypes.string,
688
+ "tooltipId": PropTypes.string,
688
689
  "tooltipPosition": PropTypes.oneOf(["bottom", "left", "right", "top"]),
689
690
  "translate": PropTypes.oneOf(["no", "yes"]),
690
691
  "typeof": PropTypes.string,
@@ -624,6 +624,7 @@ if (process.env.NODE_ENV !== "production") {
624
624
  "suppressHydrationWarning": PropTypes.bool,
625
625
  "tabIndex": PropTypes.number,
626
626
  "title": PropTypes.string,
627
+ "tooltipId": PropTypes.string,
627
628
  "tooltipPosition": PropTypes.oneOf(["bottom", "left", "right", "top"]),
628
629
  "translate": PropTypes.oneOf(["no", "yes"]),
629
630
  "typeof": PropTypes.string,
@@ -4,21 +4,20 @@ import PropTypes from "prop-types";
4
4
  import invariant from "invariant";
5
5
  import { filterStyledSystemMarginProps } from "../../style/utils";
6
6
  import Events from "../../__internal__/utils/helpers/events";
7
- import { StyledNumeralDate, StyledDateField } from "./numeral-date.style";
7
+ import { StyledNumeralDate, StyledDateField, StyledFieldset } from "./numeral-date.style";
8
8
  import Textbox from "../textbox";
9
9
  import Box from "../box";
10
- import Typography from "../typography";
11
10
  import { ErrorBorder, StyledHintText } from "../textbox/textbox.style";
12
11
  import ValidationMessage from "../../__internal__/validation-message";
13
12
  import guid from "../../__internal__/utils/helpers/guid";
14
13
  import useLocale from "../../hooks/__internal__/useLocale";
15
- import FormField from "../../__internal__/form-field";
16
- import { InputGroupBehaviour } from "../../__internal__/input-behaviour";
17
14
  import { TooltipProvider } from "../../__internal__/tooltip-provider";
18
15
  import NewValidationContext from "../carbon-provider/__internal__/new-validation.context";
19
16
  import NumeralDateContext from "./__internal__/numeral-date.context";
20
- import FormSpacingProvider from "../../__internal__/form-spacing-provider";
21
17
  import Logger from "../../__internal__/utils/logger";
18
+ import FieldHelp from "../../__internal__/field-help";
19
+ import useIsAboveBreakpoint from "../../hooks/__internal__/useIsAboveBreakpoint";
20
+ import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility";
22
21
  let deprecateUncontrolledWarnTriggered = false;
23
22
  export const ALLOWED_DATE_FORMATS = [["dd", "mm", "yyyy"], ["mm", "dd", "yyyy"], ["yyyy", "mm", "dd"], ["dd", "mm"], ["mm", "dd"], ["mm", "yyyy"]];
24
23
  const incorrectDateFormatMessage = "Forbidden prop dateFormat supplied to NumeralDate. " + "Only one of these date formats is allowed: " + "['dd', 'mm', 'yyyy'], " + "['mm', 'dd', 'yyyy'], " + "['yyyy', 'mm', 'dd'], " + "['dd', 'mm'], " + "['mm', 'dd'], " + "['mm', 'yyyy']";
@@ -105,7 +104,7 @@ export const NumeralDate = ({
105
104
  required,
106
105
  isOptional,
107
106
  readOnly,
108
- size,
107
+ size = "medium",
109
108
  enableInternalError,
110
109
  enableInternalWarning,
111
110
  tooltipPosition,
@@ -119,14 +118,18 @@ export const NumeralDate = ({
119
118
  const {
120
119
  validationRedesignOptIn
121
120
  } = useContext(NewValidationContext);
122
- const labelInlineWithNewValidation = validationRedesignOptIn ? false : labelInline;
123
121
  const {
124
122
  current: uniqueId
125
123
  } = useRef(id || guid());
124
+ const inputIds = useRef({
125
+ dd: guid(),
126
+ mm: guid(),
127
+ yyyy: guid()
128
+ });
129
+ const inputHintId = useRef(guid());
126
130
  const isControlled = useRef(value !== undefined);
127
131
  const initialValue = isControlled.current ? value : defaultValue;
128
132
  const refs = useRef(dateFormat.map(() => null));
129
- const labelIds = useRef([guid(), guid(), guid()]);
130
133
  const [internalMessages, setInternalMessages] = useState({
131
134
  ...Object.fromEntries(dateFormat.map(datePart => [datePart, ""]))
132
135
  });
@@ -196,109 +199,143 @@ export const NumeralDate = ({
196
199
  deprecateUncontrolledWarnTriggered = true;
197
200
  Logger.deprecate("Uncontrolled behaviour in `Numeral Date` is deprecated and support will soon be removed. Please make sure all your inputs are controlled.");
198
201
  }
199
- return /*#__PURE__*/React.createElement(TooltipProvider, {
200
- helpAriaLabel: helpAriaLabel
201
- }, /*#__PURE__*/React.createElement(InputGroupBehaviour, null, /*#__PURE__*/React.createElement(FormField, _extends({
202
- "data-component": dataComponent,
203
- "data-element": dataElement,
204
- "data-role": dataRole,
205
- disabled: disabled,
206
- useValidationIcon: validationOnLabel,
202
+ const largeScreen = useIsAboveBreakpoint(adaptiveLabelBreakpoint);
203
+ let inline = labelInline;
204
+ if (adaptiveLabelBreakpoint) {
205
+ inline = largeScreen;
206
+ }
207
+ const handleRef = (element, index, inputRef) => {
208
+ refs.current[index] = element;
209
+ if (!inputRef) {
210
+ return;
211
+ }
212
+ if (typeof inputRef === "function") {
213
+ inputRef(element);
214
+ } else {
215
+ inputRef.current = element;
216
+ }
217
+ };
218
+ const {
219
+ validationId,
220
+ fieldHelpId,
221
+ ariaDescribedBy
222
+ } = useInputAccessibility({
207
223
  id: uniqueId,
224
+ // we still want to add the validationId to aria-describedby with the legacy validation
225
+ validationRedesignOptIn: true,
208
226
  error: internalError,
209
227
  warning: internalWarning,
210
- info: info,
211
- label: label,
212
- labelInline: labelInlineWithNewValidation,
213
- labelWidth: labelWidth,
214
- labelAlign: labelAlign,
215
- labelHelp: !validationRedesignOptIn && labelHelp,
216
- labelSpacing: labelSpacing,
217
- fieldHelp: fieldHelp,
218
- adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
228
+ info,
229
+ fieldHelp
230
+ });
231
+ const combinedAriaDescribedBy = [ariaDescribedBy, inputHintId.current].filter(Boolean).join(" ");
232
+ const renderInputs = () => {
233
+ return /*#__PURE__*/React.createElement(StyledNumeralDate, {
234
+ onKeyDown: onKeyDown
235
+ }, dateFormat.map((datePart, index) => {
236
+ const isEnd = index === dateFormat.length - 1;
237
+ let inputRef;
238
+ const validation = internalError || internalWarning || info;
239
+ const validationInField = !validationRedesignOptIn && typeof validation === "string" && validation !== "";
240
+ switch (datePart.slice(0, 2)) {
241
+ case "dd":
242
+ inputRef = dayRef;
243
+ break;
244
+ case "mm":
245
+ inputRef = monthRef;
246
+ break;
247
+ case "yy":
248
+ inputRef = yearRef;
249
+ break;
250
+ /* istanbul ignore next */
251
+ default:
252
+ break;
253
+ }
254
+ return /*#__PURE__*/React.createElement(NumeralDateContext.Provider, {
255
+ value: {
256
+ disableErrorBorder: true
257
+ },
258
+ key: datePart
259
+ }, /*#__PURE__*/React.createElement(StyledDateField, {
260
+ key: datePart,
261
+ size: size,
262
+ isYearInput: datePart.length === 4,
263
+ hasValidationIconInField: !validationOnLabel && isEnd && validationInField
264
+ }, /*#__PURE__*/React.createElement(Textbox, _extends({
265
+ id: inputIds.current[datePart],
266
+ label: getDateLabel(datePart, locale),
267
+ disabled: disabled,
268
+ readOnly: readOnly,
269
+ error: !!internalError,
270
+ warning: !!internalWarning,
271
+ info: !!info,
272
+ size: size,
273
+ value: dateValue[datePart],
274
+ onChange: e => handleChange(e, datePart),
275
+ onBlur: handleBlur,
276
+ ref: element => handleRef(element, index, inputRef)
277
+ }, isEnd && !validationOnLabel && !validationRedesignOptIn && {
278
+ error: internalError,
279
+ warning: internalWarning,
280
+ info
281
+ }, {
282
+ tooltipPosition: tooltipPosition,
283
+ tooltipId: validationId
284
+ }))));
285
+ }));
286
+ };
287
+ if (!validationRedesignOptIn) {
288
+ return /*#__PURE__*/React.createElement(TooltipProvider, {
289
+ helpAriaLabel: helpAriaLabel
290
+ }, /*#__PURE__*/React.createElement(StyledFieldset, _extends({
291
+ "data-component": dataComponent || "numeral-date",
292
+ "data-element": dataElement,
293
+ "data-role": dataRole,
294
+ id: uniqueId,
295
+ legend: label,
296
+ isRequired: required,
297
+ isOptional: isOptional,
298
+ isDisabled: disabled,
299
+ name: name,
300
+ error: validationOnLabel && internalError,
301
+ warning: validationOnLabel && internalWarning,
302
+ info: validationOnLabel && info,
303
+ inline: inline,
304
+ labelHelp: labelHelp,
305
+ legendAlign: labelAlign,
306
+ legendWidth: labelWidth,
307
+ legendSpacing: labelSpacing,
308
+ validationId: validationId,
309
+ "aria-describedby": ariaDescribedBy
310
+ }, filterStyledSystemMarginProps(rest)), /*#__PURE__*/React.createElement(Box, {
311
+ display: "block",
312
+ mt: 1
313
+ }, renderInputs(), fieldHelp && /*#__PURE__*/React.createElement(FieldHelp, {
314
+ id: fieldHelpId
315
+ }, fieldHelp))));
316
+ }
317
+ return /*#__PURE__*/React.createElement(StyledFieldset, _extends({
318
+ "data-component": dataComponent || "numeral-date",
319
+ "data-element": dataElement,
320
+ "data-role": dataRole,
321
+ id: uniqueId,
322
+ legend: label,
219
323
  isRequired: required,
220
324
  isOptional: isOptional,
221
- validationRedesignOptIn: validationRedesignOptIn
222
- }, filterStyledSystemMarginProps(rest)), validationRedesignOptIn && labelHelp && /*#__PURE__*/React.createElement(StyledHintText, null, labelHelp), /*#__PURE__*/React.createElement(Box, {
223
- position: "relative"
224
- }, validationRedesignOptIn && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ValidationMessage, {
325
+ isDisabled: disabled,
326
+ name: name,
327
+ "aria-describedby": combinedAriaDescribedBy
328
+ }, filterStyledSystemMarginProps(rest)), labelHelp && /*#__PURE__*/React.createElement(StyledHintText, {
329
+ id: inputHintId.current
330
+ }, labelHelp), /*#__PURE__*/React.createElement(Box, {
331
+ position: "relative",
332
+ mt: 1
333
+ }, (internalError || internalWarning) && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ValidationMessage, {
225
334
  error: internalError,
226
- warning: internalWarning
227
- }), (internalError || internalWarning) && /*#__PURE__*/React.createElement(ErrorBorder, {
335
+ warning: internalWarning,
336
+ validationId: validationId
337
+ }), /*#__PURE__*/React.createElement(ErrorBorder, {
228
338
  warning: !!(!internalError && internalWarning)
229
- })), /*#__PURE__*/React.createElement(StyledNumeralDate, {
230
- name: name,
231
- onKeyDown: onKeyDown,
232
- "data-component": "numeral-date"
233
- }, dateFormat.map((datePart, index) => {
234
- const isEnd = index === dateFormat.length - 1;
235
- const labelId = labelIds.current[index];
236
- const validation = internalError || internalWarning || info;
237
- const isStringValidation = typeof validation === "string";
238
- const hasValidationIcon = isStringValidation && !!validation.length;
239
- let inputRef;
240
- switch (datePart.slice(0, 2)) {
241
- case "dd":
242
- inputRef = dayRef;
243
- break;
244
- case "mm":
245
- inputRef = monthRef;
246
- break;
247
- case "yy":
248
- inputRef = yearRef;
249
- break;
250
- /* istanbul ignore next */
251
- default:
252
- break;
253
- }
254
- return /*#__PURE__*/React.createElement(NumeralDateContext.Provider, {
255
- value: {
256
- disableErrorBorder: true
257
- },
258
- key: datePart
259
- }, /*#__PURE__*/React.createElement(StyledDateField, {
260
- key: datePart,
261
- isYearInput: datePart.length === 4,
262
- isEnd: isEnd,
263
- hasValidationIconInField: hasValidationIcon && !validationOnLabel && !validationRedesignOptIn
264
- }, /*#__PURE__*/React.createElement(FormSpacingProvider, {
265
- marginBottom: undefined
266
- }, /*#__PURE__*/React.createElement(Typography, {
267
- mb: "4px",
268
- id: labelId,
269
- "data-role": "numeral-date-input-text"
270
- }, getDateLabel(datePart, locale)), /*#__PURE__*/React.createElement(Textbox, _extends({}, index === 0 && {
271
- id: uniqueId
272
- }, {
273
- disabled: disabled,
274
- readOnly: readOnly,
275
- value: dateValue[datePart],
276
- onChange: e => handleChange(e, datePart),
277
- onBlur: handleBlur,
278
- ref: element => {
279
- refs.current[index] = element;
280
- if (!inputRef) {
281
- return;
282
- }
283
- if (typeof inputRef === "function") {
284
- inputRef(element);
285
- } else {
286
- inputRef.current = element;
287
- }
288
- },
289
- error: !!internalError,
290
- warning: !!internalWarning,
291
- info: !!info
292
- }, isEnd && !validationRedesignOptIn && !validationOnLabel && {
293
- error: internalError,
294
- warning: internalWarning,
295
- info
296
- }, {
297
- size: size,
298
- tooltipPosition: tooltipPosition,
299
- "aria-labelledby": labelId,
300
- required: required
301
- })))));
302
- }))))));
339
+ })), renderInputs()));
303
340
  };
304
341
  export default NumeralDate;
@@ -1,10 +1,12 @@
1
+ /// <reference types="react" />
1
2
  interface StyledDateFieldProps {
2
- isEnd?: boolean;
3
3
  isYearInput?: boolean;
4
- hasValidationIconInField?: boolean;
4
+ hasValidationIconInField: boolean;
5
+ size?: "small" | "medium" | "large";
5
6
  }
6
7
  export declare const StyledNumeralDate: import("styled-components").StyledComponent<"div", any, {
7
8
  name?: string | undefined;
8
9
  }, never>;
9
10
  export declare const StyledDateField: import("styled-components").StyledComponent<"div", any, StyledDateFieldProps, never>;
11
+ export declare const StyledFieldset: import("styled-components").StyledComponent<({ legend, children, inline, legendWidth, legendAlign, legendSpacing, error, warning, info, isRequired, blockGroupBehaviour, legendMargin, isDisabled, isOptional, labelHelp, validationId, ...rest }: import("../../__internal__/fieldset").FieldsetProps) => import("react").JSX.Element, any, {}, never>;
10
12
  export {};