forked from langgenius/dify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore : option card (langgenius#6800)
- Loading branch information
Showing
2 changed files
with
74 additions
and
33 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
web/app/components/workflow/nodes/_base/components/option-card.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof variants> | ||
|
||
const OptionCard: FC<Props> = ({ | ||
className, | ||
title, | ||
onSelect, | ||
selected, | ||
disabled, | ||
align = 'center', | ||
}) => { | ||
const handleSelect = useCallback(() => { | ||
if (selected || disabled) | ||
return | ||
onSelect() | ||
}, [onSelect, selected, disabled]) | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
'flex items-center px-2 h-8 rounded-md system-sm-regular bg-components-option-card-option-bg border border-components-option-card-option-bg text-text-secondary cursor-default', | ||
(!selected && !disabled) && 'hover:bg-components-option-card-option-bg-hover hover:border-components-option-card-option-border-hover hover:shadow-xs cursor-pointer', | ||
selected && 'bg-components-option-card-option-selected-bg border-[1.5px] border-components-option-card-option-selected-border system-sm-medium shadow-xs', | ||
disabled && 'text-text-disabled', | ||
variants({ align }), | ||
className, | ||
)} | ||
onClick={handleSelect} | ||
> | ||
{title} | ||
</div> | ||
) | ||
} | ||
|
||
export default React.memo(OptionCard) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters