| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.WizardToggle = void 0; |
| 4 |
const tslib_1 = require("tslib"); |
| 5 |
const jsx_runtime_1 = require("react/jsx-runtime"); |
| 6 |
const react_1 = require("react"); |
| 7 |
const react_styles_1 = require("@patternfly/react-styles"); |
| 8 |
const wizard_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Wizard/wizard")); |
| 9 |
const rh_microns_caret_right_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-microns-caret-right-icon')); |
| 10 |
const rh_microns_caret_down_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-microns-caret-down-icon')); |
| 11 |
const rh_ui_error_fill_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-ui-error-fill-icon')); |
| 12 |
const rh_ui_check_circle_fill_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-ui-check-circle-fill-icon')); |
| 13 |
const constants_1 = require("../../helpers/constants"); |
| 14 |
const types_1 = require("./types"); |
| 15 |
const WizardStep_1 = require("./WizardStep"); |
| 16 |
const WizardBody_1 = require("./WizardBody"); |
| 17 |
const WizardToggle = ({ steps, activeStep, footer, nav, isNavExpanded, toggleNavExpanded, 'aria-label': ariaLabel = 'Wizard toggle' }) => { |
| 18 |
const isActiveSubStep = (0, types_1.isWizardSubStep)(activeStep); |
| 19 |
const parentStep = isActiveSubStep && steps.find((step) => step.id === activeStep.parentId); |
| 20 |
const nonSubSteps = steps.filter((step) => !(0, types_1.isWizardSubStep)(step)); |
| 21 |
const wizardToggleIndex = nonSubSteps.indexOf(parentStep || activeStep) + 1; |
| 22 |
const isActiveStepStatus = activeStep.status; |
| 23 |
const handleKeyClicks = (0, react_1.useCallback)((event) => { |
| 24 |
if (isNavExpanded && event.key === constants_1.KeyTypes.Escape) { |
| 25 |
toggleNavExpanded === null || toggleNavExpanded === void 0 ? void 0 : toggleNavExpanded(event); |
| 26 |
} |
| 27 |
}, [isNavExpanded, toggleNavExpanded]); |
| 28 |
// Open/close collapsable navigation on keydown event |
| 29 |
(0, react_1.useEffect)(() => { |
| 30 |
const target = typeof document !== 'undefined' ? document.body : null; |
| 31 |
target === null || target === void 0 ? void 0 : target.addEventListener('keydown', handleKeyClicks, false); |
| 32 |
return () => { |
| 33 |
target === null || target === void 0 ? void 0 : target.removeEventListener('keydown', handleKeyClicks, false); |
| 34 |
}; |
| 35 |
}, [handleKeyClicks]); |
| 36 |
const bodyContent = steps.map((step) => { |
| 37 |
var _a; |
| 38 |
const props = ((_a = step.component) === null || _a === void 0 ? void 0 : _a.props) || {}; |
| 39 |
const { children, body } = props, propsWithoutChildren = tslib_1.__rest(props, ["children", "body"]); |
| 40 |
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(activeStep === null || activeStep === void 0 ? void 0 : activeStep.id) === step.id && (0, jsx_runtime_1.jsx)(WizardBody_1.WizardBody, Object.assign({}, body, { children: children })), (0, jsx_runtime_1.jsx)("div", { style: { display: 'none' }, children: (0, jsx_runtime_1.jsx)(WizardStep_1.WizardStep, Object.assign({}, propsWithoutChildren)) }, step.id)] }, step.id)); |
| 41 |
}); |
| 42 |
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("button", { onClick: toggleNavExpanded, className: (0, react_styles_1.css)(wizard_1.default.wizardToggle, isNavExpanded && 'pf-m-expanded'), "aria-label": ariaLabel, "aria-expanded": isNavExpanded, children: [(0, jsx_runtime_1.jsxs)("span", { className: (0, react_styles_1.css)(wizard_1.default.wizardToggleList), children: [(0, jsx_runtime_1.jsxs)("span", { className: (0, react_styles_1.css)(wizard_1.default.wizardToggleListItem, isActiveStepStatus === 'error' && wizard_1.default.modifiers.danger, isActiveStepStatus === 'success' && wizard_1.default.modifiers.success), children: [isActiveStepStatus === 'error' && ((0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(wizard_1.default.wizardToggleStatusIcon), children: (0, jsx_runtime_1.jsx)(rh_ui_error_fill_icon_1.default, {}) })), isActiveStepStatus === 'success' && ((0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(wizard_1.default.wizardToggleStatusIcon), children: (0, jsx_runtime_1.jsx)(rh_ui_check_circle_fill_icon_1.default, {}) })), isActiveStepStatus !== 'success' && isActiveStepStatus !== 'error' && ((0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(wizard_1.default.wizardToggleNum), children: wizardToggleIndex })), ' ', (parentStep === null || parentStep === void 0 ? void 0 : parentStep.name) || (activeStep === null || activeStep === void 0 ? void 0 : activeStep.name), isActiveSubStep && ((0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(wizard_1.default.wizardToggleSeparator), children: (0, jsx_runtime_1.jsx)(rh_microns_caret_right_icon_1.default, {}) }))] }), isActiveSubStep && (0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(wizard_1.default.wizardToggleListItem), children: activeStep === null || activeStep === void 0 ? void 0 : activeStep.name })] }), (0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(wizard_1.default.wizardToggleIcon), children: (0, jsx_runtime_1.jsx)(rh_microns_caret_down_icon_1.default, {}) })] }), (0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(wizard_1.default.wizardOuterWrap), children: [(0, jsx_runtime_1.jsxs)("div", { className: (0, react_styles_1.css)(wizard_1.default.wizardInnerWrap), children: [nav, bodyContent] }), footer] })] })); |
| 43 |
}; |
| 44 |
exports.WizardToggle = WizardToggle; |
| 45 |
exports.WizardToggle.displayName = 'WizardToggle'; |
| 46 |
//# sourceMappingURL=WizardToggle.js.map |