Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional wrapper component #48

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ function (_Component) {
_createClass(Hyperlink, [{
key: "render",
value: function render() {
var viewProps = _extends({}, this.props);

delete viewProps.onPress;
delete viewProps.linkDefault;
delete viewProps.onLongPress;
delete viewProps.linkStyle;
return _react["default"].createElement(_reactNative.View, _extends({}, viewProps, {
var wrapperProps = _extends({}, this.props);

delete wrapperProps.onPress;
delete wrapperProps.linkDefault;
delete wrapperProps.onLongPress;
delete wrapperProps.linkStyle;
delete wrapperProps.wrapperComponent;
var Wrapper = this.props.wrapperComponent || _reactNative.View;
return _react["default"].createElement(Wrapper, _extends({}, wrapperProps, {
style: this.props.style
}), !this.props.onPress && !this.props.onLongPress && !this.props.linkStyle ? this.props.children : this.parse(this).props.children);
}
Expand All @@ -174,7 +176,8 @@ Hyperlink.propTypes = {
linkText: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].func]),
onPress: _propTypes["default"].func,
onLongPress: _propTypes["default"].func,
injectViewProps: _propTypes["default"].func
injectViewProps: _propTypes["default"].func,
wrapperComponent: _propTypes["default"].elementType
};
Hyperlink.defaultProps = {
linkify: linkify,
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Props {
linkText?: string | ((text: string) => string);
onPress?: (url: string, text: string) => void;
onLongPress?: (url: string, text: string) => void;
wrapperComponent?: Component;
}

declare class HyperLink extends Component<Props> {}
Expand Down
19 changes: 11 additions & 8 deletions src/Hyperlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ class Hyperlink extends Component {
}

render() {
const { ...viewProps } = this.props
delete viewProps.onPress
delete viewProps.linkDefault
delete viewProps.onLongPress
delete viewProps.linkStyle

const { ...wrapperProps } = this.props
delete wrapperProps.onPress
delete wrapperProps.linkDefault
delete wrapperProps.onLongPress
delete wrapperProps.linkStyle
delete wrapperProps.wrapperComponent

const Wrapper = this.props.wrapperComponent || View;
return (
<View { ...viewProps } style={ this.props.style }>
<Wrapper { ...wrapperProps } style={ this.props.style }>
{ !this.props.onPress && !this.props.onLongPress && !this.props.linkStyle
? this.props.children
: this.parse(this).props.children }
</View>
</Wrapper>
)
}

Expand Down Expand Up @@ -136,6 +138,7 @@ Hyperlink.propTypes = {
onPress: PropTypes.func,
onLongPress: PropTypes.func,
injectViewProps: PropTypes.func,
wrapperComponent: PropTypes.elementType,
}

Hyperlink.defaultProps = { linkify, injectViewProps: i => ({}) }
Expand Down