GithubHelp home page GithubHelp logo

riek's Introduction

React Inline Edit Kit

An assortment of common HTML form elements, editable in-line the React way.

Try out the demo and see what it looks like.

Installation

npm install riek --save-dev

or

yarn add riek --dev

Use --save-dev because you don't want to build and pack JS/CSS in production

Usage

Import the library:

import { RIEToggle, RIEInput, RIETextArea, RIENumber, RIETags, RIESelect } from 'riek'
import _ from 'lodash'

Suppose we want to be able to edit title of a Task and send changes to server. Here is a Task stored flat inside of our parent React component:

this.state = {
  id: 1,
  title: 'Cover with tests',
  completed: false
}

Now we need a function which will send the single altered { key: value } and upsert local state. You can implement it inside of your flux/redux/mobx store:

const httpTaskCallback = (task) => {
  request.post(`/api/task/${this.state.id}`)
    .send(task)
    .end((err, res) => {
      if (!err) return this.setState({ ...task })
      // Handle HTTP error
    })
}

Meanwhile, there is a simple Express handler on our API server:

app.use('/api/task/:id', async (req, res) => {
  // req.body will equal to { title: 'A new title' }
  const { id } = req.params
  await Task.update({ ...req.body }).where({ id })
  res.send('OK')
})

Finally, in our render method, we add a minimal RIEInput:

<RIEInput
  value={this.state.text}
  change={this.httpTaskCallback}
  propName='title'
  validate={_.isString} />

...repeat the last step, adding a Riek component for any object property we wish to edit.

Components come unstyled, so take a look at demo.jsx for examples.

Common props

Required

  • value: initial prop value
  • propName: name of the prop to return to the change function
  • change: function which will receive a plain object with a single key, provided in propName

Optional

  • validate: validator function, returning a boolean
  • shouldBlockWhileLoading: disables editing until a new value is confirmed by parent
  • shouldRemainWhileInvalid: remain in editing mode if validation fails
  • defaultProps: Additional props for idle component.

Customization

  • classLoading: CSS class name to use when loading
  • classEditing: CSS class name to apply while in editing mode
  • classInvalid: CSS class name to apply when validate returned false
  • className: CSS base class
  • editProps: Additional props for the editing component. This allows you to, for example, specify a maxLength attribute to control the maximum number of characters in the textarea, or add style.

Hooks

  • beforeStart: Fires before editing starts
  • afterStart: Fires after editing starts
  • beforeFinish: Fires before editing ends, before validations
  • afterFinish: Fires after editing ends, after validations

Component-specific props

RIENumber

  • format: custom formatting function, returns formatted string

RIETextArea

  • rows: rows property on textarea tag while editing
  • cols: rows property on textarea tag while editing

RIESelect

  • options: an array of objects containing values and text for select options
<RIESelect ... options={[
  {id: '1', text: 'one'},
  {id: '2', text: 'two'},
  {id: '3', text: 'three'}
]} />

Contributing

The build process does not work with Node v6 at the moment: use Node Version Manager, or just plain Node v5.6.0.

  1. Clone this repo locally, run npm i
  2. Make your changes
  3. Do npm run build to compile the lib and demo
  4. Open index.html and check if it works
  5. Open JS console in browser, set localStorage.debug = '*' to see debug messages, add more if necessary
  6. ???
  7. Submit a pull request

riek's People

Contributors

devvmh avatar emerzh avatar errorname avatar galileo avatar jackbackes avatar kaivi avatar murphysierra avatar nk1tz avatar springuper avatar swilson96 avatar tda avatar tim-phillips avatar ugputu18 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

riek's Issues

In IE not properly working

In IE textarea is not working properly.
ie issue
As you can see in the above gif, on blur is not working properly and sometime it is opening and immediately closing. In chrome it is working fine

RIEInput doesn't pass down ID prop

I want to give an id (as in the vanilla HTML attribute) to the rendered <span>, but it seems like <RIEInput> doesn't pass it through.

Empty value causes edit field to disappear

If there is no data in the input field, the element vanishes and the user cannot put in a new value. E.g., in the demo, click the "Example text value" value, erase it, press enter, and you're hosed.

How to add autocomplete to a riek field?

Hi

I need to add word completion to some of my riek fields. Currently I am using Awesomplete [1] in my project, and according to the documentation a very simple setup would be, with no explicit Javascript needed (after including css and js):

<input class="awesomplete" list="mylist" />
<datalist id="mylist">
	<option>Ada</option>
	<option>Java</option>
	<option>JavaScript</option>
	<option>Brainfuck</option>
	<option>LOLCODE</option>
	<option>Node.js</option>
	<option>Ruby on Rails</option>
