[NEW] Emphasis Elements (italic, strike and bold) in Message Parser Components (#4621)
* [NEW] Emphasis Elements (italic, strike and bold) in Message Parser Components * update storyshot * minor tweak and remove of isLink * Add theme provider to new md stories * Cleanup * Update tests Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
0ad5545a4c
commit
a5e538c13f
File diff suppressed because one or more lines are too long
|
@ -41,18 +41,21 @@ const Link = ({ value }: ILinkProps) => {
|
|||
return (
|
||||
<Text onPress={handlePress} onLongPress={onLongPress} style={[styles.link, { color: themes[theme].actionTintColor }]}>
|
||||
{(block => {
|
||||
switch (block.type) {
|
||||
case 'PLAIN_TEXT':
|
||||
return block.value;
|
||||
case 'STRIKE':
|
||||
return <Strike value={block.value} />;
|
||||
case 'ITALIC':
|
||||
return <Italic value={block.value} />;
|
||||
case 'BOLD':
|
||||
return <Bold value={block.value} />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
const blockArray = Array.isArray(block) ? block : [block];
|
||||
return blockArray.map(blockInArray => {
|
||||
switch (blockInArray.type) {
|
||||
case 'PLAIN_TEXT':
|
||||
return blockInArray.value;
|
||||
case 'STRIKE':
|
||||
return <Strike value={blockInArray.value} />;
|
||||
case 'ITALIC':
|
||||
return <Italic value={blockInArray.value} />;
|
||||
case 'BOLD':
|
||||
return <Bold value={blockInArray.value} />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
});
|
||||
})(label)}
|
||||
</Text>
|
||||
);
|
||||
|
|
|
@ -3,22 +3,25 @@ import { StyleSheet, View } from 'react-native';
|
|||
import { NavigationContainer } from '@react-navigation/native';
|
||||
|
||||
import NewMarkdownComponent from '.';
|
||||
import { themes } from '../../../lib/constants';
|
||||
import { colors, themes } from '../../../lib/constants';
|
||||
import { longText } from '../../../../.storybook/utils';
|
||||
import { ThemeContext } from '../../../theme';
|
||||
|
||||
const theme = 'light';
|
||||
|
||||
export default {
|
||||
title: 'NewMarkdown',
|
||||
decorators: [
|
||||
(Story: any) => (
|
||||
<NavigationContainer>
|
||||
<Story />
|
||||
<ThemeContext.Provider value={{ theme, colors: colors[theme] }}>
|
||||
<Story />
|
||||
</ThemeContext.Provider>
|
||||
</NavigationContainer>
|
||||
)
|
||||
]
|
||||
};
|
||||
|
||||
const theme = 'light';
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
marginHorizontal: 15,
|
||||
|
@ -420,10 +423,73 @@ const markdownLink = [
|
|||
}
|
||||
];
|
||||
|
||||
const markdownLinkWithEmphasis = [
|
||||
{
|
||||
type: 'PARAGRAPH',
|
||||
value: [
|
||||
{
|
||||
type: 'LINK',
|
||||
value: {
|
||||
src: {
|
||||
type: 'PLAIN_TEXT',
|
||||
value: 'https://rocket.chat/'
|
||||
},
|
||||
label: [
|
||||
{
|
||||
type: 'PLAIN_TEXT',
|
||||
value: 'Normal Link - '
|
||||
},
|
||||
{
|
||||
type: 'BOLD',
|
||||
value: [
|
||||
{
|
||||
type: 'PLAIN_TEXT',
|
||||
value: 'Bold'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'PLAIN_TEXT',
|
||||
value: ' '
|
||||
},
|
||||
{
|
||||
type: 'STRIKE',
|
||||
value: [
|
||||
{
|
||||
type: 'PLAIN_TEXT',
|
||||
value: 'strike'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'PLAIN_TEXT',
|
||||
value: ' and '
|
||||
},
|
||||
{
|
||||
type: 'ITALIC',
|
||||
value: [
|
||||
{
|
||||
type: 'PLAIN_TEXT',
|
||||
value: 'Italic'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'PLAIN_TEXT',
|
||||
value: ' Styles'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
export const Links = () => (
|
||||
<View style={styles.container}>
|
||||
<NewMarkdown tokens={rocketChatLink} />
|
||||
<NewMarkdown tokens={markdownLink} />
|
||||
<NewMarkdown tokens={markdownLinkWithEmphasis} />
|
||||
</View>
|
||||
);
|
||||
|
||||
|
|
|
@ -3,20 +3,15 @@ import { Text } from 'react-native';
|
|||
import { Plain as PlainProps } from '@rocket.chat/message-parser';
|
||||
|
||||
import styles from '../styles';
|
||||
import { useTheme } from '../../../theme';
|
||||
import { themes } from '../../../lib/constants';
|
||||
|
||||
interface IPlainProps {
|
||||
value: PlainProps['value'];
|
||||
}
|
||||
|
||||
const Plain = ({ value }: IPlainProps) => {
|
||||
const { theme } = useTheme();
|
||||
return (
|
||||
<Text accessibilityLabel={value} style={[styles.plainText, { color: themes[theme].bodyText }]}>
|
||||
{value}
|
||||
</Text>
|
||||
);
|
||||
};
|
||||
const Plain = ({ value }: IPlainProps) => (
|
||||
<Text accessibilityLabel={value} style={styles.plainText}>
|
||||
{value}
|
||||
</Text>
|
||||
);
|
||||
|
||||
export default Plain;
|
||||
|
|
Loading…
Reference in New Issue