Extracted default window constants

This commit is contained in:
Dustin Brett
2021-03-27 21:28:13 -07:00
parent 118fe24474
commit 746832ec0e
2 changed files with 18 additions and 14 deletions

View File

@@ -2,8 +2,9 @@ import { useCallback, useMemo, useState } from 'react';
import type { DraggableEventHandler } from 'react-draggable';
import type { Position, RndResizeCallback } from 'react-rnd';
import { useTheme } from 'styled-components';
import { DEFAULT_WINDOW_POSITION, DEFAULT_WINDOW_SIZE } from 'utils/constants';
type Size = {
export type Size = {
height: string;
width: string;
};
@@ -18,20 +19,10 @@ type Resizable = Size & {
type DraggableAndResizable = Resizable & Draggable;
const defaultWindowSize = {
height: '200px',
width: '250px'
};
const defaultWindowPosition = {
x: 0,
y: 0
};
const useDraggableAndResizable = (maximized = false): DraggableAndResizable => {
const { sizes } = useTheme();
const [{ height, width }, setSize] = useState<Size>(defaultWindowSize);
const [{ x, y }, setPosition] = useState<Position>(defaultWindowPosition);
const [{ height, width }, setSize] = useState<Size>(DEFAULT_WINDOW_SIZE);
const [{ x, y }, setPosition] = useState<Position>(DEFAULT_WINDOW_POSITION);
const updatePosition = useCallback<DraggableEventHandler>(
(_event, { x: positionX, y: positionY }) =>
setPosition({ x: positionX, y: positionY }),

View File

@@ -1,4 +1,15 @@
export const MILLISECONDS_IN_SECOND = 1000;
import type { Size } from 'hooks/useDraggableAndResizable';
import type { Position } from 'react-rnd';
export const DEFAULT_WINDOW_POSITION: Position = {
x: 0,
y: 0
};
export const DEFAULT_WINDOW_SIZE: Size = {
height: '200px',
width: '250px'
};
export const IMAGE_FILE_EXTENSIONS = [
'.apng',
@@ -21,3 +32,5 @@ export const IMAGE_FILE_EXTENSIONS = [
'.webp',
'.xbm'
];
export const MILLISECONDS_IN_SECOND = 1000;