mirror of
https://github.com/Radarr/Radarr
synced 2026-01-26 17:33:13 +01:00
Bulk update to make all component props immutable at the type level. This prevents accidental prop mutation and improves type safety. Resolves ~50 SonarCloud code smells.
84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import classNames from 'classnames';
|
|
import React, { SyntheticEvent, useCallback } from 'react';
|
|
import Icon from 'Components/Icon';
|
|
import Link from 'Components/Link/Link';
|
|
import { icons } from 'Helpers/Props';
|
|
import CheckInput from '../CheckInput';
|
|
import styles from './EnhancedSelectInputOption.css';
|
|
|
|
function handleCheckPress() {
|
|
// CheckInput requires a handler. Swallow the change event because onPress will already handle it via event propagation.
|
|
}
|
|
|
|
export interface EnhancedSelectInputOptionProps {
|
|
className?: string;
|
|
id: string | number;
|
|
depth?: number;
|
|
isSelected: boolean;
|
|
isDisabled?: boolean;
|
|
isHidden?: boolean;
|
|
isMultiSelect?: boolean;
|
|
isMobile: boolean;
|
|
children: React.ReactNode;
|
|
onSelect: (...args: unknown[]) => unknown;
|
|
}
|
|
|
|
function EnhancedSelectInputOption({
|
|
className = styles.option,
|
|
id,
|
|
depth = 0,
|
|
isSelected,
|
|
isDisabled = false,
|
|
isHidden = false,
|
|
isMultiSelect = false,
|
|
isMobile,
|
|
children,
|
|
onSelect,
|
|
}: Readonly<EnhancedSelectInputOptionProps>) {
|
|
const handlePress = useCallback(
|
|
(event: SyntheticEvent) => {
|
|
event.preventDefault();
|
|
|
|
onSelect(id);
|
|
},
|
|
[id, onSelect]
|
|
);
|
|
|
|
return (
|
|
<Link
|
|
className={classNames(
|
|
className,
|
|
isSelected && !isMultiSelect && styles.isSelected,
|
|
isDisabled && !isMultiSelect && styles.isDisabled,
|
|
isHidden && styles.isHidden,
|
|
isMobile && styles.isMobile
|
|
)}
|
|
component="div"
|
|
isDisabled={isDisabled}
|
|
onPress={handlePress}
|
|
>
|
|
{depth !== 0 && <div style={{ width: `${depth * 20}px` }} />}
|
|
|
|
{isMultiSelect && (
|
|
<CheckInput
|
|
className={styles.optionCheckInput}
|
|
containerClassName={styles.optionCheck}
|
|
name={`select-${id}`}
|
|
value={isSelected}
|
|
isDisabled={isDisabled}
|
|
onChange={handleCheckPress}
|
|
/>
|
|
)}
|
|
|
|
{children}
|
|
|
|
{isMobile && (
|
|
<div className={styles.iconContainer}>
|
|
<Icon name={isSelected ? icons.CHECK_CIRCLE : icons.CIRCLE_OUTLINE} />
|
|
</div>
|
|
)}
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
export default EnhancedSelectInputOption;
|