Skip to content

Commit f8fabbd

Browse files
rvsiaHyperkid123
authored andcommitted
fix(blueprint): add missing wizard component
1 parent 26f5251 commit f8fabbd

File tree

6 files changed

+492
-4
lines changed

6 files changed

+492
-4
lines changed

packages/blueprint-component-mapper/demo/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import demoSchema from '@data-driven-forms/common/src/demoschema';
1919
const Summary = (props) => <div>Custom summary component.</div>;
2020

2121
const fieldArrayState = {
22-
schema: demoSchema,
22+
schema: wizardSchema,
2323
additionalOptions: {
24+
wizard: true,
25+
showFormControls: false,
2426
initialValues: {
2527
number: [1, 2, 3, 4],
2628
minMax: [null, null, null, null]

packages/blueprint-component-mapper/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,7 @@
7272
"@blueprintjs/datetime": "^3.17.0",
7373
"@blueprintjs/select": "^3.12.3"
7474
},
75-
"dependencies": {}
75+
"dependencies": {
76+
"clsx": "^1.1.0"
77+
}
7678
}
Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
1-
const Wizard = (props) => {
2-
return 'wizard';
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import WizardCommon from '@data-driven-forms/common/src/wizard/wizard';
4+
import { FormSpy } from '@data-driven-forms/react-form-renderer';
5+
6+
import StepButtons from './wizard/step-buttons';
7+
8+
const WizardInternal = ({ currentStep, formOptions, onKeyDown, WizardProps, ...props }) => (
9+
<div onKeyDown={onKeyDown} {...WizardProps}>
10+
{currentStep.fields.map((item) => formOptions.renderForm([item], formOptions))}
11+
<FormSpy subscription={{ valid: true, submitting: true, validating: true }}>
12+
{({ valid, submitting, validating }) => (
13+
<StepButtons isNextDisabled={!valid || submitting || validating} {...props} currentStep={currentStep} formOptions={formOptions} />
14+
)}
15+
</FormSpy>
16+
</div>
17+
);
18+
19+
WizardInternal.propTypes = {
20+
currentStep: PropTypes.object,
21+
onKeyDown: PropTypes.func,
22+
formOptions: PropTypes.shape({
23+
onCancel: PropTypes.func,
24+
renderForm: PropTypes.func,
25+
getState: PropTypes.func
26+
}),
27+
WizardProps: PropTypes.object
28+
};
29+
30+
const defaultLabels = {
31+
submit: 'Submit',
32+
cancel: 'Cancel',
33+
back: 'Back',
34+
next: 'Next'
35+
};
36+
37+
const Wizard = ({ buttonLabels, ...props }) => (
38+
<WizardCommon Wizard={WizardInternal} {...props} buttonLabels={{ ...defaultLabels, ...buttonLabels }} />
39+
);
40+
41+
Wizard.propTypes = {
42+
buttonLabels: PropTypes.object
343
};
444

545
export default Wizard;
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import selectNext from '@data-driven-forms/common/src/wizard/select-next';
4+
import clsx from 'clsx';
5+
6+
import { Button, Intent } from '@blueprintjs/core';
7+
8+
import './step-buttons.scss';
9+
10+
const NextButton = ({ nextStep, handleNext, buttonLabels, getState, handleSubmit, isDisabled, ...props }) => (
11+
<Button
12+
disabled={isDisabled}
13+
onClick={() => (nextStep ? handleNext(selectNext(nextStep, getState)) : handleSubmit())}
14+
rightIcon={nextStep ? 'arrow-right' : 'arrow-up'}
15+
intent={Intent.SUCCESS}
16+
{...props}
17+
>
18+
{nextStep ? buttonLabels.next : buttonLabels.submit}
19+
</Button>
20+
);
21+
22+
NextButton.propTypes = {
23+
handleNext: PropTypes.func,
24+
formOptions: PropTypes.shape({
25+
onCancel: PropTypes.func,
26+
renderForm: PropTypes.func,
27+
getState: PropTypes.func
28+
}),
29+
buttonLabels: PropTypes.object,
30+
nextStep: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
31+
getState: PropTypes.func,
32+
handleSubmit: PropTypes.func,
33+
isDisabled: PropTypes.bool
34+
};
35+
36+
const StepButtons = ({
37+
handleNext,
38+
currentStep,
39+
formOptions,
40+
activeStepIndex,
41+
buttonLabels,
42+
handlePrev,
43+
isNextDisabled,
44+
ButtonToolbarProps,
45+
DirectionButtonProps,
46+
CancelButtonProps,
47+
BackButtonProps,
48+
NextButtonProps,
49+
SubmitButtonProps
50+
}) => (
51+
<div {...ButtonToolbarProps} className={clsx('ddorg__blueprint_mapper--wizard-button-group', ButtonToolbarProps && ButtonToolbarProps.className)}>
52+
<Button onClick={formOptions.onCancel} minimal {...CancelButtonProps}>
53+
{buttonLabels.cancel}
54+
</Button>
55+
<div {...DirectionButtonProps}>
56+
<Button onClick={handlePrev} disabled={activeStepIndex === 0} {...BackButtonProps}>
57+
{buttonLabels.back}
58+
</Button>
59+
<NextButton
60+
getState={formOptions.getState}
61+
nextStep={currentStep.nextStep}
62+
buttonLabels={buttonLabels}
63+
handleNext={handleNext}
64+
isDisabled={!formOptions.valid || isNextDisabled}
65+
handleSubmit={formOptions.handleSubmit}
66+
{...(currentStep.nextStep ? NextButtonProps : SubmitButtonProps)}
67+
/>
68+
</div>
69+
</div>
70+
);
71+
72+
StepButtons.propTypes = {
73+
currentStep: PropTypes.object,
74+
handlePrev: PropTypes.func,
75+
handleNext: PropTypes.func,
76+
formOptions: PropTypes.shape({
77+
onCancel: PropTypes.func,
78+
renderForm: PropTypes.func,
79+
getState: PropTypes.func,
80+
handleSubmit: PropTypes.func,
81+
valid: PropTypes.bool
82+
}),
83+
activeStepIndex: PropTypes.number,
84+
buttonLabels: PropTypes.object,
85+
isNextDisabled: PropTypes.bool,
86+
ButtonToolbarProps: PropTypes.object,
87+
DirectionButtonProps: PropTypes.object,
88+
CancelButtonProps: PropTypes.object,
89+
BackButtonProps: PropTypes.object,
90+
NextButtonProps: PropTypes.object,
91+
SubmitButtonProps: PropTypes.object
92+
};
93+
94+
export default StepButtons;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.ddorg__blueprint_mapper--wizard-button-group {
2+
margin-top: 16px;
3+
display: flex;
4+
justify-content: space-between;
5+
6+
button:not(:first-child) {
7+
margin-left: 8px;
8+
}
9+
}

0 commit comments

Comments
 (0)