From 4974b8cf16bca22013e44246c1a4d4d74225e9ee Mon Sep 17 00:00:00 2001 From: Kuba Date: Thu, 25 Apr 2019 12:24:20 +0200 Subject: [PATCH] feat: missing titleStyle and descriptionStyle for List.Accordion and List.Section (#997) This PR introduces missing style props: List.Accordion: - `titleStyle` - `descriptionStyle` List.Section - `titleStyle` Also improves `style` prop type and description in these components. Fixes #973 --- src/components/List/ListAccordion.tsx | 32 +- src/components/List/ListSection.tsx | 16 +- src/components/List/ListSubheader.tsx | 3 + .../__tests__/ListAccordion.test.js | 17 + src/components/__tests__/ListSection.test.js | 19 + .../__snapshots__/ListAccordion.test.js.snap | 160 +++++++++ .../__snapshots__/ListSection.test.js.snap | 333 ++++++++++++++++++ 7 files changed, 575 insertions(+), 5 deletions(-) diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index 9a80fa0de8..53864818c2 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -1,6 +1,12 @@ import color from 'color'; import * as React from 'react'; -import { View, ViewStyle, StyleSheet, StyleProp } from 'react-native'; +import { + View, + ViewStyle, + StyleSheet, + StyleProp, + TextStyle, +} from 'react-native'; import TouchableRipple from '../TouchableRipple'; import Icon from '../Icon'; import Text from '../Typography/Text'; @@ -38,7 +44,18 @@ type Props = { * @optional */ theme: Theme; + /** + * Style that is passed to the wrapping TouchableRipple element. + */ style?: StyleProp; + /** + * Style that is passed to Title element. + */ + titleStyle?: StyleProp; + /** + * Style that is passed to Description element. + */ + descriptionStyle?: StyleProp; }; type State = { @@ -117,7 +134,16 @@ class ListAccordion extends React.Component { }; render() { - const { left, title, description, children, theme, style } = this.props; + const { + left, + title, + description, + children, + theme, + titleStyle, + descriptionStyle, + style, + } = this.props; const titleColor = color(theme.colors.text) .alpha(0.87) .rgb() @@ -155,6 +181,7 @@ class ListAccordion extends React.Component { { color: expanded ? theme.colors.primary : titleColor, }, + titleStyle, ]} > {title} @@ -167,6 +194,7 @@ class ListAccordion extends React.Component { { color: descriptionColor, }, + descriptionStyle, ]} > {description} diff --git a/src/components/List/ListSection.tsx b/src/components/List/ListSection.tsx index 745f86f22c..fc88efa81a 100644 --- a/src/components/List/ListSection.tsx +++ b/src/components/List/ListSection.tsx @@ -1,5 +1,11 @@ import * as React from 'react'; -import { View, ViewStyle, StyleSheet, StyleProp } from 'react-native'; +import { + View, + ViewStyle, + StyleSheet, + StyleProp, + TextStyle, +} from 'react-native'; import ListSubheader from './ListSubheader'; import { withTheme } from '../../core/theming'; import { Theme } from '../../types'; @@ -17,6 +23,10 @@ type Props = React.ComponentProps & { * @optional */ theme: Theme; + /** + * Style that is passed to Title element. + */ + titleStyle?: StyleProp; style?: StyleProp; }; @@ -57,11 +67,11 @@ class ListSection extends React.Component { static displayName = 'List.Section'; render() { - const { children, title, style, ...rest } = this.props; + const { children, title, titleStyle, style, ...rest } = this.props; return ( - {title && {title}} + {title && {title}} {children} ); diff --git a/src/components/List/ListSubheader.tsx b/src/components/List/ListSubheader.tsx index 17cff98e84..9d9dab6889 100644 --- a/src/components/List/ListSubheader.tsx +++ b/src/components/List/ListSubheader.tsx @@ -10,6 +10,9 @@ type Props = React.ComponentProps & { * @optional */ theme: Theme; + /** + * Style that is passed to Text element. + */ style?: StyleProp; }; diff --git a/src/components/__tests__/ListAccordion.test.js b/src/components/__tests__/ListAccordion.test.js index 62c70a996f..c7f91e49e0 100644 --- a/src/components/__tests__/ListAccordion.test.js +++ b/src/components/__tests__/ListAccordion.test.js @@ -63,3 +63,20 @@ it('renders expanded accordion', () => { expect(tree).toMatchSnapshot(); }); + +it('renders list accordion with custom title and description styles', () => { + const tree = renderer + .create( + + + + ) + .toJSON(); + + expect(tree).toMatchSnapshot(); +}); diff --git a/src/components/__tests__/ListSection.test.js b/src/components/__tests__/ListSection.test.js index 89c2d5c045..a903c51c24 100644 --- a/src/components/__tests__/ListSection.test.js +++ b/src/components/__tests__/ListSection.test.js @@ -43,3 +43,22 @@ it('renders list section with subheader', () => { expect(tree).toMatchSnapshot(); }); + +it('renders list section with custom title style', () => { + 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 3fb2b43e5c..f7eb9e79c0 100644 --- a/src/components/__tests__/__snapshots__/ListAccordion.test.js.snap +++ b/src/components/__tests__/__snapshots__/ListAccordion.test.js.snap @@ -64,6 +64,7 @@ exports[`renders expanded accordion 1`] = ` Object { "color": "#6200ee", }, + undefined, ], ] } @@ -306,6 +307,7 @@ exports[`renders list accordion with children 1`] = ` Object { "color": "rgba(0, 0, 0, 0.87)", }, + undefined, ], ] } @@ -363,6 +365,161 @@ exports[`renders list accordion with children 1`] = ` `; +exports[`renders list accordion with custom title and description styles 1`] = ` + + + + + + Accordion item 1 + + + Describes the expandable list item + + + + +  + + + + + +`; + exports[`renders list accordion with left items 1`] = ` + + Some title + + + + + +  + + + + + First Item + + + + + + + + +  + + + + + Second Item + + + + + +`; + exports[`renders list section with subheader 1`] = `