addons/components/multi_stepper/VerticalStepperProgress.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 'isl-components/multi_stepper/MultiStepperContext';
b69ab319
b69ab3110import * as stylex from '@stylexjs/stylex';
b69ab3111import {Icon} from 'isl-components/Icon';
b69ab3112
b69ab3113const styles = stylex.create({
b69ab3114 stepItem: {
b69ab3115 display: 'flex',
b69ab3116 alignItems: 'center',
b69ab3117 gap: '12px',
b69ab3118 padding: '12px',
b69ab3119 borderRadius: '4px',
b69ab3120 marginBottom: '8px',
b69ab3121 },
b69ab3122 stepItemActive: {
b69ab3123 backgroundColor: 'var(--highlight-background)',
b69ab3124 },
b69ab3125 stepItemCompleted: {
b69ab3126 cursor: 'pointer',
b69ab3127 },
b69ab3128 stepNumber: {
b69ab3129 display: 'flex',
b69ab3130 alignItems: 'center',
b69ab3131 justifyContent: 'center',
b69ab3132 width: '20px',
b69ab3133 height: '20px',
b69ab3134 borderRadius: '50%',
b69ab3135 border: '2px solid var(--foreground)',
b69ab3136 fontSize: '12px',
b69ab3137 fontWeight: 'bold',
b69ab3138 },
b69ab3139 stepNumberActive: {
b69ab3140 backgroundColor: 'var(--button-primary-background)',
b69ab3141 borderColor: 'var(--button-primary-background)',
b69ab3142 color: 'var(--button-primary-foreground)',
b69ab3143 },
b69ab3144 stepNumberCompleted: {
b69ab3145 backgroundColor: 'var(--success-background)',
b69ab3146 borderColor: 'var(--success-background)',
b69ab3147 },
b69ab3148 stepLabel: {
b69ab3149 fontSize: '14px',
b69ab3150 },
b69ab3151 stepLabelActive: {
b69ab3152 fontWeight: 'bold',
b69ab3153 },
b69ab3154});
b69ab3155
b69ab3156type Props<TKey> = {
b69ab3157 stepper: MultiStepperContext<TKey>;
b69ab3158};
b69ab3159
b69ab3160/**
b69ab3161 * A vertical progress bar for a multi-step stepper.
b69ab3162 */
b69ab3163export function VerticalStepperProgress<TKey>({stepper}: Props<TKey>) {
b69ab3164 const icon = <Icon icon="check" />;
b69ab3165
b69ab3166 const steps = stepper.getAllSteps();
b69ab3167 const currentIndex = stepper.getStepIndex();
b69ab3168
b69ab3169 return (
b69ab3170 <div>
b69ab3171 {steps.map((step, index) => {
b69ab3172 const isActive = index === currentIndex;
b69ab3173 const isCompleted = index < currentIndex;
b69ab3174
b69ab3175 return (
b69ab3176 <div
b69ab3177 key={String(step.key)}
b69ab3178 onClick={() => (isCompleted ? stepper.goToStepByKey(step.key) : undefined)}
b69ab3179 {...stylex.props(
b69ab3180 styles.stepItem,
b69ab3181 isActive && styles.stepItemActive,
b69ab3182 isCompleted && styles.stepItemCompleted,
b69ab3183 )}>
b69ab3184 <div
b69ab3185 {...stylex.props(
b69ab3186 styles.stepNumber,
b69ab3187 isActive && styles.stepNumberActive,
b69ab3188 isCompleted && styles.stepNumberCompleted,
b69ab3189 )}>
b69ab3190 {isCompleted ? icon : index + 1}
b69ab3191 </div>
b69ab3192 <div {...stylex.props(styles.stepLabel, isActive && styles.stepLabelActive)}>
b69ab3193 {step.label}
b69ab3194 </div>
b69ab3195 </div>
b69ab3196 );
b69ab3197 })}
b69ab3198 </div>
b69ab3199 );
b69ab31100}