@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
71 lines (67 loc) • 2.07 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
import { extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import cx from 'classnames';
import React__default, { useContext } from 'react';
import uniqueId from '../../../tools/uniqueId.js';
import StepperContext from '../StepperContext.js';
import { StepButton } from './StepButton.js';
import StepContext from './StepContext.js';
import { StepLabel } from './StepLabel.js';
const StepperStep = _ref => {
let {
label = '',
active = false,
completed = false,
disabled = false,
className,
index = 0,
icon,
children,
...rest
} = _ref;
const {
activeStep
} = useContext(StepperContext);
if (activeStep === index) {
active = true;
} else if (activeStep > index && !active && !disabled) {
completed = true;
} else if (activeStep < index && !active && !completed) {
disabled = true;
}
const contextValue = {
active,
completed,
disabled,
index
};
const stepId = uniqueId();
const ariaCurrent = active ? 'step' : undefined;
const ariaDisabled = disabled ? true : undefined;
const ariaLabel = label ? label : `Step ${index + 1}`;
const ariaLabelledBy = label ? `StepLabel-${stepId}` : undefined;
return /*#__PURE__*/React__default.createElement(StepContext.Provider, {
value: contextValue
}, /*#__PURE__*/React__default.createElement("div", {
className: 'stepper-step',
role: "step",
"aria-current": ariaCurrent,
"aria-disabled": ariaDisabled,
"aria-label": ariaLabel,
"aria-labelledby": ariaLabelledBy
}, /*#__PURE__*/React__default.createElement(StepButton, _extends({
className: cx('step-button', {
active: !disabled && !completed,
completed
}, className),
contentClasses: cx('step-button-content')
}, rest), children || icon || index + 1), label && /*#__PURE__*/React__default.createElement(StepLabel, {
id: `StepLabel-${stepId}`,
className: cx('label-container', {
active: !disabled && !completed
})
}, label)));
};
export { StepperStep };