UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

101 lines (100 loc) 3.36 kB
import { BaseComponent } from '../../Utilities'; import { ISpinButton, ISpinButtonProps } from './SpinButton.Props'; 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; } export declare class SpinButton extends BaseComponent<ISpinButtonProps, ISpinButtonState> implements ISpinButton { static defaultProps: ISpinButtonProps; private _input; private _inputId; private _labelId; private _lastValidValue; private _spinningByMouse; private _onValidate?; private _onIncrement?; private _onDecrement?; private _currentStepFunctionHandle; private _initialStepDelay; private _stepDelay; private _formattedValidUnitOptions; 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(ev); private _onBlur(ev); /** * Gets the value of the spin button. */ readonly value: string | undefined; /** * Validate function to use if one is not passed in */ private _defaultOnValidate; /** * Increment function to use if one is not passed in */ private _defaultOnIncrement; /** * 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(event); /** * 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(event); /** * 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(shouldSpin, stepDelay, stepFunction); /** * 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(event); /** * 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(event); private _onIncrementMouseDown(); private _onDecrementMouseDown(); }