-
Notifications
You must be signed in to change notification settings - Fork 0
Update palette #303
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
Merged
Merged
Update palette #303
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c87cf5c
Palette items now show explanations when hovering over them
Daan0709 4230182
Merge branch 'master' into feat/update-palette
Daan0709 890eed5
Merge branch 'master' into feat/update-palette
Daan0709 cb48bf1
Can now close locked element by clicking on flow aswell, hovercard do…
Daan0709 d70832e
Added links to frankdoc for each element, also added deprecated label…
Daan0709 ef4f475
Merge branch 'master' into feat/update-palette
Daan0709 a78ae20
Merge branch 'master' into feat/update-palette
Daan0709 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
src/main/frontend/app/routes/studio/context/element-hover-card.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import { useEffect, useLayoutEffect, useRef, useState } from 'react' | ||
| import { createPortal } from 'react-dom' | ||
| import type { ElementDetails } from '~/types/ff-doc.types' | ||
| import { getFirstLabelGroup } from '~/utils/flow-utils' | ||
| import ExternalLinkIcon from '../../../../icons/solar/External Link.svg?react' | ||
|
|
||
| interface ElementHoverCardProps { | ||
| anchorRect: DOMRect | ||
| element: ElementDetails | ||
| isLocked: boolean | ||
| onComplete?: () => void | ||
| onUnlock?: () => void | ||
| } | ||
|
|
||
| export default function ElementHoverCard({ | ||
| anchorRect, | ||
| element, | ||
| isLocked, | ||
| onComplete, | ||
| onUnlock, | ||
| }: ElementHoverCardProps) { | ||
| const ref = useRef<HTMLDivElement>(null) | ||
| const [position, setPosition] = useState<{ top: number; left: number }>({ top: 0, left: 0 }) | ||
| const [fillWidth, setFillWidth] = useState(0) | ||
| const offset = 10 // distance between anchor and tooltip | ||
| const [labelGroup, label] = getFirstLabelGroup(element.labels) | ||
| const route = element.labels ? [labelGroup, label, element.name].join('/') : element.className | ||
| const frankdocUrl = `https://frankdoc.frankframework.org/#/${route}` | ||
|
|
||
| useLayoutEffect(() => { | ||
| if (!ref.current || !anchorRect) return | ||
|
|
||
| const tooltip = ref.current | ||
| const tooltipHeight = tooltip.offsetHeight | ||
| const tooltipWidth = tooltip.offsetWidth | ||
|
|
||
| const viewportHeight = window.innerHeight | ||
| const margin = 8 // space from top/bottom of screen | ||
|
|
||
| // Desired centered position | ||
| const centeredTop = anchorRect.top + anchorRect.height / 2 - tooltipHeight / 2 | ||
|
|
||
| // Clamp within viewport | ||
| const clampedTop = Math.min(Math.max(centeredTop, margin), viewportHeight - tooltipHeight - margin) | ||
|
|
||
| const left = anchorRect.left - tooltipWidth - offset | ||
|
|
||
| setPosition({ | ||
| top: clampedTop, | ||
| left, | ||
| }) | ||
| }, [anchorRect]) | ||
|
|
||
| useEffect(() => { | ||
| const timeout = setTimeout(() => { | ||
| setFillWidth(100) | ||
| }, 50) | ||
| return () => clearTimeout(timeout) | ||
| }, [onComplete]) | ||
|
|
||
| useEffect(() => { | ||
| function handleClickOutside(event: MouseEvent) { | ||
| if (!isLocked) return | ||
| if (!ref.current) return | ||
|
|
||
| if (!ref.current.contains(event.target as Node)) { | ||
| onUnlock?.() | ||
| } | ||
| } | ||
|
|
||
| document.addEventListener('pointerdown', handleClickOutside, true) | ||
|
|
||
| return () => { | ||
| document.removeEventListener('pointerdown', handleClickOutside, true) | ||
| } | ||
| }, [isLocked, onUnlock]) | ||
|
|
||
| return createPortal( | ||
| <div | ||
| ref={ref} | ||
| style={{ | ||
| position: 'fixed', | ||
| top: position.top, | ||
| left: position.left - offset, | ||
| pointerEvents: isLocked ? 'auto' : 'none', | ||
| zIndex: 50, | ||
| }} | ||
| className="border-border bg-background flex max-h-[70vh] max-w-[40vw] flex-col rounded-md border text-sm shadow-lg" | ||
| > | ||
| <div className="bg-backdrop h-[4px] w-full flex-shrink-0"> | ||
| <div | ||
| className="bg-foreground-active h-full transition-all duration-1000 ease-linear" | ||
| style={{ width: `${fillWidth}%` }} | ||
| onTransitionEnd={() => { | ||
| if (fillWidth === 100) { | ||
| onComplete?.() | ||
| } | ||
| }} | ||
| /> | ||
| </div> | ||
| <div className="flex-1 overflow-x-auto overflow-y-auto p-5"> | ||
| <p className="text-foreground-muted">{element.labels.Components}</p> | ||
| <h2 className="mb-2 font-semibold"> | ||
| <a | ||
| href={frankdocUrl} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="hover:text-foreground-active hover:underline" | ||
| > | ||
| {element.name} | ||
| <ExternalLinkIcon className="ml-3 inline h-4 w-4" /> | ||
| </a> | ||
| </h2> | ||
| <div className="py-2"> | ||
| {element.deprecated && ( | ||
| <span | ||
| key={'deprecated'} | ||
| className="mr-1 rounded-full border border-[var(--label-border-deprecated)] bg-[var(--label-deprecated)] p-2" | ||
| > | ||
| Deprecated | ||
| </span> | ||
| )} | ||
| {element.labels && | ||
| Object.entries(element.labels).map(([key, value]) => ( | ||
| <span | ||
| key={key} | ||
| className={'mr-1 rounded-full border p-2'} | ||
| style={{ | ||
| backgroundColor: `var(--label-${key.toLowerCase()})`, | ||
| borderColor: `var(--label-border-${key.toLowerCase()})`, | ||
| }} | ||
| > | ||
| {value} | ||
| </span> | ||
| ))} | ||
| </div> | ||
| {element.description && <p className="text-sm" dangerouslySetInnerHTML={{ __html: element.description }} />} | ||
| </div> | ||
| </div>, | ||
| document.body, | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.