Skip to content

feat(layout): implement basic app layout system #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions apps/main/src/electron/electron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export class ElectronService implements OnApplicationBootstrap {
width: 1300,
height: 800,
minWidth: 500,
titleBarStyle: 'hidden',
trafficLightPosition: {
x: 15,
y: 13,
},
webPreferences: {
preload:
process.env.NODE_ENV === 'production'
Expand Down
1 change: 1 addition & 0 deletions apps/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@emotion/css": "^11.11.2",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^6.1.6",
"@mui/material": "^5.14.5",
"apollo-link-logger": "^2.0.1",
"graphql": "^16.9.0",
Expand Down
10 changes: 3 additions & 7 deletions apps/renderer/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ import { ThemeProvider } from '@mui/material'
import { ApolloProvider } from '@apollo/client'
import apolloClient from '@graphql/client'

import { theme } from '@styles/theme'

import { Layout } from '@components/Layout'
import { darkTheme } from '@styles/theme'

import { Routes } from '@pages'

export function App() {
return (
<ApolloProvider client={apolloClient}>
<ThemeProvider theme={theme}>
<Layout>
<Routes />
</Layout>
<ThemeProvider theme={darkTheme}>
<Routes />
</ThemeProvider>
</ApolloProvider>
)
Expand Down
13 changes: 13 additions & 0 deletions apps/renderer/src/components/Layout.styles.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from '@emotion/styled'
import { css } from '@emotion/react'
import { NAVIGATOR_WIDTH, TITLE_BAR_HEIGHT } from '@constants/layout'

export const GlobalStyles = css`
html,
Expand All @@ -12,3 +13,15 @@ export const GlobalStyles = css`
export const Root = styled.div`
height: 100%;
`

export const Content = styled.div`
padding: ${({ theme }) => theme.spacing(2)};

position: fixed;
top: ${({ theme }) => theme.spacing(TITLE_BAR_HEIGHT)};
left: ${({ theme }) => theme.spacing(NAVIGATOR_WIDTH)};
right: 0;
bottom: 0;

overflow: auto;
`
20 changes: 13 additions & 7 deletions apps/renderer/src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import React from 'react'
import { Outlet } from 'react-router-dom'

import { Global } from '@emotion/react'
import { CssBaseline } from '@mui/material'

import { GlobalStyles, Root } from '@components/Layout.styles'
import TitleBar from '@components/TitleBar'
import Navigator from '@components/Navigator'

export interface LayoutProps {}
import * as Styled from '@components/Layout.styles'

export function Layout({ children }: React.PropsWithChildren<LayoutProps>) {
export function Layout() {
return (
<Root>
<Global styles={GlobalStyles} />
<Styled.Root>
<Global styles={Styled.GlobalStyles} />
<CssBaseline />
{children}
</Root>
<TitleBar />
<Navigator />
<Styled.Content>
<Outlet />
</Styled.Content>
</Styled.Root>
)
}
17 changes: 17 additions & 0 deletions apps/renderer/src/components/Navigator.styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import styled from '@emotion/styled'

import { NAVIGATOR_WIDTH, TITLE_BAR_HEIGHT } from '@constants/layout'

export const Root = styled.div`
width: ${({ theme }) => theme.spacing(NAVIGATOR_WIDTH)};

padding: ${({ theme }) => theme.spacing(1)};
border-right: 1px solid #505153;

position: fixed;
top: ${({ theme }) => theme.spacing(TITLE_BAR_HEIGHT)};
left: 0;
bottom: 0;

background-color: #3f4042;
`
66 changes: 66 additions & 0 deletions apps/renderer/src/components/Navigator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react'
import { Link, useLocation } from 'react-router-dom'

import { Box, IconButton, Stack, Tooltip } from '@mui/material'

import { NAVIGATOR_ITEMS } from '@constants/navigator'

import * as Styled from './Navigator.styled'

interface NavigatorProps {}

function Navigator({}: NavigatorProps) {
const location = useLocation()

return (
<Styled.Root>
<Stack spacing={1}>
{NAVIGATOR_ITEMS.map(({ path, label, icon: Icon }) => (
<Box
key={path}
display="flex"
justifyContent="center"
>
<Tooltip
placement="right"
title={label}
slotProps={{
popper: {
modifiers: [
{
name: 'offset',
options: {
offset: [0, -8],
},
},
],
},
}}
>
<IconButton
draggable="false"
component={Link}
to={path}
>
<Box
component={Icon}
color="inherit"
sx={{
color: location.pathname === path ? 'text.primary' : 'text.disabled',
transition: theme =>
theme.transitions.create(['color'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.shorter,
}),
}}
/>
</IconButton>
</Tooltip>
</Box>
))}
</Stack>
</Styled.Root>
)
}

export default Navigator
14 changes: 14 additions & 0 deletions apps/renderer/src/components/TitleBar.styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import styled from '@emotion/styled'

import { TITLE_BAR_HEIGHT } from '@constants/layout'

export const Root = styled.div`
height: ${({ theme }) => theme.spacing(TITLE_BAR_HEIGHT)};

border-bottom: 1px solid #505153;

background-color: #3f4042;

-webkit-app-region: drag;
user-select: none;
`
11 changes: 11 additions & 0 deletions apps/renderer/src/components/TitleBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'

import * as Styled from './TitleBar.styled'

interface TitleBarProps {}

function TitleBar({}: TitleBarProps) {
return <Styled.Root />
}

export default TitleBar
2 changes: 2 additions & 0 deletions apps/renderer/src/constants/layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const TITLE_BAR_HEIGHT = 5 // 40px
export const NAVIGATOR_WIDTH = 8 // 64px
25 changes: 25 additions & 0 deletions apps/renderer/src/constants/navigator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react'

import HomeRounded from '@mui/icons-material/HomeRounded'
import SearchRounded from '@mui/icons-material/SearchRounded'

import { SvgIconProps } from '@mui/material'

export interface NavigatorItem {
icon: React.ComponentType<SvgIconProps>
label: string
path: string
}

export const NAVIGATOR_ITEMS: NavigatorItem[] = [
{
icon: HomeRounded,
label: 'Home',
path: '/',
},
{
icon: SearchRounded,
label: 'Search',
path: '/search',
},
]
5 changes: 5 additions & 0 deletions apps/renderer/src/emotion.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createTheme } from '@mui/material'

declare module '@emotion/react' {
export interface Theme extends ReturnType<typeof createTheme> {}
}
3 changes: 3 additions & 0 deletions apps/renderer/src/pages/Search.styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import styled from '@emotion/styled'

export const Root = styled.div``
9 changes: 9 additions & 0 deletions apps/renderer/src/pages/Search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

import * as Styled from './Search.styled'

interface SearchProps {}

export function Search({}: SearchProps) {
return <Styled.Root>Search</Styled.Root>
}
16 changes: 14 additions & 2 deletions apps/renderer/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import React from 'react'
import { createHashRouter, createRoutesFromElements, Route, RouterProvider } from 'react-router-dom'

import { Layout } from '@components/Layout'

import { Home } from '@pages/Home'
import { Search } from '@pages/Search'

const router = createHashRouter(
createRoutesFromElements(
<Route
path="/"
element={<Home />}
/>,
element={<Layout />}
>
<Route
index
element={<Home />}
/>
<Route
path="search"
element={<Search />}
/>
</Route>,
),
)

Expand Down
9 changes: 8 additions & 1 deletion apps/renderer/src/styles/theme.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { createTheme } from '@mui/material'

export const theme = createTheme()
export const darkTheme = createTheme({
palette: {
mode: 'dark',
background: {
default: '#242428',
},
},
})
3 changes: 2 additions & 1 deletion apps/renderer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"@pages": ["src/pages"],
"@pages/*": ["src/pages/*"],
"@components/*": ["src/components/*"],
"@styles/*": ["src/styles/*"]
"@styles/*": ["src/styles/*"],
"@constants/*": ["src/constants/*"],
}
},
"include": ["src"]
Expand Down
2 changes: 1 addition & 1 deletion packages/tsconfig/renderer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"noUnusedParameters": true,
"noImplicitReturns": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"allowImportingTsExtensions": false,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
Expand Down
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.