| 1 |
import { __rest } from "tslib"; |
| 2 |
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; |
| 3 |
import { useEffect, useState } from 'react'; |
| 4 |
import { css } from '@patternfly/react-styles'; |
| 5 |
import styles from '@patternfly/react-styles/css/components/Wizard/wizard.mjs'; |
| 6 |
import RhMicronsCaretDownIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-down-icon'; |
| 7 |
import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon'; |
| 8 |
import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon'; |
| 9 |
import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon'; |
| 10 |
import { useOUIAProps } from '../../helpers'; |
| 11 |
import { WizardNavItemStatus } from './types'; |
| 12 |
export const WizardNavItem = (_a) => { |
| 13 |
var { children = null, content = '', isCurrent = false, isDisabled = false, |
| 14 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 15 |
isVisited = false, stepIndex, onClick, component: NavItemComponent = 'button', href, isExpandable = false, id, status = 'default', target, ouiaId, ouiaSafe = true, className } = _a, props = __rest(_a, ["children", "content", "isCurrent", "isDisabled", "isVisited", "stepIndex", "onClick", "component", "href", "isExpandable", "id", "status", "target", "ouiaId", "ouiaSafe", "className"]); |
| 16 |
const [isExpanded, setIsExpanded] = useState(false); |
| 17 |
const ouiaProps = useOUIAProps(WizardNavItem.displayName, ouiaId, ouiaSafe); |
| 18 |
useEffect(() => { |
| 19 |
setIsExpanded(isCurrent); |
| 20 |
}, [isCurrent]); |
| 21 |
if (NavItemComponent === 'a' && !href && process.env.NODE_ENV !== 'production') { |
| 22 |
// eslint-disable-next-line no-console |
| 23 |
console.error('WizardNavItem: When using an anchor, please provide an href'); |
| 24 |
} |
| 25 |
return (_jsxs("li", Object.assign({ className: css(styles.wizardNavItem, isExpandable && styles.modifiers.expandable, isExpandable && isExpanded && styles.modifiers.expanded, className) }, props, { children: [_jsxs(NavItemComponent, Object.assign({}, (NavItemComponent === 'a' |
| 26 |
? { tabIndex: isDisabled ? -1 : undefined, href, target } |
| 27 |
: { disabled: isDisabled }), (id && { id: id.toString() }), { onClick: (e) => { |
| 28 |
e.stopPropagation(); |
| 29 |
isExpandable ? setIsExpanded(!isExpanded || isCurrent) : onClick === null || onClick === void 0 ? void 0 : onClick(e, stepIndex); |
| 30 |
}, className: css(styles.wizardNavLink, isCurrent && styles.modifiers.current, isDisabled && styles.modifiers.disabled, status === WizardNavItemStatus.Error && styles.modifiers.danger, status === WizardNavItemStatus.Success && styles.modifiers.success, status === WizardNavItemStatus.Warning && styles.modifiers.warning), "aria-disabled": isDisabled ? true : null, "aria-current": isCurrent && !children ? 'step' : false }, (isExpandable && { 'aria-expanded': isExpanded }), ouiaProps, { children: [status !== WizardNavItemStatus.Default && (_jsxs(_Fragment, { children: [_jsxs("span", { className: "pf-v6-screen-reader", children: [", ", status] }), _jsxs("span", { className: css(styles.wizardNavLinkStatusIcon), children: [status === WizardNavItemStatus.Error && _jsx(RhUiErrorFillIcon, {}), status === WizardNavItemStatus.Success && _jsx(RhUiCheckCircleFillIcon, {}), status === WizardNavItemStatus.Warning && _jsx(RhUiWarningFillIcon, {})] })] })), _jsx("span", { className: css(styles.wizardNavLinkMain), children: isExpandable ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "pf-v6-c-wizard__nav-link-text", children: content }), _jsx("span", { className: css(styles.wizardNavLinkToggle), children: _jsx("span", { className: css(styles.wizardNavLinkToggleIcon), children: _jsx(RhMicronsCaretDownIcon, { "aria-label": `${isCurrent ? 'Collapse' : 'Expand'} step icon` }) }) })] })) : (_jsx(_Fragment, { children: content })) })] })), children] }))); |
| 31 |
}; |
| 32 |
WizardNavItem.displayName = 'WizardNavItem'; |
| 33 |
//# sourceMappingURL=WizardNavItem.js.map |