UNPKG

6.88 kBJavaScriptView Raw
1(function (global, factory) {
2 if (typeof define === "function" && define.amd) {
3 define(["exports", "warning", "../../globals/js/feature-flags", "../../globals/js/misc/mixin", "../../globals/js/mixins/create-component", "../../globals/js/mixins/init-component-by-event", "../../globals/js/mixins/handles", "../../globals/js/misc/on", "../removed-component"], factory);
4 } else if (typeof exports !== "undefined") {
5 factory(exports, require("warning"), require("../../globals/js/feature-flags"), require("../../globals/js/misc/mixin"), require("../../globals/js/mixins/create-component"), require("../../globals/js/mixins/init-component-by-event"), require("../../globals/js/mixins/handles"), require("../../globals/js/misc/on"), require("../removed-component"));
6 } else {
7 var mod = {
8 exports: {}
9 };
10 factory(mod.exports, global.warning, global.featureFlags, global.mixin, global.createComponent, global.initComponentByEvent, global.handles, global.on, global.removedComponent);
11 global.fab = mod.exports;
12 }
13})(this, function (_exports, _warning, _featureFlags, _mixin2, _createComponent, _initComponentByEvent, _handles, _on, _removedComponent) {
14 "use strict";
15
16 Object.defineProperty(_exports, "__esModule", {
17 value: true
18 });
19 _exports.default = void 0;
20 _warning = _interopRequireDefault(_warning);
21 _mixin2 = _interopRequireDefault(_mixin2);
22 _createComponent = _interopRequireDefault(_createComponent);
23 _initComponentByEvent = _interopRequireDefault(_initComponentByEvent);
24 _handles = _interopRequireDefault(_handles);
25 _on = _interopRequireDefault(_on);
26 _removedComponent = _interopRequireDefault(_removedComponent);
27
28 function _interopRequireDefault(obj) {
29 return obj && obj.__esModule ? obj : {
30 default: obj
31 };
32 }
33
34 function _typeof(obj) {
35 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
36 _typeof = function _typeof(obj) {
37 return typeof obj;
38 };
39 } else {
40 _typeof = function _typeof(obj) {
41 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
42 };
43 }
44
45 return _typeof(obj);
46 }
47
48 function _classCallCheck(instance, Constructor) {
49 if (!(instance instanceof Constructor)) {
50 throw new TypeError("Cannot call a class as a function");
51 }
52 }
53
54 function _defineProperties(target, props) {
55 for (var i = 0; i < props.length; i++) {
56 var descriptor = props[i];
57 descriptor.enumerable = descriptor.enumerable || false;
58 descriptor.configurable = true;
59 if ("value" in descriptor) descriptor.writable = true;
60 Object.defineProperty(target, descriptor.key, descriptor);
61 }
62 }
63
64 function _createClass(Constructor, protoProps, staticProps) {
65 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
66 if (staticProps) _defineProperties(Constructor, staticProps);
67 return Constructor;
68 }
69
70 function _possibleConstructorReturn(self, call) {
71 if (call && (_typeof(call) === "object" || typeof call === "function")) {
72 return call;
73 }
74
75 return _assertThisInitialized(self);
76 }
77
78 function _assertThisInitialized(self) {
79 if (self === void 0) {
80 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
81 }
82
83 return self;
84 }
85
86 function _getPrototypeOf(o) {
87 _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
88 return o.__proto__ || Object.getPrototypeOf(o);
89 };
90 return _getPrototypeOf(o);
91 }
92
93 function _inherits(subClass, superClass) {
94 if (typeof superClass !== "function" && superClass !== null) {
95 throw new TypeError("Super expression must either be null or a function");
96 }
97
98 subClass.prototype = Object.create(superClass && superClass.prototype, {
99 constructor: {
100 value: subClass,
101 writable: true,
102 configurable: true
103 }
104 });
105 if (superClass) _setPrototypeOf(subClass, superClass);
106 }
107
108 function _setPrototypeOf(o, p) {
109 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
110 o.__proto__ = p;
111 return o;
112 };
113
114 return _setPrototypeOf(o, p);
115 }
116
117 var didWarnAboutDeprecation;
118
119 var FabButton =
120 /*#__PURE__*/
121 function (_mixin) {
122 _inherits(FabButton, _mixin);
123 /**
124 * Floating action button.
125 * @extends CreateComponent
126 * @extends InitComponentByEvent
127 * @extends Handles
128 * @param {HTMLElement} element The element working as a floting action button.
129 */
130
131
132 function FabButton(element) {
133 var _this;
134
135 _classCallCheck(this, FabButton);
136
137 _this = _possibleConstructorReturn(this, _getPrototypeOf(FabButton).call(this, element));
138
139 if (process.env.NODE_ENV !== "production") {
140 process.env.NODE_ENV !== "production" ? (0, _warning.default)(didWarnAboutDeprecation, 'The `FabButton` component in `carbon-components` has been deprecated. It will be removed in the next major release.') : void 0;
141 didWarnAboutDeprecation = true;
142 }
143
144 _this.manage((0, _on.default)(element, 'click', function (event) {
145 _this.toggle(event);
146 }));
147
148 return _this;
149 }
150 /**
151 * A method called when this widget is created upon clicking.
152 * @param {Event} event The event triggering the creation.
153 */
154
155
156 _createClass(FabButton, [{
157 key: "createdByEvent",
158 value: function createdByEvent(event) {
159 this.toggle(event);
160 }
161 /**
162 * Toggles this floating action button.
163 * @param {Event} event The event triggering this method.
164 */
165
166 }, {
167 key: "toggle",
168 value: function toggle(event) {
169 if (this.element.tagName === 'A') {
170 event.preventDefault();
171 }
172
173 if (this.element.dataset.state === 'closed') {
174 this.element.dataset.state = 'open';
175 } else {
176 this.element.dataset.state = 'closed';
177 }
178 }
179 /**
180 * Instantiates floating action button of the given element.
181 * @param {HTMLElement} element The element.
182 */
183
184 }], [{
185 key: "create",
186 value: function create(element) {
187 return this.components.get(element) || new this(element);
188 }
189 /**
190 * The map associating DOM element and floating action button instance.
191 * @member FabButton.components
192 * @type {WeakMap}
193 */
194
195 }]);
196
197 FabButton.components = new WeakMap();
198 FabButton.options = {
199 selectorInit: '[data-fab]',
200 initEventNames: ['click']
201 };
202 return FabButton;
203 }((0, _mixin2.default)(_createComponent.default, _initComponentByEvent.default, _handles.default));
204
205 var _default = !_featureFlags.breakingChangesX ? FabButton : (0, _removedComponent.default)('FabButton');
206
207 _exports.default = _default;
208});
\No newline at end of file