Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/contexts/Modifiers/utils/getActiveModifiers.ts 954 Bytes
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  import { isSameMonth } from 'date-fns';
  
  import { ActiveModifiers, Modifiers } from 'types/Modifiers';
  
  import { isMatch } from './isMatch';
  
  /** Return the active modifiers for the given day. */
  export function getActiveModifiers(
    day: Date,
    /** The modifiers to match for the given date. */
    modifiers: Modifiers,
    /** The month where the day is displayed, to add the "outside" modifiers.  */
    displayMonth?: Date
  ): ActiveModifiers {
    const matchedModifiers = Object.keys(modifiers).reduce(
      (result: string[], key: string): string[] => {
        const modifier = modifiers[key];
        if (isMatch(day, modifier)) {
          result.push(key);
        }
        return result;
      },
      []
    );
    const activeModifiers: ActiveModifiers = {};
    matchedModifiers.forEach((modifier) => (activeModifiers[modifier] = true));
  
    if (displayMonth && !isSameMonth(day, displayMonth)) {
      activeModifiers.outside = true;
    }
  
    return activeModifiers;
  }