Merge pull request #1208 from Tagaishi/Bookmark-cosmetic-rework
This commit is contained in:
@@ -4,6 +4,12 @@
|
|||||||
"description": "Displays a static list of strings or links",
|
"description": "Displays a static list of strings or links",
|
||||||
"settings": {
|
"settings": {
|
||||||
"title": "Bookmark settings",
|
"title": "Bookmark settings",
|
||||||
|
"name": {
|
||||||
|
"label": "Widget Title",
|
||||||
|
"placeholder": {
|
||||||
|
"label" : "Leave empty to keep the title hidden"
|
||||||
|
}
|
||||||
|
},
|
||||||
"items": {
|
"items": {
|
||||||
"label": "Items"
|
"label": "Items"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,12 +7,15 @@ import {
|
|||||||
Group,
|
Group,
|
||||||
Image,
|
Image,
|
||||||
ScrollArea,
|
ScrollArea,
|
||||||
|
Divider,
|
||||||
Stack,
|
Stack,
|
||||||
Switch,
|
Switch,
|
||||||
Text,
|
Text,
|
||||||
TextInput,
|
TextInput,
|
||||||
Title,
|
Title,
|
||||||
createStyles,
|
createStyles,
|
||||||
|
useMantineTheme,
|
||||||
|
InputProps,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useForm } from '@mantine/form';
|
import { useForm } from '@mantine/form';
|
||||||
import {
|
import {
|
||||||
@@ -27,6 +30,7 @@ import { useTranslation } from 'next-i18next';
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
import { useEditModeStore } from '../../components/Dashboard/Views/useEditModeStore';
|
import { useEditModeStore } from '../../components/Dashboard/Views/useEditModeStore';
|
||||||
import { IconSelector } from '../../components/IconSelector/IconSelector';
|
import { IconSelector } from '../../components/IconSelector/IconSelector';
|
||||||
@@ -39,12 +43,18 @@ interface BookmarkItem {
|
|||||||
href: string;
|
href: string;
|
||||||
iconUrl: string;
|
iconUrl: string;
|
||||||
openNewTab: boolean;
|
openNewTab: boolean;
|
||||||
|
hideHostname: boolean;
|
||||||
|
hideIcon: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const definition = defineWidget({
|
const definition = defineWidget({
|
||||||
id: 'bookmark',
|
id: 'bookmark',
|
||||||
icon: IconBookmark,
|
icon: IconBookmark,
|
||||||
options: {
|
options: {
|
||||||
|
name: {
|
||||||
|
type: 'text',
|
||||||
|
defaultValue: '',
|
||||||
|
},
|
||||||
items: {
|
items: {
|
||||||
type: 'draggable-editable-list',
|
type: 'draggable-editable-list',
|
||||||
defaultValue: [],
|
defaultValue: [],
|
||||||
@@ -58,6 +68,8 @@ const definition = defineWidget({
|
|||||||
href: 'https://homarr.dev',
|
href: 'https://homarr.dev',
|
||||||
iconUrl: '/imgs/logo/logo.png',
|
iconUrl: '/imgs/logo/logo.png',
|
||||||
openNewTab: false,
|
openNewTab: false,
|
||||||
|
hideHostname: false,
|
||||||
|
hideIcon: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
itemComponent({ data, onChange, delete: deleteData }) {
|
itemComponent({ data, onChange, delete: deleteData }) {
|
||||||
@@ -130,6 +142,16 @@ const definition = defineWidget({
|
|||||||
label="Open in new tab"
|
label="Open in new tab"
|
||||||
checked={form.values.openNewTab}
|
checked={form.values.openNewTab}
|
||||||
/>
|
/>
|
||||||
|
<Switch
|
||||||
|
{...form.getInputProps('hideHostname')}
|
||||||
|
label="Hide Hostname"
|
||||||
|
checked={form.values.hideHostname}
|
||||||
|
/>
|
||||||
|
<Switch
|
||||||
|
{...form.getInputProps('hideIcon')}
|
||||||
|
label="Hide Icon"
|
||||||
|
checked={form.values.hideIcon}
|
||||||
|
/>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => deleteData()}
|
onClick={() => deleteData()}
|
||||||
leftIcon={<IconTrash size="1rem" />}
|
leftIcon={<IconTrash size="1rem" />}
|
||||||
@@ -186,6 +208,7 @@ function BookmarkWidgetTile({ widget }: BookmarkWidgetTileProps) {
|
|||||||
const { t } = useTranslation('modules/bookmark');
|
const { t } = useTranslation('modules/bookmark');
|
||||||
const { classes } = useStyles();
|
const { classes } = useStyles();
|
||||||
const { enabled: isEditModeEnabled } = useEditModeStore();
|
const { enabled: isEditModeEnabled } = useEditModeStore();
|
||||||
|
const { fn, colors, colorScheme } = useMantineTheme();
|
||||||
|
|
||||||
if (widget.properties.items.length === 0) {
|
if (widget.properties.items.length === 0) {
|
||||||
return (
|
return (
|
||||||
@@ -206,72 +229,126 @@ function BookmarkWidgetTile({ widget }: BookmarkWidgetTileProps) {
|
|||||||
switch (widget.properties.layout) {
|
switch (widget.properties.layout) {
|
||||||
case 'autoGrid':
|
case 'autoGrid':
|
||||||
return (
|
return (
|
||||||
<Box className={classes.grid} display="grid" mr={isEditModeEnabled ? 'xl' : undefined}>
|
<Stack h="100%" spacing={0}>
|
||||||
{widget.properties.items.map((item: BookmarkItem, index) => (
|
<Title size="h4" px="0.25rem">{widget.properties.name}</Title>
|
||||||
<Card
|
<Box
|
||||||
className={classes.autoGridItem}
|
className={classes.grid}
|
||||||
key={index}
|
mr={isEditModeEnabled && widget.properties.name === "" ? 'xl' : undefined}
|
||||||
px="xl"
|
h="100%"
|
||||||
component="a"
|
|
||||||
href={item.href}
|
|
||||||
target={item.openNewTab ? '_blank' : undefined}
|
|
||||||
withBorder
|
|
||||||
>
|
|
||||||
<BookmarkItemContent item={item} />
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
case 'horizontal':
|
|
||||||
case 'vertical':
|
|
||||||
return (
|
|
||||||
<ScrollArea
|
|
||||||
offsetScrollbars
|
|
||||||
type="always"
|
|
||||||
h="100%"
|
|
||||||
mr={isEditModeEnabled ? 'xl' : undefined}
|
|
||||||
>
|
|
||||||
<Flex
|
|
||||||
style={{ flexDirection: widget.properties.layout === 'vertical' ? 'column' : 'row' }}
|
|
||||||
gap="md"
|
|
||||||
>
|
>
|
||||||
{widget.properties.items.map((item: BookmarkItem, index) => (
|
{widget.properties.items.map((item: BookmarkItem, index) => (
|
||||||
<Card
|
<Card
|
||||||
|
className={classes.autoGridItem}
|
||||||
key={index}
|
key={index}
|
||||||
w={widget.properties.layout === 'vertical' ? '100%' : undefined}
|
|
||||||
px="xl"
|
px="xl"
|
||||||
|
radius="md"
|
||||||
component="a"
|
component="a"
|
||||||
href={item.href}
|
href={item.href}
|
||||||
target={item.openNewTab ? '_blank' : undefined}
|
target={item.openNewTab ? '_blank' : undefined}
|
||||||
withBorder
|
withBorder
|
||||||
|
bg={colorScheme === 'dark' ? colors.dark[5].concat('80') : colors.blue[0].concat('80')}
|
||||||
|
sx={{
|
||||||
|
'&:hover': { backgroundColor: fn.primaryColor().concat('40'), }, //'40' = 25% opacity
|
||||||
|
flex:'1 1 auto',
|
||||||
|
}}
|
||||||
|
display="flex"
|
||||||
>
|
>
|
||||||
<BookmarkItemContent item={item} />
|
<BookmarkItemContent item={item} />
|
||||||
</Card>
|
</Card>
|
||||||
))}
|
))}
|
||||||
</Flex>
|
</Box>
|
||||||
</ScrollArea>
|
</Stack>
|
||||||
|
);
|
||||||
|
case 'horizontal':
|
||||||
|
case 'vertical':
|
||||||
|
return (
|
||||||
|
<Stack h="100%" spacing={0}>
|
||||||
|
<Title size="h4" px="0.25rem">
|
||||||
|
{widget.properties.name}
|
||||||
|
</Title>
|
||||||
|
<ScrollArea
|
||||||
|
scrollbarSize={8}
|
||||||
|
type="auto"
|
||||||
|
h="100%"
|
||||||
|
offsetScrollbars
|
||||||
|
mr={isEditModeEnabled && widget.properties.name === ""? 'xl' : undefined}
|
||||||
|
styles={{
|
||||||
|
viewport:{
|
||||||
|
//mantine being mantine again... this might break. Needed for taking 100% of widget space
|
||||||
|
'& div[style="min-width: 100%; display: table;"]':{
|
||||||
|
height:'100%',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Flex
|
||||||
|
direction={ widget.properties.layout === 'vertical' ? 'column' : 'row' }
|
||||||
|
gap="0"
|
||||||
|
h="100%"
|
||||||
|
>
|
||||||
|
{widget.properties.items.map((item: BookmarkItem, index) => (
|
||||||
|
<>
|
||||||
|
<Divider
|
||||||
|
m="1px"
|
||||||
|
orientation={ widget.properties.layout !== 'vertical' ? 'vertical' : 'horizontal' } //Mantine doesn't let me refactor this, I tried
|
||||||
|
hidden={!(index > 0)}
|
||||||
|
/>
|
||||||
|
<Card
|
||||||
|
key={index}
|
||||||
|
px="md"
|
||||||
|
py="1px"
|
||||||
|
component="a"
|
||||||
|
href={item.href}
|
||||||
|
target={item.openNewTab ? '_blank' : undefined}
|
||||||
|
radius="md"
|
||||||
|
bg="transparent"
|
||||||
|
sx={{
|
||||||
|
'&:hover': { backgroundColor: fn.primaryColor().concat('40'),}, //'40' = 25% opacity
|
||||||
|
flex:'1 1 auto'
|
||||||
|
}}
|
||||||
|
display="flex"
|
||||||
|
>
|
||||||
|
<BookmarkItemContent item={item}/>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
))}
|
||||||
|
</Flex>
|
||||||
|
</ScrollArea>
|
||||||
|
</Stack>
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const BookmarkItemContent = ({ item }: { item: BookmarkItem }) => (
|
const BookmarkItemContent = ({ item }: { item: BookmarkItem }) => {
|
||||||
<Group>
|
const { colorScheme } = useMantineTheme();
|
||||||
<Image src={item.iconUrl} width={30} height={30} fit="contain" withPlaceholder />
|
return (
|
||||||
|
<Group spacing="0rem 1rem">
|
||||||
|
<Image
|
||||||
|
hidden={item.hideIcon}
|
||||||
|
src={item.iconUrl}
|
||||||
|
width={47}
|
||||||
|
height={47}
|
||||||
|
fit="contain"
|
||||||
|
withPlaceholder />
|
||||||
<Stack spacing={0}>
|
<Stack spacing={0}>
|
||||||
<Text>{item.name}</Text>
|
<Text size="md">{item.name}</Text>
|
||||||
<Text color="dimmed" size="sm">
|
<Text
|
||||||
|
color={colorScheme === 'dark' ? "gray.6" : "gray.7"}
|
||||||
|
size="sm"
|
||||||
|
hidden={item.hideHostname}
|
||||||
|
>
|
||||||
{new URL(item.href).hostname}
|
{new URL(item.href).hostname}
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Group>
|
</Group>
|
||||||
);
|
)};
|
||||||
|
|
||||||
const useStyles = createStyles(() => ({
|
const useStyles = createStyles(() => ({
|
||||||
grid: {
|
grid: {
|
||||||
display: 'grid',
|
display: 'grid',
|
||||||
gap: 20,
|
gap: 10,
|
||||||
gridTemplateColumns: 'repeat(auto-fit, minmax(150px, 1fr))',
|
gridTemplateColumns: 'repeat(auto-fit, minmax(150px, 1fr))',
|
||||||
},
|
},
|
||||||
autoGridItem: {
|
autoGridItem: {
|
||||||
|
|||||||
Reference in New Issue
Block a user