@rpg-engine/long-bow 0.5.94 → 0.5.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface IStep {
|
|
3
|
+
component: React.ReactNode;
|
|
4
|
+
id: number;
|
|
5
|
+
}
|
|
6
|
+
interface IStepperProps {
|
|
7
|
+
steps: IStep[];
|
|
8
|
+
finalCTAButton?: {
|
|
9
|
+
label: string;
|
|
10
|
+
onClick: () => void;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare const Stepper: React.FC<IStepperProps>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { ArrowBarProps } from '../components/Arrow/SelectArrow';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, ArrowBarProps>;
|
package/package.json
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { uiColors } from '../constants/uiColors';
|
|
4
|
+
import SelectArrow from './Arrow/SelectArrow';
|
|
5
|
+
import { Button, ButtonTypes } from './Button';
|
|
6
|
+
|
|
7
|
+
interface IStep {
|
|
8
|
+
component: React.ReactNode;
|
|
9
|
+
id: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface IStepperProps {
|
|
13
|
+
steps: IStep[];
|
|
14
|
+
finalCTAButton?: {
|
|
15
|
+
label: string;
|
|
16
|
+
onClick: () => void;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Stepper: React.FC<IStepperProps> = ({ steps, finalCTAButton }) => {
|
|
21
|
+
const [currentStep, setCurrentStep] = useState(0);
|
|
22
|
+
|
|
23
|
+
const currentComponent = steps[currentStep]?.component;
|
|
24
|
+
|
|
25
|
+
const totalSteps = steps.length;
|
|
26
|
+
|
|
27
|
+
const onStepChange = (step: number) => {
|
|
28
|
+
setCurrentStep(step);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<StepperContainer>
|
|
33
|
+
<StepperTop>
|
|
34
|
+
{Array.from({ length: totalSteps }, (_, i) => (
|
|
35
|
+
<ProgressIndicator key={i} isActive={i <= currentStep} />
|
|
36
|
+
))}
|
|
37
|
+
</StepperTop>
|
|
38
|
+
|
|
39
|
+
<StepperBody>{currentComponent}</StepperBody>
|
|
40
|
+
|
|
41
|
+
<StepperFooter>
|
|
42
|
+
{currentStep > 0 && (
|
|
43
|
+
<SelectArrow
|
|
44
|
+
direction="left"
|
|
45
|
+
onPointerDown={() => onStepChange(Math.max(0, currentStep - 1))}
|
|
46
|
+
/>
|
|
47
|
+
)}
|
|
48
|
+
|
|
49
|
+
{currentStep < totalSteps - 1 && (
|
|
50
|
+
<SelectArrow
|
|
51
|
+
direction="right"
|
|
52
|
+
onPointerDown={() =>
|
|
53
|
+
onStepChange(Math.min(totalSteps - 1, currentStep + 1))
|
|
54
|
+
}
|
|
55
|
+
/>
|
|
56
|
+
)}
|
|
57
|
+
|
|
58
|
+
{currentStep === totalSteps - 1 && finalCTAButton && (
|
|
59
|
+
<Button
|
|
60
|
+
buttonType={ButtonTypes.RPGUIButton}
|
|
61
|
+
onPointerDown={() => finalCTAButton.onClick}
|
|
62
|
+
>
|
|
63
|
+
{finalCTAButton.label}
|
|
64
|
+
</Button>
|
|
65
|
+
)}
|
|
66
|
+
</StepperFooter>
|
|
67
|
+
</StepperContainer>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const StepperContainer = styled.div`
|
|
72
|
+
display: flex;
|
|
73
|
+
flex-direction: column;
|
|
74
|
+
height: 100%; // Ensure the container takes up full height
|
|
75
|
+
`;
|
|
76
|
+
|
|
77
|
+
const StepperTop = styled.div`
|
|
78
|
+
flex: 1; // Small top
|
|
79
|
+
|
|
80
|
+
display: flex;
|
|
81
|
+
flex-wrap: wrap;
|
|
82
|
+
justify-content: center;
|
|
83
|
+
align-items: center;
|
|
84
|
+
`;
|
|
85
|
+
|
|
86
|
+
const StepperBody = styled.div`
|
|
87
|
+
flex: 8; // Big content space
|
|
88
|
+
`;
|
|
89
|
+
|
|
90
|
+
const StepperFooter = styled.div`
|
|
91
|
+
flex: 1; // Small footer
|
|
92
|
+
|
|
93
|
+
display: flex;
|
|
94
|
+
justify-content: flex-end;
|
|
95
|
+
`;
|
|
96
|
+
|
|
97
|
+
const ProgressIndicator = styled.div<{ isActive: boolean }>`
|
|
98
|
+
width: 20px;
|
|
99
|
+
height: 20px;
|
|
100
|
+
border-radius: 50%;
|
|
101
|
+
background-color: ${({ isActive }) =>
|
|
102
|
+
isActive ? uiColors.orange : uiColors.lightGray};
|
|
103
|
+
margin: 0 5px;
|
|
104
|
+
transition: background-color 0.3s;
|
|
105
|
+
|
|
106
|
+
opacity: ${({ isActive }) => (isActive ? 1 : 0.25)};
|
|
107
|
+
|
|
108
|
+
border: 1px solid ${uiColors.raisinBlack};
|
|
109
|
+
`;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Meta, Story } from '@storybook/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { RPGUIRoot } from '..';
|
|
4
|
+
import { ArrowBarProps } from '../components/Arrow/SelectArrow';
|
|
5
|
+
import { Stepper } from '../components/Stepper';
|
|
6
|
+
|
|
7
|
+
const meta: Meta = {
|
|
8
|
+
title: 'Stepper',
|
|
9
|
+
component: Stepper,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
|
|
14
|
+
const Template: Story<ArrowBarProps> = args => (
|
|
15
|
+
<RPGUIRoot>
|
|
16
|
+
<Stepper
|
|
17
|
+
steps={[
|
|
18
|
+
{
|
|
19
|
+
component: <div>Step 1</div>,
|
|
20
|
+
id: 0,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
component: <div>Step 2</div>,
|
|
24
|
+
id: 1,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
component: <div>Step 3</div>,
|
|
28
|
+
id: 2,
|
|
29
|
+
},
|
|
30
|
+
]}
|
|
31
|
+
finalCTAButton={{
|
|
32
|
+
label: 'Submit',
|
|
33
|
+
onClick: () => {
|
|
34
|
+
console.log('Submitting your data');
|
|
35
|
+
},
|
|
36
|
+
}}
|
|
37
|
+
></Stepper>
|
|
38
|
+
</RPGUIRoot>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export const Default = Template.bind({});
|
|
42
|
+
|
|
43
|
+
Default.args = {
|
|
44
|
+
direction: 'left',
|
|
45
|
+
onPointerDown: () => {
|
|
46
|
+
console.log('clicked');
|
|
47
|
+
},
|
|
48
|
+
};
|