Blame view

天文台pc/tianwentai-ui/node_modules/react-day-picker/src/components/Dropdown/Dropdown.tsx 1.8 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
  import {
    ChangeEventHandler,
    CSSProperties,
    ReactNode,
    SelectHTMLAttributes
  } from 'react';
  
  import { IconDropdown } from 'components/IconDropdown';
  import { useDayPicker } from 'contexts/DayPicker';
  
  /** The props for the {@link Dropdown} component. */
  export interface DropdownProps {
    /** The name attribute of the element. */
    name?: string;
    /** The caption displayed to replace the hidden select. */
    caption?: ReactNode;
    children?: SelectHTMLAttributes<HTMLSelectElement>['children'];
    className?: string;
    ['aria-label']?: string;
    style?: CSSProperties;
    /** The selected value. */
    value?: string | number;
    onChange?: ChangeEventHandler<HTMLSelectElement>;
  }
  
  /**
   * Render a styled select component – displaying a caption and a custom
   * drop-down icon.
   */
  export function Dropdown(props: DropdownProps): JSX.Element {
    const { onChange, value, children, caption, className, style } = props;
    const dayPicker = useDayPicker();
  
    const IconDropdownComponent =
      dayPicker.components?.IconDropdown ?? IconDropdown;
    return (
      <div className={className} style={style}>
        <span className={dayPicker.classNames.vhidden}>
          {props['aria-label']}
        </span>
        <select
          name={props.name}
          aria-label={props['aria-label']}
          className={dayPicker.classNames.dropdown}
          style={dayPicker.styles.dropdown}
          value={value}
          onChange={onChange}
        >
          {children}
        </select>
        <div
          className={dayPicker.classNames.caption_label}
          style={dayPicker.styles.caption_label}
          aria-hidden="true"
        >
          {caption}
          {
            <IconDropdownComponent
              className={dayPicker.classNames.dropdown_icon}
              style={dayPicker.styles.dropdown_icon}
            />
          }
        </div>
      </div>
    );
  }