carbon-react 147.9.0 → 147.10.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.
@@ -43,5 +43,5 @@ export interface PortraitProps extends MarginProps {
43
43
  /** The hex code of the foreground colour. This will only take effect if use in conjunction with `backgroundColor` */
44
44
  foregroundColor?: string;
45
45
  }
46
- declare const Portrait: ({ alt, backgroundColor, foregroundColor, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
46
+ export declare const Portrait: ({ alt, backgroundColor, foregroundColor, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
47
47
  export default Portrait;
@@ -5,7 +5,7 @@ import Tooltip from "../tooltip";
5
5
  import tagComponent from "../../__internal__/utils/helpers/tags/tags";
6
6
  import { StyledCustomImg, StyledIcon, StyledPortraitContainer, StyledPortraitInitials } from "./portrait.style";
7
7
  import { filterStyledSystemMarginProps } from "../../style/utils";
8
- const Portrait = ({
8
+ export const Portrait = ({
9
9
  alt,
10
10
  backgroundColor,
11
11
  foregroundColor = undefined,
@@ -5,14 +5,14 @@ export default {
5
5
  nameSize: "var(--fontSizes050)",
6
6
  emailSize: "var(--fontSizes025)",
7
7
  lineHeight: "12px",
8
- marginLeft: "16px"
8
+ marginLeft: "8px"
9
9
  },
10
10
  S: {
11
11
  initialSize: "var(--fontSizes100)",
12
12
  nameSize: "var(--fontSizes100)",
13
13
  emailSize: "var(--fontSizes100)",
14
14
  lineHeight: "16px",
15
- marginLeft: "16px"
15
+ marginLeft: "8px"
16
16
  },
17
17
  M: {
18
18
  initialSize: "var(--fontSizes300)",
@@ -9,6 +9,8 @@ export declare type TimeValue = {
9
9
  hours: string;
10
10
  minutes: string;
11
11
  period?: ToggleValue;
12
+ formattedHours?: string;
13
+ formattedMinutes?: string;
12
14
  };
13
15
  export interface TimeInputEvent {
14
16
  target: {
@@ -55,7 +57,7 @@ export interface TimeProps extends Omit<TagProps, "data-component">, MarginProps
55
57
  /** Set a name value on the component */
56
58
  name?: string;
57
59
  /** Callback called when focus is lost on input elements */
58
- onBlur?: (ev?: React.FocusEvent<HTMLInputElement>) => void;
60
+ onBlur?: (ev?: React.FocusEvent<HTMLInputElement>, value?: TimeValue) => void;
59
61
  /** Flag to configure component as mandatory */
60
62
  required?: boolean;
61
63
  /** Flag to configure component as optional */
@@ -55,7 +55,10 @@ const Time = /*#__PURE__*/React.forwardRef(({
55
55
  minutes: minuteValue,
56
56
  period: toggleValue
57
57
  } = value;
58
+ const formattedHoursValue = hourValue.length ? hourValue.padStart(2, "0") : hourValue;
59
+ const formattedMinutesValue = minuteValue.length ? minuteValue.padStart(2, "0") : minuteValue;
58
60
  const [inputValues, setInputValues] = useState([hourValue, minuteValue]);
61
+ const [formattedInputValues, setFormattedInputValues] = useState([formattedHoursValue, formattedMinutesValue]);
59
62
  const locale = useLocale();
60
63
  const showToggle = toggleValue !== undefined;
61
64
  const [period, setPeriod] = useState(toggleValue);
@@ -104,6 +107,9 @@ const Time = /*#__PURE__*/React.forwardRef(({
104
107
  const hours = inputName === "hrs" ? ev.target.value : inputValues[0];
105
108
  const minutes = inputName === "mins" ? ev.target.value : inputValues[1];
106
109
  setInputValues([hours, minutes]);
110
+ const formattedHours = hours.length ? hours.padStart(2, "0") : hours;
111
+ const formattedMinutes = minutes.length ? minutes.padStart(2, "0") : minutes;
112
+ setFormattedInputValues([formattedHours, formattedMinutes]);
107
113
  onChange({
108
114
  target: {
109
115
  name,
@@ -111,13 +117,16 @@ const Time = /*#__PURE__*/React.forwardRef(({
111
117
  value: {
112
118
  hours,
113
119
  minutes,
114
- period
120
+ period,
121
+ formattedHours,
122
+ formattedMinutes
115
123
  }
116
124
  }
117
125
  });
118
126
  };
119
127
  const handlePeriodChange = periodName => {
120
128
  const [hours, minutes] = inputValues;
129
+ const [formattedHours, formattedMinutes] = formattedInputValues;
121
130
  setPeriod(periodName);
122
131
  onChange({
123
132
  target: {
@@ -126,18 +135,29 @@ const Time = /*#__PURE__*/React.forwardRef(({
126
135
  value: {
127
136
  hours,
128
137
  minutes,
129
- period: periodName
138
+ period: periodName,
139
+ formattedHours,
140
+ formattedMinutes
130
141
  }
131
142
  }
132
143
  });
133
144
  };
134
145
  const handleBlur = useCallback(ev => {
135
146
  setTimeout(() => {
147
+ const [hours, minutes] = inputValues;
148
+ const [formattedHours, formattedMinutes] = formattedInputValues;
149
+ const timeValueObj = {
150
+ hours,
151
+ minutes,
152
+ period,
153
+ formattedHours,
154
+ formattedMinutes
155
+ };
136
156
  if (hoursRef.current !== document.activeElement && minsRef.current !== document.activeElement) {
137
- onBlur?.(ev);
157
+ onBlur?.(ev, timeValueObj);
138
158
  }
139
159
  });
140
- }, [onBlur]);
160
+ }, [formattedInputValues, inputValues, onBlur, period]);
141
161
  return /*#__PURE__*/React.createElement(Fieldset, _extends({
142
162
  legend: label,
143
163
  legendMargin: {
@@ -429,6 +449,8 @@ if (process.env.NODE_ENV !== "production") {
429
449
  })
430
450
  }),
431
451
  "value": PropTypes.shape({
452
+ "formattedHours": PropTypes.string,
453
+ "formattedMinutes": PropTypes.string,
432
454
  "hours": PropTypes.string.isRequired,
433
455
  "minutes": PropTypes.string.isRequired,
434
456
  "period": PropTypes.oneOf(["AM", "PM"])
@@ -43,5 +43,5 @@ export interface PortraitProps extends MarginProps {
43
43
  /** The hex code of the foreground colour. This will only take effect if use in conjunction with `backgroundColor` */
44
44
  foregroundColor?: string;
45
45
  }
46
- declare const Portrait: ({ alt, backgroundColor, foregroundColor, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
46
+ export declare const Portrait: ({ alt, backgroundColor, foregroundColor, name, darkBackground, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
47
47
  export default Portrait;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.Portrait = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _tooltip = _interopRequireDefault(require("../tooltip"));
@@ -95,4 +95,5 @@ const Portrait = ({
95
95
  };
96
96
  return renderComponent();
97
97
  };
98
+ exports.Portrait = Portrait;
98
99
  var _default = exports.default = Portrait;
@@ -11,14 +11,14 @@ var _default = exports.default = {
11
11
  nameSize: "var(--fontSizes050)",
12
12
  emailSize: "var(--fontSizes025)",
13
13
  lineHeight: "12px",
14
- marginLeft: "16px"
14
+ marginLeft: "8px"
15
15
  },
16
16
  S: {
17
17
  initialSize: "var(--fontSizes100)",
18
18
  nameSize: "var(--fontSizes100)",
19
19
  emailSize: "var(--fontSizes100)",
20
20
  lineHeight: "16px",
21
- marginLeft: "16px"
21
+ marginLeft: "8px"
22
22
  },
23
23
  M: {
24
24
  initialSize: "var(--fontSizes300)",
@@ -9,6 +9,8 @@ export declare type TimeValue = {
9
9
  hours: string;
10
10
  minutes: string;
11
11
  period?: ToggleValue;
12
+ formattedHours?: string;
13
+ formattedMinutes?: string;
12
14
  };
13
15
  export interface TimeInputEvent {
14
16
  target: {
@@ -55,7 +57,7 @@ export interface TimeProps extends Omit<TagProps, "data-component">, MarginProps
55
57
  /** Set a name value on the component */
56
58
  name?: string;
57
59
  /** Callback called when focus is lost on input elements */
58
- onBlur?: (ev?: React.FocusEvent<HTMLInputElement>) => void;
60
+ onBlur?: (ev?: React.FocusEvent<HTMLInputElement>, value?: TimeValue) => void;
59
61
  /** Flag to configure component as mandatory */
60
62
  required?: boolean;
61
63
  /** Flag to configure component as optional */
@@ -64,7 +64,10 @@ const Time = /*#__PURE__*/_react.default.forwardRef(({
64
64
  minutes: minuteValue,
65
65
  period: toggleValue
66
66
  } = value;
67
+ const formattedHoursValue = hourValue.length ? hourValue.padStart(2, "0") : hourValue;
68
+ const formattedMinutesValue = minuteValue.length ? minuteValue.padStart(2, "0") : minuteValue;
67
69
  const [inputValues, setInputValues] = (0, _react.useState)([hourValue, minuteValue]);
70
+ const [formattedInputValues, setFormattedInputValues] = (0, _react.useState)([formattedHoursValue, formattedMinutesValue]);
68
71
  const locale = (0, _useLocale.default)();
69
72
  const showToggle = toggleValue !== undefined;
70
73
  const [period, setPeriod] = (0, _react.useState)(toggleValue);
@@ -113,6 +116,9 @@ const Time = /*#__PURE__*/_react.default.forwardRef(({
113
116
  const hours = inputName === "hrs" ? ev.target.value : inputValues[0];
114
117
  const minutes = inputName === "mins" ? ev.target.value : inputValues[1];
115
118
  setInputValues([hours, minutes]);
119
+ const formattedHours = hours.length ? hours.padStart(2, "0") : hours;
120
+ const formattedMinutes = minutes.length ? minutes.padStart(2, "0") : minutes;
121
+ setFormattedInputValues([formattedHours, formattedMinutes]);
116
122
  onChange({
117
123
  target: {
118
124
  name,
@@ -120,13 +126,16 @@ const Time = /*#__PURE__*/_react.default.forwardRef(({
120
126
  value: {
121
127
  hours,
122
128
  minutes,
123
- period
129
+ period,
130
+ formattedHours,
131
+ formattedMinutes
124
132
  }
125
133
  }
126
134
  });
127
135
  };
128
136
  const handlePeriodChange = periodName => {
129
137
  const [hours, minutes] = inputValues;
138
+ const [formattedHours, formattedMinutes] = formattedInputValues;
130
139
  setPeriod(periodName);
131
140
  onChange({
132
141
  target: {
@@ -135,18 +144,29 @@ const Time = /*#__PURE__*/_react.default.forwardRef(({
135
144
  value: {
136
145
  hours,
137
146
  minutes,
138
- period: periodName
147
+ period: periodName,
148
+ formattedHours,
149
+ formattedMinutes
139
150
  }
140
151
  }
141
152
  });
142
153
  };
143
154
  const handleBlur = (0, _react.useCallback)(ev => {
144
155
  setTimeout(() => {
156
+ const [hours, minutes] = inputValues;
157
+ const [formattedHours, formattedMinutes] = formattedInputValues;
158
+ const timeValueObj = {
159
+ hours,
160
+ minutes,
161
+ period,
162
+ formattedHours,
163
+ formattedMinutes
164
+ };
145
165
  if (hoursRef.current !== document.activeElement && minsRef.current !== document.activeElement) {
146
- onBlur?.(ev);
166
+ onBlur?.(ev, timeValueObj);
147
167
  }
148
168
  });
149
- }, [onBlur]);
169
+ }, [formattedInputValues, inputValues, onBlur, period]);
150
170
  return /*#__PURE__*/_react.default.createElement(_fieldset.default, _extends({
151
171
  legend: label,
152
172
  legendMargin: {
@@ -438,6 +458,8 @@ if (process.env.NODE_ENV !== "production") {
438
458
  })
439
459
  }),
440
460
  "value": _propTypes.default.shape({
461
+ "formattedHours": _propTypes.default.string,
462
+ "formattedMinutes": _propTypes.default.string,
441
463
  "hours": _propTypes.default.string.isRequired,
442
464
  "minutes": _propTypes.default.string.isRequired,
443
465
  "period": _propTypes.default.oneOf(["AM", "PM"])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "147.9.0",
3
+ "version": "147.10.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",