addons/components/multi_stepper/MultiStepper.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {MultiStepperContext} from './MultiStepperContext';
b69ab319
b69ab3110import * as stylex from '@stylexjs/stylex';
b69ab3111
b69ab3112const styles = stylex.create({
b69ab3113 container: {
b69ab3114 overflowY: 'hidden',
b69ab3115 height: '100%',
b69ab3116 },
b69ab3117 contentLayout: {
b69ab3118 display: 'flex',
b69ab3119 flexDirection: 'row',
b69ab3120 gap: '24px',
b69ab3121 height: '100%',
b69ab3122 },
b69ab3123 leftContentContainer: {
b69ab3124 flexShrink: 0,
b69ab3125 minWidth: '200px',
b69ab3126 },
b69ab3127 stepContent: {
b69ab3128 flex: 1,
b69ab3129 overflowY: 'auto',
b69ab3130 },
b69ab3131});
b69ab3132
b69ab3133type Props<TKey> = {
b69ab3134 /**
b69ab3135 * Stepper state to control the current step and navigation.
b69ab3136 */
b69ab3137 stepper: MultiStepperContext<TKey>;
b69ab3138
b69ab3139 /**
b69ab3140 * Optional left content to display on the left side of the stepper.
b69ab3141 */
b69ab3142 leftContent?: React.ReactNode;
b69ab3143
b69ab3144 /**
b69ab3145 * The content to display in each step.
b69ab3146 * Each child corresponds to a step in the stepper.
b69ab3147 */
b69ab3148 children: Array<React.ReactNode>;
b69ab3149};
b69ab3150
b69ab3151/**
b69ab3152 * Component to render a set of steps, providing a way to navigate between
b69ab3153 * the steps and display the content for each step.
b69ab3154 *
b69ab3155 * Within the content of each step, you can use the `useMultiStepperContext` hook
b69ab3156 * to access the current step and navigate to other steps.
b69ab3157 */
b69ab3158export function MultiStepper<TKey>({leftContent, stepper, children}: Props<TKey>) {
b69ab3159 return (
b69ab3160 <div {...stylex.props(styles.container)}>
b69ab3161 <div {...stylex.props(styles.contentLayout)}>
b69ab3162 {leftContent && <div {...stylex.props(styles.leftContentContainer)}>{leftContent}</div>}
b69ab3163 <div {...stylex.props(styles.stepContent)}>{children[stepper.getStepIndex()]}</div>
b69ab3164 </div>
b69ab3165 </div>
b69ab3166 );
b69ab3167}