@carbon/react
Version:
React components for the Carbon Design System
48 lines (46 loc) • 1.62 kB
JavaScript
/**
* Copyright IBM Corp. 2016, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { usePrefix } from "../../../internal/usePrefix.js";
import { useId } from "../../../internal/useId.js";
import Select_default from "../../Select/index.js";
import SelectItem_default from "../../SelectItem/index.js";
import classNames from "classnames";
import "react";
import PropTypes from "prop-types";
import { jsx } from "react/jsx-runtime";
//#region src/components/Pagination/experimental/PageSelector.js
function PageSelector({ className = null, currentPage, id = 1, labelText = "Current page number", totalPages, ...other }) {
const namespace = `${usePrefix()}--unstable-pagination__page-selector`;
const instanceId = `${namespace}__select-${useId()}`;
const renderPages = (total) => {
const pages = [];
for (let counter = 1; counter <= total; counter += 1) pages.push(/* @__PURE__ */ jsx(SelectItem_default, {
value: counter,
text: String(counter)
}, counter));
return pages;
};
return /* @__PURE__ */ jsx(Select_default, {
className: classNames(namespace, className),
hideLabel: true,
id: instanceId || id,
inline: true,
labelText,
value: currentPage,
...other,
children: renderPages(totalPages)
});
}
PageSelector.propTypes = {
className: PropTypes.string,
currentPage: PropTypes.number.isRequired,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
labelText: PropTypes.string,
totalPages: PropTypes.number.isRequired
};
//#endregion
export { PageSelector as default };