0.0.1-alpha.12 • Published 3 years ago

react-native-segmented-text-input v0.0.1-alpha.12

Weekly downloads
42
License
MIT
Repository
github
Last release
3 years ago

react-native-segmented-text-input

A wickedly customizable <TextInput /> for React Native. Useful for tags, spellchecking, whatever.

🚀 Getting Started

Using npm:

npm install --save react-native-segmented-text-input

✍️ Usage

import SegmentedTextInput from "react-native-segmented-text-input";

export default () => {
  const [value, onChange] = useState(['', []]);
  return (
    <SegmentedTextInput
      value={value}
      onChange={onChange}
    />
  );
};

To initialize the view, you can supply the input text and corresponding pattern:

import { PATTERN_MENTION } from "react-native-segmented-text-input";
const [value, onChange] = useState(['', [["@cawfree", PATTERN_MENTION]]]);

🤔 Prop Types

Prop NameType StrucRequiredDefaultDescription
value[string, string, matchingRegExp]false['', []]The current state of the input. Array of the string being typed, and array of previous regexp matches relating to match string.
onChange([string, [string, matchingRegExp]) => undefinedfalsePromise.resolveCalled when the segments or input text has changed.
patterns{regExpString: React.ElementType, ...}false{["(^|\s)@a-z\d-+"] => MentionMaps a to a React component to render them. Is passed an onRequestDelete prop used to delete the segment.
placeholderstringfalse"Add some @mentions..."Placeholder for the text input.
disabledbooleanfalsefalsePrevent the user from typing.
textStylestylesfalse{fontSize: 28}Style the text. (Inherited for both Text and InputText).
textInputStylestylesfalse{}Specific additional styling for the TextInput.
invalidTextStylestylesfalse{color: "red"}Specific additional styling for the TextInput when in error.
segmentContainerStylestylesfalse{}Additional styling for segment container.
suggestionsContainerStylestylesfalse{}Styling to apply to the container of the Suggestions.
shouldRenderInvalidcurrentTextString => booleanfalsestr => !str.startsWith("@")Determines whether a particular string should be rendered using invalidTextStyle.
maxnumberfalse3Maximum number of segments.
onSuggestcurrentTextString => Promise(any)falsePromise.resolve([])A call which is made when the user is mid-typing. The string is passed to ask the parent to provide possible suggestions.
minSuggestionLengthnumberfalse2The minimum number of characters a user should have typed before attempting to make a suggestion.
debouncenumberfalse250The number of milliseconds to throttle attempts at querying for a suggestion.
renderSuggestions({suggestions:any, pickSuggestion: () => undefined, loadingSuggestions: boolean}) => false() => Used to render suggestions. This function must understand the specific format of returned suggestion data.

✌️ Licence

MIT