office-ui-fabric-react#find TypeScript Examples
The following examples show how to use
office-ui-fabric-react#find.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListPicker.tsx From sp-site-designs-studio with MIT License | 5 votes |
ListPicker = (props: IListPickerProps) => {
const [availableLists, setAvailableLists] = useState<IList[]>([]);
const selectedItemsRef = useRef<IDropdownOption[]>([]);
useEffect(() => {
// Load the lists from the specified web
const sitesService = props.serviceScope.consume(SitesServiceKey);
sitesService.getSiteLists(props.webUrl).then(lists => setAvailableLists(lists));
}, [props.webUrl]);
const getSelectedLists = () => {
if (!selectedItemsRef.current) {
return [];
}
return selectedItemsRef.current.map(option => find(availableLists, l => l.url == option.key as string));
};
const onChange = (ev: any, option: IDropdownOption, index: number) => {
selectedItemsRef.current = selectedItemsRef.current.filter(s => s.key != option.key);
if (props.multiselect && props.onListsSelected) {
if (option.selected) {
selectedItemsRef.current.push(option);
} else {
selectedItemsRef.current.splice(index, 1);
}
const selectedLists = getSelectedLists();
props.onListsSelected(selectedLists);
} else if (props.onListSelected) {
if (option) {
selectedItemsRef.current = [option];
}
const selectedLists = getSelectedLists();
props.onListSelected(selectedLists.length > 0 ? selectedLists[0] : null);
}
};
return <Dropdown
disabled={!availableLists || (availableLists && availableLists.length == 0)}
label={props.label}
multiSelect={props.multiselect}
options={availableLists.map(al => ({ key: al.url, text: al.title }))}
onChange={onChange} />;
}