2.1.0 • Published 4 years ago

react-input-with-html v2.1.0

Weekly downloads
112
License
MIT
Repository
github
Last release
4 years ago

react-input-with-html

A react input component that uses contenteditable on a div to display the input value with html cut in for that touch of fancy

NPM JavaScript Style Guide bundle size

Install

npm install --save react-input-with-html

Usage

This is starting as a bit of a custom thing for Stocksy, but I plan on making it into a more broadly useful library.

Most of the custom props and usage just arn't in this readme.

Use this at your own risk for now.

import React, { useState } from 'react'
import HTMLInput from 'react-input-with-html'
// have to import style sheet for basic input styles and special hex option style
import 'react-input-with-html/dist/index.css'

const App = () => {
  const [input, setInput] = useState('')

  const handleSubmit = () => {
    // submit what is in the input state however you want here
    console.log('input on submit: ', input)
  }

  // basic style for +'s
  const modifierArr = [
    {
      regexMatch: /\+/g,
      htmlMod: `<span style="color: #a3a3a3">+</span>`
    }
  ]

  return (
    <HTMLInput
      id='input'
      value={input}
      onChange={setInput}
      onSubmit={handleSubmit}
      modifierArr={modifierArr}
      spellCheck={false}
      hexDot={true}
    />
  )
}

Available props

propdescriptiontype
idrequired: unique idString
modifierArrrequired: more on this belowArray of Objects
disableduse true to disable editingBoolean
onChangerequired: react hook for keeping input stateFunction
onBlurcalled whenever the html element is blurredFunction
onFocusevent fires when an element has received focusFunction
onKeyUpcalled whenever a key is releasedFunction
onKeyDowncalled whenever a key is pressedFunction
spellChecktoggles auto underlining spelling errorsBoolean
hexDotinfo for how to show hex dots after hex codesObj

hexDot obj = { enable: boolean style: { width: string height: string top: string left: string } }

Modifier Arr

This is the customizable part of this component.

You need to pass an Array of ModifierObj(s) see type below

type ModifierObj = {
  regexMatch: RegExp
  htmlModification: string | Function // need better function definition, it has to return a html represented as string
}

The regexMatch is a regular expression to find the instances you want to modify

The htmlModification is the string that includes the html for what you're changing it to. This can be a string or a function that returns the string.

put examples here...

Playground

will be more of a playground in the future

Try it out

Important Notes

don't use v1 of this library. It's a very limited concept with lots of bugs.

License

MIT © cbot83

2.1.0

4 years ago

2.1.0-beta.5

4 years ago

2.1.0-beta.4

4 years ago

2.1.0-beta.3

4 years ago

2.1.0-beta.2

4 years ago

2.1.0-beta.1

4 years ago

2.0.6

4 years ago

2.0.5-beta.8

4 years ago

2.0.5

4 years ago

2.0.5-beta.7

4 years ago

2.0.5-beta.6

4 years ago

2.0.5-beta.5

4 years ago

2.0.5-beta.4

4 years ago

2.0.5-beta.3

4 years ago

2.0.5-beta.2

4 years ago

2.0.5-beta.1

4 years ago

2.0.5-beta.0

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.4

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago