misc_pterodactyl-panel/resources/scripts/components/screens/ScreenBlock.tsx

64 lines
2.1 KiB
TypeScript
Raw Normal View History

2020-04-17 21:43:03 +00:00
import React from 'react';
import PageContentBlock from '@/components/elements/PageContentBlock';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faArrowLeft, faSyncAlt } from '@fortawesome/free-solid-svg-icons';
import styled, { keyframes } from 'styled-components/macro';
2020-07-03 21:19:05 +00:00
import tw from 'twin.macro';
import Button from '@/components/elements/Button';
2020-04-17 21:43:03 +00:00
interface BaseProps {
title: string;
image: string;
message: string;
onRetry?: () => void;
onBack?: () => void;
}
interface PropsWithRetry extends BaseProps {
onRetry?: () => void;
onBack?: never | undefined;
}
interface PropsWithBack extends BaseProps {
onBack?: () => void;
onRetry?: never | undefined;
}
type Props = PropsWithBack | PropsWithRetry;
const spin = keyframes`
to { transform: rotate(360deg) }
`;
const ActionButton = styled(Button)`
2020-12-27 18:56:07 +00:00
${tw`rounded-full w-8 h-8 flex items-center justify-center p-0`};
2020-04-17 21:43:03 +00:00
&.hover\\:spin:hover {
animation: ${spin} 2s linear infinite;
2020-04-17 21:43:03 +00:00
}
`;
export default ({ title, image, message, onBack, onRetry }: Props) => (
<PageContentBlock>
2020-07-03 21:19:05 +00:00
<div css={tw`flex justify-center`}>
<div css={tw`w-full sm:w-3/4 md:w-1/2 p-12 md:p-20 bg-neutral-100 rounded-lg shadow-lg text-center relative`}>
2020-04-17 21:43:03 +00:00
{(typeof onBack === 'function' || typeof onRetry === 'function') &&
2020-07-03 21:19:05 +00:00
<div css={tw`absolute left-0 top-0 ml-4 mt-4`}>
2020-04-17 21:43:03 +00:00
<ActionButton
onClick={() => onRetry ? onRetry() : (onBack ? onBack() : null)}
className={onRetry ? 'hover:spin' : undefined}
2020-04-17 21:43:03 +00:00
>
<FontAwesomeIcon icon={onRetry ? faSyncAlt : faArrowLeft}/>
</ActionButton>
</div>
}
<img src={image} css={tw`w-2/3 h-auto select-none mx-auto`}/>
<h2 css={tw`mt-10 text-neutral-900 font-bold text-4xl`}>{title}</h2>
2020-07-03 21:19:05 +00:00
<p css={tw`text-sm text-neutral-700 mt-2`}>
2020-04-17 21:43:03 +00:00
{message}
</p>
</div>
</div>
</PageContentBlock>
);