Skip to content

Commit

Permalink
🔀 Merge pull request ajnart#197 from Darkham42/dev
Browse files Browse the repository at this point in the history
feat: could position widgets at left
  • Loading branch information
ajnart authored Jun 12, 2022
2 parents 2c6e868 + 89804da commit 6ac82bd
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/components/Settings/CommonSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IconBrandGithub as BrandGithub } from '@tabler/icons';
import { CURRENT_VERSION } from '../../../data/constants';
import { useConfig } from '../../tools/state';
import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch';
import { WidgetsPositionSwitch } from '../WidgetsPositionSwitch/WidgetsPositionSwitch';
import ConfigChanger from '../Config/ConfigChanger';
import SaveConfigComponent from '../Config/SaveConfig';
import ModuleEnabler from './ModuleEnabler';
Expand Down Expand Up @@ -67,8 +68,8 @@ export default function CommonSettings(args: any) {
/>
)}
</Group>

<ColorSchemeSwitch />
<WidgetsPositionSwitch />
<ModuleEnabler />
<ConfigChanger />
<SaveConfigComponent />
Expand Down
56 changes: 56 additions & 0 deletions src/components/WidgetsPositionSwitch/WidgetsPositionSwitch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useState } from 'react';
import { createStyles, Switch, Group } from '@mantine/core';
import { useConfig } from '../../tools/state';

const useStyles = createStyles((theme) => ({
root: {
position: 'relative',
'& *': {
cursor: 'pointer',
},
},

icon: {
pointerEvents: 'none',
position: 'absolute',
zIndex: 1,
top: 3,
},

iconLight: {
left: 4,
color: theme.white,
},

iconDark: {
right: 4,
color: theme.colors.gray[6],
},
}));

export function WidgetsPositionSwitch() {
const { config, setConfig } = useConfig();
const { classes, cx } = useStyles();
const defaultPosition = config?.settings?.widgetPosition || 'right';
const [widgetPosition, setWidgetPosition] = useState(defaultPosition);
const toggleWidgetPosition = () => {
const position = widgetPosition === 'right' ? 'left' : 'right';
setWidgetPosition(position);
setConfig({
...config,
settings: {
...config.settings,
widgetPosition: position,
},
});
};

return (
<Group>
<div className={classes.root}>
<Switch checked={widgetPosition === 'left'} onChange={() => toggleWidgetPosition()} size="md" />
</div>
Position widgets on left
</Group>
);
}
19 changes: 3 additions & 16 deletions src/components/layout/Aside.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Aside as MantineAside, createStyles, Group } from '@mantine/core';
import { useMediaQuery } from '@mantine/hooks';
import { WeatherModule, DateModule, CalendarModule, TotalDownloadsModule } from '../modules';
import { ModuleWrapper } from '../modules/moduleWrapper';
import { Aside as MantineAside, createStyles } from '@mantine/core';
import Widgets from './Widgets';

const useStyles = createStyles((theme) => ({
hide: {
Expand All @@ -18,8 +16,6 @@ const useStyles = createStyles((theme) => ({

export default function Aside(props: any) {
const { classes, cx } = useStyles();
const matches = useMediaQuery('(min-width: 800px)');

return (
<MantineAside
pr="md"
Expand All @@ -34,16 +30,7 @@ export default function Aside(props: any) {
base: 'auto',
}}
>
<>
{matches && (
<Group my="sm" grow direction="column" style={{ width: 300 }}>
<ModuleWrapper module={CalendarModule} />
<ModuleWrapper module={TotalDownloadsModule} />
<ModuleWrapper module={WeatherModule} />
<ModuleWrapper module={DateModule} />
</Group>
)}
</>
<Widgets />
</MantineAside>
);
}
12 changes: 11 additions & 1 deletion src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ import { AppShell, createStyles } from '@mantine/core';
import { Header } from './Header';
import { Footer } from './Footer';
import Aside from './Aside';
import Navbar from './Navbar';
import { HeaderConfig } from './HeaderConfig';
import { Background } from './Background';
import { useConfig } from '../../tools/state';

const useStyles = createStyles((theme) => ({
main: {},
}));

export default function Layout({ children, style }: any) {
const { classes, cx } = useStyles();
const { config } = useConfig();
const widgetPosition = config?.settings?.widgetPosition === 'left';

return (
<AppShell aside={<Aside />} header={<Header />} footer={<Footer links={[]} />}>
<AppShell
header={<Header />}
navbar={widgetPosition ? <Navbar /> : <></>}
aside={widgetPosition ? <></> : <Aside />}
footer={<Footer links={[]} />}
>
<HeaderConfig />
<Background />
<main
Expand Down
31 changes: 22 additions & 9 deletions src/components/layout/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
import { Group, Navbar as MantineNavbar } from '@mantine/core';
import { WeatherModule, DateModule } from '../modules';
import { ModuleWrapper } from '../modules/moduleWrapper';
import { createStyles, Navbar as MantineNavbar } from '@mantine/core';
import Widgets from './Widgets';

const useStyles = createStyles((theme) => ({
hide: {
[theme.fn.smallerThan('xs')]: {
display: 'none',
},
},
burger: {
[theme.fn.largerThan('sm')]: {
display: 'none',
},
},
}));

export default function Navbar() {
const { classes, cx } = useStyles();

return (
<MantineNavbar
hiddenBreakpoint="lg"
pl="md"
hiddenBreakpoint="sm"
hidden
className={cx(classes.hide)}
style={{
border: 'none',
background: 'none',
}}
width={{
base: 'auto',
}}
>
<Group mt="sm" direction="column" align="center">
<ModuleWrapper module={DateModule} />
<ModuleWrapper module={WeatherModule} />
<ModuleWrapper module={WeatherModule} />
</Group>
<Widgets />
</MantineNavbar>
);
}
21 changes: 21 additions & 0 deletions src/components/layout/Widgets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Group } from '@mantine/core';
import { useMediaQuery } from '@mantine/hooks';
import { CalendarModule, DateModule, TotalDownloadsModule, WeatherModule } from '../modules';
import { ModuleWrapper } from '../modules/moduleWrapper';

export default function Widgets(props: any) {
const matches = useMediaQuery('(min-width: 800px)');

return (
<>
{matches && (
<Group my="sm" grow direction="column" style={{ width: 300 }}>
<ModuleWrapper module={CalendarModule} />
<ModuleWrapper module={TotalDownloadsModule} />
<ModuleWrapper module={WeatherModule} />
<ModuleWrapper module={DateModule} />
</Group>
)}
</>
);
}
1 change: 1 addition & 0 deletions src/tools/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Settings {
primaryShade?: MantineTheme['primaryShade'];
background?: string;
appOpacity?: number;
widgetPosition?: string;
}

export interface Config {
Expand Down

0 comments on commit 6ac82bd

Please sign in to comment.