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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | /*
Copyright (c) 2018-2019 Uber Technologies, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// @flow
/* eslint-disable flowtype/generic-spacing */
import * as React from 'react';
import type {OverrideT} from '../helpers/overrides.js';
import type {TetherPlacementT} from '../layer/types.js';
import {
ACCESSIBILITY_TYPE,
STATE_CHANGE_TYPE,
TRIGGER_TYPE,
} from './constants.js';
export type {
PopperDataObjectT,
PopperOffsetT,
PopperOptionsT,
} from '../layer/types.js';
export type PopoverPlacementT = TetherPlacementT;
export type TriggerTypeT = $Keys<typeof TRIGGER_TYPE>;
export type AccessibilityTypeT = $Keys<typeof ACCESSIBILITY_TYPE>;
export type StateT = {
isOpen: boolean,
};
export type StateChangeTypeT = $Keys<typeof STATE_CHANGE_TYPE>;
export type StateReducerT = (
stateChangeType: StateChangeTypeT,
nextState: StateT,
currentState: StateT,
) => StateT;
export type ContentRenderPropT = () => React.Node;
export type StatefulContentRenderPropT = ({
close: () => void,
}) => React.Node;
export type OverridesT = {
Body?: OverrideT<SharedStylePropsArgT>,
Arrow?: OverrideT<SharedStylePropsArgT>,
Inner?: OverrideT<SharedStylePropsArgT>,
};
// re-exports to maintain same public interface
export type ChildT = React.Node;
export type ChildrenT = React.ChildrenArray<ChildT>;
// Props shared by all flavors of popover
export type BasePopoverPropsT = {
/** Controls how this popover behaves for screen readers and other assistive devices.
* See the A11Y section at the bottom of this document for more details.
*/
accessibilityType?: AccessibilityTypeT,
'data-baseweb'?: string,
id?: string,
/** If true, popover element will not avoid element boundaries. */
ignoreBoundary?: boolean,
/** Number of milliseconds to wait before showing the popover after mouse enters the trigger element (for triggerType `hover`). */
onMouseEnterDelay?: number,
/** Number of milliseconds to wait before showing the popover after mouse leaves the trigger element (for triggerType `hover`). */
onMouseLeaveDelay?: number,
overrides?: OverridesT,
/** How to position the popover relative to the target. */
placement: TetherPlacementT,
/** Whether or not to show the arrow pointing from the popover to the trigger. */
showArrow?: boolean,
/** Whether to toggle the popover when trigger is clicked or hovered. */
triggerType: TriggerTypeT,
/** Where to mount the popover */
mountNode?: HTMLElement,
/** How long should be fade out animation in ms, default 0ms */
animateOutTime?: number,
};
// Props for stateless render logic
export type PopoverPropsT = BasePopoverPropsT & {
/** Content that should trigger the popover to be shown (also acts as the anchor against
* which the popover will be positioned).
*/
children: React.Node,
/** Content to render within the popover when it's shown. */
content: React.Node | ContentRenderPropT,
/** Whether or not to show the popover. */
isOpen: boolean,
/** Handler for blur events on trigger element. */
onBlur?: () => mixed,
/** Handler for click events on trigger element. */
onClick?: (e: Event) => mixed,
/** Handler for clicks outside the anchor/popover elements. */
onClickOutside?: (event: MouseEvent) => mixed,
/** Handler for click events on trigger element. */
onEsc?: () => mixed,
/** Handler for 'Esc' keypress events */
onFocus?: () => mixed,
/** Handler for mouseenter events on trigger element. */
onMouseEnter?: () => mixed,
/** Handler for mouseleave events on trigger element. */
onMouseLeave?: () => mixed,
};
// Props for stateful wrapper
export type StatefulPopoverPropsT = BasePopoverPropsT & {
/** Content that should trigger the popover to be shown (also acts as the anchor against
* which the popover will be positioned).
*/
children: React.Node,
/** Content to render within the popover when it's shown. */
content: React.Node | StatefulContentRenderPropT,
/** Whether to hide the popover when the user clicks anywhere outside the trigger/popover. */
dismissOnClickOutside: boolean,
/** Whether to hide the popover when the user presses the escape key. */
dismissOnEsc: boolean,
/** Initial state populated into the component */
initialState?: StateT,
/** Event handler when popover is hidden. */
onClose?: () => mixed,
/** Event handler when popover is shown. */
onOpen?: () => mixed,
/** Reducer function to manipulate internal state updates. */
stateReducer?: StateReducerT,
};
// Props for state container
export type StatefulPopoverContainerPropsT = $Diff<
StatefulPopoverPropsT,
{children: React.Node},
> & {
children: (props: $Diff<PopoverPropsT, {children: React.Node}>) => React.Node,
};
export type PopoverPropsWithoutChildrenT = $Diff<
PopoverPropsT,
{children: React.Node},
>;
export type OffsetT = {
top: number,
left: number,
};
export type PopoverPrivateStateT = {
isAnimating: boolean,
arrowOffset: OffsetT,
popoverOffset: OffsetT,
placement: TetherPlacementT,
isLayerMounted: boolean,
isMounted: boolean,
};
export type SharedStylePropsArgT = {
$arrowOffset: OffsetT,
$isAnimating: boolean,
$isOpen: boolean,
$popoverOffset: OffsetT,
$placement: TetherPlacementT,
$showArrow: boolean,
children?: React.Node,
};
export type AnchorPropsT = {
'aria-controls'?: string | null,
'aria-describedby'?: string | null,
'aria-expanded'?: string,
'aria-haspopup'?: string,
'aria-owns'?: string | null,
id?: string | null,
onBlur?: () => mixed,
onClick?: (e: Event) => mixed,
onFocus?: () => mixed,
onMouseEnter?: (e: Event) => mixed,
onMouseLeave?: (e: Event) => mixed,
ref?: React.Ref<*>,
tabIndex?: number,
};
|