input-plus-minus
v1.0.8
Published
wrapper around input
Readme
input-plus-minus
input-plus-minus is a ts library creates stylized input.
Library depends on Inputmask.
Setup
add with:
npm
npm install input-plus-minus --saveyarn
yarn add input-plus-minusClassic web with script tag
<script src="public/InputPlusMinusWindow.js"></script>ES6 import
import InputPlusMinus from 'InputPlusMinus';Usage
InputPlusMinus('#id', InputPlusMinusSettings, ['themes']);Settings
interface InputPlusMinusSettings {
plusText?: string;
minusText?: string;
min?: number;
max?: number;
start?: number;
step?: number | InputPlusMinusSteps;
digits?: number;
grid?: boolean;
gridSuffix?: string;
gridCompression?: boolean;
gridCompressionValues?: InputPlusMinusGridCompression[];
thumb?: string;
thumbCreator?: (thumb: string, input: HTMLInputElement) => Element;
}Fields
elements
elements: InputPlusMinusElementssaveValidValue
last valid number
saveValidValue: numberself
self: HTMLInputElementcallbacks
callbacks: CallbacksMethods
constructor
constructor(initElement: Element | string, settings?: InputPlusMinusSettings, themes?: string[])changeValue
changeValue(value: number): voidupdateConfiguration
updateConfiguration(
settings: InputPlusMinusSettings,
themes?: string[],
fireInput: boolean = false,
start: boolean = false
): voidnext
next(): voidprev
prev(): voiddestructor
destructor(): voidInterfaces and types
InputPlusMinusElements
interface InputPlusMinusElements {
wrapper: Element;
minus: Element;
plus: Element;
grid: Element;
gridMin: Element;
gridMax: Element;
}InputPlusMinusEvents
type InputPlusMinusEvents = 'input' | 'beforeChange' | 'afterChange'InputPlusMinusSteps
interface InputPlusMinusSteps {
[key: string]: number;
}InputPlusMinusGridCompression
interface InputPlusMinusGridCompression {
text: string;
compression: number;
digits: number;
}Events
- beforeChange
- afterChange
const second = new InputPlusMinus('#second');
const secondInput = document.getElementById('#second');
secondInput.addEventListener(
'beforeChange_InputPlusMinus',
(e: InputPlusMinusEventBeforeChange) => {
const detail = e.detail;
const current = detail.current;
console.log('before change', current, detail.next);
}
);Callbacks
- beforeChange
- afterChange
add
const example = new InputPlusMinus('#example');
example.callbacks.add(
'test',
'beforeChange',
(data: InputPlusMinusEventDataBeforeChange) => {
console.log(data);
}
);remove
const example = new InputPlusMinus('#example');
example.callbacks.remove(
'test'
);Static callbacks
getInstance
InputPlusMinus.getInstance(info: Element | string): InputPlusMinus;checkInstance
InputPlusMinus.checkInstance(info: HTMLInputElement): boolean;Compatibility with ie11
Include to your project packages classlist-polyfill and custom-event-polyfill
