Giter VIP home page Giter VIP logo

ember-inline-edit's Introduction

Ember Observer Score CircleCI

ember-inline-edit

ember-inline-edit provides inline editing for your ember apps. Has basic keyboard support, too.

Installation

ember install ember-inline-edit

Usage

Use the ember-inline-edit component and provide it a default value.

  {{ember-inline-edit
    value=value}}

This will give you a component that can be edited inline. By default, it is a textfield. You can, however, change the field type. Here's how:

  {{ember-inline-edit
    value=value
    field='textarea'}}

This will make it a textarea. The current supported types are: text, email, phone, textarea (if you need more, feel free to create an issue).

It also exposes an action onSave that is called (with the value as an argument) when the user hits save. Here's how that works:

  {{ember-inline-edit
    value=value
    field='textarea'
    onSave=(action (mut someValue))}}

There's an onClose action that is called when the editor is closed (either by clicking outside or pressing the esc key). You can use this to handle cases where, for example, you want to rollback unsaved changes.

Here's how you can use that:

  {{ember-inline-edit
    value=value
    field='textarea'
    onSave=(action (mut someValue))
    onClose=(action "rollback" "attr")}}

By default, name the value is empty, it says 'Not provided'. You have the option to customize that. Here's how you can do that:

  {{ember-inline-edit
    value=value
    placeholder='It is empty'
    field='textarea'
    onSave=(action (mut someValue))}}

With this, if the value is empty, it will show It is empty instead.

By default, the save button is labeled 'Save'. You can change that easily:

  {{ember-inline-edit
    value=value
    field='text'
    saveLabel=''
    onSave=(action (mut someValue))}}

Editing can be conditionally prevented with the enabled property. When the component becomes disabled, the onClose event will be fired.

  {{ember-inline-edit
    value=value
    enabled=session.isAuthenticated
    onSave=(action (mut someValue))}}

There's no styling provided by default. Feel free to add your own.

Block Usage

In case you need to go beyond the default textfields and control what shows as the editable (say an header tag) and what shows as the editor (say a custom select component), you can do that too.

Here’s an example:

  {{#ember-inline-edit value=value as |inline-edit|}}
    {{#inline-edit.editable}}
      <h3>Edit this</h3>
    {{/inline-edit.editable}}

    {{#inline-edit.editor field="textarea"}}
      <select id="some-select" name="some-name">
        <option value="option-1">Option 1</option>
        <option value="option-2">Option 2</option>
      </select>
    {{/inline-edit.editor}}
  {{/ember-inline-edit}}

Everything else (the actions, keyboard support, etc.) works just the same.

Keyboard Support

Inside the inputs (the textarea, input fields, etc.), if the user hits enter, it does exactly what a click on the save button would do (i.e. sends an onSave action and closes the editor).

If the user hits esc, the editor closes and sends the onClose action.

Issues? Bugs?

Please report any issues or bugs you find.

ember-inline-edit's People

Contributors

ember-tomster avatar oskarrough avatar suryaprasad7500 avatar

Watchers

 avatar

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.