diff --git a/src/components/input/SelectInput.tsx b/src/components/input/SelectInput.tsx index d35e7589..e3dbc011 100644 --- a/src/components/input/SelectInput.tsx +++ b/src/components/input/SelectInput.tsx @@ -35,6 +35,7 @@ interface SelectInputBaseProps { bottomLabel?: ReactNode; options: T[]; optionComponent?: OptionComponent; + components?: Partial; isDisabled?: boolean; isLoading?: boolean; isClearable?: boolean; @@ -56,9 +57,12 @@ interface SelectInputBaseProps { onInputChange?: (search: string) => void; startAdornment?: ReactNode; menuPortalTarget?: HTMLElement | null; + closeMenuOnSelect?: boolean; + hideSelectedOptions?: boolean; } -interface SelectInputProps extends SelectInputBaseProps { +export interface SelectInputProps + extends SelectInputBaseProps { createables?: boolean; value?: T | T[] | null; onChange?: (val: T | T[] | null) => void; @@ -101,6 +105,7 @@ const SelectInput = (props: SelectInputProps) => { onChange, options, optionComponent, + components: customComponents, isDisabled, isLoading, isClearable, @@ -119,6 +124,8 @@ const SelectInput = (props: SelectInputProps) => { onInputChange, startAdornment, menuPortalTarget, + closeMenuOnSelect, + hideSelectedOptions, } = props; const [internalInputValue, setInternalInputValue] = useState(''); @@ -128,14 +135,18 @@ const SelectInput = (props: SelectInputProps) => { const components = useMemo(() => { const base = isAnimated ? animatedComponents : {}; - const customComponents = { ...base, IndicatorSeparator: () => null }; + const mergedComponents = { ...base, IndicatorSeparator: () => null }; if (startAdornment) { - customComponents.Control = CustomControl; + mergedComponents.Control = CustomControl; } - return customComponents; - }, [isAnimated, startAdornment]); + if (customComponents) { + Object.assign(mergedComponents, customComponents); + } + + return mergedComponents; + }, [isAnimated, startAdornment, customComponents]); const internalInputChangeHandler = (val: string, meta: InputActionMeta) => { if (meta.action === 'input-change') setInternalInputValue(val); @@ -205,6 +216,8 @@ const SelectInput = (props: SelectInputProps) => { isRtl={isRtl} isSearchable={isSearchable} placeholder={placeholder} + closeMenuOnSelect={closeMenuOnSelect} + hideSelectedOptions={hideSelectedOptions} className={cn('w-full', className?.select)} classNames={{ ...(!startAdornment && { diff --git a/src/components/input/SelectInputCheckbox.tsx b/src/components/input/SelectInputCheckbox.tsx new file mode 100644 index 00000000..0827a70a --- /dev/null +++ b/src/components/input/SelectInputCheckbox.tsx @@ -0,0 +1,82 @@ +'use client'; + +import { useMemo } from 'react'; +import { + OptionProps, + GroupBase, + components as ReactSelectComponents, +} from 'react-select'; +import SelectInput, { OptionType, SelectInputProps } from './SelectInput'; +import { cn } from '@/lib/helper'; + +interface SelectInputCheckboxProps + extends Omit< + SelectInputProps, + 'closeMenuOnSelect' | 'hideSelectedOptions' | 'optionComponent' + > { + closeMenuOnSelect?: boolean; + hideSelectedOptions?: boolean; +} + +const CheckboxOption = < + T extends OptionType, + IsMulti extends boolean, + Group extends GroupBase, +>( + props: OptionProps +) => { + const { isSelected, label, innerRef, innerProps, className } = props; + + return ( +
+ null} + className='checkbox checkbox-sm checkbox-primary pointer-events-none' + /> + +
+ ); +}; + +const SelectInputCheckbox = ( + props: SelectInputCheckboxProps +) => { + const { + closeMenuOnSelect = false, + hideSelectedOptions = false, + isMulti = true, + className, + ...restProps + } = props; + + const customComponents = useMemo(() => { + return { + Option: CheckboxOption as typeof ReactSelectComponents.Option, + }; + }, []); + + return ( + + {...restProps} + isMulti={isMulti} + closeMenuOnSelect={closeMenuOnSelect} + hideSelectedOptions={hideSelectedOptions} + className={{ + ...className, + select: cn(className?.select, 'select-checkbox'), + }} + components={customComponents} + /> + ); +}; + +export default SelectInputCheckbox; diff --git a/src/components/pages/report/finance/tab/CustomerPaymentTab.tsx b/src/components/pages/report/finance/tab/CustomerPaymentTab.tsx index 2b2c09a2..dfadd1ec 100644 --- a/src/components/pages/report/finance/tab/CustomerPaymentTab.tsx +++ b/src/components/pages/report/finance/tab/CustomerPaymentTab.tsx @@ -7,6 +7,7 @@ import SelectInput, { useSelect, OptionType, } from '@/components/input/SelectInput'; +import SelectInputCheckbox from '@/components/input/SelectInputCheckbox'; import DateInput from '@/components/input/DateInput'; import { CustomerApi } from '@/services/api/master-data'; import { FinanceApi } from '@/services/api/report/finance-report'; @@ -608,10 +609,9 @@ const CustomerPaymentTab = () => {
- {