@fluentui/react-bindings

中文文档
0.71.4发布于 2026/04/29MITTypeScriptESM + CJS近 30 天下载 8.6万

A set of components and hooks to build components libraries and UI kits.

原始使用文档
文档目录7 节
  1. useAccesibility()
  2. useStyles()
  3. Usage
  4. Reference
  5. useUnhandledProps()
  6. Usage
  7. Reference

@fluentui/react-bindings

A set of reusable components and hooks to build component libraries and UI kits.

Installation

NPM

npm install --save @fluentui/react-bindings

Yarn

yarn add @fluentui/react-bindings

Hooks

useAccesibility()

A React hook that provides bindings for accessibility behaviors.

Usage

The example below assumes a component called <Image> will be used this way:

const imageBehavior: Accessibility<{ disabled: boolean }> = props => ({
  attributes: {
    root: {
      'aria-disabled': props.disabled,
      tabIndex: -1,
    },
    img: {
      role: 'presentation',
    },
  },
  keyActions: {
    root: {
      click: {
        keyCombinations: [{ keyCode: 13 /* equals Enter */ }],
      },
    },
  },
});

type ImageProps = {
  disabled?: boolean;
  onClick?: (e: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
  src: string;
};

const Image: React.FC<ImageProps> = props => {
  const { disabled, onClick, src, ...rest } = props;
  const getA11Props = useAccessibility(imageBehavior, {
    mapPropsToBehavior: () => ({
      disabled,
    }),
    actionHandlers: {
      click: (e: React.KeyboardEvent<HTMLDivElement>) => {
        if (onClick) onClick(e);
      },
    },
  });

  return (
    <div {...getA11Props('root', { onClick, ...rest })}>
      <img {...getA11Props('img', { src })} />
    </div>
  );
};

useStyles()

A React hook that provides bindings for usage CSSinJS styles and Fluent theming.

Usage

The example below assumes a component called <Text> will be used this way:

type TextComponentProps = {
  className?: string;
  color?: string;
};

const Text: React.FunctionComponent<TextComponentProps> = props => {
  const { className, children, color } = props;

  const { classes } = useStyles('Text', {
    className: 'ui-text',
    mapPropsToStyles: () => ({ color }),
  });

  return <span className={classes.root}>{children}</span>;
};

Reference

const { classes } = useStyles(
  displayName: string,
  options: UseStylesOptions<Props>,
)
  • displayName - a component name to lookup in theme
  • options.className - optional, a special class name that will be always added to the root slot
  • options.mapPropsToStyles - optional, a set of props that will be passed style functions, only primitives are allowed
  • options.rtl - optional, sets RTL mode

useUnhandledProps()

A React hook that returns an object consisting of props beyond the scope of the component. Useful for getting and spreading unknown props from the user.

Usage

The example below assumes a component called <Text> will be used this way:

type TextComponentProps = React.HTMLAttributes<HTMLSpanElement> * {
  className?: string;
};

const Text: React.FunctionComponent<TextComponentProps> = props => {
  const { className, children } = props;
  const unhandledProps = useUnhandledProps(['className'], props);

  return <span {...unhandledProps} className={classes.root}>{children}</span>;
};

Reference

const unhandledProps = useUnhandledProps(handledProps, props);
  • unhandledProps - an object with unhandled props by component
  • handledProps - an array with names of handled props
  • props - an object with all props that are passed to a component

版本与发布记录

@fluentui/react-bindings 共发布 92 个版本,首次发布于 2019/12/06;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.71.4latest2026/04/296 个月前
0.71.32026/02/258 个月前
0.71.22026/02/258 个月前
0.71.12025/11/2011 个月前
0.71.02025/11/031 年前
0.70.02025/10/301 年前

其他发布通道:canary → 0.31.1-alpha.6224,experimental → 0.47.10-experimental.0,patch → 0.47.15,beta → 0.66.1-beta.0。

关于 @fluentui/react-bindings 的常见问题

@fluentui/react-bindings 是什么?

A set of components and hooks to build components libraries and UI kits.

如何安装 @fluentui/react-bindings?

在项目目录运行 npm install @fluentui/react-bindings,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18)、react-dom(^18)、scheduler(^0.23.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fluentui/react-bindings 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fluentui/react-bindings 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fluentui/react-bindings 可以商用吗?

@fluentui/react-bindings 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fluentui/react-bindings 的下载量有多少?

根据 npm 官方下载统计,@fluentui/react-bindings 在 2026/10/15 – 2026/11/13 这 30 天内被下载 86,230 次,日均约 2,874 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fluentui/react-bindings 还在维护吗?

最新版本 0.71.4 发布于 2026/04/29(6 个月前);至今共发布 92 个版本,其中过去 12 个月发布了 4 个;首次发布于 2019/12/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。