API Docs 0.11.3.33c7ec07

public
Extends Ember.Component

Implements a HTML button element, with support for all Bootstrap button CSS styles as well as advanced functionality such as button states.

Basic Usage

{{#bs-button type="primary" icon="glyphicon glyphicon-download"}}
Downloads
{{/bs-button}}

Actions

Set the action property of the component to send an action to your controller. The following parameters will be sent:

  • value: the button's value, see the value property
  • event: the browsers event object
  • callback: a function that may be called from the action handler to supply a Promise to the button component for automatic state handling
{{#bs-button type="primary" icon="glyphicon glyphicon-download" action="download"}}
Download
{{/bs-button}}

States

Use the textState property to change the label of the button. You can bind it to a controller property to set a "loading" state for example. The label of the button will be taken from the <state>Text property.

{{bs-button type="primary" icon="glyphicon glyphicon-download" textState=buttonState defaultText="Download" loadingText="Loading..." action="download"}}
App.ApplicationController = Ember.Controller.extend({
  buttonState: "default"
  actions: {
    download: function() {
      this.set("buttonState", "loading");
    }
  }
});

Promise support for automatic state change

When returning a Promise for any asynchronous operation from the click closure action the button will manage its textState property automatically, changing its value according to the state of the promise: "default" > "pending" > "resolved"/"rejected"

{{bs-button type="primary" icon="glyphicon glyphicon-download" defaultText="Download" pendingText="Loading..." resolvedText="Completed!" rejectedText="Oups!?" action=(action "download")}}
// controller.js
export default Ember.Controller.extend({
  actions: {
    download(actionParam, evt) {
      return new Ember.RSVP.Promise(...);
    }
  }
});
Show:

Methods

click

protected

Click handler. This will send the default "action" action, with the following parameters:

  • value of the button (that is the value of the "value" property)
  • original event object of the click event
  • callback: call that with a promise object, and the buttons state will automatically set to "pending", "resolved" and/or "rejected"

When using closure actions just return the promise instead of calling the above mentioned callback.

Parameters:

  • evt Object

resetState

protected

This will reset the state property to 'default', and with that the button's label to defaultText

Properties

active boolean

public

Set the 'active' class to apply active/pressed CSS styling

Default: false

block boolean

public

Property for block level buttons

See the Bootstrap docs

Default: false

buttonType String

public

Set the type of the button, either 'button' or 'submit'

Default: 'button'

classTypePrefix String

protected

Inherited from Mixins.TypeClass but overwritten in addon/components/bs-button.js:86

Default: 'btn'

defaultText string

public

Default label of the button. Not need if used as a block component

disabled boolean

public

Property to disable the button

Default: false

icon String

protected

Class(es) (e.g. glyphicons or font awesome) to use as a button icon This will render a element in front of the button's label

iconActive String

public

If button is active and this is set, the icon property will match this property

iconInactive String

public

If button is inactive and this is set, the icon property will match this property

reset boolean

public

Set this to true to reset the state. A typical use case is to bind this attribute with ember-data isDirty flag.

size String

public
Property for size styling, set to 'lg', 'sm' or 'xs' Also see the [Bootstrap docs](http://getbootstrap.com/css/#buttons-sizes)

textState String

protected

State of the button. The button's label (if not used as a block component) will be set to the <state>Text property. This property will automatically be set when using a click action that supplies the callback with an promise

Default: 'default'

title string

public

The HTML title attribute

toggle boolean

public

If toggle property is true, clicking the button will toggle the active state

Default: false

type String

public
Property for type styling For the available types see the [Bootstrap docs](http://getbootstrap.com/css/#buttons-options) (use without "btn-" prefix)

Default: 'default'

value any

public

Supply a value that will be associated with this button. This will be send as a parameter of the default action triggered when clicking the button