forked from syndesisio/syndesis-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectionCreatorLayout.tsx
139 lines (137 loc) · 4.79 KB
/
ConnectionCreatorLayout.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// tslint:disable react-unused-props-and-state
// remove the above line after this goes GA https://github.com/Microsoft/tslint-microsoft-contrib/pull/824
import * as H from '@syndesis/history';
import classnames from 'classnames';
import * as React from 'react';
import { ButtonLink, Loader } from '../Layout';
import { toTestId } from '../utils';
/**
* @param header - a PatternFly Wizard Steps component.
* @param sidebar - the sidebar container takes the size of its content. If no
* sidebar is defined, a layout with just the header, the footer and the body
* will be shown.
* @param content - the main content of the wizard. In case of overflow, only
* the body will scroll.
* @param onCancel - if passed, the Cancel button will be render as a `button`
* and this callback will be used as its `onClick` handler.
* @param onBack - if passed, the Back button will be render as a `button`
* and this callback will be used as its `onClick` handler.
* @param onNext - if passed, the Next button will be render as a `button`
* and this callback will be used as its `onClick` handler.
* @param cancelHref - if passed, the Cancel button will be render as a `Link`
* using this as its `to` parameter.
* @param backHref - if passed, the Back button will be render as a `Link`
* using this as its `to` parameter.
* @param nextHref - if passed, the Next button will be render as a `Link`
* using this as its `to` parameter.
* @param isNextLoading - if set to true, a `Loading` component will be shown
* inside the Next button before its label. The button will also be disabled.
* @param isNextDisabled - if set to true, the Next button will be disabled.
* @param isLastStep - if set to true, it changes the Next button label to
* 'Done'.
* @param extraButtons - buttons to add between the cancel and the back/next
*/
export interface IConnectionCreatorProps {
header: React.ReactNode;
content: React.ReactNode;
onCancel?: (e: React.MouseEvent<any>) => void;
onBack?: (e: React.MouseEvent<any>) => void;
onNext?: (e: React.MouseEvent<any>) => void;
cancelHref?: H.LocationDescriptor;
backHref?: H.LocationDescriptor;
nextHref?: H.LocationDescriptor;
isNextDisabled?: boolean;
isNextLoading?: boolean;
isLastStep?: boolean;
extraButtons?: React.ReactNode;
}
/**
* Provides the layout for the integration editor. It uses the PatternFly Wizard
* component under the hood.
* The footer is pre-defined and follows the PF Wizard pattern, with
* Cancel/Previous/Next buttons.
*
* @todo in the CSS we use hardcoded values for the heights of various
* elements of the page to be able to size the element to take all the available
* height and show the right scrollbars.
* We should really find a smarter way to handle this.
*/
export const ConnectionCreatorLayout: React.FunctionComponent<
IConnectionCreatorProps
> = ({
header,
content,
onCancel,
onBack,
onNext,
cancelHref,
backHref,
nextHref,
isNextLoading,
isNextDisabled,
isLastStep = false,
extraButtons,
}: IConnectionCreatorProps) => {
return (
<div
className={classnames(
'wizard-pf-body integration-editor-layout syn-scrollable',
{
'has-footer': true,
}
)}
>
{header}
<div className="wizard-pf-row integration-editor-layout__body syn-scrollable--body">
<div
className={
'wizard-pf-main cards-pf integration-editor-layout__contentWrapper'
}
>
<div className="integration-editor-layout__content">{content}</div>
</div>
</div>
<div className="wizard-pf-footer integration-editor-layout__footer">
<ButtonLink
data-testid={`${toTestId('ConnectionCreatorLayout', 'back-button')}`}
onClick={onBack}
href={backHref}
className={'wizard-pf-back'}
>
<i className="fa fa-angle-left" /> Back
</ButtonLink>
{extraButtons && (
<div className={'wizard-pf-extrabuttons'}>{extraButtons}</div>
)}
<ButtonLink
data-testid={`${toTestId('ConnectionCreatorLayout', 'next-button')}`}
onClick={onNext}
href={nextHref}
as={'primary'}
className={'wizard-pf-next'}
disabled={isNextLoading || isNextDisabled}
>
{isNextLoading ? <Loader size={'xs'} inline={true} /> : null}
{isLastStep ? (
'Create'
) : (
<>
Next <i className="fa fa-angle-right" />
</>
)}
</ButtonLink>
<ButtonLink
data-testid={`${toTestId(
'ConnectionCreatorLayout',
'cancel-button'
)}`}
onClick={onCancel}
href={cancelHref}
className={'wizard-pf-cancel'}
>
Cancel
</ButtonLink>
</div>
</div>
);
};