react-native-cross-components
Version:
Beautiful React-Native components using RN Paper by Callstack
68 lines • 2.84 kB
JavaScript
import React from 'react';
import { View, Linking, TouchableHighlight, } from 'react-native';
import { Text, Headline, Subheading, Title, Caption, Paragraph, } from 'react-native-paper';
import styles from '../../styles';
import _ from 'lodash';
/**
* Renders the relevant react-native-paper component based on props
*/
class TextComponent extends React.Component {
constructor(props) {
super(props);
}
render() {
let label = null;
if (this.props.isHeadline) {
label = React.createElement(Headline, Object.assign({}, this.props), this.props.children);
}
if (this.props.isSubheading) {
label = React.createElement(Subheading, Object.assign({}, this.props), this.props.children);
}
if (this.props.isTitle) {
label = React.createElement(Title, Object.assign({}, this.props), this.props.children);
}
if (this.props.isCaption) {
label = React.createElement(Caption, Object.assign({}, this.props), this.props.children);
}
if (this.props.isParagraph) {
label = React.createElement(Paragraph, Object.assign({}, this.props), this.props.children);
}
const url = _.get(this.props, ['onPressUrlTarget']);
if (url && !label)
return (React.createElement(Text, Object.assign({}, this.props, { onPress: () => Linking.openURL(url.toString()) }), this.props.children));
if (url && label)
return (React.createElement(TouchableHighlight, { onPress: () => Linking.openURL(url.toString()) }, label));
return label ? (Object.assign({}, label)) : (React.createElement(Text, Object.assign({}, this.props), this.props.children));
}
}
/**
* Wrapper for {@link https://callstack.github.io/react-native-paper/text.html react-native-paper Text} component
* that displays as a clickable link if {@link ICrossLabelProps.onPressUrlTarget} is supplied.
*
* Link color can also be specified through {@link ICrossLabelProps.linkColor}.
*
* Properties are {@link ICrossLabelProps}
*
* @param param0 {@link ICrossLabelProps}
* @returns {@link View}
*/
export class CrossLabel extends React.Component {
constructor(props) {
super(props);
}
render() {
return (React.createElement(View, { style: styles.container },
React.createElement(TextComponent, Object.assign({}, this.props, { style: [
this.props.onPressUrlTarget ? linkStyle : {},
this.props.style,
this.props.linkColor ? { color: this.props.linkColor } : {},
] }), this.props.children)));
}
}
const linkStyle = {
color: 'blue',
fontWeight: 'bold',
backgroundColor: 'transparent',
};
export default CrossLabel;
//# sourceMappingURL=CrossLabel.js.map