Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/components/ResponsiveToolBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react'
import { Flex, IconButton, useTheme } from '@chakra-ui/react'
import { HiOutlineDesktopComputer } from 'react-icons/hi'
import { MdOutlineTabletMac } from 'react-icons/md'
import { ImMobile } from 'react-icons/im'
import useDispatch from '~hooks/useDispatch'
import { getEditorWidth } from '~core/selectors/app'
import { useSelector } from 'react-redux'

const ResponsiveToolBar = () => {
const dispatch = useDispatch()
const theme = useTheme()
const editorWidth = useSelector(getEditorWidth)

return (
<Flex
w="100%"
p={4}
backgroundSize="20px 20px"
bgColor="#edf2f6"
align="center"
justify="center"
position="absolute"
zIndex={10}
boxShadow="lg"
>
<IconButton
icon={<HiOutlineDesktopComputer />}
size="lg"
fontSize="30px"
color={editorWidth === '100%' ? 'teal.500' : 'black.500'}
aria-label="Desktop version"
onClick={() => dispatch.app.updateEditorWidth({ width: '100%' })}
/>

<IconButton
icon={<MdOutlineTabletMac />}
size="lg"
color={editorWidth === theme.breakpoints.md ? 'teal.500' : 'black.500'}
fontSize="30px"
aria-label="Tablet version"
mx={12}
onClick={() =>
dispatch.app.updateEditorWidth({ width: theme.breakpoints.md })
}
/>

<IconButton
icon={<ImMobile />}
size="lg"
color={editorWidth === theme.breakpoints.sm ? 'teal.500' : 'black.500'}
fontSize="30px"
aria-label="Mobile version"
onClick={() =>
dispatch.app.updateEditorWidth({ width: theme.breakpoints.sm })
}
/>
</Flex>
)
}

export default ResponsiveToolBar
8 changes: 8 additions & 0 deletions src/core/models/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type AppState = {
showLayout: boolean
showCode: boolean
inputTextFocused: boolean
editorWidth: string
overlay: undefined | Overlay
}

Expand All @@ -14,6 +15,7 @@ const app = createModel({
showLayout: true,
showCode: false,
inputTextFocused: false,
editorWidth: '100%',
overlay: undefined,
} as AppState,
reducers: {
Expand Down Expand Up @@ -41,6 +43,12 @@ const app = createModel({
overlay,
}
},
updateEditorWidth(state: AppState, payload: { width: string }): AppState {
return {
...state,
editorWidth: payload.width,
}
},
'components/deleteComponent': (state: AppState): AppState => {
return {
...state,
Expand Down
2 changes: 2 additions & 0 deletions src/core/selectors/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export const getFocusedComponent = (id: IComponent['id']) => (

export const getInputTextFocused = (state: RootState) =>
state.app.inputTextFocused

export const getEditorWidth = (state: RootState) => state.app.editorWidth
21 changes: 19 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import EditorErrorBoundary from '~components/errorBoundaries/EditorErrorBoundary
import Editor from '~components/editor/Editor'
import { InspectorProvider } from '~contexts/inspector-context'
import Inspector from '~components/inspector/Inspector'
import ResponsiveToolBar from '~components/ResponsiveToolBar'
import { useSelector } from 'react-redux'
import { getEditorWidth } from '~core/selectors/app'

const App = () => {
const editorWidth = useSelector(getEditorWidth)

useShortcuts()

return (
Expand All @@ -28,8 +33,20 @@ const App = () => {
<Flex h="calc(100vh - 3rem)">
<Sidebar />
<EditorErrorBoundary>
<Box bg="white" flex={1} position="relative">
<Editor />
<Box bg="#edf2f6" flex={1} position="relative">
<ResponsiveToolBar />
<Flex
w={editorWidth}
transition="all ease 0.5s"
h="100%"
align="center"
justify="center"
alignItems="stretch"
pt={12}
m="0 auto"
>
<Editor />
</Flex>
</Box>
</EditorErrorBoundary>

Expand Down