@commercetools-uikit/time-input 16.0.0 → 16.1.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.
@@ -52,112 +52,87 @@ var _styled__default = /*#__PURE__*/_interopDefault(_styled);
52
52
  const getClearSectionStyles = () => {
53
53
  return /*#__PURE__*/react.css("align-items:center;box-sizing:border-box;display:flex;margin:", designSystem.designTokens.spacing10, ";cursor:pointer;& svg *:not([fill='none']){fill:", designSystem.designTokens.iconColorForDatetimeInputIcon, ";}&:hover svg *{fill:", designSystem.designTokens.iconColorForDatetimeInputIconWhenHovered, ";}" + ("" ), "" );
54
54
  };
55
-
56
55
  const getClockIconContainerColor = props => {
57
56
  if (props.isDisabled) {
58
57
  return designSystem.designTokens.borderColorForInputWhenDisabled;
59
58
  }
60
-
61
59
  if (props.hasError) {
62
60
  return designSystem.designTokens.borderColorForInputWhenError;
63
61
  }
64
-
65
62
  if (props.isReadOnly) {
66
63
  return designSystem.designTokens.borderColorForInputWhenReadonly;
67
64
  }
68
-
69
65
  return designSystem.designTokens.borderColorForInput;
70
66
  };
71
-
72
67
  const getClockIconContainerFontColor = props => {
73
68
  if (props.isDisabled) {
74
69
  return designSystem.designTokens.fontColorForInputWhenDisabled;
75
70
  }
76
-
77
71
  if (props.hasError) {
78
72
  return designSystem.designTokens.fontColorForInputWhenError;
79
73
  }
80
-
81
74
  if (props.isReadOnly) {
82
75
  return designSystem.designTokens.fontColorForInputWhenReadonly;
83
76
  }
84
-
85
77
  return designSystem.designTokens.fontColorForInput;
86
78
  };
87
-
88
79
  const getClockIconContainerStyles = (props, isNewTheme) => {
89
80
  return [/*#__PURE__*/react.css("align-items:center;box-sizing:border-box;background:none;background-color:", props.isDisabled ? designSystem.designTokens.backgroundColorForInputWhenDisabled : 'none', ";border:0;border-top-right-radius:", designSystem.designTokens.borderRadiusForInput, ";border-bottom-right-radius:", designSystem.designTokens.borderRadiusForInput, ";border-color:", getClockIconContainerColor(props), ";color:", getClockIconContainerFontColor(props), ";cursor:", props.isDisabled ? 'not-allowed' : 'default', ";height:100%;display:flex;padding:", designSystem.designTokens.spacing10, ";outline:0;transition:color ", designSystem.designTokens.transitionStandard, ",border-color ", designSystem.designTokens.transitionStandard, ";&:hover:not(:disabled):not(:read-only),&:focus{border-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";}" + ("" ), "" ), !isNewTheme && /*#__PURE__*/react.css("border-left:1px solid ", getClockIconContainerColor(props), ";" + ("" ), "" )];
90
81
  };
91
-
92
82
  const getInputContainerBorderColor = props => {
93
83
  if (props.isDisabled) {
94
84
  return designSystem.designTokens.borderColorForInputWhenDisabled;
95
85
  }
96
-
97
86
  if (props.hasError) {
98
87
  return designSystem.designTokens.borderColorForInputWhenError;
99
88
  }
100
-
101
89
  if (props.isReadOnly) {
102
90
  return designSystem.designTokens.borderColorForInputWhenReadonly;
103
91
  }
104
-
105
92
  return designSystem.designTokens.borderColorForInput;
106
93
  };
107
-
108
94
  const getInputContainerFontColor = props => {
109
95
  if (props.isDisabled) {
110
96
  return designSystem.designTokens.fontColorForInputWhenDisabled;
111
97
  }
112
-
113
98
  if (props.hasError) {
114
99
  return designSystem.designTokens.fontColorForInputWhenError;
115
100
  }
116
-
117
101
  if (props.isReadOnly) {
118
102
  return designSystem.designTokens.fontColorForInputWhenReadonly;
119
103
  }
120
-
121
104
  return designSystem.designTokens.fontColorForInput;
122
105
  };
123
-
124
106
  const getInputContainerBackgroundColor = props => {
125
107
  if (props.isDisabled) {
126
108
  return designSystem.designTokens.backgroundColorForInputWhenDisabled;
127
109
  }
128
-
129
110
  if (props.isReadOnly) {
130
111
  return designSystem.designTokens.backgroundColorForInputWhenReadonly;
131
112
  }
132
-
133
113
  return designSystem.designTokens.backgroundColorForInput;
134
- }; // This styled component is only useful because it's referenced in the styles below
135
-
114
+ };
136
115
 
