baseui 0.0.0-next-42b8311 → 0.0.0-next-7202ef9

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.
@@ -152,24 +152,28 @@ class TimePicker extends React.Component {
152
152
  _defineProperty(this, "getTimeWindowInSeconds", step => {
153
153
  let {
154
154
  minTime: min,
155
- maxTime: max
155
+ maxTime: max,
156
+ ignoreMinMaxDateComponent
156
157
  } = this.props;
157
- let midnight = this.setTime(this.props.value, 0, 0, 0);
158
+ const dayStart = this.setTime(this.props.value, 0, 0, 0);
159
+ const dayEnd = this.setTime(this.props.value, 24, 0, 0);
158
160
 
159
- if (!min) {
160
- min = midnight;
161
+ if (!min || this.props.adapter.isBefore(min, dayStart) && !ignoreMinMaxDateComponent) {
162
+ min = dayStart;
163
+ } else {
164
+ min = this.setTime(this.props.value, this.props.adapter.getHours(min), this.props.adapter.getMinutes(min), this.props.adapter.getSeconds(min));
161
165
  }
162
166
 
163
- if (!max) {
164
- max = this.setTime(this.props.value, 24, 0, 0);
167
+ if (!max || this.props.adapter.isAfter(max, dayEnd) && !ignoreMinMaxDateComponent) {
168
+ max = dayEnd;
165
169
  } else {
166
- // maxTime (if provided) should be inclusive, so add an extra step here
167
- max = this.props.adapter.setSeconds(this.props.adapter.date(max), this.props.adapter.getSeconds(max) + step);
170
+ max = this.setTime(this.props.value, this.props.adapter.getHours(max), this.props.adapter.getMinutes(max), // maxTime (if provided) should be inclusive, so add an extra second here
171
+ this.props.adapter.getSeconds(max) + 1);
168
172
  }
169
173
 
170
174
  const minDate = this.props.adapter.toJsDate(min);
171
175
  const maxDate = this.props.adapter.toJsDate(max);
172
- const midnightDate = this.props.adapter.toJsDate(midnight);
176
+ const midnightDate = this.props.adapter.toJsDate(dayStart);
173
177
  return {
174
178
  start: (minDate - midnightDate) / 1000,
175
179
  end: (maxDate - midnightDate) / 1000
@@ -248,7 +252,7 @@ class TimePicker extends React.Component {
248
252
  steps: steps,
249
253
  value: this.props.nullable ? undefined : {
250
254
  id: closestStep,
251
- label: this.secondsToLabel(closestStep, undefined)
255
+ label: this.secondsToLabel(closestStep, this.props.format)
252
256
  }
253
257
  });
254
258
 
@@ -337,7 +341,8 @@ _defineProperty(TimePicker, "defaultProps", {
337
341
  format: '12',
338
342
  step: 900,
339
343
  creatable: false,
340
- adapter: dateFnsAdapter
344
+ adapter: dateFnsAdapter,
345
+ ignoreMinMaxDateComponent: false
341
346
  });
342
347
 
343
348
  export default TimePicker;
@@ -206,26 +206,31 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
206
206
  _defineProperty(_assertThisInitialized(_this), "getTimeWindowInSeconds", function (step) {
207
207
  var _this$props = _this.props,
208
208
  min = _this$props.minTime,
209
- max = _this$props.maxTime;
209
+ max = _this$props.maxTime,
210
+ ignoreMinMaxDateComponent = _this$props.ignoreMinMaxDateComponent;
210
211
 
211
- var midnight = _this.setTime(_this.props.value, 0, 0, 0);
212
+ var dayStart = _this.setTime(_this.props.value, 0, 0, 0);
212
213
 
213
- if (!min) {
214
- min = midnight;
214
+ var dayEnd = _this.setTime(_this.props.value, 24, 0, 0);
215
+
216
+ if (!min || _this.props.adapter.isBefore(min, dayStart) && !ignoreMinMaxDateComponent) {
217
+ min = dayStart;
218
+ } else {
219
+ min = _this.setTime(_this.props.value, _this.props.adapter.getHours(min), _this.props.adapter.getMinutes(min), _this.props.adapter.getSeconds(min));
215
220
  }
216
221
 
217
- if (!max) {
218
- max = _this.setTime(_this.props.value, 24, 0, 0);
222
+ if (!max || _this.props.adapter.isAfter(max, dayEnd) && !ignoreMinMaxDateComponent) {
223
+ max = dayEnd;
219
224
  } else {
220
- // maxTime (if provided) should be inclusive, so add an extra step here
221
- max = _this.props.adapter.setSeconds(_this.props.adapter.date(max), _this.props.adapter.getSeconds(max) + step);
225
+ max = _this.setTime(_this.props.value, _this.props.adapter.getHours(max), _this.props.adapter.getMinutes(max), // maxTime (if provided) should be inclusive, so add an extra second here
226
+ _this.props.adapter.getSeconds(max) + 1);
222
227
  }
223
228
 
224
229
  var minDate = _this.props.adapter.toJsDate(min);
225
230
 
226
231
  var maxDate = _this.props.adapter.toJsDate(max);
227
232
 
228
- var midnightDate = _this.props.adapter.toJsDate(midnight);
233
+ var midnightDate = _this.props.adapter.toJsDate(dayStart);
229
234
 
230
235
  return {
231
236
  start: (minDate - midnightDate) / 1000,
@@ -312,7 +317,7 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
312
317
  steps: steps,
313
318
  value: this.props.nullable ? undefined : {
314
319
  id: closestStep,
315
- label: this.secondsToLabel(closestStep, undefined)
320
+ label: this.secondsToLabel(closestStep, this.props.format)
316
321
  }
317
322
  });
318
323
 
@@ -414,7 +419,8 @@ _defineProperty(TimePicker, "defaultProps", {
414
419
  format: '12',
415
420
  step: 900,
416
421
  creatable: false,
417
- adapter: dateFnsAdapter
422
+ adapter: dateFnsAdapter,
423
+ ignoreMinMaxDateComponent: false
418
424
  });
419
425
 
420
426
  export default TimePicker;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baseui",
3
- "version": "0.0.0-next-42b8311",
3
+ "version": "0.0.0-next-7202ef9",
4
4
  "description": "A React Component library implementing the Base design language",
5
5
  "keywords": [
6
6
  "react",
@@ -22,6 +22,7 @@ export interface TimePickerProps {
22
22
  size?: SIZE[keyof SIZE];
23
23
  minTime?: Date;
24
24
  maxTime?: Date;
25
+ ignoreMinMaxDateComponent?: boolean;
25
26
  }
26
27
  export interface TimePickerState {
27
28
  steps: number[];
@@ -219,26 +219,31 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
219
219
  _defineProperty(_assertThisInitialized(_this), "getTimeWindowInSeconds", function (step) {
220
220
  var _this$props = _this.props,
221
221
  min = _this$props.minTime,
222
- max = _this$props.maxTime;
222
+ max = _this$props.maxTime,
223
+ ignoreMinMaxDateComponent = _this$props.ignoreMinMaxDateComponent;
223
224
 
224
- var midnight = _this.setTime(_this.props.value, 0, 0, 0);
225
+ var dayStart = _this.setTime(_this.props.value, 0, 0, 0);
225
226
 
226
- if (!min) {
227
- min = midnight;
227
+ var dayEnd = _this.setTime(_this.props.value, 24, 0, 0);
228
+
229
+ if (!min || _this.props.adapter.isBefore(min, dayStart) && !ignoreMinMaxDateComponent) {
230
+ min = dayStart;
231
+ } else {
232
+ min = _this.setTime(_this.props.value, _this.props.adapter.getHours(min), _this.props.adapter.getMinutes(min), _this.props.adapter.getSeconds(min));
228
233
  }
229
234
 
230
- if (!max) {
231
- max = _this.setTime(_this.props.value, 24, 0, 0);
235
+ if (!max || _this.props.adapter.isAfter(max, dayEnd) && !ignoreMinMaxDateComponent) {
236
+ max = dayEnd;
232
237
  } else {
233
- // maxTime (if provided) should be inclusive, so add an extra step here
234
- max = _this.props.adapter.setSeconds(_this.props.adapter.date(max), _this.props.adapter.getSeconds(max) + step);
238
+ max = _this.setTime(_this.props.value, _this.props.adapter.getHours(max), _this.props.adapter.getMinutes(max), // maxTime (if provided) should be inclusive, so add an extra second here
239
+ _this.props.adapter.getSeconds(max) + 1);
235
240
  }
236
241
 
237
242
  var minDate = _this.props.adapter.toJsDate(min);
238
243
 
239
244
  var maxDate = _this.props.adapter.toJsDate(max);
240
245
 
241
- var midnightDate = _this.props.adapter.toJsDate(midnight);
246
+ var midnightDate = _this.props.adapter.toJsDate(dayStart);
242
247
 
243
248
  return {
244
249
  start: (minDate - midnightDate) / 1000,
@@ -325,7 +330,7 @@ var TimePicker = /*#__PURE__*/function (_React$Component) {
325
330
  steps: steps,
326
331
  value: this.props.nullable ? undefined : {
327
332
  id: closestStep,
328
- label: this.secondsToLabel(closestStep, undefined)
333
+ label: this.secondsToLabel(closestStep, this.props.format)
329
334
  }
330
335
  });
331
336
 
@@ -427,7 +432,8 @@ _defineProperty(TimePicker, "defaultProps", {
427
432
  format: '12',
428
433
  step: 900,
429
434
  creatable: false,
430
- adapter: _dateFnsAdapter.default
435
+ adapter: _dateFnsAdapter.default,
436
+ ignoreMinMaxDateComponent: false
431
437
  });
432
438
 
433
439
  var _default = TimePicker;
@@ -34,6 +34,7 @@ class TimePicker<T = Date> extends React.Component<
34
34
  step: 900,
35
35
  creatable: false,
36
36
  adapter: dateFnsAdapter,
37
+ ignoreMinMaxDateComponent: false,
37
38
  };
38
39
  dateHelpers: DateHelpers<T>;
39
40
 
@@ -66,7 +67,7 @@ class TimePicker<T = Date> extends React.Component<
66
67
  ? undefined
67
68
  : {
68
69
  id: closestStep,
69
- label: this.secondsToLabel(closestStep, undefined),
70
+ label: this.secondsToLabel(closestStep, this.props.format),
70
71
  },
71
72
  });
72
73
  if (this.props.value || (!this.props.nullable && !this.props.value)) {
@@ -200,24 +201,42 @@ class TimePicker<T = Date> extends React.Component<
200
201
  };
201
202
 
202
203
  getTimeWindowInSeconds = (step: number): {start: number, end: number} => {
203
- let {minTime: min, maxTime: max} = this.props;
204
- let midnight = this.setTime(this.props.value, 0, 0, 0);
205
- if (!min) {
206
- min = midnight;
204
+ let {minTime: min, maxTime: max, ignoreMinMaxDateComponent} = this.props;
205
+ const dayStart = this.setTime(this.props.value, 0, 0, 0);
206
+ const dayEnd = this.setTime(this.props.value, 24, 0, 0);
207
+
208
+ if (
209
+ !min ||
210
+ (this.props.adapter.isBefore(min, dayStart) && !ignoreMinMaxDateComponent)
211
+ ) {
212
+ min = dayStart;
213
+ } else {
214
+ min = this.setTime(
215
+ this.props.value,
216
+ this.props.adapter.getHours(min),
217
+ this.props.adapter.getMinutes(min),
218
+ this.props.adapter.getSeconds(min),
219
+ );
207
220
  }
208
- if (!max) {
209
- max = this.setTime(this.props.value, 24, 0, 0);
221
+
222
+ if (
223
+ !max ||
224
+ (this.props.adapter.isAfter(max, dayEnd) && !ignoreMinMaxDateComponent)
225
+ ) {
226
+ max = dayEnd;
210
227
  } else {
211
- // maxTime (if provided) should be inclusive, so add an extra step here
212
- max = this.props.adapter.setSeconds(
213
- this.props.adapter.date(max),
214
- this.props.adapter.getSeconds(max) + step,
228
+ max = this.setTime(
229
+ this.props.value,
230
+ this.props.adapter.getHours(max),
231
+ this.props.adapter.getMinutes(max),
232
+ // maxTime (if provided) should be inclusive, so add an extra second here
233
+ this.props.adapter.getSeconds(max) + 1,
215
234
  );
216
235
  }
217
236
 
218
237
  const minDate = this.props.adapter.toJsDate(min);
219
238
  const maxDate = this.props.adapter.toJsDate(max);
220
- const midnightDate = this.props.adapter.toJsDate(midnight);
239
+ const midnightDate = this.props.adapter.toJsDate(dayStart);
221
240
  return {
222
241
  start: (minDate - midnightDate) / 1000,
223
242
  end: (maxDate - midnightDate) / 1000,
@@ -37,6 +37,15 @@ export type TimePickerPropsT<T = Date> = {
37
37
  size?: SizeT,
38
38
  minTime?: T,
39
39
  maxTime?: T,
40
+ /**
41
+ * There are two strategies available for setting min/max times. If the min/max datetimes are
42
+ * beyond the start/end times of the current value's date, Timepicker could either clamp the
43
+ * min/max time of the start/end of the day or it can ignore the min/max date components and
44
+ * only apply the time components. Each strategy has the potential to save developer time in
45
+ * avoiding the need to perform conversion before providing min/max datetimes to the component.
46
+ * By default the component will clamp the time window and setting this flag will ignore dates.
47
+ */
48
+ ignoreMinMaxDateComponent?: boolean,
40
49
  };
41
50
  export type TimePickerStateT = {
42
51
  /** List of times (in seconds) displayed in the dropdown menu. */
@@ -50,6 +59,7 @@ export type TimePickerDefaultPropsT = {
50
59
  step: 900,
51
60
  creatable: false,
52
61
  adapter: DateIOAdapter<Date>,
62
+ ignoreMinMaxDateComponent: false,
53
63
  };
54
64
 
55
65
  declare var __DEV__: boolean;