Skip to content

Commit a88963c

Browse files
committed
feat: add mentionTextStyle property
resolves 1 point of #9
1 parent 1e12327 commit a88963c

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/components/mentions.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99

1010
import { MentionsProps, Position, Suggestion } from '../types';
1111
import {
12+
defaultMentionTextStyle,
1213
getChangedPositions,
1314
getMentionPart,
1415
getMentionValue,
@@ -28,10 +29,12 @@ const Mentions: FC<MentionsProps> = (
2829

2930
isInsertSpaceAfterMention = false,
3031

31-
containerStyle,
32-
3332
inputRef: propInputRef,
3433

34+
mentionTextStyle = defaultMentionTextStyle,
35+
36+
containerStyle,
37+
3538
onSelectionChange,
3639

3740
...textInputProps
@@ -280,7 +283,7 @@ const Mentions: FC<MentionsProps> = (
280283
>
281284
<Text>
282285
{parts.map(({text, data}, index) => data ? (
283-
<Text key={`${index}-m`} style={{fontWeight: 'bold', color: '#4f69f3'}}>{text}</Text>
286+
<Text key={`${index}-m`} style={mentionTextStyle}>{text}</Text>
284287
) : (
285288
<Text key={index}>{text}</Text>
286289
))}

src/types/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StyleProp, TextInput, TextInputProps, ViewStyle } from 'react-native';
1+
import { StyleProp, TextInput, TextInputProps, TextStyle, ViewStyle } from 'react-native';
22
import { MutableRefObject, ReactNode } from 'react';
33

44
type Suggestion = {
@@ -51,6 +51,8 @@ type MentionsProps = Omit<TextInputProps, 'onChange'> & {
5151

5252
inputRef?: MutableRefObject<TextInput | null>;
5353

54+
mentionTextStyle?: StyleProp<TextStyle>;
55+
5456
containerStyle?: StyleProp<ViewStyle>;
5557
};
5658

src/utils/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { Change, diffChars } from 'diff';
2+
import { StyleProp, TextStyle } from 'react-native';
23
// @ts-ignore the lib do not have TS declarations yet
34
import matchAll from 'string.prototype.matchall';
45
import { MentionData, Part, Position, RegexMatchResult, Suggestion } from '../types';
56

67
const mentionRegEx = /(?<original>@\[(?<name>([^@[]*))]\((?<id>([0-9]*))\))/gi;
78

9+
const defaultMentionTextStyle: StyleProp<TextStyle> = {fontWeight: 'bold', color: '#4f69f3'};
10+
811
type CharactersDiffChange = Omit<Change, 'count'> & { count: number };
912

1013
/**
@@ -167,6 +170,7 @@ const replaceMentionValues = (
167170

168171
export {
169172
mentionRegEx,
173+
defaultMentionTextStyle,
170174
getChangedPositions,
171175
getPart,
172176
getMentionPart,

0 commit comments

Comments
 (0)