Skip to content

Commit 190e12b

Browse files
authored
Fixed alignemnt of interactive method (#15)
1 parent c4f2501 commit 190e12b

File tree

7 files changed

+215
-149
lines changed

7 files changed

+215
-149
lines changed

src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx

+42-46
Original file line numberDiff line numberDiff line change
@@ -35,54 +35,50 @@ export default function ArrayFieldItemTemplate<
3535
fontWeight: 'bold',
3636
};
3737
return (
38-
<div className={className + ' row'}>
38+
<div className={className + ' row'} >
3939
<div className={hasToolbar ? 'col col--9' : 'col col--12'}>{children}</div>
4040
{hasToolbar && (
41-
<div className='col col--3 array-item-toolbox'>
42-
<div
43-
className='btn-group'
44-
style={{
45-
display: 'flex',
46-
justifyContent: 'space-around',
47-
}}
48-
>
49-
{(hasMoveUp || hasMoveDown) && (
50-
<MoveUpButton
51-
style={btnStyle}
52-
disabled={disabled || readonly || !hasMoveUp}
53-
onClick={onReorderClick(index, index - 1)}
54-
uiSchema={uiSchema}
55-
registry={registry}
56-
/>
57-
)}
58-
{(hasMoveUp || hasMoveDown) && (
59-
<MoveDownButton
60-
style={btnStyle}
61-
disabled={disabled || readonly || !hasMoveDown}
62-
onClick={onReorderClick(index, index + 1)}
63-
uiSchema={uiSchema}
64-
registry={registry}
65-
/>
66-
)}
67-
{hasCopy && (
68-
<CopyButton
69-
style={btnStyle}
70-
disabled={disabled || readonly}
71-
onClick={onCopyIndexClick(index)}
72-
uiSchema={uiSchema}
73-
registry={registry}
74-
/>
75-
)}
76-
{hasRemove && (
77-
<RemoveButton
78-
style={btnStyle}
79-
disabled={disabled || readonly}
80-
onClick={onDropIndexClick(index)}
81-
uiSchema={uiSchema}
82-
registry={registry}
83-
/>
84-
)}
85-
</div>
41+
<div className='col col--3 array-item-toolbox' style={{
42+
display: 'flex',
43+
justifyContent: 'center',
44+
alignItems: 'center',
45+
}}>
46+
{(hasMoveDown || hasMoveUp) && (
47+
<MoveUpButton
48+
style={btnStyle}
49+
disabled={disabled || readonly || !hasMoveUp}
50+
onClick={onReorderClick(index, index - 1)}
51+
uiSchema={uiSchema}
52+
registry={registry}
53+
/>
54+
)}
55+
{(hasMoveUp || hasMoveDown) && (
56+
<MoveDownButton
57+
style={btnStyle}
58+
disabled={disabled || readonly || !hasMoveDown}
59+
onClick={onReorderClick(index, index + 1)}
60+
uiSchema={uiSchema}
61+
registry={registry}
62+
/>
63+
)}
64+
{hasCopy && (
65+
<CopyButton
66+
style={btnStyle}
67+
disabled={disabled || readonly}
68+
onClick={onCopyIndexClick(index)}
69+
uiSchema={uiSchema}
70+
registry={registry}
71+
/>
72+
)}
73+
{hasRemove && (
74+
<RemoveButton
75+
style={btnStyle}
76+
disabled={disabled || readonly}
77+
onClick={onDropIndexClick(index)}
78+
uiSchema={uiSchema}
79+
registry={registry}
80+
/>
81+
)}
8682
</div>
8783
)}
8884
</div>

src/ArrayFieldTemplate/ArrayFieldTemplate.tsx

+9-15
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,18 @@ T = any,
6464
registry={registry}
6565
/>
6666

67-
{/* <ArrayFieldDescriptionTemplate
68-
idSchema={idSchema}
69-
description={uiOptions.description || schema.description}
70-
schema={schema}
71-
uiSchema={uiSchema}
72-
registry={registry}
73-
/> */}
74-
<div className='col col--12 array-item-list'>
75-
<div className='container'>
76-
{items &&
77-
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType<T, S, F>) => (
78-
<ArrayFieldItemTemplate key={key} {...itemProps} />
79-
))}
80-
</div>
67+
<div className='array-item-list'>
68+
{items &&
69+
items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType<T, S, F>) => (
70+
<ArrayFieldItemTemplate key={key} {...itemProps} />
71+
))}
8172
</div>
8273

