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 | 1x | /*
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_TYPE} from './constants.js';
const stateChangeType = Object.freeze(STATE_CHANGE_TYPE);
export type StateTypeT = $Values<typeof stateChangeType>;
export type StateT = {
activeItemId?: string,
};
export type StateReducerT = (
stateType: StateTypeT,
nextState: StateT,
currentState: StateT,
) => StateT;
export type SharedPropsT = {
/** Defines if the nav item is currently selected */
$active: boolean,
/** Defines the nesting level of the rendered nav item */
$level: number,
/** Defines if the nav item is selectable/clickable */
$selectable: boolean,
};
export type NavPropsT = {
/** Defines the current active itemId. Used for the default calculation of the $active prop */
activeItemId: string,
/**
Is called on the nav item render to test if the item is currently selected.
If returns true the item will be rendered as an active one
*/
activePredicate: ?(item: *, activeItemId: string) => boolean,
/** List of navigation items */
items: Item[],
/** onChange handler that is called when a nav item is selected */
onChange?: ({item: *, event: Event | KeyboardEvent}) => mixed,
/** Overrides for the internal elements and components */
overrides: {
Root?: OverrideT<*>,
NavItemContainer?: OverrideT<*>,
NavLink?: OverrideT<*>,
NavItem?: OverrideT<*>,
SubNavContainer?: OverrideT<*>,
},
/** Optional transform function that is called for each Item */
mapItem: ?(item: Item) => Item,
};
export type Item = {
/** Navigation item's title to render */
title: React.Node,
/**
Identifier for the navigation item.
Can be a path value or an action name.
It's also used in the default `activePredicate` to
identify a currently active item
*/
itemId?: string,
/** A list of sub-navigation items */
subNav?: Item[],
};
export type NavItemPropsT = SharedPropsT & {
item: Item,
onSelect?: ({item: *, event: Event | KeyboardEvent}) => mixed,
overrides: {
NavLink?: OverrideT<*>,
NavItem?: OverrideT<*>,
},
};
export type StatefulContainerPropsT = {
children: NavPropsT => React.Node,
/** Initial state of an uncontrolled component. */
initialState?: StateT,
/** A state change handler. Used to override default state transitions. */
stateReducer?: StateReducerT,
onChange?: ({item: *, event: Event | KeyboardEvent}) => mixed,
};
type ExcludeT = {
children: NavPropsT => React.Node,
};
export type StatefulNavPropsT = $Diff<StatefulContainerPropsT, ExcludeT>;
|