This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UserPicker): Add UserPicker wrapper for NormalPeoplePicker from …
…Fabric
- Loading branch information
Andrew Brassington
committed
May 16, 2018
1 parent
88efb38
commit 98075f4
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
### Notes for use | ||
|
||
The UserPicker is a thin wrapper of Fabric's [NormalPeoplePicker](https://developer.microsoft.com/en-us/fabric#/components/peoplepicker) is used to select one or more entities, such as people or groups. Entry points for PeoplePickers are typically specialized TextField-like input fields known as a "well", which are used to search for recipients from a list. When a recipient is selected from the list, it is added to the well as a specialized Persona that can be interacted with or removed. Clicking on a Persona from the well should invoke a PersonaCard or open a profile pane for that recipient. | ||
|
||
Only required prop is onResolveSuggestions which can be a promise or function which returns a list of the IPersona or other supplied type. | ||
|
||
### Examples | ||
|
||
Basic usage: | ||
|
||
```js { "props": { "data-description": "basic" } } | ||
const people = [ | ||
{ | ||
key: 1, | ||
imageUrl: user.imageUrl, | ||
imageInitials: 'PV', | ||
primaryText: 'Annie Lindqvist', | ||
secondaryText: 'Designer', | ||
}, | ||
{ | ||
key: 2, | ||
imageUrl: user.imageUrl, | ||
imageInitials: 'AR', | ||
primaryText: 'Aaron Reid', | ||
secondaryText: 'Designer', | ||
}, | ||
{ | ||
key: 3, | ||
imageUrl: user.imageUrl, | ||
imageInitials: 'AL', | ||
primaryText: 'Alex Lundberg', | ||
secondaryText: 'Software Developer', | ||
}, | ||
{ | ||
key: 4, | ||
imageUrl: user.imageUrl, | ||
imageInitials: 'RK', | ||
primaryText: 'Roko Kolar', | ||
secondaryText: 'Financial Analyst', | ||
}, | ||
{ | ||
key: 5, | ||
imageUrl: user.imageUrl, | ||
imageInitials: 'CB', | ||
primaryText: 'Christian Bergqvist', | ||
secondaryText: 'Sr. Designer', | ||
}, | ||
]; | ||
|
||
<UserPicker onResolveSuggestions={() => people} /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*! Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. */ | ||
import * as React from 'react'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import UserPicker, { IBasePickerProps, IPersona } from '.'; | ||
|
||
describe('<PeoplePicker />', () => { | ||
let component: ShallowWrapper<IBasePickerProps<IPersona>>; | ||
|
||
describe('when given only required prop', () => { | ||
beforeEach(() => { | ||
const onResolveSuggestions = jest.fn(); | ||
component = shallow(<UserPicker onResolveSuggestions={onResolveSuggestions} />); | ||
}); | ||
|
||
it('matches its snapshot', () => { | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*! Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. */ | ||
import '../../yamui'; | ||
import { IBasePickerProps, IBasePickerSuggestionsProps, NormalPeoplePicker } from 'office-ui-fabric-react/lib/Pickers'; | ||
import * as React from 'react'; | ||
import { IPersona } from 'office-ui-fabric-react/lib/Persona'; | ||
|
||
export { IPersona, IBasePickerProps, IBasePickerSuggestionsProps }; | ||
|
||
/** | ||
* The UserPicker is a thin wrapper of Fabric's | ||
* [NormalPeoplePicker](https://developer.microsoft.com/en-us/fabric#/components/peoplepicker) is used to select one | ||
* or more entities, such as people or groups. | ||
*/ | ||
export default class UserPicker extends React.Component<IBasePickerProps<IPersona>> { | ||
public render() { | ||
const { onResolveSuggestions } = this.props; | ||
return <NormalPeoplePicker onResolveSuggestions={onResolveSuggestions} />; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/components/UserPicker/__snapshots__/UserPicker.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<PeoplePicker /> when given only required prop matches its snapshot 1`] = ` | ||
<NormalPeoplePicker | ||
createGenericItem={[Function]} | ||
onRenderItem={[Function]} | ||
onRenderSuggestionsItem={[Function]} | ||
onResolveSuggestions={[MockFunction]} | ||
/> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/*! Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. */ | ||
export { default } from './UserPicker'; | ||
export * from './UserPicker'; |