diff --git a/web/app/components/workflow/nodes/_base/components/option-card.tsx b/web/app/components/workflow/nodes/_base/components/option-card.tsx new file mode 100644 index 00000000000000..62fe8937fd43dd --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/option-card.tsx @@ -0,0 +1,62 @@ +'use client' +import type { FC } from 'react' +import React, { useCallback } from 'react' +import type { VariantProps } from 'class-variance-authority' +import { cva } from 'class-variance-authority' +import cn from '@/utils/classnames' + +const variants = cva([], { + variants: { + align: { + left: 'justify-start', + center: 'justify-center', + right: 'justify-end', + }, + }, + defaultVariants: { + align: 'center', + }, +}, +) + +type Props = { + className?: string + title: string + onSelect: () => void + selected: boolean + disabled?: boolean + align?: 'left' | 'center' | 'right' +} & VariantProps + +const OptionCard: FC = ({ + className, + title, + onSelect, + selected, + disabled, + align = 'center', +}) => { + const handleSelect = useCallback(() => { + if (selected || disabled) + return + onSelect() + }, [onSelect, selected, disabled]) + + return ( +
+ {title} +
+ ) +} + +export default React.memo(OptionCard) diff --git a/web/app/components/workflow/nodes/llm/components/resolution-picker.tsx b/web/app/components/workflow/nodes/llm/components/resolution-picker.tsx index 6ea48b1f72fbe3..76763de520c633 100644 --- a/web/app/components/workflow/nodes/llm/components/resolution-picker.tsx +++ b/web/app/components/workflow/nodes/llm/components/resolution-picker.tsx @@ -2,35 +2,11 @@ import type { FC } from 'react' import React, { useCallback } from 'react' import { useTranslation } from 'react-i18next' -import cn from '@/utils/classnames' +import OptionCard from '@/app/components/workflow/nodes/_base/components/option-card' import { Resolution } from '@/types/app' const i18nPrefix = 'workflow.nodes.llm' -type ItemProps = { - title: string - value: Resolution - onSelect: (value: Resolution) => void - isSelected: boolean -} - -const Item: FC = ({ title, value, onSelect, isSelected }) => { - const handleSelect = useCallback(() => { - if (isSelected) - return - onSelect(value) - }, [value, onSelect, isSelected]) - - return ( -
- {title} -
- ) -} - type Props = { value: Resolution onChange: (value: Resolution) => void @@ -42,21 +18,24 @@ const ResolutionPicker: FC = ({ }) => { const { t } = useTranslation() + const handleOnChange = useCallback((value: Resolution) => { + return () => { + onChange(value) + } + }, [onChange]) return (
{t(`${i18nPrefix}.resolution.name`)}
- -