@ohu-mobile/core
Version:
74 lines (73 loc) • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _stickybits = _interopRequireDefault(require("stickybits"));
var _defineComponent = require("../_utils/defineComponent");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var eventMap = {
default: 'normal',
sticky: 'fixed',
stuck: 'stuck'
};
var Sticky = (0, _defineComponent.defineComponent)('sticky').create({
props: {
top: (0, _defineComponent.props)(Number).default(0),
bottom: (0, _defineComponent.props)(Number).optional,
disableEvents: (0, _defineComponent.props)(Boolean).default(false),
useFixed: (0, _defineComponent.props)(Boolean).default(false),
tag: (0, _defineComponent.props)(String).default('div')
},
computed: {
options: function options() {
var _this = this;
var stickyOptions = {
useStickyClasses: !this.disableEvents,
useFixed: this.useFixed,
applyStyle: function applyStyle(_, instance) {
var state = instance.state;
if (state && eventMap[state]) {
_this.$emit(eventMap[state], state);
}
}
};
if (this.top !== undefined) {
stickyOptions.stickyBitStickyOffset = this.top;
}
if (this.bottom !== undefined) {
stickyOptions.stickyBitStickyOffset = this.bottom;
stickyOptions.verticalPosition = 'bottom';
}
return stickyOptions;
}
},
mounted: function mounted() {
var _this2 = this;
var el = this.$refs.stickyEl;
if (el) {
var instance = (0, _stickybits.default)(el, this.options);
this.$once('hook:updated', function () {
instance.update(_this2.options);
});
this.$once('hook:beforeDestroy', function () {
instance.cleanup();
});
}
},
render: function render(h) {
var node = this.$slots.default && this.$slots.default[0];
var style = {};
if (this.bottom !== undefined) {
style.bottom = this.bottom + 'px';
} else {
style.top = this.top + 'px';
}
return h(this.tag, {
class: this.$rootCls(),
style: style,
ref: 'stickyEl'
}, [node]);
}
});
var _default = exports.default = Sticky;