forked from ajnart/homarr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request ajnart#197 from Darkham42/dev
feat: could position widgets at left
- Loading branch information
Showing
7 changed files
with
116 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/components/WidgetsPositionSwitch/WidgetsPositionSwitch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
)} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters