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