Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questionmark tooltip #325

Merged
merged 7 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@heroicons/react": "^2.0.16",
"@monaco-editor/react": "^4.4.6",
"@next/font": "^13.2.1",
"@popperjs/core": "^2.11.8",
"@tanstack/react-query": "^4.13.5",
"@tanstack/react-virtual": "^3.0.0-beta.32",
"@tauri-apps/api": "^1.4.0",
Expand Down Expand Up @@ -51,6 +52,7 @@
"react-draggable": "^4.4.5",
"react-ga4": "^1.4.1",
"react-no-ssr": "^1.1.0",
"react-popper": "^2.3.0",
"react-router-dom": "^6.5.0",
"react-spinners": "^0.13.4",
"react-toastify": "^9.1.1",
Expand Down
15 changes: 14 additions & 1 deletion dashboard/src/components/Atoms/Config/InputBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
faEyeSlash,
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import Tooltip from 'components/Tooltip';
import { useCallback, useEffect, useRef, useState } from 'react';
import BeatLoader from 'react-spinners/BeatLoader';
import {
Expand Down Expand Up @@ -43,6 +44,8 @@ export default function InputBox({
isLoading: isLoadingProp = false,
id = '',
showIcons = true,
tooltip = false,
tooltipText,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be nice to use just 1 prop for tooltip,
since we want to enable tooltip if and only if we have tooltip text

validate: validateProp, //throws error if invalid
onChange: onChangeProp,
description,
Expand All @@ -64,6 +67,8 @@ export default function InputBox({
isLoading?: boolean;
id?: string;
showIcons?: boolean;
tooltip?: boolean;
tooltipText?: string;
onSubmit: (arg: string) => Promise<void>;
validate?: (arg: string) => Promise<void>;
onChange?: (arg: string) => Promise<void>;
Expand Down Expand Up @@ -230,7 +235,15 @@ export default function InputBox({
className={`flex flex-row items-center justify-between ${className} group relative gap-4 bg-gray-800 px-4 py-3 text-medium`}
>
<div className={`flex min-w-0 grow flex-col`}>
<label className="text-medium font-medium text-gray-300">{label}</label>
<div className="flex row">
<label className="text-medium font-medium text-gray-300">{label}</label>
{ tooltip && tooltipText &&
<Tooltip
tooltip={tooltipText}
className="ml-2"
/>
}
</div>
{errorText ? (
<div className="text-small font-medium tracking-medium text-red">
{errorText || 'Unknown error'}
Expand Down
50 changes: 50 additions & 0 deletions dashboard/src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type React from "react";
import { useState } from "react";
import { usePopper } from "react-popper";
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';
import clsx from 'clsx';


const Tooltip = ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be best to pick a more specific name/make this component more general since we hard coded an "info" icon. Maybe something like "InfoTooltip"?

className,
tooltip,
} : {
className?: string,
tooltip: string,
}) => {

const [isOpen, setIsOpen] = useState(false);
const [referenceElement, setReferenceElement] = useState<HTMLDivElement | null>(null);
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
const { styles, attributes } = usePopper(referenceElement, popperElement, {
placement: "top",
});

return (
<div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this outer div necessary?

<div
ref={setReferenceElement}
onMouseEnter={() => setIsOpen(true)}
onMouseLeave={() => setIsOpen(false)}
className="relative inline-block w-auto"
>
<FontAwesomeIcon
icon={faInfoCircle}
className={clsx(className, "text-gray-400")}
/>
</div>

<div
ref={setPopperElement}
style={styles.popper}
{...attributes.popper}
className={`relative rounded-md bg-gray-900 text-white shadow-lg max-w-xs p-2 transition-opacity ${isOpen ? "opacity-100" : "opacity-0"}`}
>
{tooltip}
</div>
</div>
)
}

export default Tooltip;
1 change: 1 addition & 0 deletions dashboard/src/pages/login/CoreConfigNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useGlobalSettings } from 'data/GlobalSettings';
import { LodestoneContext } from 'data/LodestoneContext';
import { useCoreInfo } from 'data/SystemInfo';
import { useDocumentTitle } from 'usehooks-ts';
import TooltipButton from 'components/Tooltip';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where's this being used?


type ConfigNewCoreFormValues = {
coreName: string;
Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/pages/settings/CoreSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export const CoreSettings = () => {
domain: domain,
});
}}
tooltip={true}
tooltipText={"This is your public IP if you are port-forwarded. If not, leave this as is."}
/>
);

Expand Down
Loading