123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import { __awaiter, __generator } from "tslib";
- import { useMemo, useState } from 'functional-mini/compat';
- import { useComponent, useEvent } from 'functional-mini/component';
- import { mountComponent } from '../_util/component';
- import { useEvent as useStableCallback } from '../_util/hooks/useEvent';
- import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
- import { PaginationDefaultProps } from './props';
- var Pagination = function () {
- var componentInstance = useComponent();
- var _a = useState(0), pageDeg = _a[0], setPageDeg = _a[1];
- function getInstance() {
- if (componentInstance.$id) {
- return my;
- }
- return componentInstance;
- }
- var clacWidth = useStableCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
- var instance, rect;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- instance = getInstance();
- return [4 /*yield*/, getInstanceBoundingClientRect(getInstance(), "#ant-pageInfinite-".concat(instance.$id ? "-".concat(instance.$id) : ''))];
- case 1:
- rect = _a.sent();
- if (rect) {
- return [2 /*return*/, rect.width];
- }
- return [2 /*return*/, 0];
- }
- });
- }); });
- useEvent('onScroll', function (e) { return __awaiter(void 0, void 0, void 0, function () {
- var _a, scrollLeft, scrollWidth, viewWidth;
- return __generator(this, function (_b) {
- switch (_b.label) {
- case 0:
- _a = e.detail, scrollLeft = _a.scrollLeft, scrollWidth = _a.scrollWidth;
- return [4 /*yield*/, clacWidth()];
- case 1:
- viewWidth = _b.sent();
- if (viewWidth) {
- setPageDeg(Math.ceil((scrollLeft / (scrollWidth - viewWidth)) * 100));
- }
- return [2 /*return*/];
- }
- });
- }); });
- var supportSjs = useMemo(function () {
- if (typeof my === 'undefined') {
- return true;
- }
- return my.canIUse('sjs.event');
- }, []);
- return {
- pageDeg: pageDeg,
- supportSjs: supportSjs,
- };
- };
- mountComponent(Pagination, PaginationDefaultProps);
|