Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/components/Caption/Caption.tsx 2.41 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  import { CaptionDropdowns } from 'components/CaptionDropdowns';
  import { CaptionLabel } from 'components/CaptionLabel';
  import { CaptionNavigation } from 'components/CaptionNavigation';
  import { useDayPicker } from 'contexts/DayPicker';
  
  /** Represent the props of the {@link Caption} component. */
  export interface CaptionProps {
    /** The ID for the heading element. Must be the same as the labelled-by in Table. */
    id?: string;
    /** The month where the caption is displayed. */
    displayMonth: Date;
    /** The index of the month where the caption is displayed. Older custom components may miss this prop. */
    displayIndex?: number | undefined;
  }
  
  /**
   * The layout of the caption:
   *
   * - `dropdown`: display dropdowns for choosing the month and the year.
   * - `buttons`: display previous month / next month buttons.
   * - `dropdown-buttons`: display both month / year dropdowns and previous month / next month buttons.
   */
  export type CaptionLayout = 'dropdown' | 'buttons' | 'dropdown-buttons';
  
  /**
   * Render the caption of a month. The caption has a different layout when
   * setting the {@link DayPickerBase.captionLayout} prop.
   */
  export function Caption(props: CaptionProps): JSX.Element {
    const { classNames, disableNavigation, styles, captionLayout, components } =
      useDayPicker();
  
    const CaptionLabelComponent = components?.CaptionLabel ?? CaptionLabel;
  
    let caption: JSX.Element;
    if (disableNavigation) {
      caption = (
        <CaptionLabelComponent id={props.id} displayMonth={props.displayMonth} />
      );
    } else if (captionLayout === 'dropdown') {
      caption = (
        <CaptionDropdowns displayMonth={props.displayMonth} id={props.id} />
      );
    } else if (captionLayout === 'dropdown-buttons') {
      caption = (
        <>
          <CaptionDropdowns
            displayMonth={props.displayMonth}
            displayIndex={props.displayIndex}
            id={props.id}
          />
          <CaptionNavigation
            displayMonth={props.displayMonth}
            displayIndex={props.displayIndex}
            id={props.id}
          />
        </>
      );
    } else {
      caption = (
        <>
          <CaptionLabelComponent
            id={props.id}
            displayMonth={props.displayMonth}
            displayIndex={props.displayIndex}
          />
          <CaptionNavigation displayMonth={props.displayMonth} id={props.id} />
        </>
      );
    }
  
    return (
      <div className={classNames.caption} style={styles.caption}>
        {caption}
      </div>
    );
  }