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

Подсказки при наведении #119

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/renderer/src/assets/icons/question-mark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 18 additions & 1 deletion src/renderer/src/components/ComponentFormFieldLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import React from 'react';

import { ReactComponent as QuestionMark } from '@renderer/assets/icons/question-mark.svg';

import { WithHint } from './WithHint';

interface ComponentFormFieldLabelProps {
label: string;
hint?: string;
children: React.ReactNode;
}

export const ComponentFormFieldLabel: React.FC<ComponentFormFieldLabelProps> = ({
label,
hint,
children,
}) => {
return (
<label className="flex items-center gap-2">
<span className="w-24">{label}</span>
<div className="flex w-28 items-center gap-1">
<span>{label}</span>
{hint && (
<WithHint hint={hint}>
{(props) => (
<div className="shrink-0" {...props}>
<QuestionMark className="h-5 w-5" />
</div>
)}
</WithHint>
)}
</div>
{children}
</label>
);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/ComponentFormFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const ComponentFormFields: React.FC<ComponentFormFieldsProps> = ({
const name = param.name ?? idx;
const value = parameters[name] ?? '';
return (
<ComponentFormFieldLabel key={idx} label={name + ':'}>
<ComponentFormFieldLabel key={idx} label={name + ':'} hint={param.description}>
<input
className="w-[250px] rounded border border-border-primary bg-transparent px-2 py-1 text-text-primary outline-none"
value={value}
Expand Down
71 changes: 44 additions & 27 deletions src/renderer/src/components/CreateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { defaultTransColor } from './DiagramEditor';
import { ColorInput } from './Modal/ColorInput';
import { Modal } from './Modal/Modal';
import { TextInput } from './Modal/TextInput';
import { WithHint } from './WithHint';

const operandOptions = [
{
Expand Down Expand Up @@ -128,28 +129,38 @@ export const CreateModal: React.FC<CreateModalProps> = ({
const isEditingEvent = isData === undefined;

const compoEntry = (idx: string) => {
const proto = machine.platform.getComponent(idx);

return {
value: idx,
label: (
<div className="flex items-center">
{machine.platform.getFullComponentIcon(idx, 'mr-1 h-7 w-7')}
{idx}
</div>
<WithHint hint={proto?.description ?? ''} offset={15} placement="right">
{(props) => (
<div className="flex items-center" {...props}>
{machine.platform.getFullComponentIcon(idx, 'mr-1 h-7 w-7')}
{idx}
</div>
)}
</WithHint>
),
};
};

const eventEntry = (name: string, compo?: string) => {
const eventEntry = (name: string, compo?: string, description?: string) => {
return {
value: name,
label: (
<div className="flex items-center">
<img
src={machine.platform.getEventIconUrl(compo ?? components.value, name, true)}
className="mr-1 h-7 w-7 object-contain"
/>
{name}
</div>
<WithHint hint={description ?? ''} offset={15} placement="right">
{(props) => (
<div className="flex items-center" {...props}>
<img
src={machine.platform.getEventIconUrl(compo ?? components.value, name, true)}
className="mr-1 h-7 w-7 object-contain"
/>
{name}
</div>
)}
</WithHint>
),
};
};
Expand All @@ -169,21 +180,25 @@ export const CreateModal: React.FC<CreateModalProps> = ({
};
};

const conditionEntry = (name: string, compo?: string) => {
const conditionEntry = (name: string, compo?: string, description?: string) => {
return {
value: name,
label: (
<div className="flex items-center">
<img
src={machine.platform.getVariableIconUrl(
compo ? param1Components.value : param2Components.value,
name,
true
)}
className="mr-1 h-7 w-7 object-contain"
/>
{name}
</div>
<WithHint hint={description ?? ''} offset={15} placement="right">
{(props) => (
<div className="flex items-center" {...props}>
<img
src={machine.platform.getVariableIconUrl(
compo ? param1Components.value : param2Components.value,
name,
true
)}
className="mr-1 h-7 w-7 object-contain"
/>
{name}
</div>
)}
</WithHint>
),
};
};
Expand Down Expand Up @@ -215,18 +230,20 @@ export const CreateModal: React.FC<CreateModalProps> = ({

const optionsMethods = !components
? []
: machine.platform.getAvailableEvents(components.value).map(({ name }) => eventEntry(name));
: machine.platform
.getAvailableEvents(components.value)
.map(({ name, description }) => eventEntry(name, undefined, description));

const optionsParam1Methods = !components
? []
: machine.platform
.getAvailableVariables(param1Components.value)
.map(({ name }) => conditionEntry(name, param1Components.value));
.map(({ name, description }) => conditionEntry(name, param1Components.value, description));
const optionsParam2Methods = !components
? []
: machine.platform
.getAvailableVariables(param2Components.value)
.map(({ name }) => conditionEntry(name, param2Components.value));
.map(({ name, description }) => conditionEntry(name, param2Components.value, description));

const [methods, setMethods] = useState<SelectOption | null>(optionsMethods[0]);
const [param1Methods, setParam1Methods] = useState<SelectOption | null>(optionsParam1Methods[0]);
Expand Down
64 changes: 42 additions & 22 deletions src/renderer/src/components/EventsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { State } from '@renderer/lib/drawable/State';
import { Action, Event } from '@renderer/types/diagram';
import { ArgumentProto } from '@renderer/types/platform';

import { WithHint } from './WithHint';

import { EventSelection } from '../lib/drawable/Events';

type ArgSet = { [k: string]: string };
Expand Down Expand Up @@ -54,43 +56,57 @@ export const CreateEventsModal: React.FC<EventsModalProps> = ({
const isEditingEvent = props.isData?.event.actionIdx === null;

const compoEntry = (idx: string) => {
const proto = machine.platform.getComponent(idx);

return {
value: idx,
label: (
<div className="flex items-center">
{machine.platform.getFullComponentIcon(idx, 'mr-1 h-7 w-7')}
{idx}
</div>
<WithHint hint={proto?.description ?? ''} offset={15} placement="right">
{(props) => (
<div className="flex items-center" {...props}>
{machine.platform.getFullComponentIcon(idx, 'mr-1 h-7 w-7')}
{idx}
</div>
)}
</WithHint>
),
};
};

const eventEntry = (name: string, compo?: string) => {
const eventEntry = (name: string, compo?: string, description?: string) => {
return {
value: name,
label: (
<div className="flex items-center">
<img
src={machine.platform.getEventIconUrl(compo ?? components.value, name, true)}
className="mr-1 h-7 w-7 object-contain"
/>
{name}
</div>
<WithHint hint={description ?? ''} offset={15} placement="right">
{(props) => (
<div className="flex items-center" {...props}>
<img
src={machine.platform.getEventIconUrl(compo ?? components.value, name, true)}
className="mr-1 h-7 w-7 object-contain"
/>
{name}
</div>
)}
</WithHint>
),
};
};

const actionEntry = (name: string, compo?: string) => {
const actionEntry = (name: string, compo?: string, description?: string) => {
return {
value: name,
label: (
<div className="flex items-center">
<img
src={machine.platform.getActionIconUrl(compo ?? components.value, name, true)}
className="mr-1 h-7 w-7 object-contain"
/>
{name}
</div>
<WithHint hint={description ?? ''} offset={15} placement="right">
{(props) => (
<div className="flex items-center" {...props}>
<img
src={machine.platform.getActionIconUrl(compo ?? components.value, name, true)}
className="mr-1 h-7 w-7 object-contain"
/>
{name}
</div>
)}
</WithHint>
),
};
};
Expand All @@ -107,8 +123,12 @@ export const CreateEventsModal: React.FC<EventsModalProps> = ({
const optionsMethods = !components
? []
: isEditingEvent
? machine.platform.getAvailableEvents(components.value).map(({ name }) => eventEntry(name))
: machine.platform.getAvailableMethods(components.value).map(({ name }) => actionEntry(name));
? machine.platform
.getAvailableEvents(components.value)
.map(({ name, description }) => eventEntry(name, undefined, description))
: machine.platform
.getAvailableMethods(components.value)
.map(({ name, description }) => actionEntry(name, undefined, description));

const [methods, setMethods] = useState<SelectOption | null>(optionsMethods[0]);

Expand Down
38 changes: 25 additions & 13 deletions src/renderer/src/components/Sidebar/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { useComponents } from '@renderer/hooks';
import { CanvasEditor } from '@renderer/lib/CanvasEditor';
import { EditorManager } from '@renderer/lib/data/EditorManager';

import { WithHint } from '../WithHint';

interface ExplorerProps {
editor: CanvasEditor | null;
manager: EditorManager;
Expand Down Expand Up @@ -58,6 +60,28 @@ export const Explorer: React.FC<ExplorerProps> = ({ editor, manager }) => {
onRequestAddComponent();
};

const renderComponent = (name: string) => {
const proto = editor?.container.machineController.platform.getComponent(name);

return (
<WithHint key={name} hint={proto?.description ?? ''} placement="right">
{(props) => (
<div
className={twMerge('flex items-center p-1', name == cursor && 'bg-bg-active')}
onClick={() => onClick(name)}
onAuxClick={() => onAuxClick(name)}
onDoubleClick={() => onCompDblClick(name)}
onContextMenu={() => onCompRightClick(name)}
{...props}
>
{editor?.container.machineController.platform?.getFullComponentIcon(name)}
<p className="ml-2 line-clamp-1">{name}</p>
</div>
)}
</WithHint>
);
};

return (
<section className="flex flex-col" onClick={() => onUnClick()}>
<h3 className="mx-4 mb-3 border-b border-border-primary py-2 text-center text-lg">
Expand All @@ -80,19 +104,7 @@ export const Explorer: React.FC<ExplorerProps> = ({ editor, manager }) => {
listItems={Object.keys(components)}
heightOfItem={10}
maxItemsToRender={50}
renderItem={(key) => (
<div
key={key}
className={twMerge('flex items-center p-1', key == cursor && 'bg-bg-active')}
onClick={() => onClick(key)}
onAuxClick={() => onAuxClick(key)}
onDoubleClick={() => onCompDblClick(key)}
onContextMenu={() => onCompRightClick(key)}
>
{editor?.container.machineController.platform?.getFullComponentIcon(key)}
<p className="ml-2 line-clamp-1">{key}</p>
</div>
)}
renderItem={renderComponent}
/>
</div>

Expand Down
Loading