mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-03 12:05:57 +01:00
Add Date module
This commit is contained in:
7
components/modules/date/DateModule.story.tsx
Normal file
7
components/modules/date/DateModule.story.tsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import DateComponent from "./DateModule";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
title: 'Date module',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Default = (args: any) => <DateComponent {...args} />;
|
||||||
41
components/modules/date/DateModule.tsx
Normal file
41
components/modules/date/DateModule.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { Box, Card, Group, Text, Title } from '@mantine/core';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Clock } from 'tabler-icons-react';
|
||||||
|
import { IModule } from '../modules';
|
||||||
|
|
||||||
|
export const DateModule: IModule = {
|
||||||
|
title: 'Date',
|
||||||
|
description: 'Show the current time and date in a card',
|
||||||
|
icon: Clock,
|
||||||
|
component: DateComponent,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function DateComponent(props: any) {
|
||||||
|
const [date, setDate] = useState(new Date());
|
||||||
|
const hours = date.getHours();
|
||||||
|
const minutes = date.getMinutes();
|
||||||
|
|
||||||
|
// Change date on minute change
|
||||||
|
// Note: Using 10 000ms instead of 1000ms to chill a little :)
|
||||||
|
useEffect(() => {
|
||||||
|
setInterval(() => {
|
||||||
|
setDate(new Date());
|
||||||
|
}, 10000);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Group p={'sm'} direction="column">
|
||||||
|
<Title>
|
||||||
|
{hours < 10 ? `0${hours}` : hours}:{minutes < 10 ? `0${minutes}` : minutes}
|
||||||
|
</Title>
|
||||||
|
<Text size="xl">
|
||||||
|
{
|
||||||
|
// Use dayjs to format the date
|
||||||
|
// https://day.js.org/en/getting-started/installation/
|
||||||
|
dayjs(date).format('dddd, MMMM D YYYY')
|
||||||
|
}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user