From 37d8d3e10b2850add01467f843b32a014dcfbd3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Baranx?= Date: Tue, 13 Feb 2024 10:53:10 +0700 Subject: [PATCH] chore: add a ? button to display a modal explaining how to use the arguments input field --- components/Editor/EditorControls.tsx | 70 ++++++++++++++++++++++++++-- components/ui/Input.tsx | 3 ++ components/ui/Modal.tsx | 36 ++++++++++++++ components/ui/index.ts | 1 + 4 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 components/ui/Modal.tsx diff --git a/components/Editor/EditorControls.tsx b/components/Editor/EditorControls.tsx index 42bbf59..a65cd94 100644 --- a/components/Editor/EditorControls.tsx +++ b/components/Editor/EditorControls.tsx @@ -1,9 +1,9 @@ -import { useRef } from 'react' +import { useRef, useState } from 'react' -import { RiLinksLine } from '@remixicon/react' +import { RiLinksLine, RiQuestionLine } from '@remixicon/react' import cn from 'classnames' -import { Button, Input } from 'components/ui' +import { Button, Input, Modal } from 'components/ui' type EditorControlsProps = { isCompileDisabled: boolean @@ -23,6 +23,68 @@ const EditorControls = ({ onProgramArgumentsUpdate, }: EditorControlsProps) => { const inputRef = useRef(null) + const [showArgumentsHelper, setShowArgumentsHelper] = useState(false) + + const argumentHelperModal = ( + +
e.stopPropagation()} + onKeyDown={(e) => e.stopPropagation()} + > +

+ This input field accepts a list of program arguments separated by a{' '} + whitespace. +

+

Each argument could be:

+
    +
  • + a single + felt252, +
  • +
  • + an array of + felt252 where items + are also separated by a{' '} + whitespace. +
  • +
+

+ Note that only decimal values are supported for{' '} + felt252. That means + neither hexadecimal value nor short string are supported yet. +

+

+ Of course, the signature of your{' '} + main() function must be + adapted accordingly. +

+

+ For example,{' '} + 1 [3 4 5] 9{' '} + contains 3 parameters and the corresponding main function should be{' '} + + main(x: felt252, y: Array<felt252>, z: felt252) + + . +

+
+
+ ) + const argumentHelperIcon = ( + <> + + {showArgumentsHelper && argumentHelperModal} + + ) return (
@@ -42,6 +104,7 @@ const EditorControls = ({ { onProgramArgumentsUpdate(e.target.value) }} @@ -56,7 +119,6 @@ const EditorControls = ({ 'text-red-500': !areProgramArgumentsValid, })} /> -
) }, diff --git a/components/ui/Modal.tsx b/components/ui/Modal.tsx new file mode 100644 index 0000000..ff12345 --- /dev/null +++ b/components/ui/Modal.tsx @@ -0,0 +1,36 @@ +export type ModalProps = { + title: string + visible: boolean + setVisible: (_visible: boolean) => void + children: React.ReactNode +} + +export const Modal = ({ + title, + visible, + setVisible, + children, +}: ModalProps): JSX.Element => { + return visible ? ( +
setVisible(false)} + onKeyDown={() => setVisible(false)} + > +
+
+
+

+ {title} +

+
+ {children} +
+
+
+ ) : ( + <> + ) +} diff --git a/components/ui/index.ts b/components/ui/index.ts index 59fcaf7..d5b8f16 100644 --- a/components/ui/index.ts +++ b/components/ui/index.ts @@ -9,3 +9,4 @@ export * from './Message' export * from './Radio' export * from './RelativeLink' export * from './StackBox' +export * from './Modal'