@carbon/ibm-products
Version:
Carbon for IBM Products
85 lines (83 loc) • 3.62 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_index = require("../../node_modules/classnames/index.js");
const require_settings = require("../../settings.js");
require("../../global/js/utils/props-helper.js");
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let _carbon_react = require("@carbon/react");
//#region src/components/CreateInfluencer/CreateInfluencer.tsx
/**
* Copyright IBM Corp. 2021, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const blockClass = `${require_settings.pkg.prefix}--create-influencer`;
const componentName = "CreateInfluencer";
const CreateInfluencer = ({ className, currentStep, onClickStep, stepData, title }) => {
const getNumberOfDynamicStepsBeforeCurrentStep = (array, key) => {
const dynamicSteps = [];
array.forEach((item, index) => {
if (array[index]?.[key] === false && index <= currentStep - 1) dynamicSteps.push(item);
});
return dynamicSteps.length;
};
const renderProgressSteps = () => {
const progressSteps = (stepData?.filter((item) => !item?.introStep))?.filter((item) => item?.shouldIncludeStep);
const totalDynamicSteps = getNumberOfDynamicStepsBeforeCurrentStep(stepData, "shouldIncludeStep") || 0;
return /* @__PURE__ */ react.default.createElement(_carbon_react.Section, { className: `${blockClass}__left-nav` }, title && /* @__PURE__ */ react.default.createElement(_carbon_react.Heading, { className: `${blockClass}__title` }, title), currentStep === 1 && stepData[0]?.introStep ? null : /* @__PURE__ */ react.default.createElement(_carbon_react.ProgressIndicator, {
currentIndex: stepData[0]?.introStep ? currentStep - totalDynamicSteps - 2 : currentStep - totalDynamicSteps - 1,
spaceEqually: true,
vertical: true,
className: (0, import_classnames.default)(`${blockClass}__progress-indicator`),
onChange: onClickStep
}, progressSteps.map((step, stepIndex) => {
return /* @__PURE__ */ react.default.createElement(_carbon_react.ProgressStep, {
label: step?.title,
key: stepIndex,
secondaryLabel: step.secondaryLabel || void 0,
invalid: step.invalid
});
})));
};
return /* @__PURE__ */ react.default.createElement("div", { className: (0, import_classnames.default)(blockClass, className) }, renderProgressSteps());
};
CreateInfluencer.displayName = componentName;
CreateInfluencer.propTypes = {
/**
* Provide an optional class to be applied to the containing node.
*/
className: prop_types.default.string,
/**
* Used to mark the current step on the ProgressIndicator component
*/
currentStep: prop_types.default.number.isRequired,
/**
* onChange event for Progress Indicator
*/
onClickStep: prop_types.default.func,
/**
* The step data that renders the progress items
*/
stepData: prop_types.default.arrayOf(prop_types.default.shape({
introStep: prop_types.default.bool,
secondaryLabel: prop_types.default.string,
shouldIncludeStep: prop_types.default.bool,
title: prop_types.default.node
})),
/**
* The main title of the full page, displayed in the influencer area.
*/
title: prop_types.default.string
};
//#endregion
exports.CreateInfluencer = CreateInfluencer;