From 30fed6f3668bef1c75c69761137cce1fd581b1eb Mon Sep 17 00:00:00 2001 From: Dawid Date: Thu, 14 Mar 2019 12:53:56 +0200 Subject: [PATCH] feat: add titleStyle and descriptionStyle props to List.Item (#911) --- src/components/List/ListItem.js | 22 +++- src/components/__tests__/ListItem.test.js | 15 +++ .../__snapshots__/ListAccordion.test.js.snap | 1 + .../__snapshots__/ListItem.test.js.snap | 106 ++++++++++++++++++ .../__snapshots__/ListSection.test.js.snap | 4 + typings/components/List.d.ts | 12 +- 6 files changed, 156 insertions(+), 4 deletions(-) diff --git a/src/components/List/ListItem.js b/src/components/List/ListItem.js index 3bb891b892..2bd5173a57 100644 --- a/src/components/List/ListItem.js +++ b/src/components/List/ListItem.js @@ -3,6 +3,10 @@ import color from 'color'; import * as React from 'react'; import { View, StyleSheet } from 'react-native'; +import type { + ViewStyleProp, + TextStyleProp, +} from 'react-native/Libraries/StyleSheet/StyleSheet'; import TouchableRipple from '../TouchableRipple'; import Text from '../Typography/Text'; import { withTheme } from '../../core/theming'; @@ -33,7 +37,18 @@ type Props = $RemoveChildren & {| * @optional */ theme: Theme, - style?: any, + /** + * Style that is passed to the wrapping TouchableRipple element. + */ + style?: ViewStyleProp, + /** + * Style that is passed to Title element. + */ + titleStyle?: TextStyleProp, + /** + * Style that is passed to Description element. + */ + descriptionStyle?: TextStyleProp, |}; /** @@ -73,6 +88,8 @@ class ListItem extends React.Component { onPress, theme, style, + titleStyle, + descriptionStyle, ...rest } = this.props; const titleColor = color(theme.colors.text) @@ -95,7 +112,7 @@ class ListItem extends React.Component { {title} @@ -107,6 +124,7 @@ class ListItem extends React.Component { { color: descriptionColor, }, + descriptionStyle, ]} > {description} diff --git a/src/components/__tests__/ListItem.test.js b/src/components/__tests__/ListItem.test.js index e1869026c1..3fd172b170 100644 --- a/src/components/__tests__/ListItem.test.js +++ b/src/components/__tests__/ListItem.test.js @@ -51,3 +51,18 @@ it('renders list item with left and right items', () => { expect(tree).toMatchSnapshot(); }); + +it('renders list item with custom title and description styles', () => { + const tree = renderer + .create( + + ) + .toJSON(); + + expect(tree).toMatchSnapshot(); +}); diff --git a/src/components/__tests__/__snapshots__/ListAccordion.test.js.snap b/src/components/__tests__/__snapshots__/ListAccordion.test.js.snap index 3c5ab1287f..762c1b7bfd 100644 --- a/src/components/__tests__/__snapshots__/ListAccordion.test.js.snap +++ b/src/components/__tests__/__snapshots__/ListAccordion.test.js.snap @@ -176,6 +176,7 @@ exports[`renders expanded accordion 1`] = ` Object { "color": "rgba(0, 0, 0, 0.87)", }, + undefined, ], ] } diff --git a/src/components/__tests__/__snapshots__/ListItem.test.js.snap b/src/components/__tests__/__snapshots__/ListItem.test.js.snap index 946ebd4cd3..f1c52d5387 100644 --- a/src/components/__tests__/__snapshots__/ListItem.test.js.snap +++ b/src/components/__tests__/__snapshots__/ListItem.test.js.snap @@ -1,5 +1,105 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`renders list item with custom title and description styles 1`] = ` + + + + + First Item + + + Item description + + + + +`; + exports[`renders list item with left and right items 1`] = ` React.ReactNode; right?: (props: { color: string }) => React.ReactNode; + titleStyle?: StyleProp; + descriptionStyle?: StyleProp; } export declare class Item extends React.Component {} @@ -43,7 +51,7 @@ export declare class Section extends React.Component {} export interface SubheaderProps extends TextProps { style?: StyleProp; - theme?: ThemeShape + theme?: ThemeShape; } export declare class Subheader extends React.Component {}