@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
108 lines (107 loc) • 6.17 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JumpToLastButton = exports.StepToNextButton = exports.StepToPreviousButton = exports.JumpToFirstButton = exports.PaginationControls = exports.paginationControlsStencil = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const React = __importStar(require("react"));
const canvas_system_icons_web_1 = require("@workday/canvas-system-icons-web");
const common_1 = require("@workday/canvas-kit-react/common");
const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
const layout_1 = require("@workday/canvas-kit-react/layout");
const button_1 = require("@workday/canvas-kit-react/button");
const canvas_tokens_web_1 = require("@workday/canvas-tokens-web");
const usePaginationModel_1 = require("./usePaginationModel");
exports.paginationControlsStencil = (0, canvas_kit_styling_1.createStencil)({
base: { name: "32ivvi", styles: "box-sizing:border-box;display:flex;gap:var(--cnvs-sys-space-x1);align-items:center;" }
}, "pagination-controls-103bfc");
const controlButtonStencil = (0, canvas_kit_styling_1.createStencil)({
base: { name: "17g8a", styles: "box-sizing:border-box;&:dir(rtl){& .wd-icon{transform:scaleX(-1);}}" }
}, "control-button-595088");
exports.PaginationControls = (0, common_1.createComponent)('div')({
displayName: 'Pagination.Controls',
Component(elemProps, ref, Element) {
return (0, jsx_runtime_1.jsx)(Element, { ref: ref, ...(0, layout_1.mergeStyles)(elemProps, (0, exports.paginationControlsStencil)()) });
},
});
exports.JumpToFirstButton = (0, common_1.createComponent)('button')({
displayName: 'Pagination.JumpToFirstButton',
Component({ onClick, ...restProps }, ref, Element) {
const model = React.useContext(usePaginationModel_1.PaginationContext);
const isDisabled = model.state.currentPage <= model.state.firstPage;
const handleClick = (e) => {
if (isDisabled) {
return;
}
onClick === null || onClick === void 0 ? void 0 : onClick(e);
model.events.setCurrentPage(model.state.firstPage);
};
return ((0, jsx_runtime_1.jsx)(button_1.TertiaryButton, { ref: ref, as: Element, "aria-disabled": isDisabled || undefined, size: "small", icon: canvas_system_icons_web_1.chevron2xLeftSmallIcon, onClick: handleClick, ...(0, layout_1.mergeStyles)(restProps, controlButtonStencil()) }));
},
});
exports.StepToPreviousButton = (0, common_1.createComponent)('button')({
displayName: 'Pagination.StepToPreviousButton',
Component({ onClick, ...restProps }, ref, Element) {
const model = React.useContext(usePaginationModel_1.PaginationContext);
const isDisabled = model.state.currentPage <= model.state.firstPage;
const handleClick = (e) => {
if (isDisabled) {
return;
}
onClick === null || onClick === void 0 ? void 0 : onClick(e);
model.events.setCurrentPage(model.state.currentPage - 1);
};
return ((0, jsx_runtime_1.jsx)(button_1.TertiaryButton, { ref: ref, as: Element, "aria-disabled": isDisabled || undefined, size: "small", icon: canvas_system_icons_web_1.chevronLeftSmallIcon, onClick: handleClick, ...(0, layout_1.mergeStyles)(restProps, controlButtonStencil()) }));
},
});
exports.StepToNextButton = (0, common_1.createComponent)('button')({
displayName: 'Pagination.StepToNextButton',
Component({ onClick, ...restProps }, ref, Element) {
const model = React.useContext(usePaginationModel_1.PaginationContext);
const isDisabled = model.state.currentPage >= model.state.lastPage;
const handleClick = (e) => {
if (isDisabled) {
return;
}
onClick === null || onClick === void 0 ? void 0 : onClick(e);
model.events.setCurrentPage(model.state.currentPage + 1);
};
return ((0, jsx_runtime_1.jsx)(button_1.TertiaryButton, { ref: ref, as: Element, "aria-disabled": isDisabled || undefined, size: "small", icon: canvas_system_icons_web_1.chevronRightSmallIcon, onClick: handleClick, ...(0, layout_1.mergeStyles)(restProps, controlButtonStencil()) }));
},
});
exports.JumpToLastButton = (0, common_1.createComponent)('button')({
displayName: 'Paganation.JumpToLastButton',
Component({ onClick, ...restProps }, ref, Element) {
const model = React.useContext(usePaginationModel_1.PaginationContext);
const isDisabled = model.state.currentPage >= model.state.lastPage;
const handleClick = (e) => {
if (isDisabled) {
return;
}
onClick === null || onClick === void 0 ? void 0 : onClick(e);
model.events.setCurrentPage(model.state.lastPage);
};
return ((0, jsx_runtime_1.jsx)(button_1.TertiaryButton, { ref: ref, as: Element, "aria-disabled": isDisabled || undefined, size: "small", icon: canvas_system_icons_web_1.chevron2xRightSmallIcon, onClick: handleClick, ...(0, layout_1.mergeStyles)(restProps, controlButtonStencil()) }));
},
});