Skip to content

Commit cece7f1

Browse files
authored
Add props to change default section header colors (#991)
1 parent e70e034 commit cece7f1

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
@@ -21,6 +21,8 @@ interface AdditionalSectionListProps<T> {
2121
}) => JSX.Element;
2222
keyExtractor?: (item: T, index: number) => string;
2323
listComponent?: ListComponentType;
24+
sectionHeaderBackgroundColor?: string;
25+
sectionHeaderTextColor?: string;
2426
}
2527

2628
export type FlatListSectionListProps<T> = Omit<FlatListProps<T>, "renderItem"> &
@@ -55,6 +57,8 @@ const SectionList = React.forwardRef(
5557
data: dataProp,
5658
renderItem: renderItemProp,
5759
keyExtractor: keyExtractorProp,
60+
sectionHeaderBackgroundColor,
61+
sectionHeaderTextColor,
5862
...rest
5963
}: FlatListSectionListProps<T> | FlashListSectionListProps<T>,
6064
ref: React.Ref<FlatListComponent | FlashList<any>>
@@ -164,7 +168,11 @@ const SectionList = React.forwardRef(
164168
});
165169
return (
166170
extractSectionHeader(renderedItem) || (
167-
<DefaultSectionHeader title={item.title} />
171+
<DefaultSectionHeader
172+
title={item.title}
173+
backgroundColor={sectionHeaderBackgroundColor}
174+
textColor={sectionHeaderTextColor}
175+
/>
168176
)
169177
);
170178
}

0 commit comments

Comments
 (0)