| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {MultiStepperContext} from './MultiStepperContext'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | import * as stylex from '@stylexjs/stylex'; |
| b69ab31 | | | 11 | |
| b69ab31 | | | 12 | const styles = stylex.create({ |
| b69ab31 | | | 13 | container: { |
| b69ab31 | | | 14 | overflowY: 'hidden', |
| b69ab31 | | | 15 | height: '100%', |
| b69ab31 | | | 16 | }, |
| b69ab31 | | | 17 | contentLayout: { |
| b69ab31 | | | 18 | display: 'flex', |
| b69ab31 | | | 19 | flexDirection: 'row', |
| b69ab31 | | | 20 | gap: '24px', |
| b69ab31 | | | 21 | height: '100%', |
| b69ab31 | | | 22 | }, |
| b69ab31 | | | 23 | leftContentContainer: { |
| b69ab31 | | | 24 | flexShrink: 0, |
| b69ab31 | | | 25 | minWidth: '200px', |
| b69ab31 | | | 26 | }, |
| b69ab31 | | | 27 | stepContent: { |
| b69ab31 | | | 28 | flex: 1, |
| b69ab31 | | | 29 | overflowY: 'auto', |
| b69ab31 | | | 30 | }, |
| b69ab31 | | | 31 | }); |
| b69ab31 | | | 32 | |
| b69ab31 | | | 33 | type Props<TKey> = { |
| b69ab31 | | | 34 | /** |
| b69ab31 | | | 35 | * Stepper state to control the current step and navigation. |
| b69ab31 | | | 36 | */ |
| b69ab31 | | | 37 | stepper: MultiStepperContext<TKey>; |
| b69ab31 | | | 38 | |
| b69ab31 | | | 39 | /** |
| b69ab31 | | | 40 | * Optional left content to display on the left side of the stepper. |
| b69ab31 | | | 41 | */ |
| b69ab31 | | | 42 | leftContent?: React.ReactNode; |
| b69ab31 | | | 43 | |
| b69ab31 | | | 44 | /** |
| b69ab31 | | | 45 | * The content to display in each step. |
| b69ab31 | | | 46 | * Each child corresponds to a step in the stepper. |
| b69ab31 | | | 47 | */ |
| b69ab31 | | | 48 | children: Array<React.ReactNode>; |
| b69ab31 | | | 49 | }; |
| b69ab31 | | | 50 | |
| b69ab31 | | | 51 | /** |
| b69ab31 | | | 52 | * Component to render a set of steps, providing a way to navigate between |
| b69ab31 | | | 53 | * the steps and display the content for each step. |
| b69ab31 | | | 54 | * |
| b69ab31 | | | 55 | * Within the content of each step, you can use the `useMultiStepperContext` hook |
| b69ab31 | | | 56 | * to access the current step and navigate to other steps. |
| b69ab31 | | | 57 | */ |
| b69ab31 | | | 58 | export function MultiStepper<TKey>({leftContent, stepper, children}: Props<TKey>) { |
| b69ab31 | | | 59 | return ( |
| b69ab31 | | | 60 | <div {...stylex.props(styles.container)}> |
| b69ab31 | | | 61 | <div {...stylex.props(styles.contentLayout)}> |
| b69ab31 | | | 62 | {leftContent && <div {...stylex.props(styles.leftContentContainer)}>{leftContent}</div>} |
| b69ab31 | | | 63 | <div {...stylex.props(styles.stepContent)}>{children[stepper.getStepIndex()]}</div> |
| b69ab31 | | | 64 | </div> |
| b69ab31 | | | 65 | </div> |
| b69ab31 | | | 66 | ); |
| b69ab31 | | | 67 | } |