3 exports.__esModule = true;
5 var _clickableComponent = require('./clickable-component.js');
7 var _clickableComponent2 = _interopRequireDefault(_clickableComponent);
9 var _component = require('./component');
11 var _component2 = _interopRequireDefault(_component);
13 var _log = require('./utils/log.js');
15 var _log2 = _interopRequireDefault(_log);
17 var _obj = require('./utils/obj');
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
21 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
25 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
31 * Base class for all buttons.
33 * @extends ClickableComponent
35 var Button = function (_ClickableComponent) {
36 _inherits(Button, _ClickableComponent);
39 _classCallCheck(this, Button);
41 return _possibleConstructorReturn(this, _ClickableComponent.apply(this, arguments));
45 * Create the `Button`s DOM element.
47 * @param {string} [tag=button]
48 * Element's node type. e.g. 'button'
50 * @param {Object} [props={}]
51 * An object of properties that should be set on the element.
53 * @param {Object} [attributes={}]
54 * An object of attributes that should be set on the element.
57 * The element that gets created.
59 Button.prototype.createEl = function createEl() {
60 var tag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'button';
61 var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
62 var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
64 props = (0, _obj.assign)({
65 className: this.buildCSSClass()
68 if (tag !== 'button') {
69 _log2['default'].warn('Creating a Button with an HTML element of ' + tag + ' is deprecated; use ClickableComponent instead.');
71 // Add properties for clickable element which is not a native HTML button
72 props = (0, _obj.assign)({
76 // Add ARIA attributes for clickable element which is not a native HTML button
77 attributes = (0, _obj.assign)({
82 // Add attributes for button element
83 attributes = (0, _obj.assign)({
85 // Necessary since the default button type is "submit"
88 // let the screen reader user know that the text of the button may change
92 var el = _component2['default'].prototype.createEl.call(this, tag, props, attributes);
94 this.createControlTextEl(el);
100 * Add a child `Component` inside of this `Button`.
102 * @param {string|Component} child
103 * The name or instance of a child to add.
105 * @param {Object} [options={}]
106 * The key/value store of options that will get passed to children of
109 * @return {Component}
110 * The `Component` that gets added as a child. When using a string the
111 * `Component` will get created by this process.
113 * @deprecated since version 5
117 Button.prototype.addChild = function addChild(child) {
118 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
120 var className = this.constructor.name;
122 _log2['default'].warn('Adding an actionable (user controllable) child to a Button (' + className + ') is not supported; use a ClickableComponent instead.');
124 // Avoid the error message generated by ClickableComponent's addChild method
125 return _component2['default'].prototype.addChild.call(this, child, options);
129 * Enable the `Button` element so that it can be activated or clicked. Use this with
130 * {@link Button#disable}.
134 Button.prototype.enable = function enable() {
135 _ClickableComponent.prototype.enable.call(this);
136 this.el_.removeAttribute('disabled');
140 * Enable the `Button` element so that it cannot be activated or clicked. Use this with
141 * {@link Button#enable}.
145 Button.prototype.disable = function disable() {
146 _ClickableComponent.prototype.disable.call(this);
147 this.el_.setAttribute('disabled', 'disabled');
151 * This gets called when a `Button` has focus and `keydown` is triggered via a key
154 * @param {EventTarget~Event} event
155 * The event that caused this function to get called.
161 Button.prototype.handleKeyPress = function handleKeyPress(event) {
163 // Ignore Space (32) or Enter (13) key operation, which is handled by the browser for a button.
164 if (event.which === 32 || event.which === 13) {
168 // Pass keypress handling up for unsupported keys
169 _ClickableComponent.prototype.handleKeyPress.call(this, event);
173 }(_clickableComponent2['default']);
175 _component2['default'].registerComponent('Button', Button);
176 exports['default'] = Button;