Add update button and tooltips to IconButtons
This commit is contained in:
@@ -11,12 +11,14 @@ import { Card } from './Card';
|
|||||||
export interface ModalProps {
|
export interface ModalProps {
|
||||||
title: string;
|
title: string;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
|
actions?: React.ReactNode;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Modal = ({
|
export const Modal = ({
|
||||||
title,
|
title,
|
||||||
onClose,
|
onClose,
|
||||||
|
actions,
|
||||||
children,
|
children,
|
||||||
}: ModalProps): JSX.Element => {
|
}: ModalProps): JSX.Element => {
|
||||||
const darkMode = useAppSelector((state) => state.app.darkMode);
|
const darkMode = useAppSelector((state) => state.app.darkMode);
|
||||||
@@ -43,7 +45,10 @@ export const Modal = ({
|
|||||||
<div className="text-2xl font-medium dark:text-white">
|
<div className="text-2xl font-medium dark:text-white">
|
||||||
{title}
|
{title}
|
||||||
</div>
|
</div>
|
||||||
<IconButton icon={<FiX />} onClick={onClose} />
|
<div className="flex gap-2">
|
||||||
|
{actions}
|
||||||
|
<IconButton tooltip="Close" icon={<FiX />} onClick={onClose} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{children}
|
{children}
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
|
|
||||||
|
import { Tooltip } from '@components/generic/Tooltip';
|
||||||
|
|
||||||
type DefaulButtonProps = JSX.IntrinsicElements['button'];
|
type DefaulButtonProps = JSX.IntrinsicElements['button'];
|
||||||
|
|
||||||
export interface IconButtonProps extends DefaulButtonProps {
|
export interface IconButtonProps extends DefaulButtonProps {
|
||||||
icon: React.ReactNode;
|
icon: React.ReactNode;
|
||||||
|
tooltip?: string;
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const IconButton = ({
|
export const IconButton = ({
|
||||||
icon,
|
icon,
|
||||||
active,
|
active,
|
||||||
|
tooltip,
|
||||||
disabled,
|
disabled,
|
||||||
...props
|
...props
|
||||||
}: IconButtonProps): JSX.Element => {
|
}: IconButtonProps): JSX.Element => {
|
||||||
return (
|
return (
|
||||||
|
<Tooltip disabled={!tooltip} content={tooltip}>
|
||||||
<div className="my-auto text-gray-500 dark:text-gray-400">
|
<div className="my-auto text-gray-500 dark:text-gray-400">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -23,7 +28,9 @@ export const IconButton = ({
|
|||||||
? 'bg-gray-200 dark:bg-gray-600'
|
? 'bg-gray-200 dark:bg-gray-600'
|
||||||
: 'hover:bg-gray-200 dark:hover:bg-gray-600'
|
: 'hover:bg-gray-200 dark:hover:bg-gray-600'
|
||||||
} ${
|
} ${
|
||||||
disabled ? 'cursor-not-allowed text-gray-400 dark:text-gray-700' : ''
|
disabled
|
||||||
|
? 'cursor-not-allowed text-gray-400 dark:text-gray-700'
|
||||||
|
: ''
|
||||||
}`}
|
}`}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -31,5 +38,6 @@ export const IconButton = ({
|
|||||||
<span className="sr-only">Refresh</span>
|
<span className="sr-only">Refresh</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</Tooltip>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const BottomNavItem = ({
|
|||||||
children,
|
children,
|
||||||
}: BottomNavItemProps) => {
|
}: BottomNavItemProps) => {
|
||||||
return (
|
return (
|
||||||
<Tooltip content={tooltip}>
|
<Tooltip disabled={!tooltip} content={tooltip}>
|
||||||
<div
|
<div
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
className={`group flex h-full cursor-pointer select-none p-1 hover:bg-gray-200 dark:text-white dark:hover:bg-primaryDark ${className}`}
|
className={`group flex h-full cursor-pointer select-none p-1 hover:bg-gray-200 dark:text-white dark:hover:bg-primaryDark ${className}`}
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { AnimatePresence } from 'framer-motion';
|
import { AnimatePresence } from 'framer-motion';
|
||||||
|
import { MdUpgrade } from 'react-icons/md';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
|
||||||
import { setUpdateAvaliable } from '@app/core/slices/appSlice.js';
|
import { connectionUrl } from '@app/core/connection.js';
|
||||||
import { fetcher } from '@app/core/utils/fetcher.js';
|
import { setUpdateAvaliable } from '@app/core/slices/appSlice';
|
||||||
import { useAppDispatch } from '@app/hooks/useAppDispatch.js';
|
import { fetcher } from '@app/core/utils/fetcher';
|
||||||
|
import { useAppDispatch } from '@app/hooks/useAppDispatch';
|
||||||
|
import { useAppSelector } from '@app/hooks/useAppSelector';
|
||||||
import { Modal } from '@components/generic/Modal';
|
import { Modal } from '@components/generic/Modal';
|
||||||
|
|
||||||
|
import { IconButton } from '../generic/button/IconButton';
|
||||||
|
|
||||||
export interface Commit {
|
export interface Commit {
|
||||||
sha: string;
|
sha: string;
|
||||||
node_id: string;
|
node_id: string;
|
||||||
@@ -36,6 +41,7 @@ export const VersionInfo = ({
|
|||||||
visible,
|
visible,
|
||||||
onClose,
|
onClose,
|
||||||
}: VersionInfoProps): JSX.Element => {
|
}: VersionInfoProps): JSX.Element => {
|
||||||
|
const appState = useAppSelector((state) => state.app);
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const { data } = useSWR<Commit[]>(
|
const { data } = useSWR<Commit[]>(
|
||||||
@@ -63,6 +69,13 @@ export const VersionInfo = ({
|
|||||||
{visible && (
|
{visible && (
|
||||||
<Modal
|
<Modal
|
||||||
title="Version Info"
|
title="Version Info"
|
||||||
|
actions={
|
||||||
|
appState.updateAvaliable && (
|
||||||
|
<a href={`http://${connectionUrl}/admin/spiffs`}>
|
||||||
|
<IconButton tooltip="Update now" icon={<MdUpgrade />} />
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
onClose={(): void => {
|
onClose={(): void => {
|
||||||
onClose();
|
onClose();
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user