Open reboottime opened 1 year ago
Mantine UI Stepper component's API design has considered nearly all the usage scenarios mentioned earlier.
type StepperComponent = ForwardRefWithStaticComponents<
StepperProps,
{
Step: typeof Step;
Completed: typeof StepCompleted;
}
>;
Stepper.Step = Step;
Stepper.Completed = StepCompleted;
Stepper.displayName = '@mantine/core/Stepper';
export type ForwardRefWithStaticComponents<
Props extends Record<string, any>,
Static extends Record<string, any>
> = ((props: Props) => React.ReactElement) &
Static & {
displayName: string;
};
Utilizing the composition pattern enhances developer flexibility in structuring code, but poses challenges in enforcing expected usage.
To avoid unexpected content rendered inside of the Stepper, Mantine handles the concern in the following way
const _children = convertedChildren.filter((child) => child.type === Step);
const completedStep = convertedChildren.find((item) => item.type === StepCompleted);
acc.push( cloneElement(item, {/**some other code**/}));
The side note, the child.type can either be a html tag name, or a reference to the type of a React component. See example bellow
import React from 'react';
const Title = () => <h1>Hello, Title!</h1>;
const App = () => {
const htmlChild = <div>This is a div.</div>;
const componentChild = <Title />;
console.log('HTML child type:', htmlChild.type); // Outputs: "div"
console.log('Component child type:', componentChild.type); // Outputs: Reference to the Title component
};
export default App;
There are situations where you'd like to control the layout between Step content and the Stepper progress bar. Although the Stepper component provides two orientation modes: vertical and horizontal, the horizontal mode does not necessarily mean that the Mantine Stepper aligns its Step content on the right side, as shown bellow:
Given the source code of the Stepper, the solutions for achieving the desired UI layout are as follows:
The logical design of allowStepClick
and allowStepSelect
might not be immediately intuitive for developer users, unless they delve into the source code.
Overview
This article talks about Mantine UI Stepper component, including:
When and How Stepper Components Are Used
When user are in a complex flow of doing something, such as
In Front end Development domain and real world use cases: