UNPKG

@carbon/ibm-products

Version:
181 lines (179 loc) 7.24 kB
/** * 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_pconsole = require("../../global/js/utils/pconsole.js"); const require_settings = require("../../settings.js"); const require_usePreviousValue = require("../../global/js/hooks/usePreviousValue.js"); const require_useRetrieveStepData = require("../../global/js/hooks/useRetrieveStepData.js"); const require_CreateFullPage = require("./CreateFullPage.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/CreateFullPage/CreateFullPageStep.tsx /** * Copyright IBM Corp. 2021, 2025 * * 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 componentName = "CreateFullPageStep"; const blockClass = `${require_settings.pkg.prefix}--create-full-page__step`; const defaults = { includeStep: true }; const CreateFullPageStep = (0, react.forwardRef)(({ children, className, subtitle, description, disableSubmit, includeStep = defaults.includeStep, introStep, invalid, title, hasFieldset, fieldsetLegendText, onNext, onPrevious, onMount, secondaryLabel, ...rest }, ref) => { const stepsContext = (0, react.useContext)(require_CreateFullPage.StepsContext); const stepNumber = (0, react.useContext)(require_CreateFullPage.StepNumberContext); const [shouldIncludeStep, setShouldIncludeStep] = (0, react.useState)(); const previousState = require_usePreviousValue.usePreviousValue({ currentStep: stepsContext?.currentStep }); require_useRetrieveStepData.useRetrieveStepData({ invalid, stepsContext, stepNumber, introStep, shouldIncludeStep, secondaryLabel, title }); (0, react.useEffect)(() => { if (stepNumber === stepsContext?.currentStep && previousState?.currentStep !== stepsContext?.currentStep) stepsContext?.setOnMount(onMount); }, [ onMount, stepsContext, stepNumber, previousState?.currentStep ]); (0, react.useEffect)(() => { setShouldIncludeStep(includeStep); }, [ includeStep, stepsContext, title ]); (0, react.useEffect)(() => { if (stepNumber === stepsContext?.currentStep) { stepsContext.setIsDisabled(disableSubmit); stepsContext?.setOnNext(onNext); stepsContext?.setOnPrevious(onPrevious); } }, [ stepsContext, stepNumber, disableSubmit, onNext, onPrevious ]); const span = { span: 50 }; const renderDescription = () => { if (description) { const common = { children: description, className: `${blockClass}-description`, ...span }; if (typeof description === "string") return /* @__PURE__ */ react.default.createElement(_carbon_react.Column, { ...common, as: "p" }); else if ((0, react.isValidElement)(description)) return /* @__PURE__ */ react.default.createElement(_carbon_react.Column, { ...common, as: "div" }); } return null; }; return stepsContext ? /* @__PURE__ */ react.default.createElement(_carbon_react.Section, { ...rest, className: (0, import_classnames.default)(blockClass, className, { [`${blockClass}__step--hidden-step`]: stepNumber !== stepsContext?.currentStep, [`${blockClass}__step--visible-step`]: stepNumber === stepsContext?.currentStep }), ref }, /* @__PURE__ */ react.default.createElement(_carbon_react.Grid, null, /* @__PURE__ */ react.default.createElement(_carbon_react.Column, span, /* @__PURE__ */ react.default.createElement(_carbon_react.Grid, null, /* @__PURE__ */ react.default.createElement(_carbon_react.Column, { className: `${blockClass}-title`, as: _carbon_react.Heading, ...span }, title), subtitle && /* @__PURE__ */ react.default.createElement(_carbon_react.Column, { className: `${blockClass}-subtitle`, as: "p", ...span }, subtitle), renderDescription()))), hasFieldset ? /* @__PURE__ */ react.default.createElement(_carbon_react.FormGroup, { legendText: fieldsetLegendText, className: `${blockClass}-fieldset` }, children) : children) : require_pconsole.default.warn(`You have tried using a ${componentName} component outside of a CreateFullPage. This is not allowed. ${componentName}s should always be children of the CreateFullPage`); }); CreateFullPageStep.propTypes = { /** * Content that shows in the CreateFullPage step */ children: prop_types.default.node, /** * Sets an optional className to be added to the CreateFullPage step */ className: prop_types.default.string, /** * Sets an optional description on the progress step component */ description: prop_types.default.node, /** * This will conditionally disable the submit button in the multi step CreateFullPage */ disableSubmit: prop_types.default.bool, /** * This is the legend text that appears above a fieldset html element for accessibility purposes. It is required when the optional `hasFieldset` prop is provided to a FullPageStep. */ /**@ts-ignore */ fieldsetLegendText: prop_types.default.string, /** * This optional prop will render your form content inside of a fieldset html element */ hasFieldset: prop_types.default.bool, /** * This prop is used to help track dynamic steps. If this value is `false` then the step is not included in the visible steps or the ProgressIndicator * steps. If this value is `true` then the step will be included in the list of visible steps, as well as being included in the ProgressIndicator step list */ includeStep: prop_types.default.bool, /** * This prop can be used on the first step to mark it as an intro step, which will not render the progress indicator steps */ introStep: prop_types.default.bool, /** * This optional prop will indicate an error icon on the progress indicator step item */ invalid: prop_types.default.bool, /** * Optional function to be called on initial mount of a step. * For example, this can be used to fetch data that is required on a particular step. */ onMount: prop_types.default.func, /** * Optional function to be called on a step change. * For example, this can be used to validate input fields before proceeding to the next step. * This function can _optionally_ return a promise that is either resolved or rejected and the CreateFullPage will handle the submitting state of the next button. */ onNext: prop_types.default.func, /** * Optional function to be called when you move to the previous step. */ onPrevious: prop_types.default.func, /** * Sets the optional secondary label on the progress step component */ secondaryLabel: prop_types.default.string, /** * Sets an optional subtitle on the progress step component */ subtitle: prop_types.default.string, /** * Sets the title text for a create full page step */ title: prop_types.default.node.isRequired }; //#endregion exports.CreateFullPageStep = CreateFullPageStep;