-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiSegment.tsx
More file actions
51 lines (46 loc) · 1.32 KB
/
MultiSegment.tsx
File metadata and controls
51 lines (46 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { badgeCVA, typeIcons } from '@/components/design'
interface Segment<T> {
text?: string
type: keyof typeof typeIcons
value: T
}
interface MultiSegmentProps<T> {
segments: Segment<T>[]
value: T
onValueChange: (value: T) => void
}
const MultiSegment = <T,>({ segments, value, onValueChange }: MultiSegmentProps<T>) => {
return (
<div className='inline-flex items-center gap-0'>
{segments.map((segment, index) => {
const Icon = typeIcons[segment.type]
const isFirst = index === 0
const isLast = index === segments.length - 1
const roundedClasses =
isFirst && isLast
? ''
: isFirst
? '!rounded-r-none'
: isLast
? '!rounded-l-none'
: '!rounded-none'
return (
<button
key={String(segment.value)}
className={`${badgeCVA({
clickable: true,
selected: value === segment.value,
type: segment.type,
})} ${roundedClasses}`}
onClick={() => onValueChange(segment.value)}
type='button'
>
{segment.type === 'blank' || <Icon className='h-3 w-3' />}
{segment.text}
</button>
)
})}
</div>
)
}
export default MultiSegment