import React from 'react' import cn from '@/utils/classnames' import type { RemixiconComponentType } from '@remixicon/react' import Divider from '../divider' import type { VariantProps } from 'class-variance-authority' import { cva } from 'class-variance-authority' import './index.css' type SegmentedControlOption = { value: T text?: string Icon: RemixiconComponentType count?: number } type SegmentedControlProps = { options: SegmentedControlOption[] value: T onChange: (value: T) => void className?: string activeClassName?: string } const SegmentedControlVariants = cva( 'segmented-control', { variants: { size: { regular: 'segmented-control-regular', small: 'segmented-control-small', large: 'segmented-control-large', }, padding: { none: 'no-padding', with: 'padding', }, }, defaultVariants: { size: 'regular', padding: 'with', }, }, ) const SegmentedControlItemVariants = cva( 'segmented-control-item disabled:segmented-control-item-disabled', { variants: { size: { regular: ['segmented-control-item-regular', 'system-sm-medium'], small: ['segmented-control-item-small', 'system-xs-medium'], large: ['segmented-control-item-large', 'system-md-semibold'], }, activeState: { default: '', accent: 'accent', accentLight: 'accent-light', }, }, defaultVariants: { size: 'regular', activeState: 'default', }, }, ) const ItemTextWrapperVariants = cva( 'item-text', { variants: { size: { regular: 'item-text-regular', small: 'item-text-small', large: 'item-text-large', }, }, defaultVariants: { size: 'regular', }, }, ) export const SegmentedControl = ({ options, value, onChange, className, size, padding, activeState, activeClassName, }: SegmentedControlProps & VariantProps & VariantProps & VariantProps) => { const selectedOptionIndex = options.findIndex(option => option.value === value) return (
{options.map((option, index) => { const { Icon, text, count } = option const isSelected = index === selectedOptionIndex const isNextSelected = index === selectedOptionIndex - 1 const isLast = index === options.length - 1 return ( ) })}
) } export default React.memo(SegmentedControl)