Skip to content

Commit d3419fa

Browse files
authored
Add a Submit and close icon to the Customize component. (#2087)
* Add a Submit and close icon. Signed-off-by: bgravenorst <[email protected]> * Implement Copilot suggestions. Signed-off-by: bgravenorst <[email protected]> --------- Signed-off-by: bgravenorst <[email protected]>
1 parent 8dda749 commit d3419fa

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

src/components/ParserOpenRPC/InteractiveBox/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { RemoveButton } from '@site/src/components/ParserOpenRPC/InteractiveBox/
2828
import { AddButton } from '@site/src/components/ParserOpenRPC/InteractiveBox/buttonTemplates/AddButton'
2929
import ClearIcon from '@site/static/img/icons/clear-icon.svg'
3030
import ResetIcon from '@site/static/img/icons/reset-icon.svg'
31+
import SubmitIcon from '@site/static/img/icons/submit-icon.svg'
3132

3233
interface InteractiveBoxProps {
3334
params: MethodParam[]
@@ -37,6 +38,7 @@ interface InteractiveBoxProps {
3738
drawerLabel?: string | null
3839
closeComplexTypeView?: () => void
3940
isOpen?: boolean
41+
onModalClose?: () => void
4042
}
4143

4244
type ObjectType = { [key: string]: any }
@@ -90,6 +92,7 @@ export default function InteractiveBox({
9092
drawerLabel,
9193
closeComplexTypeView,
9294
isOpen = false,
95+
onModalClose,
9396
}: InteractiveBoxProps) {
9497
const [parsedSchema, setParsedSchema] = useState<RJSFSchema>(null)
9598
const [defaultFormData, setDefaultFormData] = useState<any>({})
@@ -203,6 +206,15 @@ export default function InteractiveBox({
203206
formRef?.current?.reset()
204207
}
205208
}
209+
const handleSubmitAndClose = (e: React.MouseEvent<HTMLButtonElement>) => {
210+
e.preventDefault()
211+
onParamChange(currentFormData)
212+
if (isComplexTypeView) {
213+
closeComplexTypeView()
214+
} else {
215+
onModalClose?.()
216+
}
217+
}
206218
const isLightTheme = colorMode === 'light'
207219

208220
useEffect(() => {
@@ -333,6 +345,11 @@ export default function InteractiveBox({
333345
<ClearIcon className={styles.footerButtonIcon} />
334346
</button>
335347
</Tooltip>
348+
<Tooltip message="Submit and close">
349+
<button className={styles.footerButtonLeft} onClick={handleSubmitAndClose}>
350+
<SubmitIcon className={styles.footerButtonIcon} />
351+
</button>
352+
</Tooltip>
336353
</div>
337354
{isComplexTypeView ? (
338355
<div className={clsx(styles.footerButtons)}>

src/components/ParserOpenRPC/InteractiveBox/styles.module.scss

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,31 @@
308308
display: flex;
309309
}
310310
.footerButtonsLeft {
311-
width: 4.8rem;
311+
display: flex;
312+
gap: 1rem;
312313
align-items: center;
313-
justify-content: space-between;
314-
padding: 0.6rem 0;
315314
}
316315
.footerButtonLeft {
317316
display: flex;
318-
width: 1.6rem;
319-
height: 2.2rem;
320-
padding: 0;
321317
align-items: center;
322-
background: none;
323-
border: none;
324-
border-radius: 0;
325-
cursor: pointer;
318+
justify-content: center;
319+
width: 3.2rem;
320+
height: 3.2rem;
321+
border-radius: 0.4rem;
322+
background: var(--general-gray-light);
323+
transition: background-color var(--ifm-transition-fast) ease;
324+
325+
&:hover {
326+
background: var(--general-gray);
327+
}
328+
329+
[data-theme='dark'] & {
330+
background: var(--general-gray-dark);
331+
332+
&:hover {
333+
background: var(--general-gray);
334+
}
335+
}
326336
}
327337
.footerButtonRight {
328338
padding: 0.5rem 1.6rem !important;

src/components/ParserOpenRPC/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ export default function ParserOpenRPC({ network, method, extraContent }: ParserP
318318
drawerLabel={drawerLabel}
319319
closeComplexTypeView={closeComplexTypeView}
320320
isOpen={isModalOpen}
321+
onModalClose={onModalClose}
321322
/>
322323
</ModalDrawer>
323324
</div>

static/img/icons/submit-icon.svg

Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)