All files / button-group types.js

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

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                                                                                                                                                                               
/*
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 {SIZE, SHAPE} from '../button/index.js';
import type {OverrideT} from '../helpers/overrides.js';
 
import {MODE, STATE_CHANGE_TYPE} from './constants.js';
 
// button-group
export type PropsT = {|
  /** Accessible label. */
  ariaLabel?: string,
  /** Set of more than one `Button` components */
  children: Array<React.Node>,
  /** Defines if the button group is disabled. */
  disabled?: boolean,
  /**
   * Use the `mode` prop to render toggleable Buttons:
   * the value `radio` will cause Buttons to behave like radio buttons,
   * the value `checkbox` will cause Buttons to behave like checkboxes.
   */
  mode?: $Values<typeof MODE>,
  /**
   * Called with click events from children. If a child button has its
   * own click handler, the local handler will be called first, then
   * this handler will trigger.
   */
  onClick?: ClickHandlerT,
  overrides?: OverridesT<*>,
  /**
   * Index or array of indices of the selected Button(s).
   * Primarily for use with controlled components with a `mode` prop defined.
   */
  selected?: number | Array<number>,
  /** Defines the shape of the buttons in the button group. */
  shape?: $Values<typeof SHAPE>,
  /** Defines the size of the buttons in the button group. */
  size?: $Values<typeof SIZE>,
|};
 
type OverridesT<T> = {
  Root?: OverrideT<T>,
};
 
// stateful-group
// eslint-disable-next-line flowtype/generic-spacing
export type StatefulPropsT = $Diff<
  {|
    ...PropsT,
    initialState?: {selected: number | Array<number>},
    stateReducer?: StateReducerT,
  |},
  {selected: mixed}, // excluded from type definition
>;
 
// stateful-container
export type StatefulContainerPropsT = {|
  ...StatefulPropsT,
  children: (props: {
    ...$Diff<PropsT, {children: mixed}>,
    onClick: ClickHandlerT,
    selected: number | Array<number>,
  }) => React.Node,
|};
 
export type StateT = {
  selected: Array<number>,
};
 
export type StateReducerT = (
  stateType: $Values<typeof STATE_CHANGE_TYPE>,
  nextState: StateT,
  currentState: StateT,
) => StateT;
 
// general
type ClickHandlerT = (
  event: SyntheticEvent<HTMLButtonElement>,
  index: number,
) => mixed;