116
+ // This styled component is only useful because it's referenced in the styles below
137
117
  const StyledClockIconContainer = /*#__PURE__*/_styled__default["default"]("label", {
138
118
  target: "e1dwg5ng1"
139
119
  } )("" );
140
-
141
120
  const getInputContainerStyles = (props, isNewTheme) => {
142
121
  return [/*#__PURE__*/react.css("appearance:none;background-color:", props.isDisabled ? designSystem.designTokens.backgroundColorForInputWhenDisabled : designSystem.designTokens.backgroundColorForInput, ";background-color:", getInputContainerBackgroundColor(props), ";border:1px solid ", getInputContainerBorderColor(props), ";border-radius:", designSystem.designTokens.borderRadiusForInput, ";box-sizing:border-box;color:", getInputContainerFontColor(props), ";cursor:", props.isDisabled ? 'not-allowed' : 'default', ";width:100%;height:", designSystem.designTokens.heightForInput, ";align-items:center;display:flex;font-size:", designSystem.designTokens.fontSizeForInput, ";font-family:inherit;transition:border-color ", designSystem.designTokens.transitionStandard, ",box-shadow ", designSystem.designTokens.transitionStandard, ";svg{fill:", props.isReadOnly ? designSystem.designTokens.fontColorForInputWhenReadonly : 'inherit', ";}&:focus{border-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";}" + ("" ), "" ), !props.isDisabled && !props.isReadOnly && /*#__PURE__*/react.css("&:hover{background-color:", designSystem.designTokens.backgroundColorForInputWhenHovered, ";}&:focus-within{border-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";box-shadow:", designSystem.designTokens.boxShadowForDatetimeInputWhenHovered, " ", designSystem.designTokens.borderColorForInputWhenFocused, ";&:hover{background-color:", designSystem.designTokens.colorSurface, ";}}" + ("" ), "" ), !isNewTheme && !props.isDisabled && !props.isReadOnly && /*#__PURE__*/react.css(":hover:not(:disabled):not(:read-only){border-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";}&:hover,&:hover ", StyledClockIconContainer, ",&:focus-within ", StyledClockIconContainer, "{border-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";}" + ("" ), "" ), isNewTheme && props.hasError && /*#__PURE__*/react.css("box-shadow:", designSystem.designTokens.boxShadowForDatetimeInputWhenHovered, ";" + ("" ), "" )];
143
122
  };
144
-
145
123
  var _ref = {
146
124
  name: "v9rb4r",
147
125
  styles: "border:none;box-shadow:none;background:none;&,&:focus,&:focus:not(:read-only){box-shadow:none;}&:focus,&:hover{background-color:transparent!important;}"
148
126
  } ;
149
-
150
127
  const getTimeInputStyles = props => {
151
128
  const baseStyles = [inputUtils.getInputStyles(props), _ref];
152
129
  return baseStyles;
153
130
  };
154
-
155
131
  const StyledInputContainer = /*#__PURE__*/_styled__default["default"]("div", {
156
132
  target: "e1dwg5ng0"
157
133
  } )("" );
158
134
 
159
135
  function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
