(function () {
'use strict';
/**
* The ButtonTableRow class provides functionality to work with table rows.
*
* @class ButtonTableRow
*/
var ButtonTableRow = createReactClass({
// Allows validating props being passed to the component.
propTypes: {
/**
* List of the commands the button is able to handle.
*
* @instance
* @memberof ButtonTableRow
* @property {Array} commands
*/
commands: PropTypes.arrayOf(PropTypes.object),
/**
* The editor instance where the component is being used.
*
* @instance
* @memberof ButtonTableRow
* @property {Object} editor
*/
editor: PropTypes.object.isRequired,
/**
* Indicates whether the styles list is expanded or not.
*
* @instance
* @memberof ButtonTableRow
* @property {Boolean} expanded
*/
expanded: PropTypes.bool,
/**
* The label that should be used for accessibility purposes.
*
* @instance
* @memberof ButtonTableRow
* @property {String} label
*/
label: PropTypes.string,
/**
* The tabIndex of the button in its toolbar current state. A value other than -1
* means that the button has focus and is the active element.
*
* @instance
* @memberof ButtonTableRow
* @property {Number} tabIndex
*/
tabIndex: PropTypes.number,
/**
* Callback provided by the button host to notify when the styles list has been expanded.
*
* @instance
* @memberof ButtonTableRow
* @property {Function} toggleDropdown
*/
toggleDropdown: PropTypes.func
},
// Lifecycle. Provides static properties to the widget.
statics: {
/**
* The name which will be used as an alias of the button in the configuration.
*
* @default tableRow
* @memberof ButtonTableRow
* @property {String} key
* @static
*/
key: 'tableRow'
},
/**
* Lifecycle. Renders the UI of the button.
*
* @instance
* @memberof ButtonTableRow
* @method render
* @return {Object} The content which should be rendered.
*/
render: function() {
var buttonCommandsList;
var buttonCommandsListId;
if (this.props.expanded) {
buttonCommandsListId = ButtonTableRow.key + 'List';
buttonCommandsList = <AlloyEditor.ButtonCommandsList commands={this._getCommands()} editor={this.props.editor} listId={buttonCommandsListId} onDismiss={this.props.toggleDropdown} />
}
return (
<div className="ae-container ae-has-dropdown">
<button aria-expanded={this.props.expanded} aria-label={AlloyEditor.Strings.row} aria-owns={buttonCommandsListId} className="ae-button" onClick={this.props.toggleDropdown} role="combobox" tabIndex={this.props.tabIndex} title={AlloyEditor.Strings.row}>
<span className="ae-icon-row"></span>
</button>
{buttonCommandsList}
</div>
);
},
/**
* Returns a list of commands. If a list of commands was passed
* as property `commands`, it will take a precedence over the default ones.
*
* @instance
* @memberof ButtonTableRow
* @method _getCommands
* @protected
* @return {Array} The list of available commands.
*/
_getCommands: function () {
return this.props.commands || [
{
command: 'rowInsertBefore',
label: AlloyEditor.Strings.rowInsertBefore
},
{
command: 'rowInsertAfter',
label: AlloyEditor.Strings.rowInsertAfter
},
{
command: 'rowDelete',
label: AlloyEditor.Strings.rowDelete
}
];
}
});
AlloyEditor.Buttons[ButtonTableRow.key] = AlloyEditor.ButtonTableRow = ButtonTableRow;
}());