Skip to content

Commit

Permalink
Merge pull request #1 from jaipaljadeja/help/fullscreen
Browse files Browse the repository at this point in the history
Refactor of Fullscreen Implentation and Footer theme changes
  • Loading branch information
LukaszMMazur authored Mar 27, 2024
2 parents b2b316d + 2ebf7c5 commit 26f7dff
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 293 deletions.
62 changes: 26 additions & 36 deletions components/AboutCairoVMBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { useState, useEffect, useContext } from 'react'
import { useState, useEffect } from 'react'

import { RiCloseLine } from '@remixicon/react'

import { AppUiContext } from 'context/appUiContext'

const AboutCairoVMBanner = () => {
const [isShown, setIsShown] = useState(false)

const { isFullScreen } = useContext(AppUiContext)

useEffect(() => {
// Check if the banner was closed previously
const isBannerClosed = localStorage.getItem('isBannerClosed')
Expand All @@ -27,38 +23,32 @@ const AboutCairoVMBanner = () => {
}

return (
<>
{!isFullScreen && (
<div className="relative bg-gray-50 dark:bg-black-700 pb-6 mt-0 mb-10">
<button
className="absolute top-6 right-6 focus:outline-none"
onClick={handleCloseBanner}
aria-label="Close banner"
<div className="relative bg-gray-50 dark:bg-black-700 pb-6 mt-0 mb-10">
<button
className="absolute top-6 right-6 focus:outline-none"
onClick={handleCloseBanner}
aria-label="Close banner"
>
<RiCloseLine size={24} />
</button>
<div className="container mx-auto px-4 md:px-6">
<p className="font-medium md:text-xl mb-4 pt-6">About cairovm.codes</p>
<p className="font-normal text-2base text-gray-400 mb-4">
Built by{' '}
<a
className="underline text-indigo-500"
href="https://walnut.dev"
target="_blank"
rel="noreferrer"
>
<RiCloseLine size={24} />
</button>
<div className="container mx-auto px-4 md:px-6">
<p className="font-medium md:text-xl mb-4 pt-6">
About cairovm.codes
</p>
<p className="font-normal text-2base text-gray-400 mb-4">
Built by{' '}
<a
className="underline text-indigo-500"
href="https://walnut.dev"
target="_blank"
rel="noreferrer"
>
Walnut
</a>
, this app lets you compile Cairo programs into Sierra and CASM.
Gradually, we will introduce step-through execution for CASM,
Sierra, and Cairo, as part of our Cairo debugger development.
</p>
</div>
</div>
)}
</>
Walnut
</a>
, this app lets you compile Cairo programs into Sierra and CASM.
Gradually, we will introduce step-through execution for CASM, Sierra,
and Cairo, as part of our Cairo debugger development.
</p>
</div>
</div>
)
}

Expand Down
80 changes: 6 additions & 74 deletions components/Editor/EditorControls.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useMemo, useRef, useState } from 'react'
import { useRef } from 'react'

import { RiLinksLine, RiQuestionLine, RiFileCodeLine } from '@remixicon/react'
import { RiLinksLine, RiQuestionLine } from '@remixicon/react'
import cn from 'classnames'
import { Priority, useRegisterActions } from 'kbar'
import { OnChangeValue } from 'react-select'

import examples from 'components/Editor/examples'
import { Button, Input } from 'components/ui'

import ExampleSelector from './ExampleSelector'

type SelectOption = {
value: number
label: string
Expand All @@ -17,7 +18,6 @@ type EditorControlsProps = {
isCompileDisabled: boolean
programArguments: string
areProgramArgumentsValid: boolean
exampleName: number
handleChangeExampleOption: (
option: OnChangeValue<SelectOption, false>,
) => void
Expand All @@ -31,15 +31,13 @@ const EditorControls = ({
isCompileDisabled,
programArguments,
areProgramArgumentsValid,
exampleName,
handleChangeExampleOption,
onCopyPermalink,
onCompileRun,
onProgramArgumentsUpdate,
onShowArgumentsHelper,
}: EditorControlsProps) => {
const inputRef = useRef<HTMLInputElement>(null)
const [isExampleSelectorOpen, setIsExampleSelectorOpen] = useState(false)

const actions = [
{
Expand Down Expand Up @@ -70,27 +68,7 @@ const EditorControls = ({

useRegisterActions(actions, [onCompileRun, onCopyPermalink])

const CairoNameExamples = useMemo(
() => [
'Simple',
'Variables & mutability',
'Type casting',
'Control flow',
'Functions',
'Arrays',
'Dictionaries',
'Ownership',
],
[],
)

const examplesOptions = examples.Cairo.map((example, i) => ({
value: i,
label: CairoNameExamples[i],
}))

const onExampleSelectorItemClick = (option: SelectOption) => {
setIsExampleSelectorOpen(false)
const onExampleChange = (option: SelectOption | null) => {
handleChangeExampleOption(option)
}

Expand All @@ -108,53 +86,7 @@ const EditorControls = ({
<RiLinksLine size={16} />
</Button>

<div className="relative">
<Button
onClick={() => setIsExampleSelectorOpen((prev) => !prev)}
transparent
padded={false}
tooltip="Change Cairo code example"
tooltipId="change-cairo-example"
className={`p-2 text-indigo-500 hover:text-indigo-600 focus:outline-none ${cn(
{
'bg-indigo-100': isExampleSelectorOpen,
},
)}`}
>
<RiFileCodeLine size={16} />
</Button>

{isExampleSelectorOpen && (
<ul
className="absolute left-0 bottom-0 z-20 mb-10 w-72 border-0 border-slate-200 origin-top-right overflow-hidden rounded-md bg-white shadow-lg ring-1 ring-gray-200 focus:outline-none"
tabIndex={-1}
role="listbox"
aria-labelledby="listbox-label"
aria-activedescendant="listbox-option-0"
>
<li className="p-4 border-l-2 border-white text-2xs text-gray-400 uppercase dark:text-gray-600">
Cairo Examples
</li>
{examplesOptions.map((option, idx) => (
<li
key={option.value}
className="text-gray-900 dark:text-gray-200 border-l-2 border-white cursor-pointer select-none p-4 text-sm hover:bg-gray-50 dark:hover:bg-black-50 hover:border-indigo-500"
id={`listbox-option-${idx}`}
role="option"
aria-selected={option.value === exampleName}
onKeyDown={(e) =>
e.key === 'Enter' && onExampleSelectorItemClick(option)
}
onClick={() => onExampleSelectorItemClick(option)}
>
<div className="flex flex-col">
<p>{option.label}</p>
</div>
</li>
))}
</ul>
)}
</div>
<ExampleSelector onExampleChange={onExampleChange} />
</div>

<div className="flex flex-row grow gap-x-2 items-center justify-end">
Expand Down
53 changes: 53 additions & 0 deletions components/Editor/EditorFooter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useContext } from 'react'

import cn from 'classnames'

import { AppUiContext } from '../../context/appUiContext'
import { CairoVMApiContext } from '../../context/cairoVMApiContext'
import KBarButton from '../KBar/Button'
import ThemeSelector from '../ThemeSelector'
import ToggleFullScreen from '../ToggleFullScreen'
import ToggleThreeColumnLayout from '../ToggleThreeColumnLayout'

function EditorFooter() {
const { cairoLangCompilerVersion } = useContext(CairoVMApiContext)
const { isFullScreen } = useContext(AppUiContext)
return (
<div
className={cn(
'px-5 bg-gray-100 dark:bg-black-700 border-t border-gray-200 dark:border-black-500 text-xs h-[42px] items-center text-gray-600 ml-auto flex justify-between',
!isFullScreen && 'rounded-b-lg',
)}
>
<span>
{cairoLangCompilerVersion !== ''
? `Cairo Compiler v${cairoLangCompilerVersion}`
: ' '}
</span>

{isFullScreen && (
<div className="flex items-center justify-end divide-x divide-gray-200 dark:divide-black-500">
<span className="pr-4">
Made with ❤️ by{' '}
<a
className="underline font-medium"
href="https://walnut.dev"
target="_blank"
rel="noreferrer"
>
Walnut
</a>
</span>
<div className="items-center flex">
<KBarButton />
<ToggleFullScreen />
<ToggleThreeColumnLayout />
<ThemeSelector />
</div>
</div>
)}
</div>
)
}

export default EditorFooter
87 changes: 87 additions & 0 deletions components/Editor/ExampleSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React, { useId } from 'react'

import { RiFileCodeLine } from '@remixicon/react'
import cn from 'classnames'
import Select, {
components,
DropdownIndicatorProps,
StylesConfig,
GroupBase,
} from 'react-select'

import { Button } from '../ui'

import { Examples, CairoExampleNames } from './examples'

type SelectOption = {
value: number
label: string
}

type Props = {
onExampleChange: (option: SelectOption | null) => void
}

const examplesOptions = Examples.Cairo.map((_, i) => ({
value: i,
label: CairoExampleNames[i],
}))

function ExampleSelector({ onExampleChange }: Props) {
return (
<Select
onChange={onExampleChange}
options={examplesOptions}
components={{
DropdownIndicator,
}}
controlShouldRenderValue={false}
classNamePrefix="select"
styles={reactSelectStyles}
menuPlacement="top"
isSearchable={false}
instanceId={useId()}
/>
)
}

export default ExampleSelector

const reactSelectStyles: StylesConfig<
SelectOption,
false,
GroupBase<SelectOption>
> = {
// as we dont want to show value field in react-select
// and just want to show an icon, but input field takes some space
// so we hide the valueContainer with css properties
// Question: Why not remove the ValueContainer completely from 'components' prop in react-select?
// Ans: react-select needs a valuefield
// as many features like click outside to close drop down etc depends on it
// so we just add display none (it doesn't hurt)
valueContainer: (styles) => ({
...styles,
width: '0',
opacity: 0,
padding: '0 !important',
}),
}

const DropdownIndicator = (props: DropdownIndicatorProps<SelectOption>) => {
return (
<components.DropdownIndicator {...props}>
<Button
transparent
padded={false}
tooltip="Cairo Examples"
tooltipId="cairo-examples"
className={cn(
'p-2 text-indigo-500 hover:text-indigo-600 focus:outline-none',
props.selectProps.menuIsOpen ? 'bg-black-900/5 dark:bg-white/5' : '',
)}
>
<RiFileCodeLine size={16} />
</Button>
</components.DropdownIndicator>
)
}
2 changes: 1 addition & 1 deletion components/Editor/ExtraColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ExtraColumn = ({

return (
<div className="w-full md:w-1/3 flex flex-col">
<div className="border-b border-gray-200 dark:border-black-500 flex items-center pl-6 pr-2 h-14 md:border-r">
<div className="border-b border-gray-200 dark:border-black-500 flex items-center pl-6 pr-2 h-14 md:border-r flex-none">
<Header
codeType={codeType}
onCodeTypeChange={({ value }) => setCodeType(value)}
Expand Down
Loading

0 comments on commit 26f7dff

Please sign in to comment.