UNPKG

2.8 kBJavaScriptView Raw
1function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
3import * as React from 'react';
4import { Platform, StyleSheet, TouchableWithoutFeedback, View } from 'react-native';
5import color from 'color';
6import Text from '../Typography/Text';
7import { withTheme } from '../../core/theming';
8import { white } from '../../styles/colors';
9
10/**
11 * A component used to display a title and optional subtitle in an appbar.
12 *
13 * <div class="screenshots">
14 * <figure>
15 * <img class="medium" src="screenshots/appbar-content.png" />
16 * </figure>
17 * </div>
18 *
19 * ## Usage
20 * ```js
21 * import * as React from 'react';
22 * import { Appbar } from 'react-native-paper';
23 *
24 * const MyComponent = () => (
25 * <Appbar.Header>
26 * <Appbar.Content title="Title" subtitle={'Subtitle'} />
27 * </Appbar.Header>
28 * );
29 *
30 * export default MyComponent;
31 * ```
32 */
33const AppbarContent = _ref => {
34 let {
35 color: titleColor = white,
36 subtitle,
37 subtitleStyle,
38 onPress,
39 style,
40 titleRef,
41 titleStyle,
42 theme,
43 title,
44 ...rest
45 } = _ref;
46 const {
47 fonts
48 } = theme;
49 const subtitleColor = color(titleColor).alpha(0.7).rgb().string();
50 return /*#__PURE__*/React.createElement(TouchableWithoutFeedback, {
51 onPress: onPress,
52 disabled: !onPress
53 }, /*#__PURE__*/React.createElement(View, _extends({
54 style: [styles.container, style]
55 }, rest), /*#__PURE__*/React.createElement(Text, {
56 ref: titleRef,
57 style: [{
58 color: titleColor,
59 ...(Platform.OS === 'ios' ? fonts.regular : fonts.medium)
60 }, styles.title, titleStyle],
61 numberOfLines: 1,
62 accessible: true,
63 accessibilityTraits: "header" // @ts-expect-error React Native doesn't accept 'heading' as it's web-only
64 ,
65 accessibilityRole: Platform.OS === 'web' ? 'heading' : 'header'
66 }, title), subtitle ? /*#__PURE__*/React.createElement(Text, {
67 style: [styles.subtitle, {
68 color: subtitleColor
69 }, subtitleStyle],
70 numberOfLines: 1
71 }, subtitle) : null));
72};
73
74AppbarContent.displayName = 'Appbar.Content';
75const styles = StyleSheet.create({
76 container: {
77 flex: 1,
78 paddingHorizontal: 12
79 },
80 title: {
81 fontSize: Platform.OS === 'ios' ? 17 : 20
82 },
83 subtitle: {
84 fontSize: Platform.OS === 'ios' ? 11 : 14
85 }
86});
87export default withTheme(AppbarContent); // @component-docs ignore-next-line
88
89const AppbarContentWithTheme = withTheme(AppbarContent); // @component-docs ignore-next-line
90
91export { AppbarContentWithTheme as AppbarContent };
92//# sourceMappingURL=AppbarContent.js.map
\No newline at end of file