</datalist>

However, it doesn't seem like riek preserves the list attribute. The field is defined:

<RIEInput change={propObj => this.onChange(index, propObj)}
                    className="awesomplete"
                    list="mylist"
                    propName="name"
                    value=""
                    {...validator} />

The Chrome inspection tool shows me that in editing mode the field is:

<input class="awesomplete" value="hat">

The list attribute is missing and awesomplete does not work. Is there some way to make this work or to add any other word completion to a riek field?

Thank you,

[1] http://leaverou.github.io/awesomplete/

w/o propName

if propName is unset then call change back with just value instead of state with [propName]

Change handler does not fire in iOS Safari upon element blur

In iOS Safari, the change handler doesn't fire upon element blur, likely because iOS handles blur events differently than a desktop browser.

Not sure the best way to handle this case. You could perhaps add a global window onClick/onTouchTap handler to pretend like the element has been blurred.

Steps to reproduce:

  1. Render a <RIETextArea /> with a change prop bound to an event handler.
  2. Open the page in Safari on iOS.
  3. Click the field to edit and enter a value.
  4. Click anywhere else on the page that isn't a focusable element.

Note that the field remains editable and the change handler does not fire.

Validator required (?)

Hello! It seems to me that RIEInput requires a validation function or else it always fails validation.

Here https://github.com/kaivi/riek/blob/master/src/RIEBase.js#L52 if there is no validator set, the state is set as invalid. RIEInput is never given a validator that defaults to true.

This is a breaking change from earlier versions and I suspect it's a bug because the docs mark validator as optional.

Inline style doesn't seem to work

When I pass in an inline style to the style prop like:

            <RIEInput
                value={this.props.item.get('name')}
                style={{
                  color: itemTypeColor,
                  textTransform: 'uppercase',
                }}
                propName={"itemName"}
                change={itemNameChange}
              />

The color doesn't change and the text transform doesn't take effect.

Add custom render?

Maybe you could add custom render function in future , because I would like to use it with Highlighter to highlight for searching word when not editing. I managed to make it work like this with workaround but , still could be good idea for custom rendering ;)

Add support for react 15

Hello,

is it possible to add support for react 15?
it seems that it sill work...
and it should be just about changing the dependencies to smth like :

 "react": "^0.14.0 || ^15.0.0"

RIETextArea auto open disabled attribute

When delete all of content in RIETextArea and save it. Then edit it, delete all of content and save again. Finally, edit it again, this textarea will be disabled. (ps: 'Add a Description' just is like a placeholder )

<textarea ### **disabled=""** class="editing loading" maxlength="1000">Add a Description</textarea>

One cannot set TextArea to empty

Steps:

  1. Load the textarea with some text.
  2. Delete text in the textarea. (Maybe you want it to be empty)
  3. Focus on another element
Uncaught TypeError: value.split is not a function
    at RIETextArea._this.renderNormalComponent (RIETextArea.js:63)
    at RIETextArea.RIEStatefulBase._this.render (RIEStatefulBase.js:142)
    at ReactCompositeComponent.js:796

Custom Formatting OnMouseOver with Edit Pencil and Confirmation buttons

Hi there,

I'm planning to use this plugin! Thanks a lot for making it!!!

My use case is the following an Edit pencil when highlighting and giving the option to Confirm (V) or Cancel (X) the action. Here are the examples...

  • Showing regular fields WITHOUT MouseOver

screen shot 2017-06-07 at 10 18 07 pm

  • Showing regular fields WITH MouseOver

screen shot 2017-06-07 at 10 18 14 pm

  • Clicking on the Field with Confirmation buttons

screen shot 2017-06-07 at 10 18 23 pm

Other options also include showing highlighted values in drop-down values...

  • Highlighted results

screen shot 2017-06-07 at 10 18 37 pm

Questions

  • How can I achieve that?
  • Any example available?

Integrate react-edit ideas?

Hi,

I did incidentally something similar at react-edit. I extracted it from my table implementation so that shaped the API somewhat.