160
-
161
136
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
162
137
  const ClearSection = props => {
163
138
  return jsxRuntime.jsx(AccessibleButton__default["default"], {
@@ -174,8 +149,7 @@ ClearSection.propTypes = {};
174
149
  ClearSection.displayName = 'ClearSection';
175
150
  const TimeInputBody = /*#__PURE__*/react$1.forwardRef((props, ref) => {
176
151
  const _useTheme = designSystem.useTheme(),
177
- isNewTheme = _useTheme.isNewTheme;
178
-
152
+ isNewTheme = _useTheme.isNewTheme;
179
153
  return jsxRuntime.jsx(Inline__default["default"], {
180
154
  alignItems: "center",
181
155
  children: jsxRuntime.jsxs(StyledInputContainer, {
@@ -229,55 +203,43 @@ var messages = reactIntl.defineMessages({
229
203
  });
230
204
 
231
205
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
232
-
233
206
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context6 = ownKeys(Object(source), !0)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context7 = ownKeys(Object(source))).call(_context7, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
234
207
  const sequentialId = utils.createSequentialId('time-input-');
235
-
236
208
  const leftPad = function (value) {
237
209
  var _context;
238
-
239
210
  let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
240
211
  return _padStartInstanceProperty__default["default"](_context = String(value)).call(_context, length, '0');
241
212
  };
242
-
243
213
  const format24hr = _ref => {
244
214
  var _context2, _context3, _context4, _context5;
245
-
246
215
  let hours = _ref.hours,
247
- minutes = _ref.minutes,
248
- seconds = _ref.seconds,
249
- milliseconds = _ref.milliseconds;
250
-
216
+ minutes = _ref.minutes,
217
+ seconds = _ref.seconds,
218
+ milliseconds = _ref.milliseconds;
251
219
  const base = _concatInstanceProperty__default["default"](_context2 = "".concat(leftPad(hours), ":")).call(_context2, leftPad(minutes));
252
-
253
220
  if (seconds === 0 && milliseconds === 0) return base;
254
- if (milliseconds === 0) return _concatInstanceProperty__default["default"](_context3 = "".concat(base, ":")).call(_context3, leftPad(seconds)); // string representation of a time without timezone in ISO 8601 format
255
-
221
+ if (milliseconds === 0) return _concatInstanceProperty__default["default"](_context3 = "".concat(base, ":")).call(_context3, leftPad(seconds));
222
+ // string representation of a time without timezone in ISO 8601 format
256
223
  return _concatInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = "".concat(base, ":")).call(_context5, leftPad(seconds), ".")).call(_context4, leftPad(milliseconds, 3));
257
224
  };
225
+ const hasMilliseconds = parsedTime => parsedTime.milliseconds !== 0;
258
226
 
259
- const hasMilliseconds = parsedTime => parsedTime.milliseconds !== 0; // Calling `eventTarget.dispatchEvent` does not natively work in React.
227
+ // Calling `eventTarget.dispatchEvent` does not natively work in React.
260
228
  // Instead, we need to grab the element value setter, set the value, and dispatch a change event.
261
-
262
-
263
229
  const dispatchReactChangeEvent = (node, value) => {
264
230
  var _Object$getOwnPropert;
265
-
266
231
  const setValue = (_Object$getOwnPropert = _Object$getOwnPropertyDescriptor__default["default"](node.constructor.prototype, 'value')) === null || _Object$getOwnPropert === void 0 ? void 0 : _Object$getOwnPropert.set;
267
232
  setValue === null || setValue === void 0 ? void 0 : setValue.call(node, value);
268
233
  node.dispatchEvent(new Event('change', {
269
234
  bubbles: true
270
235
  }));
271
236
  };
272
-
273
237
  const TimeInput = props => {
274
238
  const id = hooks.useFieldId(props.id, sequentialId);
275
239
  const intl = reactIntl.useIntl();
276
240
  const element = react$1.useRef(null);
277
241
  const onChange = props.onChange;
278
-
279
242
  if (!props.isReadOnly) ;
280
-
281
243
  const onBlur = props.onBlur;
282
244
  const handleBlur = react$1.useCallback(event => {
283
245
  const rawValue = event.target.value;
@@ -289,20 +251,20 @@ const TimeInput = props => {
289
251
  if (element.current) {
290
252
  dispatchReactChangeEvent(element.current, '');
291
253
  }
292
-
293
254
  onChange === null || onChange === void 0 ? void 0 : onChange({
294
255
  target: {
295
256
  value: ''
296
257
  }
297
258
  });
298
- }, [onChange]); // if locale has changed trigger a new change event
259
+ }, [onChange]);
299
260
 
261
+ // if locale has changed trigger a new change event
300
262
  react$1.useEffect(() => {
301
263
  if (element.current) {
302
264
  dispatchReactChangeEvent(element.current, props.value);
303
- } // Only subscribe this effect to `intl.locale` changes.
265
+ }
266
+ // Only subscribe this effect to `intl.locale` changes.
304
267
  // eslint-disable-next-line react-hooks/exhaustive-deps
305
-
306
268
  }, [intl.locale]);
307
269
  return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
308
270
  max: props.horizontalConstraint,
@@ -328,32 +290,34 @@ const TimeInput = props => {
328
290
  }))
329
291
  });
330
292
  };
331
-
332
293
  TimeInput.propTypes = {};
333
- TimeInput.displayName = 'TimeInput'; // Takes any input like 15:10, 3 AM, 3AM, 3:15AM, 3:5AM and turns it
334
- // into a 24h format (with seconds and milliseconds if present)
294
+ TimeInput.displayName = 'TimeInput';
335
295
 
296
+ // Takes any input like 15:10, 3 AM, 3AM, 3:15AM, 3:5AM and turns it
297
+ // into a 24h format (with seconds and milliseconds if present)
336
298
  TimeInput.to24h = time => {
337
299
  const parsedTime = utils.parseTime(time);
338
300
  return parsedTime ? format24hr(parsedTime) : '';
339
301
  };
340
-
341
302
  TimeInput.defaultProps = {
342
303
  horizontalConstraint: 'scale'
343
- }; // Converts any value to either a formatted value or an empty string
304
+ };
305
+
306
+ // Converts any value to either a formatted value or an empty string
344
307
  // The resulting format might use 12h or 24h, unless the time contains
345
308
  // milliseconds. If milliseconds are contained, the
346
309
  // the 24h format is returned.
347
310
  //
348
311
  // Returns time in a format suitable for the locale.
349
-
350
312
  TimeInput.toLocaleTime = (time, locale) => {
351
313
  const parsedTime = utils.parseTime(time);
352
314
  if (!parsedTime) return '';
353
- const timeIn24hFormat = format24hr(parsedTime); // return the 24h format, as the time has high precision
315
+ const timeIn24hFormat = format24hr(parsedTime);
354
316
 
355
- if (hasMilliseconds(parsedTime)) return timeIn24hFormat; // return the localized time (12h or 24h format)
317
+ // return the 24h format, as the time has high precision
318
+ if (hasMilliseconds(parsedTime)) return timeIn24hFormat;
356
319
 
320
+ // return the localized time (12h or 24h format)
357
321
  const date = new Date(1970, 0, 1, parsedTime.hours, parsedTime.minutes, parsedTime.seconds, parsedTime.milliseconds);
358
322
  const options = {
359
323
  hour: 'numeric',
@@ -364,11 +328,10 @@ TimeInput.toLocaleTime = (time, locale) => {
364
328
  const isValidDate = !isNaN(date.getTime());
365
329
  return isValidDate ? date.toLocaleTimeString(locale, options) : '';
366
330
  };
367
-
368
331
  var TimeInput$1 = TimeInput;
369
332
 
370
333
  // NOTE: This string will be replaced on build time with the package version.
371
- var version = "16.0.0";
334
+ var version = "16.1.0";
372
335
 
373
336
  exports["default"] = TimeInput$1;
374
337
  exports.version = version;