@prosperitainova/dumbo-react-native
Version:
Dumbo for React Native Library
73 lines (71 loc) • 2.02 kB
JavaScript
;
import React from 'react';
import { Keyboard, StyleSheet } from 'react-native';
import { styleReferenceBreaker } from '../../helpers';
import { getColor } from '../../styles/colors';
import { Text } from '../Text';
/** Props for InlineLink component */
import { jsx as _jsx } from "react/jsx-runtime";
/**
* InlineLink component
* Link for using in inline with other text.
*
* To use import React Native Text wrapper `import { Text as ReactText } from 'react-native';`
* Use `Text` from the Carbon package.
* Then use something like:
* ```javascript
* <ReactText>
* <Text text="Regular text before link. You can click on " />
* <InlineLink text="this link" onPress={() => openLink('https://carbondesignsystem.com')} />
* <Text text=" which will open the link." />
* </ReactText>
* ```
*
* {@link https://github.com/carbon-design-system/carbon-react-native/blob/main/example/src/Views/Link.tsx | Example code}
*/
export class InlineLink extends React.Component {
get styles() {
const {
forceDarkMode
} = this.props;
return StyleSheet.create({
wrapper: {
flexDirection: 'row',
alignItems: 'center',
color: getColor('linkPrimary', forceDarkMode ? 'dark' : undefined)
}
});
}
onPress = event => {
const {
dismissKeyboardOnPress,
onPress
} = this.props;
if (dismissKeyboardOnPress && typeof Keyboard?.dismiss === 'function') {
Keyboard.dismiss();
}
if (typeof onPress === 'function') {
onPress(event);
}
};
render() {
const {
text,
onLongPress,
textType,
style
} = this.props;
return /*#__PURE__*/_jsx(Text, {
type: textType,
text: text,
style: styleReferenceBreaker(this.styles.wrapper, style),
componentProps: {
accessibilityLabel: text,
accessibilityRole: 'link',
onPress: this.onPress,
onLongPress: onLongPress
}
});
}
}
//# sourceMappingURL=index.js.map