Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/components/Row/Row.tsx 1.37 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
  import { getUnixTime } from 'date-fns';
  
  import { Day } from 'components/Day';
  import { WeekNumber } from 'components/WeekNumber';
  import { useDayPicker } from 'contexts/DayPicker';
  
  /**
   * The props for the {@link Row} component.
   */
  export interface RowProps {
    /** The month where the row is displayed. */
    displayMonth: Date;
    /** The number of the week to render. */
    weekNumber: number;
    /** The days contained in the week. */
    dates: Date[];
  }
  
  /** Render a row in the calendar, with the days and the week number. */
  export function Row(props: RowProps): JSX.Element {
    const { styles, classNames, showWeekNumber, components } = useDayPicker();
  
    const DayComponent = components?.Day ?? Day;
    const WeeknumberComponent = components?.WeekNumber ?? WeekNumber;
  
    let weekNumberCell;
    if (showWeekNumber) {
      weekNumberCell = (
        <td className={classNames.cell} style={styles.cell}>
          <WeeknumberComponent number={props.weekNumber} dates={props.dates} />
        </td>
      );
    }
  
    return (
      <tr className={classNames.row} style={styles.row}>
        {weekNumberCell}
        {props.dates.map((date) => (
          <td
            className={classNames.cell}
            style={styles.cell}
            key={getUnixTime(date)}
            role="presentation"
          >
            <DayComponent displayMonth={props.displayMonth} date={date} />
          </td>
        ))}
      </tr>
    );
  }