An autocomplete search for persons that can be customized to work with arbitrary data.
You should have the chayns-components
package installed. If that is not the
case already, run
yarn add chayns-components
or
npm i chayns-components
After the chayns-components
package is installed, you can import the component
and use it with React:
import React from 'react'
import { PersonFinder } from 'chayns-components';
// ...
<PersonFinder {...} />
If you want to build your own autocomplete finder, e.g. for searching emails,
you can use the SimpleWrapperContext
and with object mapping and custom props.
The object mapping looks like the following:
{
showName: 'emailTitle',
identifier: 'emailId',
search: ['emailTitle', 'emailText', 'emailSenderName'],
imageUrl: 'emailSenderImageUrl',
}
In contextProps
you can then set the following props:
data
hasMore
onLoadMore
onInput
To clear the PersonFinder
you can use the clear()
-method on a reference to
the PersonFinder
-component:
const Finder = () => {
const personFinderRef = useRef();
function clear() {
if (personFinderRef.current) {
personFinderRef.current.clear();
}
}
return (
<PersonFinder
{/* ... */}
ref={personFinderRef}
/>
);
};
If the autocomplete window is not correctly positioned, check if you have a
<div class="tapp">
-element as a wrapper around your app.
If not, add it or specify the parent
-prop on the PersonFinder
.
The PersonFinder
-component takes the following props:
Name | Type | Default | Required |
---|---|---|---|
placeholder | string |
'' |
|
multiple | boolean |
false |
|
showPersons | boolean |
true |
|
showSites | boolean |
false |
|
uacId | number |
||
locationId | number |
||
reducerFunction | function |
||
context | { Provider: function, Consumer: object } |
PersonsContext |
|
onChange | function |
||
disableFriends | boolean |
false |
|
className | string |
||
defaultValue | { name: string, firstName: string, lastName: string, siteId: string, personId: string } | string |
||
defaultValues | Array<{ name: string, firstName: string, lastName: string, siteId: string, personId: string }> |
[] |
|
onAdd | function |
||
onRemove | function |
||
onInput | function |
||
contextProps | object |
||
max | number |
||
values | array |
||
value | string |
placeholder?: string
The placeholder to show when the input field is empty.
multiple?: boolean
Wether the PersonFinder
should allow multiple persons or sites to be put in.
showPersons?: boolean
Wether the PersonFinder
should show persons in its autocomplete window.
showSites?: boolean
Wether the PersonFinder
should show sites in its autocomplete window.
uacId?: number
The id of a UAC group to search persons in.
locationId?: number
The locationId of a UAC group to search persons in.
reducerFunction?: function
A function to reduce the results.
context?: { Provider: function, Consumer: object }
The context of the PersonFinder. Take a look at the Custom Finder paragraph.
onChange?: function
This callback is invoked when a person is selected, removed or the
PersonFinder
is cleared.
disableFriends?: boolean
Wether the display of friends with an empty input should be disabled.
className?: string
A classname string that will be applied to the wrapper <div>
-element.
defaultValue?: { name: string, firstName: string, lastName: string, siteId: string, personId: string } | string
The default value of the input field. Can be a string or a person/location specified with an object.
defaultValues?: Array<{ name: string, firstName: string, lastName: string, siteId: string, personId: string }>
The default values of the input field if multiple
is true
. Can be strings or
an array of persons/locations specified with an object.
onAdd?: function
A callback that is invoked when a person is added to the PersonFinder
. Only
works when multiple
is true
onRemove?: function
A callback that is invoked when a person is removed from the PersonFinder
.
Only works when multiple
is true
onInput?: function
The onInput
-callback for the <input>
element of the PersonFinder
.
contextProps?: object
Props for the context.
max?: number
The maximum amount of people selected at once. Only has an effect when
multiple
is true
.
values?: array
The currently selected values when multiple
is true
.
value?: string
The value for the