# react-taxonomypicker-pnp

> PnP JS version of Office 365 - SharePoint React Taxonomy Picker

Latest version **0.2.4** (published 2019-12-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-taxonomypicker-pnp
pnpm add react-taxonomypicker-pnp
yarn add react-taxonomypicker-pnp
bun add react-taxonomypicker-pnp
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.4 |
| Published | 2019-12-05 |
| First published | 2019-09-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 2.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jose Quinto |
| Maintainers | martinlingstuyl |
| Keywords | React, Taxonomy, Picker, Managed, Metadata, TermSet, TermStore, SharePoint, Office, 365, PnPJS |

## Links

- npm: https://www.npmjs.com/package/react-taxonomypicker-pnp
- Repository: https://github.com/martinlingstuyl/react-taxonomypicker
- Homepage: https://github.com/martinlingstuyl/react-taxonomypicker#readme
- Issues: https://github.com/martinlingstuyl/react-taxonomypicker/issues
- npm.io page: https://npm.io/package/react-taxonomypicker-pnp

## Dependencies (2)

- [react-select](https://npm.io/package/react-select.md) 2.1.1
- [@types/react-select](https://npm.io/package/@types/react-select.md) 2.0.6

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.4 (latest) — 2019-12-05
- 0.2.3 — 2019-12-05
- 0.2.2 — 2019-12-04
- 0.2.1 — 2019-12-03
- 0.2.0 — 2019-12-03
- 0.1.9 — 2019-09-23
- 0.1.8 — 2019-09-23
- 0.1.7 — 2019-09-23
- 0.1.6 — 2019-09-17
- 0.1.5 — 2019-09-17
- 0.1.4 — 2019-09-17
- 0.1.3 — 2019-09-17
- 0.1.2 — 2019-09-16
- 0.1.1 — 2019-09-16
- 0.1.0 — 2019-09-16

## README

# React-TaxonomyPicker-PnP
A Taxonomy Picker control built with [TypeScript](https://www.typescriptlang.org) for [React](https://facebook.github.io/react) based on [React-Select](https://github.com/JedWatson/react-select) and [PnP JS SP-Taxonomy](https://pnp.github.io/pnpjs/sp-taxonomy/docs/). This version was built because a dependency on JSOM was considered undesirable and an SPFx webpart context was unavailable.

Always consider using the [SPFx React TaxonomyPicker](https://sharepoint.github.io/sp-dev-fx-controls-react/controls/TaxonomyPicker/) before using this one. But if you can't or won't use SPFx, this is a nice alternative.

There is one drawback to the original: async searching for terms can currently not be done on a termset, only on a termstore.

![React-Taxonomy-Picker-gif](./assets/react-taxonomy-picker.gif)

[![npm version](https://badge.fury.io/js/react-taxonomypicker-pnp.svg)](https://badge.fury.io/js/react-taxonomypicker-pnp)
[![NSP Status](https://nodesecurity.io/orgs/jquinto/projects/7dd23805-b74a-4409-9f6f-b9fd0c835cea/badge)](https://nodesecurity.io/orgs/jquinto/projects/7dd23805-b74a-4409-9f6f-b9fd0c835cea)
[![Code Climate](https://codeclimate.com/github/jquintozamora/react-taxonomypicker/badges/gpa.svg)](https://codeclimate.com/github/jquintozamora/react-taxonomypicker)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/jquintozamora/react-taxonomypicker/master/LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](Readme.md#want-to-contribute)
[![Greenkeeper badge](https://badges.greenkeeper.io/jquintozamora/react-taxonomypicker.svg)](https://greenkeeper.io/)
[![codecov](https://codecov.io/gh/jquintozamora/react-taxonomypicker/branch/master/graph/badge.svg)](https://codecov.io/gh/jquintozamora/react-taxonomypicker)

[![NPM](https://nodei.co/npm/react-taxonomypicker-pnp.png?downloads=true)](https://nodei.co/npm/react-taxonomypicker/)


## DEMO
[https://jquintozamora.github.io/react-taxonomypicker](https://jquintozamora.github.io/react-taxonomypicker)

## Features
- Retrieve Terms from a Term Set by Term Set GUID.
- Support for large Term Set using Async mode
  - Configurable via termSetCountMaxSwapToAsync property
- Use PnP JS SP-Taxonomy
- Use Promise (polyfill it if needed IE)

## Features not supported
- Add new Terms (Open TermSets)


## Scenarios supported
- SharePoint Web Part using Script Editor or Content Editor Web Part
- SharePoint Framework Web Part (SPFx)
- [ES6 project](https://github.com/jquintozamora/react-taxonomypicker-consume-es6) consumer sample
- [TypeScript project](https://github.com/jquintozamora/react-taxonomypicker-consume-typescript) consumer sample
- [SPFx project](https://github.com/jquintozamora/spfx-react-taxonomypicker) consumer sample

## Scenarios not supported
- SharePoint Provider-hosted app
- Other environment in which we are not allowed to use JSOM
- Add new terms to the Taxonomy Store (specific for get terms by now)

## Installation
Steps to use react-taxonomypicker-pnp in your React project
### 1.Install from NPM
```
npm install --save react-taxonomypicker-pnp
```
Note: You need to install the PnP packages or JS file separately!

### 2. Import and use in your application
```
import TaxonomyPicker from "react-taxonomypicker-pnp";
// Optionally include its styles in you build process as well
import "react-taxonomypicker-pnp/dist/React.TaxonomyPicker.css";
```
Though you can also use theming for this.
### 3. Usage
#### Mock / Local mode
Don't configure termSetGuid and load the options from defaultOptions object.
```js
<TaxonomyPicker
  name="Language"
  displayName="Language"
  defaultOptions={[
    { label: "English", value: "f50249b6-310d-43b6-aaa6-f0cb46d851bf" },
    { label: "Spanish", value: "237ca323-1ed8-4199-a49b-a9f7ce4256bf" },
    { label: "German", value: "44024c7e-f738-4755-90e1-15866327c806" },
    { label: "Italian", value: "65f67491-bdca-491a-84fa-f6fd913f40fa" },
  ]}
  multi
  showPath
/>
```

#### SharePoint environment mode
Configure termSetGuid with the desired term set
```js
<TaxonomyPicker
  name="Language"
  displayName="Language"
  termSetGuid="26ebf149-101a-4996-9df2-8179a537350d"
  termSetName="Language"
  termSetCountMaxSwapToAsync={100}
  multi
  showPath
/>
```

#### Setup PnP Context
Don't forget to setup the PnP context in your component constructor.
```js
sp.setup({

  sp: {
    headers: {
      Accept: "application/json;odata=verbose",
    },
    baseUrl: url
    // For example: _spPageContextInfo.webAbsoluteUrl (In classic SP)
  },
});
```

## Theming
The picker uses react-select and supports it's [theming](https://react-select.com/styles#overriding-the-theme). Simply add a theme property and implement it like so:
```js
<TaxonomyPicker
  ...
  theme={theme => ({
      ...theme,
      borderRadius: 0,
      colors: {
        ...theme.colors,
        primary: 'green',
        primary25: 'blue',
        primary50: 'red'
      },
    })}
  />
```

## Docker
For use with docker a docker file has been included. Take the following steps to use it if you are a docker user:

### 1.Update webpack/webpack.config.dev.js
the following line should be uncommented on the devServer property.
```js
host:"0.0.0.0",
```

### 2.Build the docker file
```Powershell
docker build . -t=react-taxonomypicker
```

### 3.Run the docker command
```Powershell
docker run -it --rm -p 3000:3000 -v ${PWD}:/usr/app/react-taxonomypicker react-taxonomypicker
```
This command can also be executed by running the dock.ps1

## Done
- Expose as a Module / Global / UMD library
- Upload to npm
- Create [ES6 sample application](https://github.com/jquintozamora/react-taxonomypicker-consume-es6) for usage
- Create [TypeScript sample application](https://github.com/jquintozamora/react-taxonomypicker-consume-typescript) for usage
- Create [SPFx webpart sample for usage](https://github.com/jquintozamora/spfx-react-taxonomypicker)
- Create types and include them with the npm package
- onPickerChange event handler exposed
- react-select properties exposed (extends them)
- termSetCountMaxSwapToAsync property exposed to choose between Sync / Async modes
- defaultOptions array exposed to enable input mock data when no termSetGuid configured
- Create and Expose properties for custom styles

## TODOs
- Create types to allow people include with @types


## Want to contribute?
Anyone can help make this project better


## License
MIT License

Copyright (c) 2017 - 2018 [José Quinto](https://blog.josequinto.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

---
_Source: https://npm.io/package/react-taxonomypicker-pnp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
