UNPKG

shopperman

Version:

shopping cart ui for shopify stores

76 lines 3.61 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var mobx_1 = require("mobx"); var preact_1 = require("preact"); var mobx_preact_1 = require("mobx-preact"); var CartCheckout = /** @class */ (function (_super) { __extends(CartCheckout, _super); function CartCheckout() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.reactions = []; _this.lastItemsInCart = 0; _this.lastActiveItemsLength = 0; _this.handleCheckout = function (event) { _this.props.performCheckout(); event.preventDefault(); return false; }; return _this; } CartCheckout.prototype.componentWillMount = function () { var _this = this; this.reactions.push(mobx_1.reaction(function () { return _this.props.cart.activeItems.length; }, function (activeItemsLength) { var changed = activeItemsLength !== _this.lastActiveItemsLength; if (changed) { var itemsIncreased = activeItemsLength > _this.lastActiveItemsLength; if (itemsIncreased) { setTimeout(function () { var checkoutButton = _this.base.querySelector(".checkout-button"); if (checkoutButton) checkoutButton.focus(); }, 0); } } _this.lastActiveItemsLength = activeItemsLength; })); }; CartCheckout.prototype.componentWillUnmount = function () { for (var _i = 0, _a = this.reactions; _i < _a.length; _i++) { var reaction_1 = _a[_i]; reaction_1.dispose(); } this.reactions = []; }; CartCheckout.prototype.render = function () { var handleCheckout = this.handleCheckout; var _a = this.props, cart = _a.cart, cartCheckoutText = _a.cartCheckoutText; var cartIsEmpty = !cart.activeItems.length; return (preact_1.h("div", { className: "cart-checkout" }, preact_1.h("button", { className: "checkout-button", title: cartCheckoutText.title, onClick: handleCheckout, disabled: cartIsEmpty }, cartCheckoutText.content))); }; CartCheckout = __decorate([ mobx_preact_1.observer ], CartCheckout); return CartCheckout; }(preact_1.Component)); exports.CartCheckout = CartCheckout; //# sourceMappingURL=cart-checkout.js.map