Components.Button Class
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(...);
}
}
});
Item Index
Methods
Methods
click
protectedClick 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
protectedThis will reset the state property to 'default', and with that the button's label to defaultText
Properties
active boolean
publicSet the 'active' class to apply active/pressed CSS styling
Default: false
classTypePrefix String
protectedDefault: 'btn'
defaultText string
publicDefault label of the button. Not need if used as a block component
disabled boolean
publicProperty to disable the button
Default: false
icon String
protectedClass(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
publicIf button is active and this is set, the icon property will match this property
iconInactive String
publicIf button is inactive and this is set, the icon property will match this property
reset boolean
publicSet this to true to reset the state. A typical use case is to bind this attribute with ember-data isDirty flag.
size String
publictextState String
protectedState 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
publicThe HTML title attribute
toggle boolean
publicIf toggle property is true, clicking the button will toggle the active state
Default: false
type String
publicDefault: 'default'
value any
publicSupply 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