mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
🆙 Init V3
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { GetEventDispatcher, NitroToolbarAnimateIconEvent } from '@nitrots/nitro-renderer';
|
||||
|
||||
export const CreateTransitionToIcon = (image: HTMLImageElement, fromElement: HTMLElement, icon: string) =>
|
||||
{
|
||||
const bounds = fromElement.getBoundingClientRect();
|
||||
const x = (bounds.x + (bounds.width / 2));
|
||||
const y = (bounds.y + (bounds.height / 2));
|
||||
const event = new NitroToolbarAnimateIconEvent(image, x, y);
|
||||
|
||||
event.iconName = icon;
|
||||
|
||||
GetEventDispatcher().dispatchEvent(event);
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
import { FC, useEffect, useMemo, useState } from 'react';
|
||||
import { FriendlyTime } from '../../api';
|
||||
import { Base, BaseProps } from '../Base';
|
||||
|
||||
interface FriendlyTimeViewProps extends BaseProps<HTMLDivElement>
|
||||
{
|
||||
seconds: number;
|
||||
isShort?: boolean;
|
||||
}
|
||||
|
||||
export const FriendlyTimeView: FC<FriendlyTimeViewProps> = props =>
|
||||
{
|
||||
const { seconds = 0, isShort = false, children = null, ...rest } = props;
|
||||
const [ updateId, setUpdateId ] = useState(-1);
|
||||
|
||||
const getStartSeconds = useMemo(() => (Math.round(new Date().getSeconds()) - seconds), [ seconds ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
const interval = setInterval(() => setUpdateId(prevValue => (prevValue + 1)), 10000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
const value = (Math.round(new Date().getSeconds()) - getStartSeconds);
|
||||
|
||||
return <Base { ...rest }>{ isShort ? FriendlyTime.shortFormat(value) : FriendlyTime.format(value) }</Base>;
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './CreateTransitionToIcon';
|
||||
export * from './FriendlyTimeView';
|
||||
Reference in New Issue
Block a user