Skip to content

Open source alternative to Semrush and Ahrefs

Share the Search options dialog layout as FormDialog (#697)

Carter Smith2aadc8400a8e
diff --git a/src/client/components/FormDialog.tsx b/src/client/components/FormDialog.tsx
new file mode 100644
index 00000000..92c39404
--- /dev/null
+++ b/src/client/components/FormDialog.tsx
@@ -0,0 +1,46 @@
+import { useId, type ReactNode } from "react";
+import { Modal } from "@/client/components/Modal";
+
+/** A small settings-style dialog: title, labelled rows, right-aligned actions. */
+export function FormDialog({
+ title,
+ onClose,
+ actions,
+ children,
+}: {
+ title: string;
+ onClose?: () => void;
+ actions: ReactNode;
+ children: ReactNode;
+}) {
+ const titleId = useId();
+ return (
+ <Modal maxWidth="max-w-md" onClose={onClose} labelledBy={titleId}>
+ <h3 id={titleId} className="text-lg font-semibold">
+ {title}
+ </h3>
+ {children}
+ <div className="flex justify-end gap-2 pt-2">{actions}</div>
+ </Modal>
+ );
+}
+
+export function DialogField({
+ label,
+ help,
+ children,
+}: {
+ label: string;
+ help?: string;
+ children: ReactNode;
+}) {
+ return (
+ <label className="flex flex-col gap-1.5">
+ <span className="text-sm font-medium">{label}</span>
+ {children}
+ {help ? (
+ <span className="text-xs text-base-content/60">{help}</span>
+ ) : null}
+ </label>
+ );
+}
diff --git a/src/client/features/keywords/page/KeywordSearchOptions.tsx b/src/client/features/keywords/page/KeywordSearchOptions.tsx
index fbd6b7ea..15b4f443 100644
--- a/src/client/features/keywords/page/KeywordSearchOptions.tsx
+++ b/src/client/features/keywords/page/KeywordSearchOptions.tsx
@@ -1,6 +1,6 @@
import { useState } from "react";
import { SlidersHorizontal } from "lucide-react";
-import { Modal } from "@/client/components/Modal";
+import { DialogField, FormDialog } from "@/client/components/FormDialog";
import {
isResultLimit,
normalizeKeywordMode,
@@ -45,21 +45,22 @@ export function KeywordSearchOptions({ controller }: Props) {
</button>
{open ? (
- <Modal
- maxWidth="max-w-md"
+ <FormDialog
+ title="Search options"
onClose={() => setOpen(false)}
- labelledBy="keyword-search-options-title"
+ actions={
+ <button
+ type="button"
+ className="btn btn-primary btn-sm"
+ onClick={() => setOpen(false)}
+ >
+ Done
+ </button>
+ }
>
- <h3
- id="keyword-search-options-title"
- className="text-lg font-semibold"
- >
- Search options
- </h3>
-
<controlsForm.Field name="resultLimit">
{(field) => (
- <OptionRow label="Results">
+ <DialogField label="Results">
<select
className="select select-bordered w-full"
value={field.state.value}
@@ -74,13 +75,13 @@ export function KeywordSearchOptions({ controller }: Props) {
</option>
))}
</select>
- </OptionRow>
+ </DialogField>
)}
</controlsForm.Field>
<controlsForm.Field name="mode">
{(field) => (
- <OptionRow
+ <DialogField
label="Keyword source"
help={labs ? undefined : GOOGLE_ADS_ONLY_NOTE}
>
@@ -99,7 +100,7 @@ export function KeywordSearchOptions({ controller }: Props) {
<option value="ideas">Category ideas</option>
<option value="related">People also search for</option>
</select>
- </OptionRow>
+ </DialogField>
)}
</controlsForm.Field>
@@ -129,17 +130,7 @@ export function KeywordSearchOptions({ controller }: Props) {
disabled={!labs}
onChange={setGroupKeywords}
/>
-
- <div className="flex justify-end pt-2">
- <button
- type="button"
- className="btn btn-primary btn-sm"
- onClick={() => setOpen(false)}
- >
- Done
- </button>
- </div>
- </Modal>
+ </FormDialog>
) : null}
</>
);
@@ -148,26 +139,6 @@ export function KeywordSearchOptions({ controller }: Props) {
);
}
-function OptionRow({
- label,
- help,
- children,
-}: {
- label: string;
- help?: string;
- children: React.ReactNode;
-}) {
- return (
- <label className="flex flex-col gap-1.5">
- <span className="text-sm font-medium">{label}</span>
- {children}
- {help ? (
- <span className="text-xs text-base-content/60">{help}</span>
- ) : null}
- </label>
- );
-}
-
function ToggleRow({
label,
help,