8374
{canAdd && (
84-
<div className="col col--12">
75+
<div className="col col--12" style={{
76+
justifyContent: 'end',
77+
display: 'flex'
78+
}}>
8579
<AddButton
8680
className='array-item-add'
8781
onClick={onAddClick}
+6-24
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
.MuiExpansionPanelSummary-expandIcon.Mui-expanded {
2-
transform: rotate(0deg) !important;
3-
}
4-
.MuiExpansionPanelSummary-expandIcon {
5-
order: -1;
6-
transform: rotate(-90deg) !important;
7-
margin-right: 0px !important;
8-
}
9-
10-
.MuiExpansionPanelSummary-content {
11-
align-items: center;
12-
}
13-
14-
.MuiExpansionPanelSummary-root {
15-
padding: 0 24px 0 0px !important;
16-
}
17-
18-
/* #interactive-box input {
19-
border: 1px solid black;
20-
border-radius: 5px;
21-
} */
22-
231
.glyphicon-plus {
242
--b: 4px; /* the thickness */
253
width: 40px; /* the size */
@@ -39,14 +17,18 @@ select, input {
3917
padding: 0.8rem;
4018
background: var(--docsearch-searchbox-focus-background);
4119
color: var(--docsearch-text-color);
42-
margin-bottom: 0.5rem;
4320
transition: border var(--ifm-transition-fast) ease;
4421
}
4522

46-
#interactive-box input[type=text] {
23+
#interactive-box input {
4724
width: 100%
4825
}
4926

27+
#interactive-box .form-group {
28+
margin-top: 0.25rem !important;
29+
margin-bottom: 0.25rem !important;
30+
}
31+
5032
.method section {
5133
margin-bottom: var(--ifm-heading-margin-bottom);
5234
}

src/FieldErrorTemplate/FieldErrorTemplate.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function FieldErrorTemplate<
1616
const id = errorId<T>(idSchema);
1717

1818
return (
19-
<div>
19+
<div className="col col--12">
2020
{errors
2121
.filter((elem) => !!elem)
2222
.map((error, index: number) => {

src/FieldTemplate/Label.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ export default function Label(props: LabelProps) {
1919
if (!label) {
2020
return null;
2121
}
22+
if (/-\d+/.test(label) && id && /_\d+/.test(id)) {
23+
return null;
24+
}
2225
return (
23-
<label className='control-label col col--2' htmlFor={id}>
26+
<label className='control-label' htmlFor={id}>
2427
{label}
2528
{required && <span className='required'><b> (required)</b></span>}
2629
</label>

src/InteractiveMethod/InteractiveMethod.tsx

+67-62
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ArrayFieldTemplate from '../ArrayFieldTemplate/ArrayFieldTemplate';
88
import ArrayFieldItemTemplate from '../ArrayFieldItemTemplate/ArrayFieldItemTemplate';
99
import FieldErrorTemplate from "../FieldErrorTemplate/FieldErrorTemplate";
1010
import FieldTemplate from "../FieldTemplate/FieldTemplate";
11+
import ObjectFieldTemplate from "../ObjectFieldTemplate/ObjectFieldTemplate";
1112
const qs = require('qs');
1213
const { useHistory, useLocation } = require('@docusaurus/router');
1314

@@ -27,55 +28,46 @@ interface Props {
2728
};
2829
}
2930

30-
31-
/* function ArrayFieldTemplate(props: ArrayFieldTemplateProps) {
32-
* console.log(props);
33-
* const ArrayFieldItemTemplateFromProps
34-
* return (
35-
* <div className="container">
36-
* <div className="row">
37-
* {props.title && <b className="col col--9">{props.title}</b>}
38-
* {
39-
* props.canAdd &&
40-
* <div className="col col--3">
41-
* <button className="button button--block button--outline button--primary" type='button' onClick={props.onAddClick}>+</button>
42-
* </div>
43-
* }
44-
* </div>
45-
*
46-
* <div className="row">
47-
* <div className="col col--12">
48-
* {props.items.map((element) => element.children)}
49-
* </div>
50-
* </div>
51-
* </div>
52-
* );
53-
* } */
54-
5531
function AddButton(props: IconButtonProps) {
5632
const { icon, iconType, ...btnProps } = props;
5733
return (
58-
<button {...btnProps} className={btnProps.className + " button button--outline button--primary"} type='button'>+</button>
34+
<button {...btnProps} className={btnProps.className + " button button--primary"} type='button'>+</button>
5935
);
6036
}
6137

6238
function RemoveButton(props: IconButtonProps) {
6339
const { icon, iconType, ...btnProps } = props;
40+
const style = {
41+
...btnProps.style,
42+
minWidth: '35px',
43+
maxWidth: '36px',
44+
border: undefined
45+
};
6446
return (
65-
<button {...btnProps} className="button button--outline button--primary" type='button'>-</button>
47+
<button {...btnProps} style={style} className="button button--outline button--primary" type='button'>-</button>
6648
);
6749
}
6850
function MoveUpButton(props: IconButtonProps) {
6951
const { icon, iconType, ...btnProps } = props;
52+
const style = {
53+
...btnProps.style,
54+
minWidth: '35px',
55+
maxWidth: '36px',
56+
};
7057
return (
71-
<button {...btnProps} className="button button--outline button--primary" type='button'></button>
58+
<button {...btnProps} style={style} className="button button--outline button--primary" type='button'></button>
7259
);
7360
}
7461

7562
function MoveDownButton(props: IconButtonProps) {
7663
const { icon, iconType, ...btnProps } = props;
64+
const style = {
65+
...btnProps.style,
66+
minWidth: '35px',
67+
maxWidth: '36px',
68+
};
7769
return (
78-
<button {...btnProps} className="button button--outline button--primary" type='button'></button>
70+
<button {...btnProps} style={style} className="button button--outline button--primary" type='button'></button>
7971
);
8072
}
8173

@@ -110,7 +102,14 @@ const InteractiveMethodParam: React.FC<ParamProps> = (props) => {
110102
uiSchema={uiSchema}
111103
validator={validator}
112104
ref={refref}
113-
templates={{ArrayFieldItemTemplate, ArrayFieldTemplate, FieldErrorTemplate, FieldTemplate, ButtonTemplates:{ AddButton, RemoveButton, MoveUpButton, MoveDownButton } }}
105+
templates={{
106+
ArrayFieldItemTemplate,
107+
ArrayFieldTemplate,
108+
FieldErrorTemplate,
109+
FieldTemplate,
110+
ButtonTemplates:{ AddButton, RemoveButton, MoveUpButton, MoveDownButton },
111+
ObjectFieldTemplate
112+
}}
114113
onChange={props.onChange}
115114
onError={log('errors')}
116115
liveValidate
@@ -205,53 +204,59 @@ const InteractiveMethod: React.FC<Props> = (props) => {
205204
const jsCode = `await window.ethereum.request(${JSON.stringify(methodCall, null, " ")});`;
206205

207206
return (
208-
<>
207+
<div className="container">
209208
{method.params.length > 0 &&
210209
<>
211-
<div>
210+
<div className="row">
212211
<h3>Params</h3>
213-
{method.params.map((p, i) => (
214-
<>
215-
<h4>{(p as ContentDescriptorObject).name}</h4>
216-
<InteractiveMethodParam
217-
refref={formRefs[i]}
218-
formData={requestParams[(p as ContentDescriptorObject).name]}
219-
onChange={(change) => handleChange(change, i)}
220-
param={p as ContentDescriptorObject} />
221-
</>
222-
))}
212+
<div className="col col--12">
213+
{method.params.map((p, i) => (
214+
<>
215+
<h4>{(p as ContentDescriptorObject).name}</h4>
216+
<InteractiveMethodParam
217+
refref={formRefs[i]}
218+
formData={requestParams[(p as ContentDescriptorObject).name]}
219+
onChange={(change) => handleChange(change, i)}
220+
param={p as ContentDescriptorObject} />
221+
</>
222+
))}
223+
</div>
223224
</div>
224225
<br />
225226
</>
226227
}
227-
<div>
228+
<div className="row">
228229
<h3>Request</h3>
229-
{components && components.CodeBlock && <components.CodeBlock className="language-js">{jsCode}</components.CodeBlock>}
230-
{!components?.CodeBlock &&
231-
<pre>
232-
<code>
233-
{jsCode}
234-
</code>
235-
</pre>
236-
}
230+
<div className="col col--12">
231+
{components && components.CodeBlock && <components.CodeBlock className="language-js">{jsCode}</components.CodeBlock>}
232+
{!components?.CodeBlock &&
233+
<pre>
234+
<code>
235+
{jsCode}
236+
</code>
237+
</pre>
238+
}
239+
</div>
237240
</div>
238-
{executionResult !== undefined && <div>
241+
{executionResult !== undefined && <div className="row">
239242
<h3>Response</h3>
240-
{components && components.CodeBlock && <components.CodeBlock className="language-json">{JSON.stringify(executionResult, null, ' ')}</components.CodeBlock>}
241-
{!components?.CodeBlock &&
242-
<pre>
243-
<code>
244-
{JSON.stringify(executionResult, null, ' ')}
245-
</code>
246-
</pre>
247-
}
243+
<div className="col col--12">
244+
{components && components.CodeBlock && <components.CodeBlock className="language-json">{JSON.stringify(executionResult, null, ' ')}</components.CodeBlock>}
245+
{!components?.CodeBlock &&
246+
<pre>
247+
<code>
248+
{JSON.stringify(executionResult, null, ' ')}
249+
</code>
250+
</pre>
251+
}
252+
</div>
248253
</div>}
249-
<div>
254+
<div className="row">
250255
<button className="button button--primary button--block" onClick={handleExec}>
251256
Send Request
252257
</button>
253258
</div>
254-
</>
259+
</div>
255260
);
256261

257262
}

0 commit comments

Comments
 (0)