@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
91 lines (90 loc) • 2.76 kB
JavaScript
"use client";
var _ProgressIndicator;
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Context from "../../shared/Context.js";
import ProgressIndicator from "../progress-indicator/ProgressIndicator.js";
export class PaginationIndicator extends React.PureComponent {
static contextType = Context;
static defaultProps = {
indicator_element: 'div'
};
render() {
const {
indicator_element
} = this.props;
const Element = preparePageElement(indicator_element);
const ElementChild = isTrElement(Element) ? 'td' : 'div';
return React.createElement(Element, null, React.createElement(ElementChild, {
className: "dnb-pagination__indicator"
}, React.createElement("div", {
className: "dnb-pagination__indicator__inner"
}, _ProgressIndicator || (_ProgressIndicator = React.createElement(ProgressIndicator, null)), this.context.getTranslation(this.props).Pagination.is_loading_text)));
}
}
process.env.NODE_ENV !== "production" ? PaginationIndicator.propTypes = {
indicator_element: PropTypes.oneOfType([PropTypes.object, PropTypes.node, PropTypes.func, PropTypes.string])
} : void 0;
export class ContentObject {
constructor({
pageNumber,
...props
}) {
this.content = null;
this.pageNumber = pageNumber;
this.hasContent = false;
for (let 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 React.forwardRef(({
className,
children,
...props
}, ref) => {
const params = {
...props,
className: classnames(includeClassName, className),
ref
};
return isTr ? React.createElement("td", null, React.createElement("div", params, children)) : React.createElement(Element, params, children);
});
}
return Element;
}
//# sourceMappingURL=PaginationHelpers.js.map