diff --git a/src/components/AlphabetList/index.tsx b/src/components/AlphabetList/index.tsx index db068b0..b1d6fcb 100644 --- a/src/components/AlphabetList/index.tsx +++ b/src/components/AlphabetList/index.tsx @@ -9,7 +9,7 @@ import { styles } from "./styles"; import { sizes } from "../../values/sizes"; import { DEFAULT_CHAR_INDEX } from "../../values/consts" -export const AlphabetList: React.FC = (props) => { +export const AlphabetList: React.FC> = (props) => { const { data, index = DEFAULT_CHAR_INDEX, @@ -30,7 +30,7 @@ export const AlphabetList: React.FC = (props) => { } = props const sectionListRef = useRef(null); - const [sectionData, setSectionData] = useState([]) + const [sectionData, setSectionData] = useState[]>([]) useEffect(() => { setSectionData(getSectionData(data, index, uncategorizedAtTop)) @@ -56,7 +56,7 @@ export const AlphabetList: React.FC = (props) => { listHeaderHeight, }); - const onRenderSectionHeader = ({ section }: { section: SectionListData }) => { + const onRenderSectionHeader = ({ section }: { section: SectionListData> }) => { if (renderCustomSectionHeader) return renderCustomSectionHeader(section); return ( @@ -66,7 +66,7 @@ export const AlphabetList: React.FC = (props) => { ); }; - const onRenderItem = ({ item }: { item: IData }) => { + const onRenderItem = ({ item }: { item: IData }) => { if (renderCustomItem) return renderCustomItem(item); return ( @@ -84,7 +84,7 @@ export const AlphabetList: React.FC = (props) => { testID="sectionList" ref={sectionListRef} sections={sectionData} - keyExtractor={(item: IData) => item.key} + keyExtractor={(item: IData) => item.key} renderItem={onRenderItem} renderSectionHeader={onRenderSectionHeader} ListHeaderComponent={renderCustomListHeader} diff --git a/src/components/AlphabetList/types.ts b/src/components/AlphabetList/types.ts index 0193875..8ccd7a4 100644 --- a/src/components/AlphabetList/types.ts +++ b/src/components/AlphabetList/types.ts @@ -1,33 +1,33 @@ import { SectionListData, SectionListProps, TextStyle, ViewStyle } from "react-native"; -export interface IData { - value: string; +export interface IData { + value: Type; key: string; } -export interface ISectionData { +export interface ISectionData { title: string; - data: IData[]; + data: IData[]; index?: number; } -export interface IIndexLetterProps { - item: ISectionData, +export interface IIndexLetterProps { + item: ISectionData, index: number, onPress: () => void; } -export interface AlphabetListProps extends Partial> { - data: IData[]; +export interface AlphabetListProps extends Partial>> { + data: IData[]; index?: string[], style?: ViewStyle; indexLetterStyle?: TextStyle, indexLetterContainerStyle?: ViewStyle, indexContainerStyle?: ViewStyle, letterListContainerStyle?: ViewStyle, - renderCustomItem?: (item: IData) => JSX.Element; - renderCustomSectionHeader?: (section: SectionListData) => JSX.Element; + renderCustomItem?: (item: IData) => JSX.Element; + renderCustomSectionHeader?: (section: SectionListData>) => JSX.Element; renderCustomListHeader?: () => JSX.Element; - renderCustomIndexLetter?: ({ item, index, onPress }: IIndexLetterProps) => JSX.Element; + renderCustomIndexLetter?: ({ item, index, onPress }: IIndexLetterProps) => JSX.Element; getItemHeight?: (sectionIndex: number, rowIndex: number) => number; sectionHeaderHeight?: number; listHeaderHeight?: number; diff --git a/src/components/ListLetterIndex/index.tsx b/src/components/ListLetterIndex/index.tsx index 3658885..67a923a 100644 --- a/src/components/ListLetterIndex/index.tsx +++ b/src/components/ListLetterIndex/index.tsx @@ -4,7 +4,7 @@ import { ListLetterIndexProps } from "./types" import { styles } from "./styles"; import { ISectionData } from "../AlphabetList/types"; -export const ListLetterIndex: React.FC = ({ +export const ListLetterIndex: React.FC> = ({ sectionData, onPressLetter, indexContainerStyle, @@ -13,7 +13,7 @@ export const ListLetterIndex: React.FC = ({ renderCustomIndexLetter, letterListContainerStyle }) => { - const onRenderCustomIndexLetter = ({ item, index }: { item: ISectionData, index: number }) => { + const onRenderCustomIndexLetter = ({ item, index }: { item: ISectionData, index: number }) => { const onPress = () => onPressLetter(index) if (renderCustomIndexLetter) { diff --git a/src/components/ListLetterIndex/types.ts b/src/components/ListLetterIndex/types.ts index 6ee78ce..0b7f686 100644 --- a/src/components/ListLetterIndex/types.ts +++ b/src/components/ListLetterIndex/types.ts @@ -1,11 +1,11 @@ import { AlphabetListProps, ISectionData } from "../AlphabetList/types" -export interface ListLetterIndexProps { +export interface ListLetterIndexProps { onPressLetter: (sectionIndex: number) => void; - sectionData: ISectionData[]; - indexContainerStyle?: AlphabetListProps["indexContainerStyle"], - indexLetterStyle?: AlphabetListProps["indexLetterStyle"], - indexLetterContainerStyle?: AlphabetListProps["indexLetterContainerStyle"], - renderCustomIndexLetter?: AlphabetListProps["renderCustomIndexLetter"], - letterListContainerStyle?: AlphabetListProps["letterListContainerStyle"] + sectionData: ISectionData[]; + indexContainerStyle?: AlphabetListProps["indexContainerStyle"], + indexLetterStyle?: AlphabetListProps["indexLetterStyle"], + indexLetterContainerStyle?: AlphabetListProps["indexLetterContainerStyle"], + renderCustomIndexLetter?: AlphabetListProps["renderCustomIndexLetter"], + letterListContainerStyle?: AlphabetListProps["letterListContainerStyle"] } diff --git a/src/utils/getSectionData.ts b/src/utils/getSectionData.ts index 4dd289e..fedbf65 100644 --- a/src/utils/getSectionData.ts +++ b/src/utils/getSectionData.ts @@ -1,26 +1,26 @@ import { ISectionData, IData } from "../components/AlphabetList/types"; interface IAlphabetSet { - [key: string]: IData[]; + [key: string]: IData[]; } interface IEntry { title: string; - data: IData[]; + data: IData[]; } interface ILetterMap { [key: string]: number } -export const getSectionData = (data: IData[], charIndex: string[], uncategorizedAtTop = false) => { +export const getSectionData = (data: IData[], charIndex: string[], uncategorizedAtTop = false) => { const validLettersMap = getValidLettersMap(charIndex) - const alphabetEntrySet: [string, IData[]][] = getAlphabetEntrySet(data, validLettersMap); + const alphabetEntrySet: [string, IData[]][] = getAlphabetEntrySet(data, validLettersMap); return alphabetEntrySet .map(formatEntry) .sort((a, b) => sortSectionsByCharIndex(a, b, validLettersMap, uncategorizedAtTop)) - .map((section: ISectionData, index: number) => ({ ...section, index })); + .map((section: ISectionData, index: number) => ({ ...section, index })); }; const getValidLettersMap = (letterMap: string[]) => { @@ -33,7 +33,7 @@ const getValidLettersMap = (letterMap: string[]) => { return map } -const getAlphabetEntrySet = (data: IData[], validLettersMap: ILetterMap) => { +const getAlphabetEntrySet = (data: IData[], validLettersMap: ILetterMap) => { const alphabetSet: IAlphabetSet = {} data.forEach((item) => {