@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
96 lines (95 loc) • 2.5 kB
JavaScript
"use client";
var _ProgressIndicator;
import React from 'react';
import clsx from 'clsx';
import Context from "../../shared/Context.js";
import ProgressIndicator from "../progress-indicator/ProgressIndicator.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export const PaginationIndicator = ({
indicatorElement = 'div',
...props
}) => {
const context = React.useContext(Context);
const Element = preparePageElement(indicatorElement);
const ElementChild = isTrElement(Element) ? 'td' : 'div';
return _jsx(Element, {
children: _jsx(ElementChild, {
className: "dnb-pagination__indicator",
children: _jsxs("div", {
className: "dnb-pagination__indicator__inner",
children: [_ProgressIndicator || (_ProgressIndicator = _jsx(ProgressIndicator, {})), context.getTranslation(props).Pagination.isLoadingText]
})
})
});
};
export class ContentObject {
constructor({
pageNumber,
...props
}) {
this.content = null;
this.pageNumber = pageNumber;
this.hasContent = false;
for (const k in props) {
this[k] = props[k];
}
}
insert(content) {
this.hasContent = true;
this.content = content;
if (typeof this.onInsert === 'function') {
this.onInsert(this);
}
return this;
}
update(content) {
this.hasContent = true;
this.content = content;
if (typeof this.onUpdate === 'function') {
this.onUpdate(this);
}
return this;
}
}
export function isTrElement(Element) {
let isTr = false;
if (Element === 'tr') {
isTr = true;
} else if (Element && (typeof Element === 'object' || React.isValidElement(Element))) {
if ((Element.__emotion_base || Element.target) === 'tr') {
isTr = true;
}
}
return isTr;
}
export function preparePageElement(Element, includeClassName = 'dnb-pagination__page') {
if (String(Element) === 'Symbol(react.fragment)') {
return Element;
}
if (includeClassName) {
const isTr = isTrElement(Element);
return ({
className,
children,
ref,
...props
}) => {
const params = {
...props,
className: clsx(includeClassName, className),
ref
};
return isTr ? _jsx("td", {
children: _jsx("div", {
...params,
children: children
})
}) : _jsx(Element, {
...params,
children: children
});
};
}
return Element;
}
//# sourceMappingURL=PaginationHelpers.js.map