-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1568aad
commit e00a6f7
Showing
5 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,64 @@ | ||
'use client' | ||
import { RegexEngine } from "@/engines/RegexEngine"; | ||
import React from "react"; | ||
import { useState, useEffect, useRef } from 'react'; | ||
import { createPopper } from '@popperjs/core'; | ||
|
||
type HelpButtonDropdownProps = { | ||
links: Record<string, string>; | ||
}; | ||
|
||
export function HelpButtonDropDown({ links }: HelpButtonDropdownProps) { | ||
const [showPopover, setShowPopover] = useState(false); | ||
const buttonRef = useRef(null); | ||
const popoverRef = useRef(null); | ||
|
||
useEffect(() => { | ||
if (showPopover && buttonRef.current && popoverRef.current) { | ||
const popper = createPopper(buttonRef.current, popoverRef.current, { | ||
placement: 'bottom-end', // Customize placement as needed | ||
modifiers: [ | ||
{ | ||
name: 'offset', | ||
options: { | ||
offset: [0, 0], // Adjust offset as needed | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
return () => { | ||
popper.destroy(); | ||
}; | ||
} | ||
}, [showPopover]); | ||
|
||
return ( | ||
<div className="btn-group" role="group"> | ||
<button | ||
ref={buttonRef} | ||
type="button" | ||
className="btn btn-success dropdown-toggle border-start" | ||
aria-expanded="false" | ||
onClick={(e) => { console.log(e); setShowPopover(!showPopover)}}> | ||
|
||
</button> | ||
{ showPopover && (<ul ref={popoverRef} className="dropdown-menu show"> | ||
{ Object.entries(links).map(([key, value]) => <li key={key}><a className="dropdown-item" href={value}>{key}</a></li>) } | ||
</ul>)} | ||
</div> | ||
); | ||
} | ||
|
||
type HelpButtonProps = { | ||
engine: RegexEngine; | ||
}; | ||
|
||
export function HelpButton({ engine }: HelpButtonProps) { | ||
return ( | ||
<div className="btn-group" role="group" aria-label="Button group with nested dropdown"> | ||
<a href={engine.help_url} className="btn btn-success" target="_blank">{engine.help_label}</a> | ||
{ Object.keys(engine.links).length > 0 ? <HelpButtonDropDown links={engine.links} /> : null } | ||
</div> | ||
) | ||
} |