1.1.1 • Published 6 years ago

react-text-2-list v1.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

react-text-2-list

Simple React component for entering / pasting large quantities of text to list

Usability

Peer dependencies: React and react-dom.

import { Text2List } from 'react-text-2-list';

and include css file (you may include this in different way)

require('../node_modules/react-text-2-list/css/style.css');

Demo

We prepared code sandbox demo. See demo here

props/options

Required props

There is only one mandatory prop: onAdd callback, that is gonna get fired when one or more items get added to the list

import React, {Component} from 'react';
import { Text2List } from 'react-text-2-list';
// You should not forget to include css

export default class FakeComponent extends Component {

	constructor(props) {
		super(props);

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

	onAddCallback(list) {
		console.log(list);
		// do whatever you like with your list,
		// which is an array of strings
	}

	render() {
		return (
			<div>
				<Text2List
					onAdd={this.onAddCallback}
				/>
			</div>
		);
	}
}

classNames

PropertyDefaultDescription
classNames---Object containing classnames listed below
classNames.wrapperText2ListComponent root element
classNames.headingText2List__headingh4 tag, the heading of the component
classNames.inputText2List__inputTextarea tag
classNames.buttonsWrapperText2List__buttonsWrapperDiv tag wrapping enter and remove all buttons
classNames.enterButtonButton Button--actionEnter button
classNames.removeButtonButton Button--underline Text2List__removeAllRemove all button
classNames.errorMessageText2List__errorMessageError message on duplicate entries, if you enable stopOnDuplicate prop
classNames.errorItemsText2List__errorItemsspan tag wrapping list of duplicate entries in error message
inputListClassNames---Object containing classnames for InputList component, listed below
inputListClassNames.wrapperText2List__inputListComponent root element
inputListClassNames.inputItemText2List__inputListItemLi tag, one entry in the list
inputListClassNames.inputItemTextText2List__inputListItemTextEntry text in li tag
inputListClassNames.removeButtonButton Button--underline Text2List__removeOneDelete button inside the entry

All props

PropertyTypeDefaultDescription
onAddfunctionnoneCallback to invoke on adding item(s) in the list, gets passed array of strings that are entries it the list
placeholderstring"1 or more codes accepted"Placeholder text for textarea
headingstring"Product code/number"Heading(label) text above text area
separatorsstringspace and commaString that we will use to make RegExp to separate entered text in textarea, ie. series of characters separated with pipe
stopOnDuplicatebooleanfalseIf true, it will stop submit if there are duplicate items entered or item already exists in the list. Otherwise, it will just show error message and filter out duplicates on enter
maxVisibleItemsnumber4It will determine the max-height of the list, with 45px being height of one entry and add a scroll if needed
maxItemsnumbernoneMax number of allowed entries
stopOnMaxItemsErrorbooleanfalseIf true, it will stop submit if there are more items entered than specified in maxItems prop. Otherwise, it will just show error message and truncate entries to match max items allowed in list
validateEntryfunctionnoneFunction that takes single entry as sole argument. Should return true or false
stopOnValidationErrorbooleanfalseIf true, it will stop submit if if one or more items didn't pass validateEntry check. Otherwise, it will just show error message and filter out invalid entries before enter
validationErrorMessagestring"Entries need to be valid."Error message to show if one or more items didn't pass the validateEntry check. Will get added a list of invalid entries to the end of it
enterButtonTextstring"Enter"Text that you want to show on "Enter" button
asyncValidationbooleanfalseWhether you are going to use async validation. It should work like this: you transition isInPendingState state prop to false when some API call is done and supply validateEntry that checks if entry is one of items that your API returned as invalid. You can alos feed the message from API into validationErrorMessage
isInPendingStatebooleanfalseUse it in combination with asyncValidation prop. Transition it to true while your API call for validation is in progress and to false when it's done. You can also use it for straight submitting to API
pendingEnterButtonTextstring"Validating..."Text to display on enter button while isInPendingState is true

Customizing and contributing

You can contact us in case you need some feature or want to contribute. It's possible that you may need additional className props, we haven't fully tested custom styling. Feel free to contact us should that be a case. You can also freely fork and play around with the project.

1.1.1

6 years ago

1.1.0

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago