UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

106 lines (105 loc) 3.39 kB
/// <reference types="react" /> import { BaseComponent } from '../../Utilities'; import { ISpinButton, ISpinButtonProps } from './SpinButton.types'; export declare enum KeyboardSpinDirection { down = -1, notSpinning = 0, up = 1, } export interface ISpinButtonState { /** * Is true when the control has focus. */ isFocused: boolean; /** * the value of the spin button */ value: string; /** * keyboard spin direction, used to style the up or down button * as active when up/down arrow is pressed */ keyboardSpinDirection: KeyboardSpinDirection; /** * The calculated precision for the value. */ precision: number; } export declare class SpinButton extends BaseComponent<ISpinButtonProps, ISpinButtonState> implements ISpinButton { static defaultProps: ISpinButtonProps; private _input; private _inputId; private _labelId; private _lastValidValue; private _spinningByMouse; private _valueToValidate; private _currentStepFunctionHandle; private _initialStepDelay; private _stepDelay; constructor(props: ISpinButtonProps); /** * Invoked when a component is receiving new props. This method is not called for the initial render. */ componentWillReceiveProps(newProps: ISpinButtonProps): void; render(): JSX.Element; focus(): void; private _onFocus; private _onBlur; /** * Gets the value of the spin button. */ readonly value: string | undefined; private _onValidate; /** * Validate function to use if one is not passed in */ private _defaultOnValidate; private _onIncrement; /** * Increment function to use if one is not passed in */ private _defaultOnIncrement; private _onDecrement; /** * Increment function to use if one is not passed in */ private _defaultOnDecrement; private _onChange(); /** * This is used when validating text entry * in the input (not when changed via the buttons) * @param event - the event that fired */ private _validate; /** * The method is needed to ensure we are updating the actual input value. * without this our value will never change (and validation will not have the correct number) * @param event - the event that was fired */ private _onInputChange; /** * Update the value with the given stepFunction * @param shouldSpin - should we fire off another updateValue when we are done here? This should be true * when spinning in response to a mouseDown * @param stepFunction - function to use to step by */ private _updateValue; /** * Stop spinning (clear any currently pending update and set spinning to false) */ private _stop; /** * Handle keydown on the text field. We need to update * the value when up or down arrow are depressed * @param event - the keyboardEvent that was fired */ private _handleKeyDown; /** * Make sure that we have stopped spinning on keyUp * if the up or down arrow fired this event * @param event stop spinning if we */ private _handleKeyUp; private _onIncrementMouseDown; private _onDecrementMouseDown; }