carbon-react 124.4.1 → 124.6.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.
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { MarginProps } from "styled-system";
3
3
  import { ValidationProps } from "../../__internal__/validations";
4
- export declare const ALLOWED_DATE_FORMATS: readonly [readonly ["dd", "mm", "yyyy"], readonly ["mm", "dd", "yyyy"], readonly ["dd", "mm"], readonly ["mm", "dd"], readonly ["mm", "yyyy"]];
4
+ export declare const ALLOWED_DATE_FORMATS: readonly [readonly ["dd", "mm", "yyyy"], readonly ["mm", "dd", "yyyy"], readonly ["yyyy", "mm", "dd"], readonly ["dd", "mm"], readonly ["mm", "dd"], readonly ["mm", "yyyy"]];
5
5
  export interface DayMonthDate {
6
6
  dd: string;
7
7
  mm: string;
@@ -6,7 +6,9 @@ import { filterStyledSystemMarginProps } from "../../style/utils";
6
6
  import Events from "../../__internal__/utils/helpers/events";
7
7
  import { StyledNumeralDate, StyledDateField } from "./numeral-date.style";
8
8
  import Textbox from "../textbox";
9
- import { StyledHintText } from "../textbox/textbox.style";
9
+ import Box from "../box";
10
+ import Typography from "../typography";
11
+ import { ErrorBorder, StyledHintText } from "../textbox/textbox.style";
10
12
  import ValidationMessage from "../../__internal__/validation-message";
11
13
  import guid from "../../__internal__/utils/helpers/guid";
12
14
  import useLocale from "../../hooks/__internal__/useLocale";
@@ -18,8 +20,8 @@ import NumeralDateContext from "./numeral-date-context";
18
20
  import FormSpacingProvider from "../../__internal__/form-spacing-provider";
19
21
  import Logger from "../../__internal__/utils/logger";
20
22
  let deprecateUncontrolledWarnTriggered = false;
21
- export const ALLOWED_DATE_FORMATS = [["dd", "mm", "yyyy"], ["mm", "dd", "yyyy"], ["dd", "mm"], ["mm", "dd"], ["mm", "yyyy"]];
22
- 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']";
23
+ export const ALLOWED_DATE_FORMATS = [["dd", "mm", "yyyy"], ["mm", "dd", "yyyy"], ["yyyy", "mm", "dd"], ["dd", "mm"], ["mm", "dd"], ["mm", "yyyy"]];
24
+ 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']";
23
25
  const isDayValid = day => day ? +day > 0 && +day < 32 : true;
24
26
  const isMonthValid = month => month ? +month > 0 && +month < 13 : true;
25
27
  const isYearValid = year => year ? +year > 1799 && +year < 2201 : true;
@@ -28,6 +30,16 @@ const validations = {
28
30
  mm: isMonthValid,
29
31
  yyyy: isYearValid
30
32
  };
33
+ const getDateLabel = (datePart, locale) => {
34
+ switch (datePart) {
35
+ case "mm":
36
+ return locale.numeralDate.labels.month();
37
+ case "yyyy":
38
+ return locale.numeralDate.labels.year();
39
+ default:
40
+ return locale.numeralDate.labels.day();
41
+ }
42
+ };
31
43
  export const NumeralDate = ({
32
44
  dateFormat = ["dd", "mm", "yyyy"],
33
45
  defaultValue,
@@ -64,7 +76,7 @@ export const NumeralDate = ({
64
76
  yearRef,
65
77
  ...rest
66
78
  }) => {
67
- const l = useLocale();
79
+ const locale = useLocale();
68
80
  const {
69
81
  validationRedesignOptIn
70
82
  } = useContext(NewValidationContext);
@@ -74,6 +86,7 @@ export const NumeralDate = ({
74
86
  const isControlled = useRef(value !== undefined);
75
87
  const initialValue = isControlled.current ? value : defaultValue;
76
88
  const refs = useRef(dateFormat.map(() => null));
89
+ const labelIds = useRef([guid(), guid(), guid()]);
77
90
  const [internalMessages, setInternalMessages] = useState({
78
91
  ...Object.fromEntries(dateFormat.map(datePart => [datePart, ""]))
79
92
  });
@@ -87,9 +100,9 @@ export const NumeralDate = ({
87
100
  !(isControlled.current === (value !== undefined)) ? process.env.NODE_ENV !== "production" ? invariant(false, modeSwitchedMessage) : invariant(false) : void 0;
88
101
  }, [value]);
89
102
  const validationMessages = {
90
- dd: l.numeralDate.validation.day(),
91
- mm: l.numeralDate.validation.month(),
92
- yyyy: l.numeralDate.validation.year()
103
+ dd: locale.numeralDate.validation.day(),
104
+ mm: locale.numeralDate.validation.month(),
105
+ yyyy: locale.numeralDate.validation.year()
93
106
  };
94
107
  const [dateValue, setDateValue] = useState({
95
108
  ...(initialValue || Object.fromEntries(dateFormat.map(datePart => [datePart, ""])))
@@ -101,7 +114,7 @@ export const NumeralDate = ({
101
114
  value: newValue
102
115
  }
103
116
  });
104
- const onKeyPress = event => {
117
+ const onKeyDown = event => {
105
118
  const isValidKey = Events.isNumberKey(event) || Events.isTabKey(event) || event.key === "Delete" || event.key === "Backspace";
106
119
  if (!isValidKey) {
107
120
  event.preventDefault();
@@ -166,24 +179,27 @@ export const NumeralDate = ({
166
179
  labelInline: labelInline,
167
180
  labelWidth: labelWidth,
168
181
  labelAlign: labelAlign,
169
- labelHelp: labelHelp,
182
+ labelHelp: !validationRedesignOptIn && labelHelp,
170
183
  labelSpacing: labelSpacing,
171
184
  fieldHelp: fieldHelp,
172
185
  adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
173
186
  isRequired: required,
174
187
  validationRedesignOptIn: validationRedesignOptIn
175
- }, filterStyledSystemMarginProps(rest)), validationRedesignOptIn && labelHelp && /*#__PURE__*/React.createElement(StyledHintText, null, labelHelp), validationRedesignOptIn && /*#__PURE__*/React.createElement(ValidationMessage, {
188
+ }, filterStyledSystemMarginProps(rest)), validationRedesignOptIn && labelHelp && /*#__PURE__*/React.createElement(StyledHintText, null, labelHelp), /*#__PURE__*/React.createElement(Box, {
189
+ position: "relative"
190
+ }, validationRedesignOptIn && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ValidationMessage, {
176
191
  error: internalError,
177
192
  warning: internalWarning
178
- }), /*#__PURE__*/React.createElement(StyledNumeralDate, {
193
+ }), (internalError || internalWarning) && /*#__PURE__*/React.createElement(ErrorBorder, {
194
+ warning: !!(!internalError && internalWarning)
195
+ })), /*#__PURE__*/React.createElement(StyledNumeralDate, {
179
196
  name: name,
180
- onKeyPress: onKeyPress,
197
+ onKeyDown: onKeyDown,
181
198
  "data-component": "numeral-date"
182
199
  }, dateFormat.map((datePart, index) => {
183
- const isStart = index === 0;
184
200
  const isEnd = index === dateFormat.length - 1;
185
- const isMiddle = index === 1;
186
- const validation = error || warning || info;
201
+ const labelId = labelIds.current[index];
202
+ const validation = internalError || internalWarning || info;
187
203
  const isStringValidation = typeof validation === "string";
188
204
  const hasValidationIcon = isStringValidation && !!validation.length;
189
205
  let inputRef;
@@ -203,24 +219,24 @@ export const NumeralDate = ({
203
219
  }
204
220
  return /*#__PURE__*/React.createElement(NumeralDateContext.Provider, {
205
221
  value: {
206
- disableErrorBorder: index !== 0
222
+ disableErrorBorder: true
207
223
  },
208
224
  key: datePart
209
225
  }, /*#__PURE__*/React.createElement(StyledDateField, {
210
226
  key: datePart,
211
227
  isYearInput: datePart.length === 4,
212
- isStart: isStart,
213
- isMiddle: isMiddle,
214
228
  isEnd: isEnd,
215
- hasValidationIcon: hasValidationIcon
229
+ hasValidationIconInField: hasValidationIcon && !validationOnLabel && !validationRedesignOptIn
216
230
  }, /*#__PURE__*/React.createElement(FormSpacingProvider, {
217
231
  marginBottom: undefined
218
- }, /*#__PURE__*/React.createElement(Textbox, _extends({}, index === 0 && {
232
+ }, /*#__PURE__*/React.createElement(Typography, {
233
+ mb: "4px",
234
+ id: labelId
235
+ }, getDateLabel(datePart, locale)), /*#__PURE__*/React.createElement(Textbox, _extends({}, index === 0 && {
219
236
  id: uniqueId
220
237
  }, {
221
238
  disabled: disabled,
222
239
  readOnly: readOnly,
223
- placeholder: datePart,
224
240
  value: dateValue[datePart],
225
241
  onChange: e => handleChange(e, datePart),
226
242
  ref: element => {
@@ -246,8 +262,9 @@ export const NumeralDate = ({
246
262
  info
247
263
  }, {
248
264
  size: size,
249
- tooltipPosition: tooltipPosition
265
+ tooltipPosition: tooltipPosition,
266
+ "aria-labelledby": labelId
250
267
  })))));
251
- })))));
268
+ }))))));
252
269
  };
253
270
  export default NumeralDate;
@@ -1,9 +1,7 @@
1
1
  interface StyledDateFieldProps {
2
- isStart?: boolean;
3
2
  isEnd?: boolean;
4
- isMiddle?: boolean;
5
3
  isYearInput?: boolean;
6
- hasValidationIcon?: boolean;
4
+ hasValidationIconInField?: boolean;
7
5
  }
8
6
  export declare const StyledNumeralDate: import("styled-components").StyledComponent<"div", any, {
9
7
  name?: string | undefined;
@@ -1,47 +1,44 @@
1
1
  import styled, { css } from "styled-components";
2
2
  import StyledValidationIcon from "../../__internal__/validations/validation-icon.style";
3
3
  import StyledIconSpan from "../../__internal__/input-icon-toggle/input-icon-toggle.style";
4
- import StyledInputPresentantion from "../../__internal__/input/input-presentation.style";
4
+ import StyledInputPresentation from "../../__internal__/input/input-presentation.style";
5
+ import StyledInput from "../../__internal__/input/input.style";
5
6
  import StyledFormField from "../../__internal__/form-field/form-field.style";
7
+ import StyledLabel from "../../__internal__/label/label.style";
8
+ import { StyledHintText } from "../textbox/textbox.style";
6
9
  export const StyledNumeralDate = styled.div`
7
10
  display: inline-flex;
8
- height: 40px;
9
11
  font-size: 14px;
10
12
  font-weight: 400;
11
13
 
12
14
  ${StyledFormField} {
13
15
  margin-top: 0px;
14
16
  }
17
+ ${StyledLabel} {
18
+ font-weight: 400;
19
+ }
20
+
21
+ ${StyledHintText} {
22
+ color: var(--colorsUtilityYin090);
23
+ }
15
24
  `;
16
25
  export const StyledDateField = styled.div`
17
26
  ${({
18
- isStart,
19
27
  isYearInput,
20
28
  isEnd,
21
- hasValidationIcon,
22
- isMiddle
29
+ hasValidationIconInField
23
30
  }) => {
24
- const yearInputOrError = isYearInput || isEnd && hasValidationIcon;
25
31
  return css`
26
- ${StyledInputPresentantion} {
32
+ ${StyledInputPresentation} {
27
33
  position: relative;
28
- width: ${yearInputOrError ? "78px;" : "58px;"};
29
- text-align: center;
30
- border-radius: var(--borderRadius000);
34
+ margin-right: ${isEnd ? "0" : "12px"};
35
+ min-width: ${isYearInput ? "80px" : "55px"};
31
36
 
32
- ${isStart && css`
33
- border-top-left-radius: var(--borderRadius050);
34
- border-bottom-left-radius: var(--borderRadius050);
35
- `}
36
-
37
- ${isEnd && css`
38
- border-top-right-radius: var(--borderRadius050);
39
- border-bottom-right-radius: var(--borderRadius050);
40
- `}
41
-
42
- ${(isMiddle || isEnd) && css`
43
- margin-left: -1px;
44
- `}
37
+ ${StyledInput} {
38
+ text-align: center;
39
+ padding: 0 12px;
40
+ ${hasValidationIconInField && isEnd && "padding-right: 0"}
41
+ }
45
42
 
46
43
  ${StyledIconSpan} {
47
44
  width: 32px;
@@ -51,6 +48,7 @@ export const StyledDateField = styled.div`
51
48
  ${StyledValidationIcon} {
52
49
  z-index: 9000;
53
50
  }
54
- `;
51
+ }
52
+ `;
55
53
  }}
56
54
  `;
@@ -17,7 +17,7 @@ export interface ProgressTrackerProps extends MarginProps {
17
17
  "aria-valuetext"?: string;
18
18
  /** Size of the progress bar. */
19
19
  size?: "small" | "medium" | "large";
20
- /** Length of the progress bar, any valid css string. */
20
+ /** Length of the component, any valid css string. */
21
21
  length?: string;
22
22
  /** Current progress (percentage). */
23
23
  progress?: number;
@@ -35,12 +35,14 @@ export interface ProgressTrackerProps extends MarginProps {
35
35
  customValuePreposition?: string;
36
36
  /**
37
37
  * The position the value label are rendered in.
38
- * Top/bottom apply to horizontal and left/right to vertical orientation.
38
+ * Top/bottom apply to horizontal and left applies to vertical orientation.
39
39
  */
40
- labelsPosition?: "top" | "bottom";
40
+ labelsPosition?: "top" | "bottom" | "left";
41
+ /** Label width */
42
+ labelWidth?: string;
41
43
  }
42
44
  declare const ProgressTracker: {
43
- ({ "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-valuenow": ariaValueNow, "aria-valuemin": ariaValueMin, "aria-valuemax": ariaValueMax, "aria-valuetext": ariaValueText, size, length, error, progress, description, showDefaultLabels, currentProgressLabel, customValuePreposition, maxProgressLabel, labelsPosition, ...rest }: ProgressTrackerProps): React.JSX.Element;
45
+ ({ "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-valuenow": ariaValueNow, "aria-valuemin": ariaValueMin, "aria-valuemax": ariaValueMax, "aria-valuetext": ariaValueText, size, length, error, progress, description, showDefaultLabels, currentProgressLabel, customValuePreposition, maxProgressLabel, labelsPosition, labelWidth, ...rest }: ProgressTrackerProps): React.JSX.Element;
44
46
  displayName: string;
45
47
  };
46
48
  export default ProgressTracker;
@@ -21,7 +21,8 @@ const ProgressTracker = ({
21
21
  currentProgressLabel,
22
22
  customValuePreposition,
23
23
  maxProgressLabel,
24
- labelsPosition,
24
+ labelsPosition = "top",
25
+ labelWidth,
25
26
  ...rest
26
27
  }) => {
27
28
  const l = useLocale();
@@ -51,7 +52,8 @@ const ProgressTracker = ({
51
52
  const displayedMaxProgressLabel = label(maxProgressLabel, "100%");
52
53
  return /*#__PURE__*/React.createElement(StyledValuesLabel, {
53
54
  labelsPosition: labelsPosition,
54
- size: size
55
+ size: size,
56
+ labelWidth: labelWidth
55
57
  }, displayedCurrentProgressLabel && /*#__PURE__*/React.createElement(StyledValue, {
56
58
  "data-element": "current-progress-label"
57
59
  }, displayedCurrentProgressLabel), displayedMaxProgressLabel && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
@@ -72,7 +74,8 @@ const ProgressTracker = ({
72
74
  "aria-valuenow": ariaValueNow === undefined ? defaultValueNow : ariaValueNow,
73
75
  "aria-valuemin": ariaValueMin,
74
76
  "aria-valuemax": ariaValueMax,
75
- "aria-valuetext": ariaValueText
77
+ "aria-valuetext": ariaValueText,
78
+ labelsPosition: labelsPosition
76
79
  }), prefixLabels && renderValueLabels(), /*#__PURE__*/React.createElement(StyledProgressBar, {
77
80
  size: size,
78
81
  ref: barRef,
@@ -1,8 +1,8 @@
1
1
  import { ProgressTrackerProps } from "./progress-tracker.component";
2
- declare const StyledProgressTracker: import("styled-components").StyledComponent<"div", any, Pick<ProgressTrackerProps, "length" | "margin">, never>;
2
+ declare const StyledProgressTracker: import("styled-components").StyledComponent<"div", any, Pick<ProgressTrackerProps, "length" | "margin" | "labelsPosition">, never>;
3
3
  declare const StyledProgressBar: import("styled-components").StyledComponent<"span", any, Pick<ProgressTrackerProps, "error" | "progress" | "size">, never>;
4
4
  declare const StyledValue: import("styled-components").StyledComponent<"span", any, {}, never>;
5
5
  declare const StyledDescription: import("styled-components").StyledComponent<"span", any, {}, never>;
6
- declare const StyledValuesLabel: import("styled-components").StyledComponent<"span", any, Pick<ProgressTrackerProps, "size" | "labelsPosition">, never>;
6
+ declare const StyledValuesLabel: import("styled-components").StyledComponent<"span", any, Pick<ProgressTrackerProps, "labelWidth" | "size" | "labelsPosition">, never>;
7
7
  declare const InnerBar: import("styled-components").StyledComponent<"span", any, Pick<ProgressTrackerProps, "error" | "progress" | "length" | "size">, never>;
8
8
  export { StyledProgressBar, InnerBar, StyledProgressTracker, StyledValuesLabel, StyledValue, StyledDescription, };
@@ -37,6 +37,12 @@ const StyledProgressTracker = styled.div`
37
37
  }) => css`
38
38
  width: ${length};
39
39
  `};
40
+ ${({
41
+ labelsPosition
42
+ }) => labelsPosition === "left" && css`
43
+ display: flex;
44
+ align-items: center;
45
+ `}
40
46
  `;
41
47
  const StyledProgressBar = styled.span`
42
48
  ${({
@@ -71,6 +77,11 @@ const StyledDescription = styled.span`
71
77
  color: var(--colorsUtilityYin055);
72
78
  margin-left: 4px;
73
79
  `;
80
+ const labelsPositionMargin = {
81
+ top: "bottom",
82
+ bottom: "top",
83
+ left: "right"
84
+ };
74
85
  const StyledValuesLabel = styled.span`
75
86
  text-align: start;
76
87
  display: flex;
@@ -79,12 +90,19 @@ const StyledValuesLabel = styled.span`
79
90
  font-size: ${({
80
91
  size
81
92
  }) => size && fontSizes[size]};
93
+
82
94
  ${({
83
95
  labelsPosition
84
- }) => labelsPosition === "bottom" && "margin-top: 8px"};
96
+ }) => labelsPosition && `
97
+ margin-${labelsPositionMargin[labelsPosition]}: var(--spacing100);
98
+ `};
99
+
85
100
  ${({
86
- labelsPosition
87
- }) => labelsPosition !== "bottom" && "margin-bottom: 8px"};
101
+ labelWidth
102
+ }) => labelWidth && css`
103
+ width: ${labelWidth};
104
+ flex-shrink: 0;
105
+ `};
88
106
  `;
89
107
  const InnerBar = styled.span`
90
108
  ${({
@@ -94,6 +94,11 @@ const enGB = {
94
94
  day: () => "Day should be a number within a 1-31 range.",
95
95
  month: () => "Month should be a number within a 1-12 range.",
96
96
  year: () => "Year should be a number within a 1800-2200 range."
97
+ },
98
+ labels: {
99
+ day: () => "Day",
100
+ month: () => "Month",
101
+ year: () => "Year"
97
102
  }
98
103
  },
99
104
  pager: {
@@ -78,6 +78,11 @@ interface Locale {
78
78
  month: () => string;
79
79
  year: () => string;
80
80
  };
81
+ labels: {
82
+ day: () => string;
83
+ month: () => string;
84
+ year: () => string;
85
+ };
81
86
  };
82
87
  pager: {
83
88
  show: () => string;
@@ -129,6 +129,11 @@ const plPL = {
129
129
  day: () => "Dzień musi być liczbą w zakresie 1-31.",
130
130
  month: () => "Miesiąć musi być liczbą w zakresie 1-12.",
131
131
  year: () => "Rok musi być liczbą w zakresie 1800-2200."
132
+ },
133
+ labels: {
134
+ day: () => "Dzień",
135
+ month: () => "Miesiąć",
136
+ year: () => "Rok"
132
137
  }
133
138
  },
134
139
  pager: {
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { MarginProps } from "styled-system";
3
3
  import { ValidationProps } from "../../__internal__/validations";
4
- export declare const ALLOWED_DATE_FORMATS: readonly [readonly ["dd", "mm", "yyyy"], readonly ["mm", "dd", "yyyy"], readonly ["dd", "mm"], readonly ["mm", "dd"], readonly ["mm", "yyyy"]];
4
+ export declare const ALLOWED_DATE_FORMATS: readonly [readonly ["dd", "mm", "yyyy"], readonly ["mm", "dd", "yyyy"], readonly ["yyyy", "mm", "dd"], readonly ["dd", "mm"], readonly ["mm", "dd"], readonly ["mm", "yyyy"]];
5
5
  export interface DayMonthDate {
6
6
  dd: string;
7
7
  mm: string;
@@ -11,6 +11,8 @@ var _utils = require("../../style/utils");
11
11
  var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
12
12
  var _numeralDate = require("./numeral-date.style");
13
13
  var _textbox = _interopRequireDefault(require("../textbox"));
14
+ var _box = _interopRequireDefault(require("../box"));
15
+ var _typography = _interopRequireDefault(require("../typography"));
14
16
  var _textbox2 = require("../textbox/textbox.style");
15
17
  var _validationMessage = _interopRequireDefault(require("../../__internal__/validation-message"));
16
18
  var _guid = _interopRequireDefault(require("../../__internal__/utils/helpers/guid"));
@@ -27,8 +29,8 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
27
29
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
28
30
  function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
29
31
  let deprecateUncontrolledWarnTriggered = false;
30
- const ALLOWED_DATE_FORMATS = exports.ALLOWED_DATE_FORMATS = [["dd", "mm", "yyyy"], ["mm", "dd", "yyyy"], ["dd", "mm"], ["mm", "dd"], ["mm", "yyyy"]];
31
- 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']";
32
+ const ALLOWED_DATE_FORMATS = exports.ALLOWED_DATE_FORMATS = [["dd", "mm", "yyyy"], ["mm", "dd", "yyyy"], ["yyyy", "mm", "dd"], ["dd", "mm"], ["mm", "dd"], ["mm", "yyyy"]];
33
+ 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']";
32
34
  const isDayValid = day => day ? +day > 0 && +day < 32 : true;
33
35
  const isMonthValid = month => month ? +month > 0 && +month < 13 : true;
34
36
  const isYearValid = year => year ? +year > 1799 && +year < 2201 : true;
@@ -37,6 +39,16 @@ const validations = {
37
39
  mm: isMonthValid,
38
40
  yyyy: isYearValid
39
41
  };
42
+ const getDateLabel = (datePart, locale) => {
43
+ switch (datePart) {
44
+ case "mm":
45
+ return locale.numeralDate.labels.month();
46
+ case "yyyy":
47
+ return locale.numeralDate.labels.year();
48
+ default:
49
+ return locale.numeralDate.labels.day();
50
+ }
51
+ };
40
52
  const NumeralDate = ({
41
53
  dateFormat = ["dd", "mm", "yyyy"],
42
54
  defaultValue,
@@ -73,7 +85,7 @@ const NumeralDate = ({
73
85
  yearRef,
74
86
  ...rest
75
87
  }) => {
76
- const l = (0, _useLocale.default)();
88
+ const locale = (0, _useLocale.default)();
77
89
  const {
78
90
  validationRedesignOptIn
79
91
  } = (0, _react.useContext)(_carbonProvider.NewValidationContext);
@@ -83,6 +95,7 @@ const NumeralDate = ({
83
95
  const isControlled = (0, _react.useRef)(value !== undefined);
84
96
  const initialValue = isControlled.current ? value : defaultValue;
85
97
  const refs = (0, _react.useRef)(dateFormat.map(() => null));
98
+ const labelIds = (0, _react.useRef)([(0, _guid.default)(), (0, _guid.default)(), (0, _guid.default)()]);
86
99
  const [internalMessages, setInternalMessages] = (0, _react.useState)({
87
100
  ...Object.fromEntries(dateFormat.map(datePart => [datePart, ""]))
88
101
  });
@@ -96,9 +109,9 @@ const NumeralDate = ({
96
109
  !(isControlled.current === (value !== undefined)) ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, modeSwitchedMessage) : (0, _invariant.default)(false) : void 0;
97
110
  }, [value]);
98
111
  const validationMessages = {
99
- dd: l.numeralDate.validation.day(),
100
- mm: l.numeralDate.validation.month(),
101
- yyyy: l.numeralDate.validation.year()
112
+ dd: locale.numeralDate.validation.day(),
113
+ mm: locale.numeralDate.validation.month(),
114
+ yyyy: locale.numeralDate.validation.year()
102
115
  };
103
116
  const [dateValue, setDateValue] = (0, _react.useState)({
104
117
  ...(initialValue || Object.fromEntries(dateFormat.map(datePart => [datePart, ""])))
@@ -110,7 +123,7 @@ const NumeralDate = ({
110
123
  value: newValue
111
124
  }
112
125
  });
113
- const onKeyPress = event => {
126
+ const onKeyDown = event => {
114
127
  const isValidKey = _events.default.isNumberKey(event) || _events.default.isTabKey(event) || event.key === "Delete" || event.key === "Backspace";
115
128
  if (!isValidKey) {
116
129
  event.preventDefault();
@@ -175,24 +188,27 @@ const NumeralDate = ({
175
188
  labelInline: labelInline,
176
189
  labelWidth: labelWidth,
177
190
  labelAlign: labelAlign,
178
- labelHelp: labelHelp,
191
+ labelHelp: !validationRedesignOptIn && labelHelp,
179
192
  labelSpacing: labelSpacing,
180
193
  fieldHelp: fieldHelp,
181
194
  adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
182
195
  isRequired: required,
183
196
  validationRedesignOptIn: validationRedesignOptIn
184
- }, (0, _utils.filterStyledSystemMarginProps)(rest)), validationRedesignOptIn && labelHelp && /*#__PURE__*/_react.default.createElement(_textbox2.StyledHintText, null, labelHelp), validationRedesignOptIn && /*#__PURE__*/_react.default.createElement(_validationMessage.default, {
197
+ }, (0, _utils.filterStyledSystemMarginProps)(rest)), validationRedesignOptIn && labelHelp && /*#__PURE__*/_react.default.createElement(_textbox2.StyledHintText, null, labelHelp), /*#__PURE__*/_react.default.createElement(_box.default, {
198
+ position: "relative"
199
+ }, validationRedesignOptIn && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_validationMessage.default, {
185
200
  error: internalError,
186
201
  warning: internalWarning
187
- }), /*#__PURE__*/_react.default.createElement(_numeralDate.StyledNumeralDate, {
202
+ }), (internalError || internalWarning) && /*#__PURE__*/_react.default.createElement(_textbox2.ErrorBorder, {
203
+ warning: !!(!internalError && internalWarning)
204
+ })), /*#__PURE__*/_react.default.createElement(_numeralDate.StyledNumeralDate, {
188
205
  name: name,
189
- onKeyPress: onKeyPress,
206
+ onKeyDown: onKeyDown,
190
207
  "data-component": "numeral-date"
191
208
  }, dateFormat.map((datePart, index) => {
192
- const isStart = index === 0;
193
209
  const isEnd = index === dateFormat.length - 1;
194
- const isMiddle = index === 1;
195
- const validation = error || warning || info;
210
+ const labelId = labelIds.current[index];
211
+ const validation = internalError || internalWarning || info;
196
212
  const isStringValidation = typeof validation === "string";
197
213
  const hasValidationIcon = isStringValidation && !!validation.length;
198
214
  let inputRef;
@@ -212,24 +228,24 @@ const NumeralDate = ({
212
228
  }
213
229
  return /*#__PURE__*/_react.default.createElement(_numeralDateContext.default.Provider, {
214
230
  value: {
215
- disableErrorBorder: index !== 0
231
+ disableErrorBorder: true
216
232
  },
217
233
  key: datePart
218
234
  }, /*#__PURE__*/_react.default.createElement(_numeralDate.StyledDateField, {
219
235
  key: datePart,
220
236
  isYearInput: datePart.length === 4,
221
- isStart: isStart,
222
- isMiddle: isMiddle,
223
237
  isEnd: isEnd,
224
- hasValidationIcon: hasValidationIcon
238
+ hasValidationIconInField: hasValidationIcon && !validationOnLabel && !validationRedesignOptIn
225
239
  }, /*#__PURE__*/_react.default.createElement(_formSpacingProvider.default, {
226
240
  marginBottom: undefined
227
- }, /*#__PURE__*/_react.default.createElement(_textbox.default, _extends({}, index === 0 && {
241
+ }, /*#__PURE__*/_react.default.createElement(_typography.default, {
242
+ mb: "4px",
243
+ id: labelId
244
+ }, getDateLabel(datePart, locale)), /*#__PURE__*/_react.default.createElement(_textbox.default, _extends({}, index === 0 && {
228
245
  id: uniqueId
229
246
  }, {
230
247
  disabled: disabled,
231
248
  readOnly: readOnly,
232
- placeholder: datePart,
233
249
  value: dateValue[datePart],
234
250
  onChange: e => handleChange(e, datePart),
235
251
  ref: element => {
@@ -255,9 +271,10 @@ const NumeralDate = ({
255
271
  info
256
272
  }, {
257
273
  size: size,
258
- tooltipPosition: tooltipPosition
274
+ tooltipPosition: tooltipPosition,
275
+ "aria-labelledby": labelId
259
276
  })))));
260
- })))));
277
+ }))))));
261
278
  };
262
279
  exports.NumeralDate = NumeralDate;
263
280
  var _default = exports.default = NumeralDate;
@@ -1,9 +1,7 @@
1
1
  interface StyledDateFieldProps {
2
- isStart?: boolean;
3
2
  isEnd?: boolean;
4
- isMiddle?: boolean;
5
3
  isYearInput?: boolean;
6
- hasValidationIcon?: boolean;
4
+ hasValidationIconInField?: boolean;
7
5
  }
8
6
  export declare const StyledNumeralDate: import("styled-components").StyledComponent<"div", any, {
9
7
  name?: string | undefined;
@@ -8,49 +8,46 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
8
8
  var _validationIcon = _interopRequireDefault(require("../../__internal__/validations/validation-icon.style"));
9
9
  var _inputIconToggle = _interopRequireDefault(require("../../__internal__/input-icon-toggle/input-icon-toggle.style"));
10
10
  var _inputPresentation = _interopRequireDefault(require("../../__internal__/input/input-presentation.style"));
11
+ var _input = _interopRequireDefault(require("../../__internal__/input/input.style"));
11
12
  var _formField = _interopRequireDefault(require("../../__internal__/form-field/form-field.style"));
13
+ var _label = _interopRequireDefault(require("../../__internal__/label/label.style"));
14
+ var _textbox = require("../textbox/textbox.style");
12
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
16
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
17
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
18
  const StyledNumeralDate = exports.StyledNumeralDate = _styledComponents.default.div`
16
19
  display: inline-flex;
17
- height: 40px;
18
20
  font-size: 14px;
19
21
  font-weight: 400;
20
22
 
21
23
  ${_formField.default} {
22
24
  margin-top: 0px;
23
25
  }
26
+ ${_label.default} {
27
+ font-weight: 400;
28
+ }
29
+
30
+ ${_textbox.StyledHintText} {
31
+ color: var(--colorsUtilityYin090);
32
+ }
24
33
  `;
25
34
  const StyledDateField = exports.StyledDateField = _styledComponents.default.div`
26
35
  ${({
27
- isStart,
28
36
  isYearInput,
29
37
  isEnd,
30
- hasValidationIcon,
31
- isMiddle
38
+ hasValidationIconInField
32
39
  }) => {
33
- const yearInputOrError = isYearInput || isEnd && hasValidationIcon;
34
40
  return (0, _styledComponents.css)`
35
41
  ${_inputPresentation.default} {
36
42
  position: relative;
37
- width: ${yearInputOrError ? "78px;" : "58px;"};
38
- text-align: center;
39
- border-radius: var(--borderRadius000);
43
+ margin-right: ${isEnd ? "0" : "12px"};
44
+ min-width: ${isYearInput ? "80px" : "55px"};
40
45
 
41
- ${isStart && (0, _styledComponents.css)`
42
- border-top-left-radius: var(--borderRadius050);
43
- border-bottom-left-radius: var(--borderRadius050);
44
- `}
45
-
46
- ${isEnd && (0, _styledComponents.css)`
47
- border-top-right-radius: var(--borderRadius050);
48
- border-bottom-right-radius: var(--borderRadius050);
49
- `}
50
-
51
- ${(isMiddle || isEnd) && (0, _styledComponents.css)`
52
- margin-left: -1px;
53
- `}
46
+ ${_input.default} {
47
+ text-align: center;
48
+ padding: 0 12px;
49
+ ${hasValidationIconInField && isEnd && "padding-right: 0"}
50
+ }
54
51
 
55
52
  ${_inputIconToggle.default} {
56
53
  width: 32px;
@@ -60,6 +57,7 @@ const StyledDateField = exports.StyledDateField = _styledComponents.default.div`
60
57
  ${_validationIcon.default} {
61
58
  z-index: 9000;
62
59
  }
63
- `;
60
+ }
61
+ `;
64
62
  }}
65
63
  `;
@@ -17,7 +17,7 @@ export interface ProgressTrackerProps extends MarginProps {
17
17
  "aria-valuetext"?: string;
18
18
  /** Size of the progress bar. */
19
19
  size?: "small" | "medium" | "large";
20
- /** Length of the progress bar, any valid css string. */
20
+ /** Length of the component, any valid css string. */
21
21
  length?: string;
22
22
  /** Current progress (percentage). */
23
23
  progress?: number;
@@ -35,12 +35,14 @@ export interface ProgressTrackerProps extends MarginProps {
35
35
  customValuePreposition?: string;
36
36
  /**
37
37
  * The position the value label are rendered in.
38
- * Top/bottom apply to horizontal and left/right to vertical orientation.
38
+ * Top/bottom apply to horizontal and left applies to vertical orientation.
39
39
  */
40
- labelsPosition?: "top" | "bottom";
40
+ labelsPosition?: "top" | "bottom" | "left";
41
+ /** Label width */
42
+ labelWidth?: string;
41
43
  }
42
44
  declare const ProgressTracker: {
43
- ({ "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-valuenow": ariaValueNow, "aria-valuemin": ariaValueMin, "aria-valuemax": ariaValueMax, "aria-valuetext": ariaValueText, size, length, error, progress, description, showDefaultLabels, currentProgressLabel, customValuePreposition, maxProgressLabel, labelsPosition, ...rest }: ProgressTrackerProps): React.JSX.Element;
45
+ ({ "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-valuenow": ariaValueNow, "aria-valuemin": ariaValueMin, "aria-valuemax": ariaValueMax, "aria-valuetext": ariaValueText, size, length, error, progress, description, showDefaultLabels, currentProgressLabel, customValuePreposition, maxProgressLabel, labelsPosition, labelWidth, ...rest }: ProgressTrackerProps): React.JSX.Element;
44
46
  displayName: string;
45
47
  };
46
48
  export default ProgressTracker;
@@ -30,7 +30,8 @@ const ProgressTracker = ({
30
30
  currentProgressLabel,
31
31
  customValuePreposition,
32
32
  maxProgressLabel,
33
- labelsPosition,
33
+ labelsPosition = "top",
34
+ labelWidth,
34
35
  ...rest
35
36
  }) => {
36
37
  const l = (0, _useLocale.default)();
@@ -60,7 +61,8 @@ const ProgressTracker = ({
60
61
  const displayedMaxProgressLabel = label(maxProgressLabel, "100%");
61
62
  return /*#__PURE__*/_react.default.createElement(_progressTracker.StyledValuesLabel, {
62
63
  labelsPosition: labelsPosition,
63
- size: size
64
+ size: size,
65
+ labelWidth: labelWidth
64
66
  }, displayedCurrentProgressLabel && /*#__PURE__*/_react.default.createElement(_progressTracker.StyledValue, {
65
67
  "data-element": "current-progress-label"
66
68
  }, displayedCurrentProgressLabel), displayedMaxProgressLabel && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", {
@@ -81,7 +83,8 @@ const ProgressTracker = ({
81
83
  "aria-valuenow": ariaValueNow === undefined ? defaultValueNow : ariaValueNow,
82
84
  "aria-valuemin": ariaValueMin,
83
85
  "aria-valuemax": ariaValueMax,
84
- "aria-valuetext": ariaValueText
86
+ "aria-valuetext": ariaValueText,
87
+ labelsPosition: labelsPosition
85
88
  }), prefixLabels && renderValueLabels(), /*#__PURE__*/_react.default.createElement(_progressTracker.StyledProgressBar, {
86
89
  size: size,
87
90
  ref: barRef,
@@ -1,8 +1,8 @@
1
1
  import { ProgressTrackerProps } from "./progress-tracker.component";
2
- declare const StyledProgressTracker: import("styled-components").StyledComponent<"div", any, Pick<ProgressTrackerProps, "length" | "margin">, never>;
2
+ declare const StyledProgressTracker: import("styled-components").StyledComponent<"div", any, Pick<ProgressTrackerProps, "length" | "margin" | "labelsPosition">, never>;
3
3
  declare const StyledProgressBar: import("styled-components").StyledComponent<"span", any, Pick<ProgressTrackerProps, "error" | "progress" | "size">, never>;
4
4
  declare const StyledValue: import("styled-components").StyledComponent<"span", any, {}, never>;
5
5
  declare const StyledDescription: import("styled-components").StyledComponent<"span", any, {}, never>;
6
- declare const StyledValuesLabel: import("styled-components").StyledComponent<"span", any, Pick<ProgressTrackerProps, "size" | "labelsPosition">, never>;
6
+ declare const StyledValuesLabel: import("styled-components").StyledComponent<"span", any, Pick<ProgressTrackerProps, "labelWidth" | "size" | "labelsPosition">, never>;
7
7
  declare const InnerBar: import("styled-components").StyledComponent<"span", any, Pick<ProgressTrackerProps, "error" | "progress" | "length" | "size">, never>;
8
8
  export { StyledProgressBar, InnerBar, StyledProgressTracker, StyledValuesLabel, StyledValue, StyledDescription, };
@@ -46,6 +46,12 @@ const StyledProgressTracker = exports.StyledProgressTracker = _styledComponents.
46
46
  }) => (0, _styledComponents.css)`
47
47
  width: ${length};
48
48
  `};
49
+ ${({
50
+ labelsPosition
51
+ }) => labelsPosition === "left" && (0, _styledComponents.css)`
52
+ display: flex;
53
+ align-items: center;
54
+ `}
49
55
  `;
50
56
  const StyledProgressBar = exports.StyledProgressBar = _styledComponents.default.span`
51
57
  ${({
@@ -80,6 +86,11 @@ const StyledDescription = exports.StyledDescription = _styledComponents.default.
80
86
  color: var(--colorsUtilityYin055);
81
87
  margin-left: 4px;
82
88
  `;
89
+ const labelsPositionMargin = {
90
+ top: "bottom",
91
+ bottom: "top",
92
+ left: "right"
93
+ };
83
94
  const StyledValuesLabel = exports.StyledValuesLabel = _styledComponents.default.span`
84
95
  text-align: start;
85
96
  display: flex;
@@ -88,12 +99,19 @@ const StyledValuesLabel = exports.StyledValuesLabel = _styledComponents.default.
88
99
  font-size: ${({
89
100
  size
90
101
  }) => size && fontSizes[size]};
102
+
91
103
  ${({
92
104
  labelsPosition
93
- }) => labelsPosition === "bottom" && "margin-top: 8px"};
105
+ }) => labelsPosition && `
106
+ margin-${labelsPositionMargin[labelsPosition]}: var(--spacing100);
107
+ `};
108
+
94
109
  ${({
95
- labelsPosition
96
- }) => labelsPosition !== "bottom" && "margin-bottom: 8px"};
110
+ labelWidth
111
+ }) => labelWidth && (0, _styledComponents.css)`
112
+ width: ${labelWidth};
113
+ flex-shrink: 0;
114
+ `};
97
115
  `;
98
116
  const InnerBar = exports.InnerBar = _styledComponents.default.span`
99
117
  ${({
@@ -100,6 +100,11 @@ const enGB = {
100
100
  day: () => "Day should be a number within a 1-31 range.",
101
101
  month: () => "Month should be a number within a 1-12 range.",
102
102
  year: () => "Year should be a number within a 1800-2200 range."
103
+ },
104
+ labels: {
105
+ day: () => "Day",
106
+ month: () => "Month",
107
+ year: () => "Year"
103
108
  }
104
109
  },
105
110
  pager: {
@@ -78,6 +78,11 @@ interface Locale {
78
78
  month: () => string;
79
79
  year: () => string;
80
80
  };
81
+ labels: {
82
+ day: () => string;
83
+ month: () => string;
84
+ year: () => string;
85
+ };
81
86
  };
82
87
  pager: {
83
88
  show: () => string;
@@ -136,6 +136,11 @@ const plPL = {
136
136
  day: () => "Dzień musi być liczbą w zakresie 1-31.",
137
137
  month: () => "Miesiąć musi być liczbą w zakresie 1-12.",
138
138
  year: () => "Rok musi być liczbą w zakresie 1800-2200."
139
+ },
140
+ labels: {
141
+ day: () => "Dzień",
142
+ month: () => "Miesiąć",
143
+ year: () => "Rok"
139
144
  }
140
145
  },
141
146
  pager: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "124.4.1",
3
+ "version": "124.6.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",