npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-multivalue-text-input-field

v1.0.2

Published

The `MultiInputField` component is a versatile and customizable React input field that enables users to add, clear, or remove multiple values. It’s ideal for tags, categories, keywords, or any multi-value input requirements, with extensive support for cus

Downloads

187

Readme

MultiInputField Component

The MultiInputField component is a versatile and customizable React input field that enables users to add, clear, or remove multiple values. It’s ideal for tags, categories, keywords, or any multi-value input requirements, with extensive support for custom styling and UI elements.

Features

  • Multi-value Input: Users can add and manage multiple values.
  • Clear All Values: Provides a clear-all option to reset the input.
  • Remove Individual Values: Allows users to delete specific values.
  • Customizable UI: Easily style the component, including label, input field, list items, and icons.
  • Accessible and User-friendly: Supports required fields and placeholders for enhanced UX.

Installation

First, install the package via npm:

npm install react-multivalue-text-input-field

Importing and Basic Setup

Step 1: Import the Component

import MultiInputField from 'react-multivalue-text-input-field';
import React, { useState } from 'react';

Step 2: Define State for the Values

Create a state to hold the input values using the useState hook.

const App = () => {
  const [values, setValues] = useState<string[]>([]);

  return (
    <MultiInputField
      values={values}
      setValues={setValues}
      label="Enter Tags"
      placeholder="Type and press enter"
      required={true}
    />
  );
};

export default App;

In this example, the values array will hold the current tags, and setValues updates this array when new tags are added or removed.


Detailed Props Guide

The MultiInputField component accepts the following props, allowing for comprehensive customization:

Required Props

| Prop | Type | Description | |------------|--------------------------------|---------------------------------------------------------------------| | values | string[] | Array of initial values for the input field. | | setValues| (values: string[]) => void | Function that updates the values array on adding or removing tags.|

Optional Props for Enhanced Customization

| Prop | Type | Description | |------------------------|--------------------------------|-----------------------------------------------------------------------------| | label | string | Label text for the input field. | | labelStyle | string | Additional CSS class or style string for the label styling. | | placeholder | string | Placeholder text that appears when no values are entered. | | optionStyle | OptionStyleType | Custom styling for individual list items (background color, padding, etc.). | | optionTextStyle | OptionTextType | Style properties for the text inside each list item. | | optionCloseIcon | React.ReactNode | Custom icon component for removing a value. | | optionCloseIconStyle | string | CSS class or style string for the remove icon styling. | | containerFocusedStyle| string | CSS styling applied to the container when it is focused. | | required | boolean | Marks the input field as required if set to true. |


Full Prop Example with Descriptions

Here’s an example that demonstrates how to utilize various props for a fully customized experience:

<MultiInputField
  values={values}
  setValues={setValues}
  label="Tags"
  labelStyle="custom-label-class" // Custom label CSS class for unique styling
  placeholder="Type and hit Enter" // Placeholder text when no values are entered
  optionStyle={{
    backgroundColor: '#e0f7fa',
    paddingHorizontal: '8px',
    paddingVertical: '4px',
    borderRadius: '4px'
  }} // List item styling
  optionTextStyle={{
    color: '#00796b',
    fontSize: '14px',
    fontFamily: 'Arial, sans-serif',
    fontWeight: 'bold'
  }} // Text styling inside list items
  optionCloseIcon={<span>&#10006;</span>} // Custom close icon using a 'x' symbol
  optionCloseIconStyle="custom-close-icon-class" // Custom close icon style
  containerFocusedStyle="focused-container-class" // Container style on focus
  required // Sets the field as mandatory
/>

Prop Breakdown

Required Properties

  • values: An array of strings representing the initial values.
  • setValues: A callback function that updates the values array when values are added or removed.

Label Customization

  • label: Sets a descriptive text label above the input.
  • labelStyle: Adds custom styling to the label, making it easy to match the input label with your design theme.

Placeholder Text

  • placeholder: Sets the placeholder text inside the input box. It can indicate how to interact with the input, such as "Type and hit Enter."

Styling List Items

  • optionStyle: Style the appearance of each list item, with properties like backgroundColor, paddingHorizontal, paddingVertical, and borderRadius.
  • optionTextStyle: Customize the text inside each list item with color, fontSize, fontFamily, and fontWeight.

Close Icon Customization

  • optionCloseIcon: Replace the default close icon with a custom one. For example, you could use a FontAwesome icon here.
  • optionCloseIconStyle: Apply additional styling to the close icon, such as changing color, size, or padding.

Container Styling on Focus

  • containerFocusedStyle: Specify styles that are applied to the container when it gains focus, such as adding a colored border.

Required Field Indicator

  • required: Marks the input field as required. If true, an asterisk (*) appears next to the label.

Example with Full Customization and Clear Functionality

import React, { useState } from 'react';
import MultiInputField from 'react-multivalue-text-input-field';

const TagInput = () => {
  const [tags, setTags] = useState<string[]>(['Example Tag 1', 'Example Tag 2']);

  return (
    <MultiInputField
      values={tags}
      setValues={setTags}
      label="Your Tags"
      labelStyle="custom-label-style"
      placeholder="Add a tag and press enter"
      optionStyle={{
        backgroundColor: '#ffeeff',
        paddingHorizontal: '10px',
        paddingVertical: '5px',
        borderRadius: '8px'
      }}
      optionTextStyle={{
        color: '#aa00aa',
        fontSize: '13px'
      }}
      optionCloseIcon={<span>&times;</span>}
      optionCloseIconStyle="close-icon-style"
      containerFocusedStyle="input-focused-style"
      required
    />
  );
};

export default TagInput;

Custom CSS Styling Tips

For users who want to define their own custom styles, use the following guidelines:

.custom-label-style {
  font-size: 16px;
  color: #333;
}

.custom-close-icon-class {
  font-size: 12px;
  color: #ff3333;
  cursor: pointer;
}

.input-focused-style {
  border: 2px solid #007bff;
}

License

This project is licensed under the MIT License. Please see the LICENSE file for more information.