chore : option card (#6800)

This commit is contained in:
Joel
2024-07-30 17:33:08 +08:00
committed by GitHub
parent 0a744a73b3
commit 53a89bbbc7
2 changed files with 74 additions and 33 deletions

View File

@@ -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)