General visual improvement on the calendar + Font size selection + selection box around the day clicked.

Fixes #1145
This commit is contained in:
Tagaishi
2023-07-11 23:29:14 +02:00
parent 8c3190ce46
commit b6df54c4c0
3 changed files with 82 additions and 17 deletions

View File

@@ -15,6 +15,9 @@
}, },
"hideWeekDays": { "hideWeekDays": {
"label": "Hide week days" "label": "Hide week days"
},
"fontSize": {
"label": "Font Size"
} }
} }
} }

View File

@@ -1,18 +1,45 @@
import { Container, Indicator, IndicatorProps, Popover } from '@mantine/core'; import { Container, Indicator, IndicatorProps, Popover, Center } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks'; import { useDisclosure } from '@mantine/hooks';
import { MediaList } from './MediaList'; import { MediaList } from './MediaList';
import { MediasType } from './type'; import { MediasType } from './type';
interface CalendarDayProps { interface CalendarDayProps {
date: Date; date: Date;
medias: MediasType; medias: MediasType;
size: string;
} }
export const CalendarDay = ({ date, medias }: CalendarDayProps) => { export const CalendarDay = ({ date, medias, size }: CalendarDayProps) => {
const [opened, { close, open }] = useDisclosure(false); const [opened, { close, open }] = useDisclosure(false);
var indicatorSize = 10;
if (medias.totalCount === 0) { var indicatorOffset = -4;
return <div>{date.getDate()}</div>; switch(size){
case "xs": {
indicatorSize += 0;
indicatorOffset -= 0;
break;
}
case "sm": {
indicatorSize += 1;
indicatorOffset -= 1;
break;
}
case "md": {
indicatorSize += 2;
indicatorOffset -= 1;
break;
}
case "lg": {
indicatorSize += 3;
indicatorOffset -= 2;
break;
}
case "xl": {
indicatorSize += 4;
indicatorOffset -= 3;
break;
}
} }
return ( return (
@@ -27,13 +54,22 @@ export const CalendarDay = ({ date, medias }: CalendarDayProps) => {
}} }}
onClose={close} onClose={close}
opened={opened} opened={opened}
sx={(theme : any) => ({
padding:'18% !important',
height: '100%',
width: '100%',
borderRadius: (size!=="xs" && size!=="sm")?theme.radius.lg:theme.radius.md,
borderStyle: "solid",
borderWidth: "0.2rem",
borderColor: opened? theme.fn.primaryColor() : '#00000000',
})}
> >
<Popover.Target> <Popover.Target>
<Container p={10} onClick={open}> <Container align="center" onClick={(medias.totalCount === 0)? undefined:open}>
<DayIndicator color="red" position="bottom-start" medias={medias.books}> <DayIndicator size={indicatorSize} offset={indicatorOffset} color="red" position="bottom-start" medias={medias.books}>
<DayIndicator color="yellow" position="top-start" medias={medias.movies}> <DayIndicator size={indicatorSize} offset={indicatorOffset} color="yellow" position="top-start" medias={medias.movies}>
<DayIndicator color="blue" position="top-end" medias={medias.tvShows}> <DayIndicator size={indicatorSize} offset={indicatorOffset} color="blue" position="top-end" medias={medias.tvShows}>
<DayIndicator color="green" position="bottom-end" medias={medias.musics}> <DayIndicator size={indicatorSize} offset={indicatorOffset} color="green" position="bottom-end" medias={medias.musics}>
<div>{date.getDate()}</div> <div>{date.getDate()}</div>
</DayIndicator> </DayIndicator>
</DayIndicator> </DayIndicator>
@@ -41,7 +77,7 @@ export const CalendarDay = ({ date, medias }: CalendarDayProps) => {
</DayIndicator> </DayIndicator>
</Container> </Container>
</Popover.Target> </Popover.Target>
<Popover.Dropdown> <Popover.Dropdown disabled = {(medias.totalCount === 0)? false:true}>
<MediaList medias={medias} /> <MediaList medias={medias} />
</Popover.Dropdown> </Popover.Dropdown>
</Popover> </Popover>
@@ -49,17 +85,19 @@ export const CalendarDay = ({ date, medias }: CalendarDayProps) => {
}; };
interface DayIndicatorProps { interface DayIndicatorProps {
size: any;
offset: any;
color: string; color: string;
medias: any[]; medias: any[];
children: JSX.Element; children: JSX.Element;
position: IndicatorProps['position']; position: IndicatorProps['position'];
} }
const DayIndicator = ({ color, medias, children, position }: DayIndicatorProps) => { const DayIndicator = ({ size, offset, color, medias, children, position }: DayIndicatorProps) => {
if (medias.length === 0) return children; if (medias.length === 0) return children;
return ( return (
<Indicator size={10} withBorder offset={-5} color={color} position={position}> <Indicator size={size} withBorder offset={offset} color={color} position={position}>
{children} {children}
</Indicator> </Indicator>
); );

View File

@@ -37,6 +37,17 @@ const definition = defineWidget({
{ label: 'Digital', value: 'digitalRelease' }, { label: 'Digital', value: 'digitalRelease' },
], ],
}, },
fontSize:{
type: 'select',
defaultValue: 'xs',
data: [
{ label: 'Extra Small', value: 'xs' },
{ label: 'Small', value: 'sm' },
{ label: 'Medium', value: 'md' },
{ label: 'Large', value: 'lg' },
{ label: 'Extra Large', value: 'xl' },
]
},
}, },
gridstack: { gridstack: {
minWidth: 2, minWidth: 2,
@@ -54,7 +65,7 @@ interface CalendarTileProps {
} }
function CalendarTile({ widget }: CalendarTileProps) { function CalendarTile({ widget }: CalendarTileProps) {
const { colorScheme } = useMantineTheme(); const { colorScheme, radius } = useMantineTheme();
const { name: configName } = useConfigContext(); const { name: configName } = useConfigContext();
const [month, setMonth] = useState(new Date()); const [month, setMonth] = useState(new Date());
const isEditMode = useEditModeStore((x) => x.enabled); const isEditMode = useEditModeStore((x) => x.enabled);
@@ -77,17 +88,24 @@ function CalendarTile({ widget }: CalendarTileProps) {
defaultDate={new Date()} defaultDate={new Date()}
onPreviousMonth={setMonth} onPreviousMonth={setMonth}
onNextMonth={setMonth} onNextMonth={setMonth}
size="xs" size={widget.properties.fontSize}
locale={i18n?.resolvedLanguage ?? 'en'} locale={i18n?.resolvedLanguage ?? 'en'}
firstDayOfWeek={widget.properties.sundayStart ? 0 : 1} firstDayOfWeek={widget.properties.sundayStart ? 0 : 1}
hideWeekdays={widget.properties.hideWeekDays ? true : false} hideWeekdays={widget.properties.hideWeekDays ? true : false}
style={{ position: 'relative', top: -10 }} style={{ position: 'relative' }}
date={month} date={month}
maxLevel="month" maxLevel="month"
hasNextLevel={false} hasNextLevel={false}
styles={{ styles={{
calendarHeader: { calendarHeader: {
maxWidth: 'inherit', maxWidth: 'inherit',
marginBottom: '0.35rem !important',
},
calendarHeaderLevel: {
height:"100%",
},
calendarHeaderControl:{
height:"100%",
}, },
calendar: { calendar: {
height: '100%', height: '100%',
@@ -104,15 +122,21 @@ function CalendarTile({ widget }: CalendarTileProps) {
flexDirection: 'column', flexDirection: 'column',
width: '100%', width: '100%',
}, },
monthCell:{
textAlign:'center',
},
month: { month: {
flex: 1, flex: 1,
}, },
day:{
borderRadius: (widget.properties.fontSize !== "xs" && widget.properties.fontSize!=="sm")? radius.lg:radius.md,
},
}} }}
getDayProps={(date) => ({ getDayProps={(date) => ({
bg: getBgColorByDateAndTheme(colorScheme, date), bg: getBgColorByDateAndTheme(colorScheme, date),
})} })}
renderDay={(date) => ( renderDay={(date) => (
<CalendarDay date={date} medias={getReleasedMediasForDate(medias, date, widget)} /> <CalendarDay date={date} medias={getReleasedMediasForDate(medias, date, widget)} size={widget.properties.fontSize} />
)} )}
/> />
); );