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 | /*
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 {STATE_CHANGE_TYPE} from './constants.js';
export type AccordionStateT = {
expanded: Array<React.Key>,
};
export type PanelStateT = {
expanded: boolean,
};
export type StateChangeTypeT = $Keys<typeof STATE_CHANGE_TYPE>;
export type StateReducerT = (
stateChangeType: StateChangeTypeT,
nextState: AccordionStateT,
currentState: AccordionStateT,
) => AccordionStateT;
export type PanelStateReducerT = (
stateChangeType: StateChangeTypeT,
nextState: PanelStateT,
currentState: PanelStateT,
) => PanelStateT;
export type AccordionOverridesT<T> = {
Root?: OverrideT<T>,
};
export type PanelOverridesT<T> = {
PanelContainer?: OverrideT<T>,
Header?: OverrideT<T>,
ToggleIcon?: OverrideT<T>,
Content?: OverrideT<T>,
};
export type OnChangeHandlerT = ({expanded: boolean}) => mixed;
export type AccordionOnChangeHandlerT = ({
expanded: Array<React.Key>,
}) => mixed;
type ChildrenT = React.ChildrenArray<React.Element<*>>;
export type AccordionPropsT = {
/** Determines how many panels may be expanded at a time. If set to
* true it will collapse a current panel when a new panel is expanded.
* If set to false more than one panel may be expanded at a time. */
accordion?: boolean,
/** Accordion expandable items. See Panel API below for reference. */
children: ChildrenT,
/** If set to true all its children panels will be disabled from toggling. */
disabled?: boolean,
initialState?: AccordionStateT,
/** Handler called each time a panel is toggled. expanded prop is an array
* of Panel keys that are currently expanded. */
onChange?: AccordionOnChangeHandlerT,
overrides?: AccordionOverridesT<
$Diff<SharedStylePropsArgT, {$expanded?: ?boolean}>,
>,
/** Handler called each time the component state changes.
* Used to override default state-change functionality. */
stateReducer: StateReducerT,
};
type SharedPanelPropsT = {
/** The content visible when Panel is expanded. */
children: React.Node,
/** Defaults to the disabled value provided by the parent Accordion component. */
disabled?: boolean,
/** The key of a Panel. Used to maintain list of expanded panels.
* Must be unique across children of the Accordion. */
key?: React.Key,
/** Handler for individual Panel change events. */
onChange?: OnChangeHandlerT,
/** Handler for the Header's click events. */
onClick?: (e: Event) => mixed,
/** Handler for the Header's keyDown events. */
onKeyDown?: (e: KeyboardEvent) => mixed,
overrides?: PanelOverridesT<SharedStylePropsArgT>,
/** The title of an accordion panel. */
title?: React.Node,
};
export type PanelPropsT = SharedPanelPropsT & {
/** Defines if the panel is expanded. If set to true the panel is rendered expanded. */
expanded?: boolean,
};
// Props for panel stateful container
type SharedStatefulPanelContainerPropsT = {
/** Initial state of a stateful panel component.
* The expanded prop indicates if the panel is initially expanded.
* If set to true the panel will be expanded initially */
initialState?: PanelStateT,
onChange?: OnChangeHandlerT,
stateReducer?: PanelStateReducerT,
};
export type StatefulPanelContainerPropsT = SharedStatefulPanelContainerPropsT & {
children: (props: $Diff<PanelPropsT, {children: React.Node}>) => React.Node,
};
// Props for stateful panel
export type StatefulPanelPropsT = SharedStatefulPanelContainerPropsT &
SharedPanelPropsT;
export type SharedStylePropsArgT = {
$color?: string,
$disabled: ?boolean,
$expanded?: ?boolean,
$size?: string | number,
};
|