Skip to content

Commit 2a884a6

Browse files
committed
feat(hooks): added functionality to move the calendar by a single month
affects: @datepicker-react/hooks, @datepicker-react/styled
1 parent 0c28269 commit 2a884a6

File tree

6 files changed

+1340
-1313
lines changed

6 files changed

+1340
-1313
lines changed

packages/hooks/lib/index.cjs.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,12 +2344,12 @@ function ye(t, e) {
23442344
a
23452345
)
23462346
}
2347-
function be(t, e, n) {
2348-
var r = t[n > 0 ? t.length - 1 : 0].date
2347+
function be(t, e, n, r) {
2348+
var a = t[r ? (n > 0 ? 0 : t.length - r) : n > 0 ? t.length - 1 : 0].date
23492349
return Array.from(Array(e).keys()).reduce(function (t) {
23502350
return (
2351-
(r = 0 === t.length ? le(r, n) : le(r, n >= 0 ? 1 : -1)),
2352-
n > 0 ? t.concat([ge(r)]) : [ge(r)].concat(t)
2351+
(a = 0 === t.length ? le(a, n) : le(a, n >= 0 ? 1 : -1)),
2352+
n > 0 ? t.concat([ge(a)]) : [ge(a)].concat(t)
23532353
)
23542354
}, [])
23552355
}
@@ -2679,9 +2679,15 @@ function pe(t) {
26792679
goToPreviousMonths: function () {
26802680
k(be(T, m, -1)), P(null)
26812681
},
2682+
goToPreviousMonthsByOneMonth: function () {
2683+
k(be(T, m, -1, 1)), P(null)
2684+
},
26822685
goToNextMonths: function () {
26832686
k(be(T, m, 1)), P(null)
26842687
},
2688+
goToNextMonthsByOneMonth: function () {
2689+
k(be(T, m, 1, 1)), P(null)
2690+
},
26852691
goToDate: function (t) {
26862692
k(ye(m, t)), P(null)
26872693
},

packages/hooks/lib/index.esm.js

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,13 @@ var D = {
476476
return n.replace('{{date}}', y(a, e)).replace('{{time}}', b(i, e))
477477
},
478478
}
479-
function p(t) {
479+
function T(t) {
480480
return t.getTime() % 6e4
481481
}
482-
function T(t) {
482+
function p(t) {
483483
var e = new Date(t.getTime()),
484484
n = Math.ceil(e.getTimezoneOffset())
485-
return e.setSeconds(0, 0), 6e4 * n + (n > 0 ? (6e4 + p(e)) % 6e4 : p(e))
485+
return e.setSeconds(0, 0), 6e4 * n + (n > 0 ? (6e4 + T(e)) % 6e4 : T(e))
486486
}
487487
var k = ['D', 'DD'],
488488
x = ['YY', 'YYYY']
@@ -590,7 +590,7 @@ function B(t) {
590590
n = E(e).getTime() - q(e).getTime()
591591
return Math.round(n / 6048e5) + 1
592592
}
593-
function H(t, e) {
593+
function O(t, e) {
594594
h(1, arguments)
595595
var n = e || {},
596596
r = n.locale,
@@ -603,10 +603,10 @@ function H(t, e) {
603603
var c = S(s, e)
604604
return c
605605
}
606-
function O(t, e) {
606+
function H(t, e) {
607607
h(1, arguments)
608608
var n = m(t),
609-
r = S(n, e).getTime() - H(n, e).getTime()
609+
r = S(n, e).getTime() - O(n, e).getTime()
610610
return Math.round(r / 6048e5) + 1
611611
}
612612
var L = /^(1[0-2]|0?\d)/,
@@ -999,7 +999,7 @@ var vt = {
999999
h(2, arguments)
10001000
var r = m(t),
10011001
a = f(e),
1002-
i = O(r, n) - a
1002+
i = H(r, n) - a
10031003
return r.setUTCDate(r.getUTCDate() - 7 * i), r
10041004
})(t, n, r),
10051005
r,
@@ -1620,8 +1620,8 @@ var vt = {
16201620
yt = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,
16211621
bt = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,
16221622
Dt = /^'([^]*?)'?$/,
1623-
pt = /''/g,
1624-
Tt = /\S/,
1623+
Tt = /''/g,
1624+
pt = /\S/,
16251625
kt = /[a-zA-Z]/
16261626
function xt(t, e, n, r) {
16271627
h(3, arguments)
@@ -1640,7 +1640,7 @@ function xt(t, e, n, r) {
16401640
b = null == o.weekStartsOn ? y : f(o.weekStartsOn)
16411641
if (!(b >= 0 && b <= 6)) throw new RangeError('weekStartsOn must be between 0 and 6 inclusively')
16421642
if ('' === i) return '' === a ? m(n) : new Date(NaN)
1643-
var p,
1643+
var T,
16441644
k = {firstWeekContainsDate: d, weekStartsOn: b, locale: u},
16451645
x = [{priority: 10, set: Ct, index: 0}],
16461646
S = i
@@ -1652,18 +1652,18 @@ function xt(t, e, n, r) {
16521652
.join('')
16531653
.match(yt),
16541654
P = []
1655-
for (p = 0; p < S.length; p++) {
1656-
var Y = S[p]
1655+
for (T = 0; T < S.length; T++) {
1656+
var Y = S[T]
16571657
!o.useAdditionalWeekYearTokens && M(Y) && U(Y), !o.useAdditionalDayOfYearTokens && C(Y) && U(Y)
16581658
var E = Y[0],
16591659
N = vt[E]
16601660
if (N) {
16611661
var q = N.incompatibleTokens
16621662
if (Array.isArray(q)) {
1663-
for (var B = void 0, H = 0; H < P.length; H++) {
1664-
var O = P[H].token
1665-
if (-1 !== q.indexOf(O) || O === E) {
1666-
B = P[H]
1663+
for (var B = void 0, O = 0; O < P.length; O++) {
1664+
var H = P[O].token
1665+
if (-1 !== q.indexOf(H) || H === E) {
1666+
B = P[O]
16671667
break
16681668
}
16691669
}
@@ -1698,7 +1698,7 @@ function xt(t, e, n, r) {
16981698
a = a.slice(Y.length)
16991699
}
17001700
}
1701-
if (a.length > 0 && Tt.test(a)) return new Date(NaN)
1701+
if (a.length > 0 && pt.test(a)) return new Date(NaN)
17021702
var W = x
17031703
.map(function (t) {
17041704
return t.priority
@@ -1721,10 +1721,10 @@ function xt(t, e, n, r) {
17211721
}),
17221722
F = m(n)
17231723
if (isNaN(F)) return new Date(NaN)
1724-
var Q = g(F, T(F)),
1724+
var Q = g(F, p(F)),
17251725
R = {}
1726-
for (p = 0; p < W.length; p++) {
1727-
var I = W[p]
1726+
for (T = 0; T < W.length; T++) {
1727+
var I = W[T]
17281728
if (I.validate && !I.validate(Q, I.value, k)) return new Date(NaN)
17291729
var X = I.set(Q, R, I.value, k)
17301730
X[0] ? ((Q = X[0]), v(R, X[1])) : (Q = X)
@@ -1741,7 +1741,7 @@ function Ct(t, e) {
17411741
)
17421742
}
17431743
function Mt(t) {
1744-
return t.match(Dt)[1].replace(pt, "'")
1744+
return t.match(Dt)[1].replace(Tt, "'")
17451745
}
17461746
function Ut(t) {
17471747
h(1, arguments)
@@ -1773,10 +1773,10 @@ var Pt = function (t, e) {
17731773
Bt = function (t, e) {
17741774
return St(t.getUTCMinutes(), e.length)
17751775
},
1776-
Ht = function (t, e) {
1776+
Ot = function (t, e) {
17771777
return St(t.getUTCSeconds(), e.length)
17781778
},
1779-
Ot = function (t, e) {
1779+
Ht = function (t, e) {
17801780
var n = e.length,
17811781
r = t.getUTCMilliseconds()
17821782
return St(Math.floor(r * Math.pow(10, n - 3)), e.length)
@@ -1897,7 +1897,7 @@ var Lt = 'midnight',
18971897
}
18981898
},
18991899
w: function (t, e, n, r) {
1900-
var a = O(t, r)
1900+
var a = H(t, r)
19011901
return 'wo' === e ? n.ordinalNumber(a, {unit: 'week'}) : St(a, e.length)
19021902
},
19031903
I: function (t, e, n) {
@@ -2064,10 +2064,10 @@ var Lt = 'midnight',
20642064
return 'mo' === e ? n.ordinalNumber(t.getUTCMinutes(), {unit: 'minute'}) : Bt(t, e)
20652065
},
20662066
s: function (t, e, n) {
2067-
return 'so' === e ? n.ordinalNumber(t.getUTCSeconds(), {unit: 'second'}) : Ht(t, e)
2067+
return 'so' === e ? n.ordinalNumber(t.getUTCSeconds(), {unit: 'second'}) : Ot(t, e)
20682068
},
20692069
S: function (t, e) {
2070-
return Ot(t, e)
2070+
return Ht(t, e)
20712071
},
20722072
X: function (t, e, n, r) {
20732073
var a = (r._originalDate || t).getTimezoneOffset()
@@ -2171,14 +2171,14 @@ function $t(t, e, n) {
21712171
if (!i.formatLong) throw new RangeError('locale must contain formatLong property')
21722172
var v = m(t)
21732173
if (!Ut(v)) throw new RangeError('Invalid time value')
2174-
var y = T(v),
2174+
var y = p(v),
21752175
b = g(v, y),
2176-
p = {firstWeekContainsDate: s, weekStartsOn: w, locale: i, _originalDate: v},
2176+
T = {firstWeekContainsDate: s, weekStartsOn: w, locale: i, _originalDate: v},
21772177
k = r
21782178
.match(Kt)
21792179
.map(function (t) {
21802180
var e = t[0]
2181-
return 'p' === e || 'P' === e ? (0, D[e])(t, i.formatLong, p) : t
2181+
return 'p' === e || 'P' === e ? (0, D[e])(t, i.formatLong, T) : t
21822182
})
21832183
.join('')
21842184
.match(jt)
@@ -2191,7 +2191,7 @@ function $t(t, e, n) {
21912191
return (
21922192
!a.useAdditionalWeekYearTokens && M(t) && U(t),
21932193
!a.useAdditionalDayOfYearTokens && C(t) && U(t),
2194-
n(b, t, i.localize, p)
2194+
n(b, t, i.localize, T)
21952195
)
21962196
if (e.match(_t))
21972197
throw new RangeError(
@@ -2444,7 +2444,7 @@ function De(t) {
24442444
(a && a(e))
24452445
)
24462446
}
2447-
function pe(t) {
2447+
function Te(t) {
24482448
var e = re(t)
24492449
return {
24502450
year: (function (t) {
@@ -2462,27 +2462,27 @@ function pe(t) {
24622462
date: e,
24632463
}
24642464
}
2465-
function Te() {
2466-
return pe(me(Date.now()))
2465+
function pe() {
2466+
return Te(me(Date.now()))
24672467
}
24682468
function ke(t, e) {
2469-
var n = e ? pe(e) : Te(),
2469+
var n = e ? Te(e) : pe(),
24702470
r = n.date,
24712471
a = [n]
24722472
return (
24732473
t > 1 &&
24742474
(a = Array.from(Array(t - 1).keys()).reduce(function (t) {
2475-
return (r = ge(t[t.length - 1].date, 1)), t.concat([pe(r)])
2475+
return (r = ge(t[t.length - 1].date, 1)), t.concat([Te(r)])
24762476
}, a)),
24772477
a
24782478
)
24792479
}
2480-
function xe(t, e, n) {
2481-
var r = t[n > 0 ? t.length - 1 : 0].date
2480+
function xe(t, e, n, r) {
2481+
var a = t[r ? (n > 0 ? 0 : t.length - r) : n > 0 ? t.length - 1 : 0].date
24822482
return Array.from(Array(e).keys()).reduce(function (t) {
24832483
return (
2484-
(r = 0 === t.length ? ge(r, n) : ge(r, n >= 0 ? 1 : -1)),
2485-
n > 0 ? t.concat([pe(r)]) : [pe(r)].concat(t)
2484+
(a = 0 === t.length ? ge(a, n) : ge(a, n >= 0 ? 1 : -1)),
2485+
n > 0 ? t.concat([Te(a)]) : [Te(a)].concat(t)
24862486
)
24872487
}, [])
24882488
}
@@ -2538,12 +2538,12 @@ function Pe(t) {
25382538
}
25392539
: y,
25402540
D = t.unavailableDates,
2541-
p = void 0 === D ? [] : D,
2542-
T = e(function () {
2541+
T = void 0 === D ? [] : D,
2542+
p = e(function () {
25432543
return ke(w, r || c || null)
25442544
}),
2545-
k = T[0],
2546-
x = T[1],
2545+
k = p[0],
2546+
x = p[1],
25472547
C = e(null),
25482548
M = C[0],
25492549
U = C[1],
@@ -2559,7 +2559,7 @@ function Pe(t) {
25592559
)
25602560
})
25612561
var E = function (t) {
2562-
return ve(p, t) || b(t)
2562+
return ve(T, t) || b(t)
25632563
},
25642564
N = function (t) {
25652565
Y(t), (!P || (P && !we(t, P))) && x(ke(w, t))
@@ -2692,9 +2692,15 @@ function Pe(t) {
26922692
goToPreviousMonths: function () {
26932693
x(xe(k, w, -1)), Y(null)
26942694
},
2695+
goToPreviousMonthsByOneMonth: function () {
2696+
x(xe(k, w, -1, 1)), Y(null)
2697+
},
26952698
goToNextMonths: function () {
26962699
x(xe(k, w, 1)), Y(null)
26972700
},
2701+
goToNextMonthsByOneMonth: function () {
2702+
x(xe(k, w, 1, 1)), Y(null)
2703+
},
26982704
goToDate: function (t) {
26992705
x(ke(w, t)), Y(null)
27002706
},
@@ -2753,8 +2759,8 @@ export {
27532759
Se as END_DATE,
27542760
Ue as START_DATE,
27552761
ue as dayLabelFormat,
2756-
Te as getCurrentYearMonthAndDate,
2757-
pe as getDateMonthAndYear,
2762+
pe as getCurrentYearMonthAndDate,
2763+
Te as getDateMonthAndYear,
27582764
oe as getDays,
27592765
ke as getInitialMonths,
27602766
Ce as getInputValue,

packages/hooks/lib/useDatepicker/useDatepicker.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export declare function useDatepicker({
5252
onDateSelect: (date: Date) => void
5353
onDateFocus: (date: Date) => void
5454
goToPreviousMonths: () => void
55+
goToPreviousMonthsByOneMonth: () => void
5556
goToNextMonths: () => void
57+
goToNextMonthsByOneMonth: () => void
5658
goToDate: (date: Date) => void
5759
goToPreviousYear: (numYears?: number) => void
5860
goToNextYear: (numYears?: number) => void

packages/hooks/lib/useDatepicker/useDatepicker.utils.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export declare function getNextActiveMonth(
4747
activeMonth: MonthType[],
4848
numberOfMonths: number,
4949
counter: number,
50+
step?: number,
5051
): MonthType[]
5152
export declare type FormatFunction = (date: Date) => string
5253
export declare function getInputValue(

0 commit comments

Comments
 (0)