Skip to content

Commit e7873d6

Browse files
nmetulevelisenyang
andauthored
Updated all Readmes (#824)
* Updated all Readmes * Apply suggestions from code review Co-authored-by: Elise Yang <[email protected]> * Update packages/mgt-element/README.md Co-authored-by: Elise Yang <[email protected]> * Update packages/mgt-element/README.md * Update readme.md Co-authored-by: Elise Yang <[email protected]> * added mgt-react to readme Co-authored-by: Elise Yang <[email protected]>
1 parent e558f63 commit e7873d6

File tree

9 files changed

+417
-128
lines changed

9 files changed

+417
-128
lines changed

packages/mgt-components/README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
1-
# Mgt Components
1+
# Microsoft Graph Toolkit Web Components
22

3+
[![npm](https://img.shields.io/npm/v/@microsoft/mgt-components?style=for-the-badge)](https://www.npmjs.com/package/@microsoft/mgt-components)
4+
5+
The [Microsoft Graph Toolkit (mgt)](https://aka.ms/mgt) web components package is a collection of web components powered by Microsoft Graph. The components are functional, work automatically with Microsoft Graph, and work with any web framework and on all modern browsers.
6+
7+
> Note: If you are building with React, you might find `@microsoft/mgt-react` useful as well.
8+
9+
[See docs for full documentation](https://aka.ms/mgt-docs)
10+
11+
## Components
12+
You can explore components and samples with the [playground](https://mgt.dev) powered by storybook.
13+
14+
The Toolkit currently includes the following components:
15+
16+
* [mgt-login](https://docs.microsoft.com/graph/toolkit/components/login)
17+
* [mgt-person](https://docs.microsoft.com/graph/toolkit/components/person)
18+
* [mgt-person-card](https://docs.microsoft.com/graph/toolkit/components/person-card)
19+
* [mgt-people](https://docs.microsoft.com/graph/toolkit/components/people)
20+
* [mgt-people-picker](https://docs.microsoft.com/graph/toolkit/components/people-picker)
21+
* [mgt-agenda](https://docs.microsoft.com/graph/toolkit/components/agenda)
22+
* [mgt-tasks](https://docs.microsoft.com/graph/toolkit/components/tasks)
23+
* [mgt-todo](https://docs.microsoft.com/graph/toolkit/components/todo)
24+
* [mgt-get](https://docs.microsoft.com/graph/toolkit/components/get)
25+
* [mgt-teams-channel-picker](https://docs.microsoft.com/en-us/graph/toolkit/components/teams-channel-picker)
26+
27+
The components work best when used with a [provider](https://docs.microsoft.com/graph/toolkit/providers). The provider handles authentication and the requests to the Microsoft Graph APIs used by the components.
28+
29+
## Get started
30+
31+
The components can be used on their own, but they are at their best when they are paired with an authentication provider. This example illustrates how to use the components alongside a provider (MsalProvider in this case).
32+
33+
1. Install the packages
34+
35+
```bash
36+
npm install @microsoft/mgt-element @microsoft/mgt-components @microsoft/mgt-msal-provider
37+
```
38+
39+
1. Use components in your code
40+
41+
```html
42+
<script type="module">
43+
import {Providers} from '@microsoft/mgt-element';
44+
import {MsalProvider} from '@microsoft/mgt-msal-provider';
45+
46+
// import the components
47+
import '@microsoft/mgt-components';
48+
49+
// initialize the auth provider globally
50+
Providers.globalProvider = new MsalProvider({clientId: 'clientId'});
51+
</script>
52+
53+
<mgt-login></mgt-login>
54+
<mgt-person person-query="Bill Gates" person-card="hover"></mgt-person>
55+
<mgt-agenda group-by-day></mgt-agenda>
56+
```
57+
58+
## Sea also
59+
* [Microsoft Graph Toolkit docs](https://aka.ms/mgt-docs)
60+
* [Microsoft Graph Toolkit repository](https://aka.ms/mgt)
61+
* [Microsoft Graph Toolkit playground](https://mgt.dev)

packages/mgt-element/README.md

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,93 @@
1-
# mgt-element
1+
# Microsoft Graph Toolkit Base package
2+
3+
[![npm](https://img.shields.io/npm/v/@microsoft/mgt-element?style=for-the-badge)](https://www.npmjs.com/package/@microsoft/mgt-element)
4+
5+
The [Microsoft Graph Toolkit (mgt)](https://aka.ms/mgt) library is a collection of authentication providers and UI components powered by Microsoft Graph.
6+
7+
The `@microsoft/mgt-element` package contains all base classes that enable the providers and components to work together. Use this package to set the global provider, or to create your own providers and/or components that work with Microsoft Graph.
8+
9+
[See docs for full documentation](https://aka.ms/mgt-docs)
10+
11+
## Set and use the global provider
12+
13+
The `@microsoft/mgt-element` package exposes the `Providers` namespace that enables global usage of the authentication providers across your entire app.
14+
15+
This example illustrates how to instantiate a new provider (MsalProvider in this case) and use it across your app:
16+
17+
1. Install the packages
18+
19+
```bash
20+
npm install @microsoft/mgt-element @microsoft/mgt-msal-provider
21+
```
22+
23+
1. Create the provider
24+
25+
```ts
26+
import {Providers} from '@microsoft/mgt-element';
27+
import {MsalProvider} from '@microsoft/mgt-msal-provider';
28+
29+
// initialize the auth provider globally
30+
Providers.globalProvider = new MsalProvider({clientId: 'clientId'});
31+
```
32+
33+
1. Use the provider to sign in and call the graph:
34+
35+
```ts
36+
import {Providers, ProviderState} from '@microsoft/mgt-element';
37+
38+
const handleLoginClicked = async () => {
39+
await Providers.globalProvider.login();
40+
41+
if (Providers.globalProvider.state === ProviderState.SignedIn) {
42+
let me = await Provider.globalProvider.graph.client.api('/me').get();
43+
}
44+
}
45+
```
46+
47+
You can learn more about how to use the providers in the [documentation](https://docs.microsoft.com/graph/toolkit/providers).
48+
49+
The providers work well with the `@microsoft/mgt-components` package and all components use the provider automatically when they need to call Microsoft Graph.
50+
51+
## Create your own provider
52+
53+
In scenarios where you want to use the Providers namespace and/or add Microsoft Graph Toolkit components to an application with pre-existing authentication code, you can create a custom provider that hooks into your authentication mechanism. `@microsoft/mgt-element` enables two ways to create new providers:
54+
55+
### Create a Simple Provider
56+
57+
If you already have a function that returns `accessTokens`, you can use a SimpleProvider to wrap the function:
58+
59+
```ts
60+
import {Providers, SimpleProvider} from '@microsoft/mgt-element';
61+
62+
function getAccessToken(scopes: string[]) {
63+
// return a promise with accessToken string
64+
}
65+
66+
function login() {
67+
// login code - optional
68+
69+
// make sure to set the state when signed in
70+
Providers.globalProvider.setState(ProviderState.SignedIn)
71+
}
72+
73+
function logout() {
74+
// logout code - optional
75+
76+
// make sure to set the state when signed out
77+
Providers.globalProvider.setState(ProviderState.SignedOut)
78+
}
79+
80+
Provider.globalProvider = new SimpleProvider(getAccessToken, login, logout);
81+
```
82+
83+
### Extend an IProvider
84+
85+
You can extend the IProvider abstract class to create your own provider. The IProvider is similar to the SimpleProvider in that it requires the developer to implement the `getAccessToken()` function.
86+
87+
88+
See the [custom provider documentation](https://docs.microsoft.com/en-us/graph/toolkit/providers/custom) for more details on both ways to create custom providers.
89+
90+
## Sea also
91+
* [Microsoft Graph Toolkit docs](https://aka.ms/mgt-docs)
92+
* [Microsoft Graph Toolkit repository](https://aka.ms/mgt)
93+
* [Microsoft Graph Toolkit playground](https://mgt.dev)

packages/mgt-react/readme.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
Use `mgt-react` to simplify usage of [Microsoft Graph Toolkit (mgt)](https://aka.ms/mgt) web components in React. The library wraps all mgt components and exports them as React components.
66

7-
`mgt-react` extends [`wc-react`](https://github.com/nmetulev/wc-react) adding support for templates.
8-
97
## Installation
108

119
```bash
@@ -20,7 +18,7 @@ yarn add @microsoft/mgt-react
2018

2119
## Usage
2220

23-
Import a component at the top:
21+
All components are available via the npm package and are named using PascalCase. To use a component, first import it at the top:
2422

2523
```tsx
2624
import { Person } from '@microsoft/mgt-react';
@@ -32,7 +30,7 @@ You can now use `Person` anywhere in your JSX as a regular React component.
3230
<Person personQuery="me" />
3331
```
3432

35-
### Use properties instead of attributes
33+
All properties and events map exactly as they are defined in the component documentation - [see web component docs](https://aka.ms/mgt-docs).
3634

3735
For example, you can set the `personDetails` property to an object:
3836

@@ -46,27 +44,29 @@ const App = (props) => {
4644
};
4745
```
4846

49-
### Register event handlers:
47+
Or, register an event handler:
5048

5149
```jsx
52-
import { PeoplePicker } from '@microsoft/mgt-react';
50+
import { PeoplePicker, People } from '@microsoft/mgt-react';
5351

5452
const App = (props) => {
53+
const [people, setPeople] = useState([]);
54+
5555
const handleSelectionChanged = (e) => {
56-
this.setState({ people: e.target.selectedPeople });
56+
setPeople(e.target.selectedPeople);
5757
};
5858

59-
return <PeoplePicker selectionChanged={handleSelectionChanged} />;
59+
return
60+
<div>
61+
<PeoplePicker selectionChanged={handleSelectionChanged} />
62+
Selected People: <People people={people} />
63+
</div>;
6064
};
6165
```
6266

63-
All properties and events map exactly as they are defined on the web component - [see web component docs](https://aka.ms/mgt-docs).
64-
65-
### Templates
66-
67-
`mgt-react` allows you to leverage React for writing templates for mgt components.
67+
## Templates
6868

69-
> Note: You can learn more about [templating mgt components here](https://docs.microsoft.com/graph/toolkit/templates)
69+
Most Microsoft Graph Toolkit components [support templating](https://docs.microsoft.com/graph/toolkit/customize-components/templates) and `mgt-react` allows you to leverage React for writing templates.
7070

7171
For example, to create a template to be used for rendering events in the `mgt-agenda` component, first define a component to be used for rendering an event:
7272

@@ -93,12 +93,6 @@ const App = (props) => {
9393

9494
The `template` prop allows you to specify which template to overwrite. In this case, the `MyEvent` component will be repeated for every event, and the `event` object will be passed as part of the `dataContext` prop.
9595

96-
## What components can I use?
97-
98-
The library is auto generated from the Microsoft Graph Toolkit and all components are available.
99-
100-
The names of the React components are in PascalCase and do not include the `Mgt` prefix. For example, the `mgt-person` component is available as `Person`, and the `mgt-people-picker` component is available as `PeoplePicker`. See the [Microsoft Graph Toolkit documentation](https://aka.ms/mgt-docs) for a list of all components.
101-
10296
## Why
10397

10498
If you've used web components in React, you know that proper interop between web components and React components requires a bit of extra work.

packages/mgt/README.md

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
# Microsoft Graph Toolkit
22

3-
<img align="left" height="150" src="https://github.com/microsoftgraph/microsoft-graph-toolkit/raw/main/assets/graff.png" title="Graff the Giraffe">
3+
<a href="https://www.npmjs.com/package/@microsoft/mgt"><img src="https://img.shields.io/npm/v/@microsoft/mgt.svg"></a> <a href="https://github.com/microsoftgraph/msgraph-sdk-javascript"><img src="https://cdn.jsdelivr.net/gh/storybookjs/brand@master/badge/badge-storybook.svg"></a>
44

5-
[![NPM](https://img.shields.io/npm/v/@microsoft/mgt.svg)](https://www.npmjs.com/package/@microsoft/mgt) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/microsoftgraph/msgraph-sdk-javascript) [![stackoverflow](https://img.shields.io/stackexchange/stackoverflow/t/microsoft-graph-toolkit.svg)](https://stackoverflow.com/questions/tagged/microsoft-graph-toolkit)
6-
[![Build Status](https://dev.azure.com/microsoft-graph-toolkit/microsoft-graph-toolkit/_apis/build/status/microsoftgraph.microsoft-graph-toolkit?branchName=main)](https://dev.azure.com/microsoft-graph-toolkit/microsoft-graph-toolkit/_build/latest?definitionId=1&branchName=main) [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/@microsoft/mgt) [![Storybook](https://raw.githubusercontent.com/storybooks/brand/main/badge/badge-storybook.svg?sanitize=true)](https://mgt.dev)
5+
The Microsoft Graph Toolkit is a collection of reusable, framework-agnostic components and authentication providers for accessing and working with Microsoft Graph. The components are fully functional right of out of the box, with built in providers that authenticate with and fetch data from Microsoft Graph.
76

8-
The Microsoft Graph Toolkit is a collection of web components powered by the Microsoft Graph.
7+
The `@microsoft/mgt` package brings all mgt packages together (with the exception of `@microsoft/mgt-react`) and bundles them in this one convenient package.
98

10-
Components are functional and work automatically with the Microsoft Graph
11-
12-
Components work with any web framework and on all modern browsers. IE 11 is also supported
9+
[View the full documentation](https://docs.microsoft.com/graph/toolkit/overview)
1310

14-
[Here is a quick jsfiddle](https://jsfiddle.net/metulev/9phqxLd5/)
11+
You can now explore components and samples with the [playground](https://mgt.dev).
12+
## Components
1513

16-
## Components & Documentation
14+
The Microsoft Graph Toolkit includes a collection of web components for the most commonly built experiences powered by Microsoft Graph APIs.
1715

18-
The toolkit currently includes the following components:
16+
The components are also available as [React components](https://docs.microsoft.com/graph/toolkit/get-started/mgt-react).
1917

2018
* [mgt-login](https://docs.microsoft.com/graph/toolkit/components/login)
2119
* [mgt-person](https://docs.microsoft.com/graph/toolkit/components/person)
@@ -24,21 +22,19 @@ The toolkit currently includes the following components:
2422
* [mgt-people-picker](https://docs.microsoft.com/graph/toolkit/components/people-picker)
2523
* [mgt-agenda](https://docs.microsoft.com/graph/toolkit/components/agenda)
2624
* [mgt-tasks](https://docs.microsoft.com/graph/toolkit/components/tasks)
25+
* [mgt-todo](https://docs.microsoft.com/graph/toolkit/components/todo)
2726
* [mgt-get](https://docs.microsoft.com/graph/toolkit/components/get)
2827
* [mgt-teams-channel-picker](https://docs.microsoft.com/en-us/graph/toolkit/components/teams-channel-picker)
2928

30-
And the following providers:
29+
## Providers
30+
[Providers](https://docs.microsoft.com/graph/toolkit/providers) enable authentication and provide the implementation for acquiring access tokens on various platforms and expose a Microsoft Graph Client for calling the Microsoft Graph APIs. The components work best when used with a provider, but the providers can be used on their own.
3131

3232
* [Msal Provider](https://docs.microsoft.com/graph/toolkit/providers/msal)
3333
* [SharePoint Provider](https://docs.microsoft.com/graph/toolkit/providers/sharepoint)
3434
* [Teams Provider](https://docs.microsoft.com/graph/toolkit/providers/teams)
3535
* [Proxy Provider](https://docs.microsoft.com/graph/toolkit/providers/proxy)
3636
* [Simple Provider](https://docs.microsoft.com/graph/toolkit/providers/custom)
3737

38-
[View the full documentation](https://docs.microsoft.com/graph/toolkit/overview)
39-
40-
You can now explore components and samples with the [playground](https://mgt.dev) powered by storybook.
41-
4238
## Getting Started
4339

4440
[Watch the Getting Started Video](https://www.youtube.com/watch?v=oZCGb2MMxa0)
@@ -55,13 +51,11 @@ You can then start using the components in your html page. Here is a full workin
5551

5652
```html
5753
<script src="https://unpkg.com/@microsoft/mgt/dist/bundle/mgt-loader.js"></script>
54+
5855
<mgt-msal-provider client-id="[CLIENT-ID]"></mgt-msal-provider>
59-
<mgt-login></mgt-login>
6056

61-
<!-- <script>
62-
// alternatively, you can set the provider in code and provide more options
63-
mgt.Providers.globalProvider = new mgt.MsalProvider({clientId: '[CLIENT-ID]'});
64-
</script> -->
57+
<mgt-login></mgt-login>
58+
<mgt-agenda></mgt-agenda>
6559
```
6660

6761
> NOTE: MSAL requires the page to be hosted in a web server for the authentication redirects. If you are just getting started and want to play around, the quickest way is to use something like [live server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) in vscode.
@@ -74,56 +68,24 @@ The benefits of using MGT through NPM is that you have full control of the bundl
7468
npm install @microsoft/mgt
7569
```
7670

77-
Now you can reference all components at the page you are using:
78-
79-
```html
80-
<script src="node_modules/@microsoft/mgt/dist/es6/components.js"></script>
81-
```
82-
83-
Or, just reference the component you need and avoid loading everything else:
71+
Now you can reference all components and providers at the page you are using:
8472

8573
```html
86-
<script src="node_modules/@microsoft/mgt/dist/es6/components/mgt-login/mgt-login.js"></script>
87-
```
88-
89-
Similarly, to add a provider, you can add it as a component:
90-
91-
```html
92-
<script src="node_modules/@microsoft/mgt/dist/es6/components/providers/mgt-msal-provider.js"></script>
74+
<script type="module" src="node_modules/@microsoft/mgt/dist/es6/index.js"></script>
9375

9476
<mgt-msal-provider client-id="[CLIENT-ID]"></mgt-msal-provider>
95-
```
96-
97-
or, add it in your code:
98-
99-
```html
100-
<script type="module">
101-
import { Providers, MsalProvider } from '@microsoft/mgt';
10277

103-
Providers.globalProvider = new MsalProvider({ clientId: '[CLIENT-ID]' });
104-
</script>
78+
<mgt-login></mgt-login>
79+
<mgt-agenda></mgt-agenda>
10580
```
10681

107-
## Providers
108-
109-
The components work best when used with a [provider](https://docs.microsoft.com/graph/toolkit/providers). The provider exposes authentication and Microsoft Graph apis used by the components to call into the Microsoft Graph.
110-
111-
The toolkit contains providers for [MSAL](https://docs.microsoft.com/graph/toolkit/providers/msal), [SharePoint](https://docs.microsoft.com/graph/toolkit/providers/sharepoint), and [Teams](https://docs.microsoft.com/graph/toolkit/providers/teams). You can also create your own providers by extending the [IProvider](https://docs.microsoft.com/graph/toolkit/providers/custom) abstract class.
112-
113-
## Contribute
114-
115-
We enthusiastically welcome contributions and feedback. Please read the [contributing guide](CONTRIBUTING.md) before you begin.
116-
11782
## Feedback and Requests
11883

11984
For general questions and support, please use [Stack Overflow](https://stackoverflow.com/questions/tagged/microsoft-graph-toolkit) where questions should be tagged with `microsoft-graph-toolkit`
12085

12186
Please use [GitHub Issues](https://github.com/microsoftgraph/microsoft-graph-toolkit/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) for bug reports and feature requests. We highly recommend you browse existing issues before opening new issues.
12287

123-
## License
124-
125-
All files in this GitHub repository are subject to the [MIT license](https://github.com/OfficeDev/office-ui-fabric-core/blob/master/LICENSE). This project also references fonts and icons from a CDN, which are subject to a separate [asset license](https://static2.sharepointonline.com/files/fabric/assets/license.txt).
126-
127-
## Code of Conduct
128-
129-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
88+
## Sea also
89+
* [Microsoft Graph Toolkit docs](https://aka.ms/mgt-docs)
90+
* [Microsoft Graph Toolkit repository](https://aka.ms/mgt)
91+
* [Microsoft Graph Toolkit playground](https://mgt.dev)

0 commit comments

Comments
 (0)