import * as React from 'react'; import { StyleProp, StyleSheet, TextStyle, View, ViewStyle, } from 'react-native'; import { withTheme } from '../../core/theming'; import Caption from './../Typography/Caption'; import Title from './../Typography/Title'; type Props = React.ComponentPropsWithRef & { /** * Text for the title. Note that this will only accept a string or ``-based node. */ title: React.ReactNode; /** * Style for the title. */ titleStyle?: StyleProp; /** * Number of lines for the title. */ titleNumberOfLines?: number; /** * Text for the subtitle. Note that this will only accept a string or ``-based node. */ subtitle?: React.ReactNode; /** * Style for the subtitle. */ subtitleStyle?: StyleProp; /** * Number of lines for the subtitle. */ subtitleNumberOfLines?: number; /** * Callback which returns a React element to display on the left side. */ left?: (props: { size: number }) => React.ReactNode; /** * Style for the left element wrapper. */ leftStyle?: StyleProp; /** * Callback which returns a React element to display on the right side. */ right?: (props: { size: number }) => React.ReactNode; /** * Style for the right element wrapper. */ rightStyle?: StyleProp; /** * @internal */ index?: number; /** * @internal */ total?: number; style?: StyleProp; /** * @optional */ theme: ReactNativePaper.Theme; }; const LEFT_SIZE = 40; /** * A component to show a title, subtitle and an avatar inside a Card. * *
* *
* * ## Usage * ```js * import * as React from 'react'; * import { Avatar, Card, IconButton } from 'react-native-paper'; * * const MyComponent = () => ( * } * right={(props) => {}} />} * /> * ); * * export default MyComponent; * ``` */ const CardTitle = ({ title, titleStyle, titleNumberOfLines = 1, subtitle, subtitleStyle, subtitleNumberOfLines = 1, left, leftStyle, right, rightStyle, style, }: Props) => { return ( {left ? ( {left({ size: LEFT_SIZE, })} ) : null} {title ? ( {title} ) : null} {subtitle ? ( {subtitle} ) : null} {right ? right({ size: 24 }) : null} ); }; CardTitle.displayName = 'Card.Title'; const styles = StyleSheet.create({ container: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingLeft: 16, }, left: { justifyContent: 'center', marginRight: 16, height: LEFT_SIZE, width: LEFT_SIZE, }, titles: { flex: 1, flexDirection: 'column', justifyContent: 'center', }, title: { minHeight: 30, paddingRight: 16, }, subtitle: { minHeight: 20, marginVertical: 0, paddingRight: 16, }, }); export default withTheme(CardTitle); // @component-docs ignore-next-line export { CardTitle };