Click on mode's label to activate it (#7153)

* add click event on label to activate mode

* use <label> tag instead of <span>
This commit is contained in:
Matteo Luppi 2024-09-04 15:01:09 +02:00 committed by GitHub
parent a5b5963d8c
commit d18e21fb76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 57 additions and 17 deletions

View File

@ -19,14 +19,21 @@ exports[`RegularSpec 1`] = `
>
<input
checked=""
id="mode-checkbox-:r0:"
name="mode-checkbox-:r0:"
type="checkbox"
/>
Run HTTP/S Proxy
<label
for="mode-checkbox-:r0:"
style="margin-bottom: 0px; font-weight: normal;"
>
Run HTTP/S Proxy
</label>
<div
class="mode-popover"
>
<button
popovertarget=":r0:"
popovertarget=":r1:"
>
<i
aria-hidden="true"
@ -34,7 +41,7 @@ exports[`RegularSpec 1`] = `
/>
</button>
<div
id=":r0:"
id=":r1:"
popover="auto"
>
<h4>
@ -93,14 +100,21 @@ exports[`RegularSpec 2`] = `
>
<input
checked=""
id="mode-checkbox-:r2:"
name="mode-checkbox-:r2:"
type="checkbox"
/>
Run HTTP/S Proxy
<label
for="mode-checkbox-:r2:"
style="margin-bottom: 0px; font-weight: normal;"
>
Run HTTP/S Proxy
</label>
<div
class="mode-popover"
>
<button
popovertarget=":r1:"
popovertarget=":r3:"
>
<i
aria-hidden="true"
@ -108,7 +122,7 @@ exports[`RegularSpec 2`] = `
/>
</button>
<div
id=":r1:"
id=":r3:"
popover="auto"
>
<h4>

View File

@ -49,11 +49,11 @@ function DnsRow({
<div>
<ModeToggle
value={server.active}
label="Run DNS Server"
onChange={() =>
dispatch(setActive({ server, value: !server.active }))
}
>
Run DNS Server
<Popover>
<p>Listen Host</p>
<ValueEditor

View File

@ -47,11 +47,11 @@ function LocalRow({
<div>
<ModeToggle
value={server.active}
label="Intercept traffic for"
onChange={() =>
dispatch(setActive({ server, value: !server.active }))
}
>
Intercept traffic for
<ValueEditor
className="mode-local-input"
content={server.applications || ""}

View File

@ -2,14 +2,34 @@ import * as React from "react";
type ModeToggleProps = {
value: boolean;
label: string;
onChange: (e: React.ChangeEvent) => void;
children: React.ReactNode;
};
export function ModeToggle({ value, onChange, children }: ModeToggleProps) {
export function ModeToggle({
value,
onChange,
children,
label,
}: ModeToggleProps) {
const id = React.useId();
return (
<div className="mode-entry">
<input type="checkbox" checked={value} onChange={onChange} />
<input
type="checkbox"
name={`mode-checkbox-${id}`}
id={`mode-checkbox-${id}`}
checked={value}
onChange={onChange}
/>
<label
htmlFor={`mode-checkbox-${id}`}
style={{ marginBottom: 0, fontWeight: "normal" }}
>
{label}
</label>
{children}
</div>
);

View File

@ -54,11 +54,11 @@ function RegularRow({
<div>
<ModeToggle
value={server.active}
label="Run HTTP/S Proxy"
onChange={() =>
dispatch(setActive({ server, value: !server.active }))
}
>
Run HTTP/S Proxy
<Popover>
<p>Listen Host</p>
<ValueEditor

View File

@ -85,11 +85,11 @@ function ReverseToggleRow({
<div>
<ModeToggle
value={server.active}
label="Forward"
onChange={() => {
dispatch(setActive({ server, value: !server.active }));
}}
>
Forward
<Dropdown
text={inner}
className="btn btn-default btn-xs mode-reverse-dropdown"
@ -106,7 +106,13 @@ function ReverseToggleRow({
</MenuItem>
))}
</Dropdown>{" "}
traffic from{" "}
<span
onClick={() => {
dispatch(setActive({ server, value: !server.active }));
}}
>
traffic from
</span>
<ValueEditor
className="mode-reverse-input"
content={server.listen_host || ""}

View File

@ -55,11 +55,11 @@ function SocksRow({
<div>
<ModeToggle
value={server.active}
label="Run SOCKS Proxy"
onChange={() =>
dispatch(setActive({ server, value: !server.active }))
}
>
Run SOCKS Proxy
<Popover>
<p>Listen Host</p>
<ValueEditor

View File

@ -61,11 +61,11 @@ function TransparentRow({
<div>
<ModeToggle
value={server.active}
label="Run Transparent Proxy"
onChange={() =>
dispatch(setActive({ server, value: !server.active }))
}
>
Run Transparent Proxy
<Popover>
<p>Listen Host</p>
<ValueEditor

View File

@ -55,11 +55,11 @@ function UpstreamRow({
<div>
<ModeToggle
value={server.active}
label="Run HTTP/S Proxy and forward requests to"
onChange={() => {
dispatch(setActive({ server, value: !server.active }));
}}
>
Run HTTP/S Proxy and forward requests to
<ValueEditor
className="mode-upstream-input"
content={server.destination?.toString() || ""}

View File

@ -54,11 +54,11 @@ function WireGuardRow({
<div>
<ModeToggle
value={server.active}
label="Run WireGuard Server"
onChange={() =>
dispatch(setActive({ server, value: !server.active }))
}
>
Run WireGuard Server
<Popover>
<p>Listen Host</p>
<ValueEditor