MCPcopy Index your code
hub / github.com/react-dates/react-dates / addModifier

Function addModifier

src/utils/modifiers.js:8–61  ·  view source on GitHub ↗
(updatedDays, day, modifier, props, state)

Source from the content-addressed store, hash-verified

6import { VERTICAL_SCROLLABLE } from '../constants';
7
8export function addModifier(updatedDays, day, modifier, props, state) {
9 const { numberOfMonths: numberOfVisibleMonths, enableOutsideDays, orientation } = props;
10 const { currentMonth: firstVisibleMonth, visibleDays } = state;
11
12 let currentMonth = firstVisibleMonth;
13 let numberOfMonths = numberOfVisibleMonths;
14 if (orientation === VERTICAL_SCROLLABLE) {
15 numberOfMonths = Object.keys(visibleDays).length;
16 } else {
17 currentMonth = getPreviousMonthMemoLast(currentMonth);
18 numberOfMonths += 2;
19 }
20 if (!day || !isDayVisible(day, currentMonth, numberOfMonths, enableOutsideDays)) {
21 return updatedDays;
22 }
23
24 const iso = toISODateString(day);
25
26 let updatedDaysAfterAddition = { ...updatedDays };
27 if (enableOutsideDays) {
28 const monthsToUpdate = Object.keys(visibleDays).filter((monthKey) => (
29 Object.keys(visibleDays[monthKey]).indexOf(iso) > -1
30 ));
31
32 updatedDaysAfterAddition = monthsToUpdate.reduce((acc, monthIso) => {
33 const month = updatedDays[monthIso] || visibleDays[monthIso];
34
35 if (!month[iso] || !month[iso].has(modifier)) {
36 const modifiers = new Set(month[iso]);
37 modifiers.add(modifier);
38 acc[monthIso] = {
39 ...month,
40 [iso]: modifiers,
41 };
42 }
43
44 return acc;
45 }, updatedDaysAfterAddition);
46 } else {
47 const monthIso = toISOMonthString(day);
48 const month = updatedDays[monthIso] || visibleDays[monthIso] || {};
49
50 if (!month[iso] || !month[iso].has(modifier)) {
51 const modifiers = new Set(month[iso]);
52 modifiers.add(modifier);
53 updatedDaysAfterAddition[monthIso] = {
54 ...month,
55 [iso]: modifiers,
56 };
57 }
58 }
59
60 return updatedDaysAfterAddition;
61}
62
63export function deleteModifier(updatedDays, day, modifier, props, state) {
64 const { numberOfMonths: numberOfVisibleMonths, enableOutsideDays, orientation } = props;

Callers 2

addModifierMethod · 0.90
addModifierMethod · 0.90

Calls 4

getPreviousMonthMemoLastFunction · 0.85
isDayVisibleFunction · 0.85
toISODateStringFunction · 0.85
toISOMonthStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…