// React Imports import React, { useState } from 'react' // MUI Imports import Button from '@mui/material/Button' import Menu from '@mui/material/Menu' import MenuItem from '@mui/material/MenuItem' import { styled } from '@mui/material/styles' const DropdownButton = styled(Button)(({ theme }) => ({ textTransform: 'none', fontWeight: 400, borderRadius: '8px', borderColor: '#e0e0e0', color: '#666', '&:hover': { borderColor: '#ccc', backgroundColor: 'rgba(0, 0, 0, 0.04)' } })) interface StatusFilterTabsProps { /** * Array of status options to display as filter tabs */ statusOptions: string[] /** * Currently selected status filter */ selectedStatus: string /** * Callback function when a status is selected */ onStatusChange: (status: string) => void /** * Custom className for the container */ className?: string /** * Custom styles for the container */ containerStyle?: React.CSSProperties /** * Size of the buttons */ buttonSize?: 'small' | 'medium' | 'large' /** * Maximum number of status options to show as buttons before switching to dropdown */ maxButtonsBeforeDropdown?: number /** * Label for the dropdown when there are many options */ dropdownLabel?: string } const StatusFilterTabs: React.FC = ({ statusOptions, selectedStatus, onStatusChange, className = '', containerStyle = {}, buttonSize = 'small', maxButtonsBeforeDropdown = 5, dropdownLabel = 'Lainnya' }) => { const [anchorEl, setAnchorEl] = useState(null) const open = Boolean(anchorEl) const handleDropdownClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget) } const handleDropdownClose = () => { setAnchorEl(null) } const handleDropdownItemClick = (status: string) => { onStatusChange(status) handleDropdownClose() } // If status options are <= maxButtonsBeforeDropdown, show all as buttons if (statusOptions.length <= maxButtonsBeforeDropdown) { return (
{statusOptions.map(status => ( ))}
) } // If more than maxButtonsBeforeDropdown, show first few as buttons and rest in dropdown const buttonStatuses = statusOptions.slice(0, maxButtonsBeforeDropdown - 1) const dropdownStatuses = statusOptions.slice(maxButtonsBeforeDropdown - 1) const isDropdownItemSelected = dropdownStatuses.includes(selectedStatus) return (
{/* Regular buttons for first few statuses */} {buttonStatuses.map(status => ( ))} {/* Dropdown button for remaining statuses */} } sx={{ ...(isDropdownItemSelected && { backgroundColor: 'primary.main', color: 'primary.contrastText', borderColor: 'primary.main', fontWeight: 600, '&:hover': { backgroundColor: 'primary.dark', borderColor: 'primary.dark' } }) }} > {isDropdownItemSelected ? selectedStatus : dropdownLabel} {dropdownStatuses.map(status => ( handleDropdownItemClick(status)} selected={selectedStatus === status} sx={{ fontSize: '14px', fontWeight: selectedStatus === status ? 600 : 400, color: selectedStatus === status ? 'primary.main' : 'text.primary' }} > {status} ))}
) } export default StatusFilterTabs // Example usage: /* import StatusFilterTabs from '@/components/StatusFilterTabs' // In your component: const [statusFilter, setStatusFilter] = useState('Semua') // For few statuses (will show all as buttons) const expenseStatusOptions = ['Semua', 'Belum Dibayar', 'Dibayar Sebagian', 'Lunas'] // For many statuses (will show some buttons + dropdown) const manyStatusOptions = [ 'Semua', 'Belum Dibayar', 'Dibayar Sebagian', 'Lunas', 'Void', 'Retur', 'Jatuh Tempo', 'Transaksi Berulang', 'Ditangguhkan', 'Dibatalkan' ] // With many options (will automatically use dropdown) // Custom configuration */