# @cleartrip/ct-design-style-manager 中文文档

规范地址：https://npmcn.com/package/%40cleartrip/ct-design-style-manager/

版本：5\.32\.0
npm 元数据更新时间：2026-11-16T13:03:59.405Z
中文译文更新时间：2026-11-16T13:04:33.547Z
软件包许可：ISC

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40cleartrip/ct-design-style-manager
原文对照：https://npmcn.com/package/%40cleartrip/ct-design-style-manager/?lang=original

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：353 kB，54 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：4 个
- peer 依赖：react \>=16\.8\.0，react-dom \>=16\.8\.0
- 首次发布：2025-10-19T14:09:46.489Z
- 最新版本发布：2026-11-16T13:03:58.969Z
- 近 30 天下载量：46334（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：418（近 12 个月 377 个）

## 中文简介

样式钩

## 安装

```sh
npm install @cleartrip/ct-design-style-manager
```

也可以使用：`pnpm add @cleartrip/ct-design-style-manager`、`yarn add @cleartrip/ct-design-style-manager`、`bun add @cleartrip/ct-design-style-manager`

## README

# `@cleartrip/ct-design-style-manager`

Cleartrip Design System的造型公用设施集合. 提供将样式定义转换为 [情感](https://emotion.sh/docs/introduction) class name for web,同时保持与 React 原住民风格形状的完全相容.

* * *

## 安装

```bash
pnpm add @cleartrip/ct-design-style-manager
```

* * *

## API 参考

### `makeStyles`

A 类 **无挂起** 工厂的反动第一风格.

接受接收当前主题并返回 a 的工厂函数 `NamedStyles` 对象( 使用 `ViewStyle`, (中文(简体) ), `TextStyle`,或 `ImageStyle` 属性)。 风格经过验证,预处理(RN → 网页转换,Shabow/textShadow扩展),每个键被转换为情感类名称字符串.

```ts
import { makeStyles } from '@cleartrip/ct-design-style-manager';

const styles = makeStyles((theme) => ({
  container: {
    flexDirection: 'row',
    backgroundColor: theme.color.neutral_10,
    padding: theme.spacing.s4,
  },
  title: {
    fontSize: theme.font.size.large,
    color: theme.color.neutral_90,
  },
}));

// styles.container → 'css-<hash>'
// styles.title     → 'css-<hash>'
```

**签署**

```ts
function makeStyles<T extends NamedStyles<T>>(
  styleFactory: (theme: Theme) => T | NamedStyles<T> | NamedStyles<unknown>,
  customTheme?: Theme,
): T;
```

> 使用 `customTheme` 以覆盖活动主题(例如测试或服务器侧渲染).

* * *

### `useStyles`

这个 **钩子** 对应单位 `makeStyles`用途 `useTheme()` 以被动方式读取活动主题,并通过 `useStableMemo` 所以样式只有在 `deps` 变化.

```ts
import { useStyles } from '@cleartrip/ct-design-style-manager';

function MyComponent() {
  const styles = useStyles(
    (theme) => ({
      container: { padding: theme.spacing.s4 },
      label: { color: theme.color.neutral_90 },
    }),
    [],
  );

  return <div className={styles.container}>…</div>;
}
```

**签署**

```ts
function useStyles<T extends NamedStyles<T>>(
  styleFactory: (theme: Theme) => T | NamedStyles<T> | NamedStyles<unknown>,
  deps: DependencyList,
): T;
```

* * *

### `makeWebStyles` 新设

A 类 **无挂起** 工厂 **仅网络** 使用标准反应的样式 `CSSProperties`。 。 。 .

与 `makeStyles`,不应用反应-内在预处理——数值直接传递给情感. 当您正在编写仅网络组件时使用此选项,并想要使用标准的 CSS 属性名称(例如. `backgroundColor`, (中文(简体) ), `fontSize`, (中文(简体) ), `display`) (中文(简体) ).

```ts
import { makeWebStyles } from '@cleartrip/ct-design-style-manager';

const styles = makeWebStyles((theme) => ({
  container: {
    display: 'flex',
    gap: theme.spacing.s4,
    backgroundColor: theme.color.neutral_10,
  },
  title: {
    color: theme.color.neutral_90,
    fontSize: 16,
    fontWeight: 600,
  },
}));

// styles.container → 'css-<hash>'
// styles.title     → 'css-<hash>'
```

**签署**

```ts
function makeWebStyles<T extends NamedWebStyles<T>>(
  styleFactory: (theme: Theme) => T | NamedWebStyles<T>,
  customTheme?: Theme,
): { [P in keyof T]: string };
```

地点 `NamedWebStyles<T> = { [P in keyof T]: CSSProperties }`。 。 。 .

> 使用 `customTheme` 以覆盖活动主题(例如在测试或SSSR中).

* * *

### `useWebStyles` 新设

这个 **钩子** 对应单位 `makeWebStyles`。通过 `useTheme()` 和回忆通过 `useStableMemo`。 。 。 .

```ts
import { useWebStyles } from '@cleartrip/ct-design-style-manager';

function MyComponent() {
  const styles = useWebStyles(
    (theme) => ({
      wrapper: {
        display: 'flex',
        flexDirection: 'column',
        gap: theme.spacing.s4,
      },
      heading: {
        color: theme.color.neutral_90,
        fontSize: 20,
      },
    }),
    [],
  );

  return (
    <div className={styles.wrapper}>
      <h1 className={styles.heading}>Hello</h1>
    </div>
  );
}
```

**签署**

```ts
function useWebStyles<T extends NamedWebStyles<T>>(
  styleFactory: (theme: Theme) => T | NamedWebStyles<T>,
  deps: DependencyList,
): { [P in keyof T]: string };
```

* * *

### `useWebMergeStyles` _(折旧)_

将一系列风格来源——现存的情感类名字符串或原始风格对象——合并为单一情感类字符串. 仅用于终端/叶片组件.

```ts
import { useWebMergeStyles } from '@cleartrip/ct-design-style-manager';

const className = useWebMergeStyles([styles.base, isActive && styles.active, propClassName], [isActive, propClassName]);
```

**签署**

```ts
const useWebMergeStyles: <T extends Styles | string>(styles: T[], deps: DependencyList) => string;
```

* * *

### `useNativeMergeStyles` _(折旧)_

合并本地反应数组 `StyleProp` 数值。 仅用于终端/叶生组件.

```ts
import { useNativeMergeStyles } from '@cleartrip/ct-design-style-manager';

const merged = useNativeMergeStyles([baseStyle, conditionalStyle], [dep]);
```

**签署**

```ts
function useNativeMergeStyles<T extends ViewStyle | ImageStyle | TextStyle>(
  styles: StyleProp<T>[],
  deps: DependencyList,
): StyleProp<T>;
```

* * *

### `gs` — 全局布局样式

模块加载时间( 没有主题依赖性) 已创建的全局布局工具类名称 。 根据需要导入特定密钥 .

```ts
import { gs } from '@cleartrip/ct-design-style-manager';

<div className={gs.flexRow}>…</div>
```

* * *

## 选择正确的 API

| 假设 | 使用 |
| --- | --- |
| 使用 RN 风格属性的跨平台组件( web + RN) | `makeStyles` 编号 : `useStyles` |
| 使用标准 CSS 属性的仅网络组件 | `makeWebStyles` 编号 : `useWebStyles` |
| 在运行时合并多个类名称/ 样式对象( web) | `useWebMergeStyles` |
| 在运行时合并多个样式对象( 本地) | `useNativeMergeStyles` |
| 静态布局公用事业(不需要主题) | `gs` |

* * *

## 关键差异 : `makeStyles` 对 `makeWebStyles`

|  | `makeStyles` | `makeWebStyles` |
| --- | --- | --- |
| 输入属性类型 | `ViewStyle` 编号 : `TextStyle` 编号 : `ImageStyle` (韩文) | `CSSProperties` (反应/网络) |
| 预处理 | RN – 网络转换,阴影扩展 | 没有——直接传给情感 |
| 验证 | QQ RN 样式验证 | 未应用 |
| 平台 | 跨平台 | 仅网络 |
| 产出 | 情感类名称字符串( 键形状与输入相同) | 情感类名称字符串( 键形状与输入相同) |

## 常见问题

### @cleartrip/ct-design-style-manager 是什么？

样式钩

### 如何安装 @cleartrip/ct-design-style-manager？

在项目目录运行 npm install @cleartrip/ct-design-style-manager，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（\>=16\.8\.0）、react-dom（\>=16\.8\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @cleartrip/ct-design-style-manager 支持 TypeScript 吗？

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

### @cleartrip/ct-design-style-manager 支持 ESM 还是 CommonJS？

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

### @cleartrip/ct-design-style-manager 可以商用吗？

@cleartrip/ct-design-style-manager 使用 ISC 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @cleartrip/ct-design-style-manager 的下载量有多少？

根据 npm 官方下载统计，@cleartrip/ct-design-style-manager 在 2026/10/10 – 2026/11/08 这 30 天内被下载 46,334 次，日均约 1,544 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @cleartrip/ct-design-style-manager 还在维护吗？

最新版本 5\.32\.0 发布于 2026/11/16（今天）；至今共发布 418 个版本，其中过去 12 个月发布了 377 个；首次发布于 2025/10/19。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

