Files
streamyfin/components/list/ListGroup.tsx
Uruk 75d6948a81 refactor: replace any types with proper TypeScript types
Improves type safety throughout the codebase by eliminating unsafe `any` type assertions and replacing them with proper type definitions.

Adds explicit type parameters and constraints to MMKV augmentations, component props, and router navigation calls. Updates function signatures to use `unknown` instead of `any` where appropriate, and properly types Icon glyphs, router Href parameters, and component prop spreads.

Enhances maintainability and catches potential type errors at compile time rather than runtime.
2025-11-25 19:06:43 +01:00

59 lines
1.5 KiB
TypeScript

import {
Children,
cloneElement,
isValidElement,
type PropsWithChildren,
type ReactElement,
} from "react";
import { StyleSheet, View, type ViewProps, type ViewStyle } from "react-native";
import { Text } from "../common/Text";
interface Props extends ViewProps {
title?: string | null | undefined;
description?: ReactElement;
}
export const ListGroup: React.FC<PropsWithChildren<Props>> = ({
title,
children,
description,
...props
}) => {
const childrenArray = Children.toArray(children);
return (
<View {...props}>
<Text className='ml-4 mb-1 uppercase text-[#8E8D91] text-xs'>
{title}
</Text>
<View
style={[]}
className='flex flex-col rounded-xl overflow-hidden pl-0 bg-neutral-900'
>
{Children.map(childrenArray, (child, index) => {
if (isValidElement(child)) {
const style = StyleSheet.compose(
(child.props as { style?: ViewStyle }).style,
index < childrenArray.length - 1
? styles.borderBottom
: undefined,
);
return cloneElement(child, { style } as Partial<
typeof child.props
>);
}
return child;
})}
</View>
{description && <View className='pl-4 mt-1'>{description}</View>}
</View>
);
};
const styles = StyleSheet.create({
borderBottom: {
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: "#3D3C40",
},
});