metis-desk/packages/rdx-ui/src/components/option-picker-dialog.tsx
David db57346c24 feat: add PickerHelp component and browser fixture for picker UI
- Introduced PickerHelp component for contextual help in pickers.
- Created PickerBrowserFixture for testing picker components in a browser-like environment.
- Implemented a comprehensive regression test suite for picker UI using Playwright.
- Added support for localization in picker components and tests.
2026-10-22 09:35:02 +02:00

88 lines
1.9 KiB
TypeScript

import { Button } from "@repo/shadcn-ui/components/button";
import { useState } from "react";
import { FormActions, FormBody, FormDialog } from "./form-dialog";
import { OptionPickerList } from "./option-picker-list";
export type PickerOption = {
id: string;
label: string;
description: string;
disabled?: boolean;
};
/** Selección única provisional: buscar y cancelar nunca modifican el formulario padre. */
export function OptionPickerDialog({
title,
options,
value,
onSelect,
onClose,
labels,
locale,
loading = false,
}: {
title: string;
options: readonly PickerOption[];
value: string;
onSelect: (id: string) => void;
onClose: () => void;
labels: {
selection: string;
name: string;
entity: (count: number) => string;
description: string;
confirm: string;
cancel: string;
search: string;
};
locale: string;
loading?: boolean;
}) {
const [selected, setSelected] = useState(value);
const available =
!loading && options.some((option) => option.id === selected && !option.disabled);
return (
<FormDialog
cancelLabel={labels.cancel}
formActions
layout="picker"
onOpenChange={(open) => {
if (!open) {
onClose();
}
}}
open
size="medium"
title={title}
>
<FormBody>
<OptionPickerList
labels={labels}
loading={loading}
locale={locale}
onChange={setSelected}
options={options}
title={title}
value={selected}
/>
</FormBody>
<FormActions>
<Button
disabled={!available}
onClick={() => {
if (available) {
onSelect(selected);
onClose();
}
}}
type="button"
>
{labels.confirm}
</Button>
</FormActions>
</FormDialog>
);
}