npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vte-js/react

v1.0.1

Published

React bindings for Vue Token Engine - hooks and Provider

Readme

@vte-js/react

Vue Token Engine 的 React 绑定,提供 hooks 访问 design tokens。

安装

npm install @vte-js/react
# 或
pnpm add @vte-js/react

使用

TokenProvider

在应用根部注入 token 上下文:

import { TokenProvider } from "@vte-js/react";
import { tokenMap } from "./tokens";

function App() {
  return (
    <TokenProvider tokenMap={tokenMap} platform="web">
      <MyComponent />
    </TokenProvider>
  );
}

useTokenValue

获取单个 token 的值:

import { useTokenValue } from "@vte-js/react";

function MyComponent() {
  const color = useTokenValue("semantic.color.primary");

  return <div style={{ color }}>Hello</div>;
}

支持平台转换:

// Web: var(--vte-semantic-color-primary)
const webColor = useTokenValue("semantic.color.primary");

// 小程序: #3b82f6
const mpColor = useTokenValue("semantic.color.primary", "mp");

// React Native: #3b82f6
const rnColor = useTokenValue("semantic.color.primary", "rn");

useTokenStyle

将 token 路径映射转换为样式对象:

import { useTokenStyle } from "@vte-js/react";

function MyComponent() {
  const style = useTokenStyle({
    color: "semantic.color.primary",
    backgroundColor: "semantic.color.background",
    padding: "semantic.spacing.medium",
  });

  // style = {
  //   color: "var(--vte-semantic-color-primary)",
  //   backgroundColor: "var(--vte-semantic-color-background)",
  //   padding: "var(--vte-semantic-spacing-medium)",
  // }

  return <div style={style}>Hello</div>;
}

useTokenMap

获取完整的 token 映射:

import { useTokenMap } from "@vte-js/react";

function TokenList() {
  const tokenMap = useTokenMap();

  const colors = Array.from(tokenMap.entries())
    .filter(([key]) => key.startsWith("semantic.color"))
    .map(([key, value]) => ({ key, value: value.value }));

  return (
    <ul>
      {colors.map(({ key, value }) => (
        <li key={key}>{key}: {value}</li>
      ))}
    </ul>
  );
}

useToken

获取完整的 token 上下文:

import { useToken } from "@vte-js/react";

function MyComponent() {
  const { tokenMap, platform, getToken, getTokenValue } = useToken();

  return (
    <div>
      <p>Platform: {platform}</p>
      <p>Primary color: {getToken("semantic.color.primary")}</p>
    </div>
  );
}

组件示例

Button 组件

import { useTokenValue, useTokenStyle } from "@vte-js/react";

interface ButtonProps {
  children: React.ReactNode;
  variant?: "primary" | "secondary";
}

export function Button({ children, variant = "primary" }: ButtonProps) {
  const primaryColor = useTokenValue("semantic.color.primary") as string;
  const bgColor = useTokenValue("semantic.color.background") as string;

  const style = useTokenStyle({
    padding: "semantic.spacing.medium",
  });

  return (
    <button
      style={{
        ...style,
        backgroundColor: variant === "primary" ? primaryColor : bgColor,
        color: variant === "primary" ? "#fff" : "#000",
        border: "none",
        borderRadius: "4px",
        cursor: "pointer",
      }}
    >
      {children}
    </button>
  );
}

平台值转换

| 原始值 | Web | 小程序 (mp) | React Native | |--------|-----|-------------|--------------| | #3b82f6 | var(--vte-xxx) | #3b82f6 | #3b82f6 | | 0.5rem | var(--vte-xxx) | 16rpx | 0.5rem | | 16px | var(--vte-xxx) | 32rpx | 16 | | 8 | var(--vte-xxx) | 8 | 8 |

License

ISC