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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | /*
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
import * as React from 'react';
import type {OverrideT} from '../helpers/overrides.js';
import {STATE_CHANGE_TYPES, OPTION_LIST_SIZE} from './constants.js';
export type ItemT = *;
export type ItemsT = $ReadOnlyArray<ItemT>;
export type GetItemLabelFnT = (item: ItemT) => React.Node;
export type GetProfileItemLabelsFnT = (
item: ItemT,
) => {
title?: string,
subtitle?: string,
body?: string,
};
export type GetProfileItemImgFnT = (
item: ItemT,
) => string | React.ComponentType<*>;
export type GetProfileItemImgTextFnT = (item: ItemT) => string;
export type SetRootRefFnT = (ref: React$ElementRef<*>) => void;
export type RootRefT = React$ElementRef<*>;
export type OnItemSelectFnT = ({
item: ItemT,
event?: SyntheticEvent<HTMLElement> | KeyboardEvent,
}) => mixed;
export type ProfileOverridesT = {
List?: OverrideT<*>,
ListItemProfile?: OverrideT<*>,
ProfileImgContainer?: OverrideT<*>,
ProfileImg?: OverrideT<*>,
ProfileLabelsContainer?: OverrideT<*>,
ProfileTitle?: OverrideT<*>,
ProfileSubtitle?: OverrideT<*>,
ProfileBody?: OverrideT<*>,
};
export type RenderItemPropsT = {
disabled?: boolean,
ref?: React$ElementRef<*>,
id?: ?string,
isFocused?: boolean,
// indicates when the item is visually focused
isHighlighted?: boolean,
resetMenu?: () => mixed,
};
export type GetRequiredItemPropsFnT = (
item: ItemT,
index: number,
) => RenderItemPropsT;
export type StateReducerFnT = (
changeType: ?$Keys<typeof STATE_CHANGE_TYPES>,
changes: StatefulContainerStateT,
currentState: StatefulContainerStateT,
) => StatefulContainerStateT;
export type StatefulContainerStateT = {
// id of the currently highlighted item (from keyboard control)
activedescendantId?: ?string,
// index of currently highlighted item (from keyboard control)
highlightedIndex: number,
// indicates when the menu can be navigated by keyboard and affects menu item option rendering
// see https://github.com/uber-web/baseui/issues/993 for a description.
isFocused: boolean,
};
export type RenderPropsT = StatefulContainerStateT & {
items: ItemsT,
getRequiredItemProps: GetRequiredItemPropsFnT,
};
/**
* Component Prop Types
* ====================
* Required and Optional are split into separate object types, and internals are all
* marked as required because otherwise defaultProps will not work properly
*/
export type StatefulContainerPropsT = {
/** List of menu items. */
items: ItemsT,
/** Initial state of the stateful menu. */
initialState: StatefulContainerStateT,
/** State reducer to intercept state changes and return new internal state */
stateReducer: StateReducerFnT,
/** Function to get props for each rendered item. This will have some defaults needed for keyboard
* bindings to work properly. Every rendered item should call this.
*/
getRequiredItemProps: GetRequiredItemPropsFnT,
/** Callback executed on menu item clicks. */
onItemSelect: OnItemSelectFnT,
/** Ref for the menu container element. Used to capture key events for navigation */
rootRef?: RootRefT,
/** Child as function pattern. */
children: RenderPropsT => React.Node,
addMenuToNesting?: (ref: {current: HTMLElement | null}) => void,
removeMenuFromNesting?: (ref: {current: HTMLElement | null}) => void,
getParentMenu?: (ref: {current: HTMLElement | null}) => ?{
current: HTMLElement | null,
},
getChildMenu?: (ref: {current: HTMLElement | null}) => ?{
current: HTMLElement | null,
},
};
export type MenuPropsT = {
overrides?: {
EmptyState?: OverrideT<*>,
List?: OverrideT<*>,
Option?: OverrideT<*>,
},
};
export type MenuProfilePropsT = {
/** Returns an object consisting of title, subtitle, and body to render menu item */
getProfileItemLabels: GetProfileItemLabelsFnT,
/** Returns either an image source url, or a full React component to render as the image. */
getProfileItemImg: GetProfileItemImgFnT,
/** Returns the alt text for the image */
getProfileItemImgText: GetProfileItemImgTextFnT,
overrides?: ProfileOverridesT,
};
export type SharedStatelessPropsT = {
/** Id of the highlighted menu item. */
activedescendantId?: ?string,
/** Function to get props for each rendered item. This will have some defaults needed for keyboard
* bindings to work properly. Every rendered item should call this.
*/
getRequiredItemProps?: GetRequiredItemPropsFnT,
/** Index of highlighted menu item. */
highlightedIndex?: number,
/** List of menu items. */
items: ItemsT,
/** Message to be displayed if no menu items are passed in. */
noResultsMsg?: React.Node,
onBlur?: (event: SyntheticFocusEvent<HTMLElement>) => mixed,
onFocus?: (event: SyntheticFocusEvent<HTMLElement>) => mixed,
/** Ref for the menu container element. Used to capture key events for navigation */
rootRef?: RootRefT,
focusMenu?: (event: FocusEvent | MouseEvent | KeyboardEvent) => mixed,
unfocusMenu?: () => mixed,
};
export type StatefulMenuPropsT = StatefulContainerPropsT & MenuPropsT;
export type StatefulMenuProfilePropsT = StatefulContainerPropsT &
MenuProfilePropsT;
export type StatelessMenuPropsT = SharedStatelessPropsT & MenuPropsT;
export type StatelessMenuProfilePropsT = SharedStatelessPropsT &
MenuProfilePropsT;
export type OptionListPropsT = {
/** Item to parse and render. */
item: ItemT,
/** Function used to get the string label for each item. */
getItemLabel: GetItemLabelFnT,
/** Used to render a sub menu at this menu item. You'll often render another menu from this function. */
getChildMenu?: (item: ItemT) => React.Node,
/** Callback used to change highlighted index in stateful menu. */
onMouseEnter?: (event: MouseEvent) => mixed,
/** Renders UI in defined scale. */
size?: $Keys<typeof OPTION_LIST_SIZE>,
overrides?: {
ListItem?: OverrideT<*>,
},
/** Utility to reset menu to default state. Useful for rendering child menus. */
resetMenu?: () => void,
/** Renders UI in 'highlighted' state. */
$isHighlighted?: boolean,
};
export type OptionProfilePropsT = {
/** Item to parse and render. */
item: ItemT,
/** Used to render a sub menu at this menu item. You'll often render another menu from this function. */
getChildMenu?: (item: ItemT) => React.Node,
/** Returns an object consisting of title, subtitle, and body to render menu item */
getProfileItemLabels: GetProfileItemLabelsFnT,
/** Returns either an image source url, or a full React component to render as the image. */
getProfileItemImg: GetProfileItemImgFnT,
/** Returns the alt text for the image */
getProfileItemImgText: GetProfileItemImgTextFnT,
overrides?: {
ListItemProfile?: OverrideT<*>,
ProfileImgContainer?: OverrideT<*>,
ProfileImg?: OverrideT<*>,
ProfileLabelsContainer?: OverrideT<*>,
ProfileTitle?: OverrideT<*>,
ProfileSubtitle?: OverrideT<*>,
ProfileBody?: OverrideT<*>,
},
/** Utility to reset menu to default state. Useful for rendering child menus. */
resetMenu?: () => void,
/** Renders UI in 'highlighted' state. */
$isHighlighted?: boolean,
};
|