Skip to content

Commit dc40194

Browse files
authored
Add props to change default section header colors (#993)
1 parent 466b083 commit dc40194

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/core/src/components/SectionList/SectionHeader.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ const SectionHeader: React.FC<React.PropsWithChildren<SectionHeaderProps>> = ({
1515
interface DefaultSectionHeaderProps {
1616
title: string;
1717
theme: ReadTheme;
18+
backgroundColor?: string;
19+
textColor?: string;
1820
}
1921
export const DefaultSectionHeader = withTheme(
20-
({ title, theme }: DefaultSectionHeaderProps) => {
22+
({ title, theme, backgroundColor, textColor }: DefaultSectionHeaderProps) => {
2123
return (
2224
<Text
2325
testID="default-section-header"
2426
style={{
25-
color: theme.colors.background.base,
26-
backgroundColor: theme.colors.branding.primary,
27+
color: textColor ?? theme.colors.background.base,
28+
backgroundColor: backgroundColor ?? theme.colors.branding.primary,
2729
fontSize: 16,
2830
padding: 10,
2931
}}

packages/core/src/components/SectionList/SectionList.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ interface AdditionalSectionListProps<T> {
1818
}) => JSX.Element;
1919
keyExtractor?: (item: T, index: number) => string;
2020
listComponent?: ListComponentType;
21+
sectionHeaderBackgroundColor?: string;
22+
sectionHeaderTextColor?: string;
2123
}
2224

2325
export type FlatListSectionListProps<T> = Omit<FlatListProps<T>, "renderItem"> &
@@ -52,6 +54,8 @@ const SectionList = React.forwardRef(
5254
data: dataProp,
5355
renderItem: renderItemProp,
5456
keyExtractor: keyExtractorProp,
57+
sectionHeaderBackgroundColor,
58+
sectionHeaderTextColor,
5559
...rest
5660
}: FlatListSectionListProps<T> | FlashListSectionListProps<T>,
5761
ref: React.Ref<FlatListComponent | FlashList<any>>
@@ -161,7 +165,11 @@ const SectionList = React.forwardRef(
161165
});
162166
return (
163167
extractSectionHeader(renderedItem) || (
164-
<DefaultSectionHeader title={item.title} />
168+
<DefaultSectionHeader
169+
title={item.title}
170+
backgroundColor={sectionHeaderBackgroundColor}
171+
textColor={sectionHeaderTextColor}
172+
/>
165173
)
166174
);
167175
}

0 commit comments

Comments
 (0)