0.0.2 • Published 3 years ago

lvd-fluentui-multitextfield v0.0.2

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
3 years ago

LVD-FluentUi-MultiTextField

NPM

A multiple text field input component, built using the FluentUI library, with the following features:

  • specify optional minimum, maximum and initial value count;
  • controls for adding and removing input items;
  • fine-grained control over input item configuration, including appearance and error message handling.

Also an animated demo which is configured for a minmum of 3 input items, a maximum of 10 and an initial count of 4.

Installation

npm install --save lvd-fluentui-multitextfield

Demo

The demo directory contains a compiled and ready-to-run example. Just open up the index.html file.

Basic Usage

import React from 'react';
import { MultiTextField } from 'lvd-fluentui-multitextfield';

class MultiTextFieldSamplePage extends React.Component {
	constructor(props) {
		super(props);

		this.state = {
			values: []
		};

		this._handleValuesChanged = 
			this._handleValuesChanged.bind(this);
	}

	_handleValuesChanged(values) {
		// Do something with the values
		this.setState({
			values: values
		});
	}

	render() {
		return (
			<MultiTextField 
				values={this.state.values}
				onChange={this._handleValuesChanged}
			/>
		);
	}
}

You can find a full working example here.

Styling

You can either directly include the dist/style.css into your html web page or use the @import directive inside your stylesheet if building using webpack:

@import '~lvd-fluentui-multitextfield/dist/style.css';

Also see the component itself.

Building

To build the demo application:

npm run build-app

To build the library:

npm run build-dist

To build both in one sitting:

npm run build

Customization Options

WhatProp NameTypeNotes
Set additional master container css class nameclassNamestringDefaults to null.
Set additional master inline css style propertiesstyleobjectKey-value plain javascript object. Defaults to {}.
Set input labellabelstringDefaults to empty string.
Configure all input itemsinputPropsInput Items Configuration ObjectSee below.
Configure the add input item actionaddInputItemActionPropsAdd Input Action Configuration ObjectSee below.
Configure the remove input item actionremoveInputItemActionPropsRemove Input Action Configuration ObjectSee below.
Set minimum input item countminItemCountNumberDefaults to 1.
Set maximum input item countmaxItemCountNumberDefaults to Number.MAX_SAFE_INTEGER.
Set initial input item countinitialItemCountNumberDefaults to 1. Must be within specified minimum and maximum input item counts.
Set valuesvaluesstring[]Defaults to an array of empty string values with the length equal to the specified initial item count.
Configure specific input itemonGetInputProps(itemValue:string, itemIndex:number): Input Items Configuration ObjectSee below.
Get error message for specific input itemonGetInputItemErrorMessage(itemValue:string, itemIndex:number): stringReturn empty string if no error. By default, if the input item is required, but no error message is provided, the You must fill in a value message is displayed.
Get default value for specific input itemonGetDefaultInputItemValue(itemIndex:number): stringDefault value defaults to an empty string.

Input Items Configuration Object

A plain javascript object with the following properties:

NameTypeNotes
classNamestringCSS class name for the actual input element. Defaults to null.
styleobjectAdditional inline css style properties for the actual input element. Defaults to {}.
labelstringIndividual label for the input item. Defaults to null.
placeholderstringIndividual placeholder for the actual input element. Defaults to Please enter a value.
descriptionstringIndividual description for the actual input element. Defaults to null.
requiredbooleanWhether the actual input element is required or not. Defaults to false.
underlinedbooleanWhether or not to display the actual input element in underlined style. Defaults to false.
readOnlybooleanWhether or not to make the actual input element read-only. Defaults to false.
disabledbooleanWhether or not to disable the actual input element. Defaults to false.
borderlessbooleanWhether or not to make the actual input element borderless. Defaults to false.

Add Input Action Configuration Object

A plain javascript object with the following properties:

NameTypeNotes
allowAddstringWhether or not to allow adding new input items. Automatically overridden to false if a maximum input item count is set and the current input item count reaches that limit.
iconPropsIIconPropsIcon properties. See here.
labelstringButton label. Defaults to null.
classNamestringAdditional button CSS class name

Remove Input Action Configuration Object

A plain javascript object with the following properties:

NameTypeNotes
allowRemovestringWhether or not to allow adding new input items. Automatically overridden to false if the number of input items reaches the minimum input item count.
iconPropsIIconPropsIcon properties. See here.
labelstringButton label. Defaults to null.
classNamestringAdditional button CSS class name

Events

EventProp NameArgumentsNotes
Value added at indexonInputItemAdded(newValue:string, itemIndex:number)-
Value removed at indexonInputItemRemoved(removedValue:string, itemIndex:number)-
Input item focusedonInputItemFocus(itemIndex:number)Triggered when one of the underlying TextFields gains focus.
Input item lost focusonInputItemBlur(itemIndex:number)Triggered when one of the underlying TextFields loses focus.
Value changedonChange(values:string[])Triggered when: a new input item is added, an existing input item is removed or the value of an existing input item is changed.

Changelog

Version 0.0.2

  • Removed item value console logging.

Version 0.0.1

  • First tracked version.

Donate

I put some of my free time into developing and maintaining this plugin. If helped you in your projects and you are happy with it, you can...

ko-fi