4.0.1 • Published 2 years ago

msteams-react-base-component v4.0.1

Weekly downloads
566
License
MIT
Repository
github
Last release
2 years ago

Microsoft Teams UI Controls base component

npm version npm MIT GitHub issues GitHub closed issues

This is a set of React hooks and providers based on the Microsoft Teams JavaScript SDK, the Fluent UI components and Microsoft Graph Toolkit, which is used when generating Microsoft Teams Apps using the Microsoft Teams Yeoman Generator.

@master@preview
Build StatusBuild Status

Usage

useTeams hook

To use this package in a Teams tab or extension import the useTeams Hook and then call it inside a functional component.

const [{inTeams}] = useTeams();

The useTeams hook will return a tuple of where an object of properties are in the first field and an object of methods in the second.

NOTE: using the hook will automatically initialize the Microsoft Teams JS SDK is available.

useTeams Hook arguments

The useTeams hook can take an optional object argument:

ArgumentDescription
initialTheme?: stringManually set the initial theme (default, dark or contrast)
setThemeHandler?: (theme?: string) => voidCustom handler for themes

Available properties

Property nameTypeDescription
inTeamsboolean?true if hosted in Teams and false for outside of Microsoft Teams
fullScreenboolean?true if the Tab is in full-screen, otherwise false
themeStringstringThe value of default, dark or contrast
themeThemePreparedThe Fluent UI Theme object for the current theme
contextContext?undefined while the Tab is loading or if not hosted in Teams, set to a value once the Tab is initialized and context available

Available methods

Method nameDescription
setTheme(theme?: string)Method for manually setting the theme

Full example

Example of usage:

import * as React from "react";
import { Provider, Flex, Header } from "@fluentui/react-northstar";
import { useState, useEffect } from "react";
import { useTeams } from "msteams-react-base-component";

/**
 * Implementation of the hooks Tab content page
 */
export const HooksTab = () => {
    const [{ inTeams, theme }] = useTeams({});
    const [message, setMessage] = useState("Loading...");

    useEffect(() => {
        if (inTeams === true) {
            setMessage("In Microsoft Teams!");
        } else {
            if (inTeams !== undefined) {
                setMessage("Not in Microsoft Teams");
            }
        }
    }, [inTeams]);

    return (
        <Provider theme={theme}>
            <Flex fill={true}>
                <Flex.Item>
                    <Header content={message} />
                </Flex.Item>
            </Flex>
        </Provider>
    );
};

License

Copyright (c) Wictor Wilén. All rights reserved.

Licensed under the MIT license.

4.0.0-preview.7

2 years ago

4.0.1-preview

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.0-preview.6

2 years ago

4.0.0-preview5

2 years ago

3.2.0-preview.1

2 years ago

3.2.0-preview.2

2 years ago

4.0.0-preview3

2 years ago

4.0.0-preview4

2 years ago

4.0.0-preview

2 years ago

4.0.0-preview2

2 years ago

3.1.1

3 years ago

3.1.1-preview

3 years ago

3.1.0

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.1-preview

3 years ago

3.0.0

3 years ago

3.0.0-preview2

3 years ago

3.0.0-preview

3 years ago

2.2.0

4 years ago

2.2.0-preview3

4 years ago

2.2.0-preview2

4 years ago

2.2.0-preview

4 years ago

2.1.0

4 years ago

2.1.0-preview4

4 years ago

2.1.0-preview3

4 years ago

2.1.0-preview2

4 years ago

2.1.0-preview

4 years ago

2.0.0

4 years ago

2.0.0-preview3

4 years ago

2.0.0-preview2

4 years ago

2.0.0-preview

5 years ago

1.1.1

5 years ago

1.1.1-Preview

5 years ago

1.1.0

5 years ago

1.1.0-preview

5 years ago

1.0.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago