Smart TextArea
A configurable markable react textarea component that supports multiple anchor types (people, things, places). And multiple part per anchor type for nested/dependant/parent,child/etc... senarios
Demo
e.g.
import 'smart-textarea-maa/lib/styles.css';
import { withSmartTextArea } from 'smart-textarea-maa';
const SmartTextArea = withSmartTextArea({
version: 0,
anchors: [
{
anchorChar: '@',
type: 'person',
parts: [
{
key: 'person',
endChar: ':',
searchConfig: {
loader: ({searchText}, signal) => personSearch(name, signal),
ResultItemComponent: PersonSearchResultItem,
NoResultItemComponent,
onItemSelect: ({selectedItem: person}) => ({
text: person.name,
id: person.id,
}),
debounceDuration: 350,
},
detailsConfig: {
loader: ({person: id}, signal) => personDetails(id, signal),
Component: PersonDetails,
NotFoundComponent,
getCacheKey: ({person: id}) => id,
},
},
],
},
{
anchorChar: '#',
type: 'thing',
parts: [
{
key: 'thing',
searchConfig: {
ResultsComponent: (
{ResultListComponent, ...props}
) => (
<p>
<h5>Found the following things:</h5>
<ResultListComponent {...props} /> {/*will display a selectable list of the results using ResultItemComponent*/}
</p>
),
ResultItemComponent: ThingSearchResultItem,
onItemSelect: ({selectedItem: thing}) => ({
text: thing.name,
id: thing.id,
}),
loader: ({searchText}, signal) => thingSearch(searchText, signal),
getCacheKey: ({searchText}) => searchText?.trim().toLowerCase() || null,
debounceDuration: 350,
},
detailsConfig: {
Component: ThingDetails,
loader: ({thing: id}, signal) => thingDetails(id, signal),
getCacheKey: ({thing: id}) => id,
},
},
],
},
],
classNameGetters: {
front: ({ isFirstLine, isLastLine, isTipVisible, isInEdit, marker }) => 'front-label-class',
back: ({ isFirstLine, isLastLine, isTipVisible, isInEdit, marker }) => 'back-label-class',
tip: ({ marker }) => 'marker-class',
}
ErrorComponent,
LoaderComponent,
hideTipOnEscape: true,
backgroundColor,
lineHeight,
width,
TextArea,
tipsZIndex,
isAbortError: (error) => error.message.toLowerCase().includes('abort),
debounceDuration: 500 // defaults to 300
});
... use it later
<SmartTextArea initValue={...} initMarkers={...} onChange={...} />