@plusscommunities/pluss-core-web 1.6.3-beta.0 → 1.6.3-beta.2

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.
package/dist/index.cjs.js CHANGED
@@ -4448,7 +4448,13 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4448
4448
  }, {
4449
4449
  key: "onNewProps",
4450
4450
  value: function onNewProps(nextProps, forceUpdate) {
4451
- if (this.props.multiple && nextProps.selectedDates !== this.props.selectedDates) {
4451
+ if (!!nextProps.shownMonth && nextProps.shownMonth !== this.props.shownMonth) {
4452
+ var shownMonth = new Date(nextProps.shownMonth.getFullYear(), nextProps.shownMonth.getMonth() + 1, 0);
4453
+ this.setState({
4454
+ shownMonth: shownMonth
4455
+ });
4456
+ this.generateGrid(shownMonth);
4457
+ } else if (this.props.multiple && nextProps.selectedDates !== this.props.selectedDates) {
4452
4458
  this.generateGrid(this.state.shownMonth, nextProps.selectedDates);
4453
4459
  } else if (forceUpdate || nextProps.selectedDate !== this.props.selectedDate) {
4454
4460
  var dateToUse = nextProps.selectedDate;
@@ -4461,11 +4467,13 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4461
4467
  dateToUse = new Date();
4462
4468
  }
4463
4469
 
4470
+ var _shownMonth = this.props.shownMonth ? this.state.shownMonth : dateToUse;
4471
+
4464
4472
  this.setState({
4465
- shownMonth: dateToUse,
4473
+ shownMonth: _shownMonth,
4466
4474
  selectedDate: dateToUse
4467
4475
  });
4468
- this.generateGrid(dateToUse, dateToUse);
4476
+ this.generateGrid(_shownMonth, dateToUse);
4469
4477
  }
4470
4478
  }
4471
4479
  }, {
@@ -4505,7 +4513,7 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4505
4513
  value: function isDateEnabled(date) {
4506
4514
  if (this.props.enabledDates) {
4507
4515
  var found = this.props.enabledDates.find(function (d) {
4508
- return d.day === date.format();
4516
+ return moment__default['default'](d.day).format('YYYYMMDD') === date.format('YYYYMMDD');
4509
4517
  });
4510
4518
  if (found) return found.enabled;
4511
4519
  }
@@ -4515,16 +4523,20 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4515
4523
  }, {
4516
4524
  key: "changeMonth",
4517
4525
  value: function changeMonth(change) {
4526
+ var _this2 = this;
4527
+
4518
4528
  var newShownDate = new Date(this.state.shownMonth.getFullYear(), this.state.shownMonth.getMonth() + 1 + change, 0);
4519
4529
  this.setState({
4520
4530
  shownMonth: newShownDate
4531
+ }, function () {
4532
+ if (_this2.props.changeMonth) _this2.props.changeMonth(_this2.state.shownMonth);
4521
4533
  });
4522
4534
  this.generateGrid(newShownDate);
4523
4535
  }
4524
4536
  }, {
4525
4537
  key: "selectRange",
4526
4538
  value: function selectRange(date) {
4527
- var _this2 = this;
4539
+ var _this3 = this;
4528
4540
 
4529
4541
  var d1 = moment__default['default'](this.state.lastSelected, 'DD-MM-YYYY');
4530
4542
  var d2 = moment__default['default'](date, 'DD-MM-YYYY');
@@ -4548,7 +4560,7 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4548
4560
  }
4549
4561
 
4550
4562
  if (___default['default'].includes(this.props.selectedDates, d2.format('DD-MM-YYYY')) && !___default['default'].includes(this.props.selectedDates, d1.format('DD-MM-YYYY')) || !___default['default'].some(dateRange, function (d) {
4551
- return !___default['default'].includes(_this2.props.selectedDates, d);
4563
+ return !___default['default'].includes(_this3.props.selectedDates, d);
4552
4564
  })) {
4553
4565
  // the first clicked date was just de-selected and then clicked on a selected date
4554
4566
  // or every date in the range is already selected, then
@@ -4566,11 +4578,13 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4566
4578
  key: "selectDate",
4567
4579
  value: function selectDate(date, e) {
4568
4580
  var enabled = this.isDateEnabled(date);
4581
+ var isBeforeMinDate = this.props.minDate && moment__default['default'](date).isBefore(this.props.minDate);
4569
4582
  console.log('selected a date', {
4570
4583
  date: date,
4571
- enabled: enabled
4584
+ enabled: enabled,
4585
+ isBeforeMinDate: isBeforeMinDate
4572
4586
  });
4573
- if (enabled === false) return;
4587
+ if (enabled === false || isBeforeMinDate) return;
4574
4588
 
4575
4589
  if (this.props.multiple) {
4576
4590
  var dateKey = moment__default['default'](date).format('DD-MM-YYYY');
@@ -4647,7 +4661,7 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4647
4661
  }, {
4648
4662
  key: "renderGrid",
4649
4663
  value: function renderGrid() {
4650
- var _this3 = this;
4664
+ var _this4 = this;
4651
4665
 
4652
4666
  return this.state.grid.map(function (row, index) {
4653
4667
  return /*#__PURE__*/React__default['default'].createElement("div", {
@@ -4678,7 +4692,7 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4678
4692
  }, /*#__PURE__*/React__default['default'].createElement("div", {
4679
4693
  className: "datepicker__date__inner",
4680
4694
  onClick: function onClick(e) {
4681
- return _this3.selectDate(date.date, e);
4695
+ return _this4.selectDate(date.date, e);
4682
4696
  }
4683
4697
  }, date.display));
4684
4698
  }));
package/dist/index.esm.js CHANGED
@@ -4418,7 +4418,13 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4418
4418
  }, {
4419
4419
  key: "onNewProps",
4420
4420
  value: function onNewProps(nextProps, forceUpdate) {
4421
- if (this.props.multiple && nextProps.selectedDates !== this.props.selectedDates) {
4421
+ if (!!nextProps.shownMonth && nextProps.shownMonth !== this.props.shownMonth) {
4422
+ var shownMonth = new Date(nextProps.shownMonth.getFullYear(), nextProps.shownMonth.getMonth() + 1, 0);
4423
+ this.setState({
4424
+ shownMonth: shownMonth
4425
+ });
4426
+ this.generateGrid(shownMonth);
4427
+ } else if (this.props.multiple && nextProps.selectedDates !== this.props.selectedDates) {
4422
4428
  this.generateGrid(this.state.shownMonth, nextProps.selectedDates);
4423
4429
  } else if (forceUpdate || nextProps.selectedDate !== this.props.selectedDate) {
4424
4430
  var dateToUse = nextProps.selectedDate;
@@ -4431,11 +4437,13 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4431
4437
  dateToUse = new Date();
4432
4438
  }
4433
4439
 
4440
+ var _shownMonth = this.props.shownMonth ? this.state.shownMonth : dateToUse;
4441
+
4434
4442
  this.setState({
4435
- shownMonth: dateToUse,
4443
+ shownMonth: _shownMonth,
4436
4444
  selectedDate: dateToUse
4437
4445
  });
4438
- this.generateGrid(dateToUse, dateToUse);
4446
+ this.generateGrid(_shownMonth, dateToUse);
4439
4447
  }
4440
4448
  }
4441
4449
  }, {
@@ -4475,7 +4483,7 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4475
4483
  value: function isDateEnabled(date) {
4476
4484
  if (this.props.enabledDates) {
4477
4485
  var found = this.props.enabledDates.find(function (d) {
4478
- return d.day === date.format();
4486
+ return moment(d.day).format('YYYYMMDD') === date.format('YYYYMMDD');
4479
4487
  });
4480
4488
  if (found) return found.enabled;
4481
4489
  }
@@ -4485,16 +4493,20 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4485
4493
  }, {
4486
4494
  key: "changeMonth",
4487
4495
  value: function changeMonth(change) {
4496
+ var _this2 = this;
4497
+
4488
4498
  var newShownDate = new Date(this.state.shownMonth.getFullYear(), this.state.shownMonth.getMonth() + 1 + change, 0);
4489
4499
  this.setState({
4490
4500
  shownMonth: newShownDate
4501
+ }, function () {
4502
+ if (_this2.props.changeMonth) _this2.props.changeMonth(_this2.state.shownMonth);
4491
4503
  });
4492
4504
  this.generateGrid(newShownDate);
4493
4505
  }
4494
4506
  }, {
4495
4507
  key: "selectRange",
4496
4508
  value: function selectRange(date) {
4497
- var _this2 = this;
4509
+ var _this3 = this;
4498
4510
 
4499
4511
  var d1 = moment(this.state.lastSelected, 'DD-MM-YYYY');
4500
4512
  var d2 = moment(date, 'DD-MM-YYYY');
@@ -4518,7 +4530,7 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4518
4530
  }
4519
4531
 
4520
4532
  if (_.includes(this.props.selectedDates, d2.format('DD-MM-YYYY')) && !_.includes(this.props.selectedDates, d1.format('DD-MM-YYYY')) || !_.some(dateRange, function (d) {
4521
- return !_.includes(_this2.props.selectedDates, d);
4533
+ return !_.includes(_this3.props.selectedDates, d);
4522
4534
  })) {
4523
4535
  // the first clicked date was just de-selected and then clicked on a selected date
4524
4536
  // or every date in the range is already selected, then
@@ -4536,11 +4548,13 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4536
4548
  key: "selectDate",
4537
4549
  value: function selectDate(date, e) {
4538
4550
  var enabled = this.isDateEnabled(date);
4551
+ var isBeforeMinDate = this.props.minDate && moment(date).isBefore(this.props.minDate);
4539
4552
  console.log('selected a date', {
4540
4553
  date: date,
4541
- enabled: enabled
4554
+ enabled: enabled,
4555
+ isBeforeMinDate: isBeforeMinDate
4542
4556
  });
4543
- if (enabled === false) return;
4557
+ if (enabled === false || isBeforeMinDate) return;
4544
4558
 
4545
4559
  if (this.props.multiple) {
4546
4560
  var dateKey = moment(date).format('DD-MM-YYYY');
@@ -4617,7 +4631,7 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4617
4631
  }, {
4618
4632
  key: "renderGrid",
4619
4633
  value: function renderGrid() {
4620
- var _this3 = this;
4634
+ var _this4 = this;
4621
4635
 
4622
4636
  return this.state.grid.map(function (row, index) {
4623
4637
  return /*#__PURE__*/React.createElement("div", {
@@ -4648,7 +4662,7 @@ var DatePicker = /*#__PURE__*/function (_Component) {
4648
4662
  }, /*#__PURE__*/React.createElement("div", {
4649
4663
  className: "datepicker__date__inner",
4650
4664
  onClick: function onClick(e) {
4651
- return _this3.selectDate(date.date, e);
4665
+ return _this4.selectDate(date.date, e);
4652
4666
  }
4653
4667
  }, date.display));
4654
4668
  }));
package/dist/index.umd.js CHANGED
@@ -4416,7 +4416,13 @@
4416
4416
  }, {
4417
4417
  key: "onNewProps",
4418
4418
  value: function onNewProps(nextProps, forceUpdate) {
4419
- if (this.props.multiple && nextProps.selectedDates !== this.props.selectedDates) {
4419
+ if (!!nextProps.shownMonth && nextProps.shownMonth !== this.props.shownMonth) {
4420
+ var shownMonth = new Date(nextProps.shownMonth.getFullYear(), nextProps.shownMonth.getMonth() + 1, 0);
4421
+ this.setState({
4422
+ shownMonth: shownMonth
4423
+ });
4424
+ this.generateGrid(shownMonth);
4425
+ } else if (this.props.multiple && nextProps.selectedDates !== this.props.selectedDates) {
4420
4426
  this.generateGrid(this.state.shownMonth, nextProps.selectedDates);
4421
4427
  } else if (forceUpdate || nextProps.selectedDate !== this.props.selectedDate) {
4422
4428
  var dateToUse = nextProps.selectedDate;
@@ -4429,11 +4435,13 @@
4429
4435
  dateToUse = new Date();
4430
4436
  }
4431
4437
 
4438
+ var _shownMonth = this.props.shownMonth ? this.state.shownMonth : dateToUse;
4439
+
4432
4440
  this.setState({
4433
- shownMonth: dateToUse,
4441
+ shownMonth: _shownMonth,
4434
4442
  selectedDate: dateToUse
4435
4443
  });
4436
- this.generateGrid(dateToUse, dateToUse);
4444
+ this.generateGrid(_shownMonth, dateToUse);
4437
4445
  }
4438
4446
  }
4439
4447
  }, {
@@ -4473,7 +4481,7 @@
4473
4481
  value: function isDateEnabled(date) {
4474
4482
  if (this.props.enabledDates) {
4475
4483
  var found = this.props.enabledDates.find(function (d) {
4476
- return d.day === date.format();
4484
+ return moment__default['default'](d.day).format('YYYYMMDD') === date.format('YYYYMMDD');
4477
4485
  });
4478
4486
  if (found) return found.enabled;
4479
4487
  }
@@ -4483,16 +4491,20 @@
4483
4491
  }, {
4484
4492
  key: "changeMonth",
4485
4493
  value: function changeMonth(change) {
4494
+ var _this2 = this;
4495
+
4486
4496
  var newShownDate = new Date(this.state.shownMonth.getFullYear(), this.state.shownMonth.getMonth() + 1 + change, 0);
4487
4497
  this.setState({
4488
4498
  shownMonth: newShownDate
4499
+ }, function () {
4500
+ if (_this2.props.changeMonth) _this2.props.changeMonth(_this2.state.shownMonth);
4489
4501
  });
4490
4502
  this.generateGrid(newShownDate);
4491
4503
  }
4492
4504
  }, {
4493
4505
  key: "selectRange",
4494
4506
  value: function selectRange(date) {
4495
- var _this2 = this;
4507
+ var _this3 = this;
4496
4508
 
4497
4509
  var d1 = moment__default['default'](this.state.lastSelected, 'DD-MM-YYYY');
4498
4510
  var d2 = moment__default['default'](date, 'DD-MM-YYYY');
@@ -4516,7 +4528,7 @@
4516
4528
  }
4517
4529
 
4518
4530
  if (___default['default'].includes(this.props.selectedDates, d2.format('DD-MM-YYYY')) && !___default['default'].includes(this.props.selectedDates, d1.format('DD-MM-YYYY')) || !___default['default'].some(dateRange, function (d) {
4519
- return !___default['default'].includes(_this2.props.selectedDates, d);
4531
+ return !___default['default'].includes(_this3.props.selectedDates, d);
4520
4532
  })) {
4521
4533
  // the first clicked date was just de-selected and then clicked on a selected date
4522
4534
  // or every date in the range is already selected, then
@@ -4534,11 +4546,13 @@
4534
4546
  key: "selectDate",
4535
4547
  value: function selectDate(date, e) {
4536
4548
  var enabled = this.isDateEnabled(date);
4549
+ var isBeforeMinDate = this.props.minDate && moment__default['default'](date).isBefore(this.props.minDate);
4537
4550
  console.log('selected a date', {
4538
4551
  date: date,
4539
- enabled: enabled
4552
+ enabled: enabled,
4553
+ isBeforeMinDate: isBeforeMinDate
4540
4554
  });
4541
- if (enabled === false) return;
4555
+ if (enabled === false || isBeforeMinDate) return;
4542
4556
 
4543
4557
  if (this.props.multiple) {
4544
4558
  var dateKey = moment__default['default'](date).format('DD-MM-YYYY');
@@ -4615,7 +4629,7 @@
4615
4629
  }, {
4616
4630
  key: "renderGrid",
4617
4631
  value: function renderGrid() {
4618
- var _this3 = this;
4632
+ var _this4 = this;
4619
4633
 
4620
4634
  return this.state.grid.map(function (row, index) {
4621
4635
  return /*#__PURE__*/React__default['default'].createElement("div", {
@@ -4646,7 +4660,7 @@
4646
4660
  }, /*#__PURE__*/React__default['default'].createElement("div", {
4647
4661
  className: "datepicker__date__inner",
4648
4662
  onClick: function onClick(e) {
4649
- return _this3.selectDate(date.date, e);
4663
+ return _this4.selectDate(date.date, e);
4650
4664
  }
4651
4665
  }, date.display));
4652
4666
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-web",
3
- "version": "1.6.3-beta.0",
3
+ "version": "1.6.3-beta.2",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "main": "dist/index.cjs.js",
6
6
  "scripts": {
@@ -18,7 +18,11 @@ class DatePicker extends Component {
18
18
  }
19
19
 
20
20
  onNewProps(nextProps, forceUpdate) {
21
- if (this.props.multiple && nextProps.selectedDates !== this.props.selectedDates) {
21
+ if (!!nextProps.shownMonth && nextProps.shownMonth !== this.props.shownMonth) {
22
+ const shownMonth = new Date(nextProps.shownMonth.getFullYear(), nextProps.shownMonth.getMonth() + 1, 0);
23
+ this.setState({ shownMonth });
24
+ this.generateGrid(shownMonth);
25
+ } else if (this.props.multiple && nextProps.selectedDates !== this.props.selectedDates) {
22
26
  this.generateGrid(this.state.shownMonth, nextProps.selectedDates);
23
27
  } else if (forceUpdate || nextProps.selectedDate !== this.props.selectedDate) {
24
28
  let dateToUse = nextProps.selectedDate;
@@ -28,11 +32,12 @@ class DatePicker extends Component {
28
32
  if (isNaN(dateToUse)) {
29
33
  dateToUse = new Date();
30
34
  }
35
+ const shownMonth = this.props.shownMonth ? this.state.shownMonth : dateToUse;
31
36
  this.setState({
32
- shownMonth: dateToUse,
37
+ shownMonth: shownMonth,
33
38
  selectedDate: dateToUse,
34
39
  });
35
- this.generateGrid(dateToUse, dateToUse);
40
+ this.generateGrid(shownMonth, dateToUse);
36
41
  }
37
42
  }
38
43
 
@@ -63,7 +68,7 @@ class DatePicker extends Component {
63
68
 
64
69
  isDateEnabled(date) {
65
70
  if (this.props.enabledDates) {
66
- const found = this.props.enabledDates.find((d) => d.day === date.format());
71
+ const found = this.props.enabledDates.find((d) => moment(d.day).format('YYYYMMDD') === date.format('YYYYMMDD'));
67
72
  if (found) return found.enabled;
68
73
  }
69
74
  return null;
@@ -71,9 +76,14 @@ class DatePicker extends Component {
71
76
 
72
77
  changeMonth(change) {
73
78
  const newShownDate = new Date(this.state.shownMonth.getFullYear(), this.state.shownMonth.getMonth() + 1 + change, 0);
74
- this.setState({
75
- shownMonth: newShownDate,
76
- });
79
+ this.setState(
80
+ {
81
+ shownMonth: newShownDate,
82
+ },
83
+ () => {
84
+ if (this.props.changeMonth) this.props.changeMonth(this.state.shownMonth);
85
+ },
86
+ );
77
87
  this.generateGrid(newShownDate);
78
88
  }
79
89
 
@@ -122,8 +132,9 @@ class DatePicker extends Component {
122
132
 
123
133
  selectDate(date, e) {
124
134
  const enabled = this.isDateEnabled(date);
125
- console.log('selected a date', { date, enabled });
126
- if (enabled === false) return;
135
+ const isBeforeMinDate = this.props.minDate && moment(date).isBefore(this.props.minDate);
136
+ console.log('selected a date', { date, enabled, isBeforeMinDate });
137
+ if (enabled === false || isBeforeMinDate) return;
127
138
 
128
139
  if (this.props.multiple) {
129
140
  const dateKey = moment(date).format('DD-MM-YYYY');