I wonder if it would make sense to merge these components somehow. If it was possible to get the edit wrapper to riek and port boolean to it (it's a little different there), that would allow me to deprecate react-edit in favor of a more established option.

RIEInput is disabled after being edited

I'm using React and Material UI table.
I want to make the table cells editable so I put a RIEInput in a cell of the table.
The problem is that after being edited, the RIEInput is disabled :

projet sans titre 1

you can see that the 'loading' state remains to 'true' after leaving focus the element.

here is my code :

      <TableRow key={index}>
          <TableRowColumn>
            <RIEInput
              value={item.title}
              change={(text) =>self.updateTitle(text, item.ID)}
              propName="text"
              validate={_.isString}
                />
          </TableRowColumn>
        </TableRow>

how can I manage this strange behavior?

Validation doesn't work?

I'm looking at the demo page and when I set the value of the number input to an odd number, the input accepts the change and doesn't warn me that the value is invalid. It is supposed to enforce value % 2 = 0 unless I am missing something?

ambiguous 'loading' mode

the RIEInput component assumes it is in loading mode as soon as you edit any value and assumes it is out of loading mode as soon as it receives a 'props' update.

This is not a robust mechanism for detecting loading state.

EDIT:

There should be an explicity property isLoading in the component so we can tell if its loading or not.

Editing state should remain if validation fails even if focus is lost

A user may have spent a long time entering new text in an input or text area field. If the user clicks somewhere else, and for some reason (e.g. maximum length exceeded) validation fails, all new text is lost as the field reverts to the non-editing state with old text.

Such a user experience is unacceptable, as a lot of time would have been wasted by the user and he or she would feel angry.

Therefore, if validation fails, the field should remain in editing state so that the user is given a chance to make corrections.

no windows either

I guess this is just an iOS software tool, this DOES NOT RUN on Windows... will play with it and see what makes it tick.

Is this project dead?

I really like the idea of this project, however it definitely still needs some features + bugfixes. It seems that nothing has been contributed to the main codebase for almost a year now, even with PRs stacking up.

I'm just curious if this project, as it is, is dead and no longer maintained by @kaivi ? If so, I'd be interested in picking it up or at least helping with sifting through issues/PRs to merge on a different repo.

RIENumber Error

When using the RIENumber element an error is thrown in Chrome:

RIEBase.js:36 Uncaught DOMException: Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('number') does not support selection.

And in firefox no errors are thrown, but the input does not become editable.

Avoid re-render (so editable input blur) when parent container renders

Currently, as far as the parent component is rendered, the RIEInput component is also rendered so, even if the user was editing the input, the RIEInput assumes that the parent has provided him with a new value and hides the <input> (producing mouse blur and so on).

So finally, I had to write a simple wrapper component which just holds a RIEInput component, and implements shouldComponentUpdate(nextProps, nextState) returning false if the newProps.value === this.props.value.

Of course, this makes imposible for the parent component to change other RIEInput props such as `className, and so on, but it becomes much more easier to use.

So, shouldn't RIEInput internally implement something like this?

Support React v16

@kaivi Any plans to bump peerDeps to support react 16? I can do pull request if you'd like. Been using this in a project with React 16 for a month with no issues so far.

Tag input broken?

I get the following issue when trying to add values to a RIETags element:

Uncaught TypeError: _this2.props.value.add is not a function(โ€ฆ)

If I try to remove a tag, I get the following:

newSet.delete is not a function

My change event doesn't fire regardless.

selectInputText behaviour

It would be nice if we could get more custom behavior for what happens when an input is in edit mode. For instance, cursor at end of line, start of line ( normal focus ) or all highlighted.

current implementation:

selectInputText = (element) => {

which is invoked directly after focus() I noticed the behavior is different in a handful of other components

Some Clarity on Prop value for RIESelect

Thanks for creating this - it's a great component.
Just a suggestion: on first use it wasn't clear that RIESelect needs a value of {id: XXX, text:YYY} rather than just the id. It may be worth adding a note to the README.md.

Ability to have nulls/blanks

There are instances that the value should be a null with a place holder. I cant seems to find a way to do this. Any help will be greatly appreciated.

Thanks,
Chat.

Warning: componentWillReceiveProps has been renamed, and is not recommended for use

With riek 1.1.0 and react ^16.12.0 I see this error in the browser console:

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

Please update the following components: RIEInput, RIENumber, RIESelect react-dom.development.js:12357

Validation error messages?

Is there a way to set in the input (for example RIENumber), an inline message with the errors returned from server after changing the input value? I could use client side validation of course but that doesn't guarantee nothing. Because reading through the documentation and demo i could only find that i can style it when invalid but not set an error message.

Thanks

isDisabled is, well, disabled.

The src for RIEBase has the prop isDisabled, but it is currently no-op. The expected functionality would be to prevent firing startEditing, or somehow prevent switching to the editing: true state. I believe this could be accomplished by adding a single line to the startEditing method:
if(this.props.isDisabled) return;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.