per(ui): move field desc content to own component

This commit is contained in:
psychedelicious
2025-02-17 08:04:36 +10:00
parent 6bebd2bfc8
commit 65eabde297

View File

@@ -21,15 +21,7 @@ type Props = {
};
export const InputFieldDescriptionPopover = memo(({ nodeId, fieldName }: Props) => {
const dispatch = useAppDispatch();
const { t } = useTranslation();
const description = useInputFieldDescription(nodeId, fieldName);
const onChange = useCallback(
(e: ChangeEvent<HTMLTextAreaElement>) => {
dispatch(fieldDescriptionChanged({ nodeId, fieldName, val: e.target.value }));
},
[dispatch, fieldName, nodeId]
);
return (
<Popover isLazy lazyBehavior="unmount">
@@ -44,21 +36,38 @@ export const InputFieldDescriptionPopover = memo(({ nodeId, fieldName }: Props)
/>
</PopoverTrigger>
<PopoverContent p={2} w={256}>
<FormControl orientation="vertical">
<FormLabel>{t('nodes.description')}</FormLabel>
<Textarea
className="nodrag nopan nowheel"
fontSize="sm"
value={description ?? ''}
onChange={onChange}
p={2}
resize="none"
rows={5}
/>
</FormControl>
<Content nodeId={nodeId} fieldName={fieldName} />
</PopoverContent>
</Popover>
);
});
InputFieldDescriptionPopover.displayName = 'InputFieldDescriptionPopover';
const Content = memo(({ nodeId, fieldName }: Props) => {
const dispatch = useAppDispatch();
const { t } = useTranslation();
const description = useInputFieldDescription(nodeId, fieldName);
const onChange = useCallback(
(e: ChangeEvent<HTMLTextAreaElement>) => {
dispatch(fieldDescriptionChanged({ nodeId, fieldName, val: e.target.value }));
},
[dispatch, fieldName, nodeId]
);
return (
<FormControl orientation="vertical">
<FormLabel>{t('nodes.description')}</FormLabel>
<Textarea
className="nodrag nopan nowheel"
fontSize="sm"
value={description ?? ''}
onChange={onChange}
p={2}
resize="none"
rows={5}
/>
</FormControl>
);
});
Content.displayName = 'Content';