From 505b7ece5cdaed6165478a899681351dfc365a80 Mon Sep 17 00:00:00 2001 From: Roman Mazur Date: Fri, 22 Mar 2024 14:10:18 +0100 Subject: [PATCH] Editor controls UX improvements --- components/Editor/EditorControls.tsx | 160 ++++++++++++++++----------- components/KBar/Button.tsx | 10 +- 2 files changed, 106 insertions(+), 64 deletions(-) diff --git a/components/Editor/EditorControls.tsx b/components/Editor/EditorControls.tsx index 5159018..b6abaf3 100644 --- a/components/Editor/EditorControls.tsx +++ b/components/Editor/EditorControls.tsx @@ -1,11 +1,11 @@ -import { useMemo, useRef, useId } from 'react' +import { useMemo, useRef, useState } from 'react' -import { RiLinksLine, RiQuestionLine } from '@remixicon/react' +import { RiLinksLine, RiQuestionLine, RiFileCodeLine } from '@remixicon/react' import cn from 'classnames' import { Priority, useRegisterActions } from 'kbar' -import Select, { OnChangeValue } from 'react-select' -import examples from 'components/Editor/examples' +import { OnChangeValue } from 'react-select' +import examples from 'components/Editor/examples' import { Button, Input } from 'components/ui' type SelectOption = { @@ -39,6 +39,7 @@ const EditorControls = ({ onShowArgumentsHelper, }: EditorControlsProps) => { const inputRef = useRef(null) + const [isExampleSelectorOpen, setIsExampleSelectorOpen] = useState(false) const actions = [ { @@ -71,7 +72,7 @@ const EditorControls = ({ const CairoNameExamples = useMemo( () => [ - 'Default', + 'Simple', 'Variables & mutability', 'Type casting', 'Control flow', @@ -88,75 +89,110 @@ const EditorControls = ({ label: CairoNameExamples[i], })) - const exampleNameValue = useMemo( - () => ({ - value: exampleName, - label: CairoNameExamples[exampleName], - }), - [CairoNameExamples, exampleName], - ) + const onExampleSelectorItemClick = (option: SelectOption) => { + setIsExampleSelectorOpen(false) + handleChangeExampleOption(option) + } return ( -
-
+
+
+ +
+ + + {isExampleSelectorOpen && ( +
    +
  • + Cairo Examples +
  • + {examplesOptions.map((option, idx) => ( +
  • + e.key === 'Enter' && onExampleSelectorItemClick(option) + } + onClick={() => onExampleSelectorItemClick(option)} + > +
    +

    {option.label}

    +
    +
  • + ))} +
+ )} +
-
- + + + } + onChange={(e) => { + onProgramArgumentsUpdate(e.target.value) + }} + readOnly={isCompileDisabled} + value={programArguments} + placeholder={`Program arguments`} + className={cn('max-w-64 border bg-gray-200 dark:bg-gray-800 ', { + 'dark:border-gray-800 border-gray-200': areProgramArgumentsValid, + 'border-red-500': !areProgramArgumentsValid, + })} + inputClassName={cn({ + 'text-red-500': !areProgramArgumentsValid, + })} /> -
- - - - } - onChange={(e) => { - onProgramArgumentsUpdate(e.target.value) - }} - readOnly={isCompileDisabled} - value={programArguments} - placeholder={`Program arguments`} - className={cn('grow border bg-gray-200 dark:bg-gray-800 ', { - 'dark:border-gray-800 border-gray-200': areProgramArgumentsValid, - 'border-red-500': !areProgramArgumentsValid, - })} - inputClassName={cn({ - 'text-red-500': !areProgramArgumentsValid, - })} - /> - -
- + +
+ +
) diff --git a/components/KBar/Button.tsx b/components/KBar/Button.tsx index 7e216b8..ee6fac1 100644 --- a/components/KBar/Button.tsx +++ b/components/KBar/Button.tsx @@ -5,6 +5,7 @@ import { useKBar } from 'kbar' import { isMac } from 'util/browser' import { Button } from 'components/ui' +import { RiCommandLine } from '@remixicon/react' const KBarButton = () => { const { query } = useKBar() @@ -27,8 +28,13 @@ const KBarButton = () => { outline padded={false} > - {/* {isMac && } */} - {isMacUser ? Cmd + K : Ctrl + K} + {isMacUser ? ( + + K + + ) : ( + Ctrl + K + )} ) }