@accord-coop/use-teams 中文文档教程

发布于 3年前 浏览 21 项目主页 更新于 3年前

Microsoft Teams UI Controls base component

npm 版本npmMITGitHub 问题GitHub closed issues

这是一个基于 Microsoft Teams JavaScript SDK 和 Fluent UI 组件的 React hook,它在使用 Microsoft Teams Yeoman Generator 生成 Microsoft Teams 应用程序时使用。 Accord Cooperative 的这个分支排除了 Fluent UI React Northstar 依赖项。

@master@preview
Build StatusBuild Status

Usage

要在 Teams 选项卡或扩展中使用此包,请导入 useTeams Hook,然后在功能组件中调用它。

const [{inTeams}] = useTeams();

useTeams 挂钩将返回一个元组,其中属性对象位于第一个字段中,方法对象位于第二个字段中。

注意:如果 Microsoft Teams JS SDK 可用,使用挂钩将自动调用 microsoftTeams.initialize()microsoftTeams.getContext()

useTeams Hook arguments

useTeams 挂钩可以采用可选 对象参数:

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
contextmicrosoftTeams.Context?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

使用示例:

import React, { 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 (
        <div>{message}</div>
    );
};

Additional helper methods

该包还导出两个辅助方法,均由 useTeams 挂钩在内部使用.

getQueryVariable(name: string): string - 返回由名称标识的查询字符串变量的值。

checkInTeams(): boolean - 如果托管在 Microsoft Teams 中,则返回 true。

License

版权所有 (c) Wictor Wilén。 版权所有。

根据麻省理工学院许可获得许可。

Microsoft Teams UI Controls base component

npm versionnpmMITGitHub issuesGitHub closed issues

This is a React hook based on the Microsoft Teams JavaScript SDK and the Fluent UI components, which is used when generating Microsoft Teams Apps using the Microsoft Teams Yeoman Generator. This fork for Accord Cooperative excludes the Fluent UI React Northstar dependency.

@master@preview
Build StatusBuild Status

Usage

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 call microsoftTeams.initialize() and microsoftTeams.getContext() if 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
contextmicrosoftTeams.Context?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 React, { 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 (
        <div>{message}</div>
    );
};

Additional helper methods

The package also exports two helper methods, both used internally by the useTeams hook.

getQueryVariable(name: string): string - returns the value of the query string variable identified by the name.

checkInTeams(): boolean - returns true if hosted inside Microsoft Teams.

License

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

Licensed under the MIT license.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文