1.0.9 • Published 4 years ago

react-native-complete-mentions v1.0.9

Weekly downloads
94
License
MIT
Repository
-
Last release
4 years ago

React Native Complete Mentions

A React Native component that let's you mention people in a TextInput like you are used to on Facebook or Twitter.

Getting started

Install the react-native-complete-mentions package via npm:

npm install react-native-complete-mentions --save

Or yarn:

yarn add react-native-complete-mentions

The package exports 2 components

import { MentionInput, Tag } from 'react-native-complete-mentions'

MentionInput is the main component rendering the textarea control. It takes one or multiple Mention components as its children. Each Tag component represents a data source for a specific class of mentionable objects, such as users, template variables, issues, etc.

<MentionInput value={this.state.value} onChangeText={this.handleChange}>
  <Tag
    trigger="@"
    renderSuggestions={this.renderUserSuggestion}
  />
  <Tag
    tag="#"
    renderSuggestions={this.renderTagSuggestion}
  />
</MentionInput>

Configuration

The MentionInput supports the following props for configuring the widget:

Prop nameTypeDefault valueDescription
valuestring''The value containing markup for mentions
onChangeTextfunction (string)empty functionA callback that is invoked when the user changes the value in the mentions input
inputRefReact refundefinedAccepts a React ref to forward to the underlying input element (optional)
onExtractedStringChangefunction (string)undefinedExtract the formated text when the displayed input changes. (optional)

Each data source is configured using a Tag component, which has the following props:

Prop nameTypeDefault valueDescription
tagstring'@'Defines the char sequence upon which to trigger querying the data source
renderTextfunction(mention): ReactTextNodenullAllows customizing how mentions are displayed.
renderSuggestionsfunction ({ tracking, keyword, commit })nullAllows customizing how mentions list are rendered (optional)
formatTextfunction(string): stringnullAllows customizing the mentioned text. (optional)
extractStringfunction(mention): stringnullAllows customizing the extracted string, for example extractString={mention => `@[${mention.name}](id:${mention.id})`} (optional)
extractCommitfunction(commit)nullAllows you to extract the commit (insert new mention) functionality. (optional)