Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

feat(UserPicker): Add UserPicker wrapper for PeoplePicker from Fabric #321

Merged
merged 3 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/components/UserPicker/UserPicker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*! Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. */
@import 'src/css/variables/colors.css';

.y-userpicker-suggestions__container .ms-TooltipHost {
color: $textColor;
}

.y-userpicker-suggestions__container .ms-PickerItem-removeButton__color-primary {
color: $textColor;
}
51 changes: 51 additions & 0 deletions src/components/UserPicker/UserPicker.md
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} />
```
19 changes: 19 additions & 0 deletions src/components/UserPicker/UserPicker.test.tsx
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();
});
});
});
26 changes: 26 additions & 0 deletions src/components/UserPicker/UserPicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*! 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;
const suggestionsClass: IBasePickerSuggestionsProps = { className: 'y-userpicker-suggestions__container' };
return (
<NormalPeoplePicker
className="y-userpicker__container"
pickerSuggestionsProps={suggestionsClass}
onResolveSuggestions={onResolveSuggestions}
/>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<PeoplePicker /> when given only required prop matches its snapshot 1`] = `
<NormalPeoplePicker
className="y-userpicker__container"
createGenericItem={[Function]}
onRenderItem={[Function]}
onRenderSuggestionsItem={[Function]}
onResolveSuggestions={[MockFunction]}
pickerSuggestionsProps={
Object {
"className": "y-userpicker-suggestions__container",
}
}
/>
`;
3 changes: 3 additions & 0 deletions src/components/UserPicker/index.ts
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';