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

goten-react-text-field

v1.1.4

Published

GotenTextField is a react component that facilitates the use of text inputs.

Downloads

10

Readme

Goten Text Field

GotenTextField is a React component that facilitates the use of text inputs.

  • It allows to bind an object to the value of a text input.
    • This avoids common boilerplate of state definition and setState calls.
  • It helps validating a text input using its type.
    • You can specify a pattern (Regex) for the validation.
    • You can modify the error's display message and add certain functionality like pop-ups.

Index

Install

npm install goten-react-text-field

Usage

var GotenTextField = require('goten-react-text-field').GotenTextField; // ES5
 
import { GotenTextField } from 'goten-react-text-field'; // ES6

refsGotenTextFieldWithPattern = React.createRef()
gotenTextFields = {}

<GotenTextField
    label={'Date Pattern'}
    placeholder={'Insert a date: dd/mm/yyyy'}
    type={'text'}
    pattern={'[0-9]{2}\/[0-9]{2}\/[0-9]{4}'}
    errorMessage={'Please insert a text using the correct pattern'}
    errorRequiredMessage={'This field is required'}
    required={true}
    showError={true}
    bindContainer={this.gotenTextFields}
    bindProp={'pattern'}
    ref={this.refsGotenTextFieldWithPattern}
/>

validate() {
    return refsGotenTextFieldWithPattern.current.validate()
}

Example of use

import React, { Component } from 'react'
import { GotenTextField } from 'goten-react-text-field'

const state = {
    changeOnPress: true
}

export default class App extends Component {
    constructor(props) {
        super(props)
        this.state = state
        this.refsGotenTextFieldWithPattern = React.createRef()
        this.gotenTextFields = {}
    }

    render() {
        return (
            <div>
                <div className='title'>GotenTextField</div>
                <GotenTextField
                    placeholder={'[0-9]{2}\/[0-9]{2}\/[0-9]{4}'}
                    // label={'Date Pattern'}
                    componentLabel={
                        <label>
                            Date Pattern
                        </label>
                    }
                    type={'text'} // email; number; password; date; time; url
                    pattern={'[0-9]{2}\/[0-9]{2}\/[0-9]{4}'}
                    errorMessage={'Please insert a text using the correct pattern'}
                    errorRequiredMessage={'This field is required'}
                    required={true}
                    showError={true}
                    bindContainer={this.gotenTextFields}
                    bindProp={'pattern'}
                    ref={this.refsGotenTextFieldWithPattern}
                />  
                <br/>
                <br/>
                <input
                    type='submit'
                    value='Validate And Show Input'
                    onClick={() => {
                        this.setState({changeOnPress: !this.state.changeOnPress})
                        this.refsGotenTextFieldWithPattern.current.validate()
                    }}
                />
            </div>
        )
    }
}

Props

| Prop Name | Type | Default | Description | | ---------------------|:------------- | :--------------- | -------------| | bindContainer | Object | | Container of the attributes that will be binded to the value of the text fields. | | bindProp | String | | Attribute`s name of the bindContainer object. | | componentLabel | Component | | Label component, same as 'label' but with a component. | | errorMessage | String, Component | String Message | Error message corresponding to the pattern or type. | | errorRequiredMessage | String, Component | String Message | Error message corresponding to the 'required' prop. | | label | String | | Label of the text field. | | pattern | String | | Pattern to validate the value of the text field with. | | placeholder | String | | Placeholder. | | required | Boolean | False | Whether the text field is required (true) or not.| | showError | Boolean | False | Whether to show error messages (true) or not. | | type | String | text | The text field's type. |

  • All other props are inherited from the react component input

Methods

  • validate()

Validate the GotenTextField using the props types, pattern and required.

  • clearError()

Clears the text field's error (if any).

  • clear()

Clears any text and errors the text field has.

Contributions

To contribute to this package, we use the following workflow:

  1. Add an issue with related tags to describe the contribution (is it a bug? a feature request?).
  2. Branch your solution from develop, naming it like #<issue_number>-<descriptive_name>.
  3. Send a pull request and wait for approval/corrections.