mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-14 17:26:26 +01:00
💄 Rework the bookmark widget
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
|||||||
TextInput,
|
TextInput,
|
||||||
Title,
|
Title,
|
||||||
createStyles,
|
createStyles,
|
||||||
|
useMantineTheme,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useForm } from '@mantine/form';
|
import { useForm } from '@mantine/form';
|
||||||
import {
|
import {
|
||||||
@@ -39,6 +40,7 @@ interface BookmarkItem {
|
|||||||
href: string;
|
href: string;
|
||||||
iconUrl: string;
|
iconUrl: string;
|
||||||
openNewTab: boolean;
|
openNewTab: boolean;
|
||||||
|
hideLink: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const definition = defineWidget({
|
const definition = defineWidget({
|
||||||
@@ -58,6 +60,7 @@ 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,
|
||||||
|
hideLink: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
itemComponent({ data, onChange, delete: deleteData }) {
|
itemComponent({ data, onChange, delete: deleteData }) {
|
||||||
@@ -130,6 +133,11 @@ const definition = defineWidget({
|
|||||||
label="Open in new tab"
|
label="Open in new tab"
|
||||||
checked={form.values.openNewTab}
|
checked={form.values.openNewTab}
|
||||||
/>
|
/>
|
||||||
|
<Switch
|
||||||
|
{...form.getInputProps('hideLink')}
|
||||||
|
label="Hide link"
|
||||||
|
checked={form.values.hideLink}
|
||||||
|
/>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => deleteData()}
|
onClick={() => deleteData()}
|
||||||
leftIcon={<IconTrash size="1rem" />}
|
leftIcon={<IconTrash size="1rem" />}
|
||||||
@@ -186,6 +194,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,7 +215,7 @@ 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}>
|
<Box className={classes.grid} mr={isEditModeEnabled ? 'xl' : undefined} h="100%">
|
||||||
{widget.properties.items.map((item: BookmarkItem, index) => (
|
{widget.properties.items.map((item: BookmarkItem, index) => (
|
||||||
<Card
|
<Card
|
||||||
className={classes.autoGridItem}
|
className={classes.autoGridItem}
|
||||||
@@ -216,6 +225,10 @@ function BookmarkWidgetTile({ widget }: BookmarkWidgetTileProps) {
|
|||||||
href={item.href}
|
href={item.href}
|
||||||
target={item.openNewTab ? '_blank' : undefined}
|
target={item.openNewTab ? '_blank' : undefined}
|
||||||
withBorder
|
withBorder
|
||||||
|
sx={{
|
||||||
|
backgroundColor: colorScheme === 'dark' ? colors.dark[5].concat('80') : colors.blue[0].concat('80'),
|
||||||
|
'&:hover': { backgroundColor: fn.primaryColor().concat('80'),}, //'40' = 25% opacity
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<BookmarkItemContent item={item} />
|
<BookmarkItemContent item={item} />
|
||||||
</Card>
|
</Card>
|
||||||
@@ -226,24 +239,42 @@ function BookmarkWidgetTile({ widget }: BookmarkWidgetTileProps) {
|
|||||||
case 'vertical':
|
case 'vertical':
|
||||||
return (
|
return (
|
||||||
<ScrollArea
|
<ScrollArea
|
||||||
offsetScrollbars
|
scrollbarSize={8}
|
||||||
type="always"
|
type="auto"
|
||||||
h="100%"
|
h="100%"
|
||||||
mr={isEditModeEnabled ? 'xl' : undefined}
|
mr={isEditModeEnabled ? 'xl' : undefined}
|
||||||
|
styles={{
|
||||||
|
viewport:{
|
||||||
|
//mantine being mantine again... this might break
|
||||||
|
'& div[style="min-width: 100%; display: table;"]':{
|
||||||
|
height:'100%',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Flex
|
<Flex
|
||||||
style={{ flexDirection: widget.properties.layout === 'vertical' ? 'column' : 'row' }}
|
style={{ flexDirection: widget.properties.layout === 'vertical' ? 'column' : 'row' }}
|
||||||
gap="md"
|
gap="0"
|
||||||
|
h="100%"
|
||||||
>
|
>
|
||||||
{widget.properties.items.map((item: BookmarkItem, index) => (
|
{widget.properties.items.map((item: BookmarkItem, index) => (
|
||||||
<Card
|
<Card
|
||||||
key={index}
|
key={index}
|
||||||
w={widget.properties.layout === 'vertical' ? '100%' : undefined}
|
px="md"
|
||||||
px="xl"
|
py="0"
|
||||||
component="a"
|
component="a"
|
||||||
href={item.href}
|
href={item.href}
|
||||||
target={item.openNewTab ? '_blank' : undefined}
|
target={item.openNewTab ? '_blank' : undefined}
|
||||||
withBorder
|
sx={{
|
||||||
|
border:'0.1rem solid transparent',
|
||||||
|
borderRadius:'0',
|
||||||
|
borderBottomColor:(widget.properties.layout === 'vertical' && index < widget.properties.items.length - 1) ? '#343740' : 'transparent',
|
||||||
|
borderRightColor:(widget.properties.layout === 'horizontal' && index < widget.properties.items.length - 1) ? '#343740' : 'transparent',
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
'&:hover': { backgroundColor: fn.primaryColor().concat('40'),}, //'40' = 25% opacity
|
||||||
|
flex:'1 1 auto'
|
||||||
|
}}
|
||||||
|
display="flex"
|
||||||
>
|
>
|
||||||
<BookmarkItemContent item={item}/>
|
<BookmarkItemContent item={item}/>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -256,22 +287,28 @@ function BookmarkWidgetTile({ widget }: BookmarkWidgetTileProps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 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.hideLink}
|
||||||
|
>
|
||||||
{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