# All files / src/DropdownFlyout DropdownFlyout.types.ts

100% Statements 1/1
100% Branches 0/0
100% Functions 0/0
100% Lines 1/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144

    3x

     import { Ref } from 'react'
    import { DropdownProps } from '../Dropdown/Dropdown.types'
    import { OverlayProps } from '../Overlay/Overlay'
    import { DivAttributes, Placement, Props } from '../_utils/types'

    export const rootId = 'ROOT_ID'

    export type Action =
      | { type: 'highlight'; option: FlyoutOption }
      | { type: 'expand'; option: FlyoutOption }
      | { type: 'collapse'; option: FlyoutOption }
      | { type: 'close' }
      | { type: 'open' }
      | { type: 'setMouseOver'; isMouseOver: boolean }
      | { type: 'setFocused'; isFocused: boolean }

    type ExpandedItem = FlyoutOptionId

    export type State = {
      highlighted: FlyoutOption
      expanded: ExpandedItem[]
      options: FlyoutOption[]
      isMouseOver: boolean
      isFocused: boolean
      isOpen: boolean
    }

    export interface DropdownOption {
      value: any
      label: string
      children?: DropdownOption[]
    }

    type OptionId = string
    export interface FlyoutOption {
      /**
       * @since 10.19.0
       */
      id: OptionId
      /**
       * @since 10.19.0
       */
      parentId: OptionId | typeof rootId
      /**
       * @since 10.19.0
       */
      origin: DropdownOption
      /**
       * @since 10.19.0
       */
      children?: FlyoutOption[]
    }

    export type FlyoutOptionId = FlyoutOption['id'] | typeof rootId

    export interface FlyoutCaptionProps extends DivAttributes {
      option: DropdownOption
      highlighted: boolean
      optionRenderer: (option: DropdownOption) => React.ReactNode
    }

    export interface FlyoutListProps extends DivAttributes {
      options: FlyoutOption[]
      overlayRef: Ref<HTMLDivElement>
      placement: Placement
      referenceEl: HTMLElement | null
      offset?: number
    }

    export interface DropdownFlyoutProps extends Omit<DivAttributes, 'onClick'> {
      /**
       * @since 10.19.0
       */
      disabled?: DropdownProps['disabled']

      /**
       * The text of the button.
       * @since 10.19.0
       */
      label?: DropdownProps['label']
      /**
       * @since 10.19.0
       */
      loading?: DropdownProps['loading']

      /**
       * The icon of the button.
       * @since 10.19.0
       */
      icon?: DropdownProps['icon']

      /**
       * <div>
       *  Data of the dropdown options - <Code>Option[]</Code>
       *  <CodeBlock>
       *    {`type Option = { label: string; children?: Option[] }`}
       *  </CodeBlock>
       * </div>
       * @since 10.19.0
       */
      options: DropdownOption[]

      /**
       * <div>
       *  Callback for click on dropdown option
       *  <CodeBlock>{'(option: Option) => void'}</CodeBlock>
       * </div>
       * @since 10.19.0
       */
      onClick?: (option: DropdownOption) => void

      /**
       * <div>
       *  Render prop to specify custom dropdown option content
       *  <CodeBlock>{'(option: Option) => ReactNode'}</CodeBlock>
       * </div>
       * @since 10.19.0
       */
      optionRenderer?: (option: DropdownOption) => React.ReactNode

      /**
       * @default 'right-bottom'
       * @since 10.19.0
       */
      placement?: OverlayProps['placement']

      /**
       * The button size
       * @default 'md'
       * @since 10.19.0
       */
      size?: DropdownProps['size']

      /**
       * @default 'secondary'
       * @since 10.19.0
       */
      variant?: DropdownProps['variant']
    }

    export interface FlyoutItemProps extends Props {
      option: FlyoutOption
    }