Skip to content

Commit e00a6f7

Browse files
committed
Dropdown links on help button
1 parent 1568aad commit e00a6f7

File tree

5 files changed

+70
-4
lines changed

5 files changed

+70
-4
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"dependencies": {
3+
"@popperjs/core": "^2.11.8",
34
"bootstrap": "^5.3.3",
45
"fetch-jsonp": "^1.3.0",
56
"next": "^14.2.14",

src/app/advanced/[engine]/index.html/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import TestForm from './TestForm';
66
//import { testRegexAction } from './testRegexAction';
77
//import OptionsInput from './OptionsInput';
88
import { TestInput } from '@/types/TestInput';
9+
import { HelpButton } from '@/components/HelpButton';
910

1011
export async function generateMetadata({ params }: { params: { engine: string } }) {
1112
const engine = getEngine(params.engine);
@@ -48,7 +49,7 @@ export default function Page({ params }: { params: { engine: string } }) {
4849
<>
4950
<div className="d-flex justify-content-between align-items-center">
5051
<h1>{engine.short_name} Regular Expression Test Page</h1>
51-
<a className="btn btn-success" href={engine.help_url} target="_blank">{engine.help_label}</a>
52+
<HelpButton engine={engine} />
5253
</div>
5354
<ShareLinks url={`https://regexplanet.com/advanced/${engine.handle}/index.html`} text={`Test your ${engine.short_name} regular expression`} />
5455
<hr />

src/app/share/index.html/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function lookupShareCode(shareCode: string): Promise<ShareFormState> {
2020
//shareCode = "yyyyfud6z4r";
2121
const shareApiUrl = shareCode.indexOf('-') === -1
2222
? `https://appengine.regexplanet.com/share/index.json?share=${shareCode}`
23-
: `https://www.regex.zone/share/lookup.json?share=${shareCode}`;
23+
: `https://www.regex.zone/sharing/lookup.json?share=${shareCode}`;
2424
const response = await fetch(shareApiUrl);
2525
const data = await response.json();
2626
console.log(`server response=${JSON.stringify(data)}`);
@@ -29,7 +29,7 @@ async function lookupShareCode(shareCode: string): Promise<ShareFormState> {
2929
message: `Share code ${shareCode} found!`,
3030
messageType: 'success',
3131
shareCode,
32-
regex: data.recipe,
32+
regex: data.regex /* regex.zone */ || data.recipe /* old regexplanet */,
3333
};
3434
}
3535
return {

src/components/HelpButton.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
'use client'
2+
import { RegexEngine } from "@/engines/RegexEngine";
3+
import React from "react";
4+
import { useState, useEffect, useRef } from 'react';
5+
import { createPopper } from '@popperjs/core';
6+
7+
type HelpButtonDropdownProps = {
8+
links: Record<string, string>;
9+
};
10+
11+
export function HelpButtonDropDown({ links }: HelpButtonDropdownProps) {
12+
const [showPopover, setShowPopover] = useState(false);
13+
const buttonRef = useRef(null);
14+
const popoverRef = useRef(null);
15+
16+
useEffect(() => {
17+
if (showPopover && buttonRef.current && popoverRef.current) {
18+
const popper = createPopper(buttonRef.current, popoverRef.current, {
19+
placement: 'bottom-end', // Customize placement as needed
20+
modifiers: [
21+
{
22+
name: 'offset',
23+
options: {
24+
offset: [0, 0], // Adjust offset as needed
25+
},
26+
},
27+
],
28+
});
29+
30+
return () => {
31+
popper.destroy();
32+
};
33+
}
34+
}, [showPopover]);
35+
36+
return (
37+
<div className="btn-group" role="group">
38+
<button
39+
ref={buttonRef}
40+
type="button"
41+
className="btn btn-success dropdown-toggle border-start"
42+
aria-expanded="false"
43+
onClick={(e) => { console.log(e); setShowPopover(!showPopover)}}>
44+
45+
</button>
46+
{ showPopover && (<ul ref={popoverRef} className="dropdown-menu show">
47+
{ Object.entries(links).map(([key, value]) => <li key={key}><a className="dropdown-item" href={value}>{key}</a></li>) }
48+
</ul>)}
49+
</div>
50+
);
51+
}
52+
53+
type HelpButtonProps = {
54+
engine: RegexEngine;
55+
};
56+
57+
export function HelpButton({ engine }: HelpButtonProps) {
58+
return (
59+
<div className="btn-group" role="group" aria-label="Button group with nested dropdown">
60+
<a href={engine.help_url} className="btn btn-success" target="_blank">{engine.help_label}</a>
61+
{ Object.keys(engine.links).length > 0 ? <HelpButtonDropDown links={engine.links} /> : null }
62+
</div>
63+
)
64+
}

0 commit comments

Comments
 (0)