@cleartrip/ct-design-style-manager

中文文档
5.32.0发布于 2026/11/16ISCTypeScriptESM + CJS近 30 天下载 4.6万

Style hooks

原始使用文档
文档目录11 节
  1. Installation
  2. API Reference
  3. makeStyles
  4. useStyles
  5. makeWebStyles ✨ new
  6. useWebStyles ✨ new
  7. useWebMergeStyles (deprecated)
  8. useNativeMergeStyles (deprecated)
  9. gs — Global Layout Styles
  10. Choosing the right API
  11. Key differences: makeStyles vs makeWebStyles

@cleartrip/ct-design-style-manager

A collection of styling utilities for the Cleartrip Design System. Provides hooks and factory functions that convert style definitions into Emotion class names for web, while keeping full compatibility with the React Native style shape.


Installation

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

API Reference

makeStyles

A non-hook factory for React-Native-first styles.

Accepts a factory function that receives the current theme and returns a NamedStyles object (using ViewStyle, TextStyle, or ImageStyle properties). The styles are validated, preprocessed (RN → web conversions, shadow/textShadow expansion), and each key is converted to an Emotion class name string.

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>'

Signature

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

Use customTheme to override the active theme (e.g. in tests or server-side rendering).


useStyles

The hook counterpart of makeStyles. Uses useTheme() to read the active theme reactively and memoises the result via useStableMemo so styles are only recomputed when deps change.

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>;
}

Signature

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

makeWebStyles ✨ new

A non-hook factory for web-only styles using standard React CSSProperties.

Unlike makeStyles, no React-Native preprocessing is applied — values are passed directly to Emotion. Use this when you are authoring web-only components and want to use standard CSS property names (e.g. backgroundColor, fontSize, display).

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>'

Signature

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

where NamedWebStyles<T> = { [P in keyof T]: CSSProperties }.

Use customTheme to override the active theme (e.g. in tests or SSR).


useWebStyles ✨ new

The hook counterpart of makeWebStyles. Reads the active theme via useTheme() and memoises via useStableMemo.

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>
  );
}

Signature

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

useWebMergeStyles (deprecated)

Merges an array of style sources — existing Emotion class name strings or raw style objects — into a single Emotion class string. Only use in terminal/leaf components.

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

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

Signature

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

useNativeMergeStyles (deprecated)

Merges an array of React Native StyleProp values. Only use in terminal/leaf native components.

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

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

Signature

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

gs — Global Layout Styles

Pre-built global layout utility class names generated once at module load time (no theme dependency). Import specific keys as needed.

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

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

Choosing the right API

ScenarioUse
Cross-platform component (web + RN) using RN-style propertiesmakeStyles / useStyles
Web-only component using standard CSS propertiesmakeWebStyles / useWebStyles
Merging multiple class names / style objects at runtime (web)useWebMergeStyles
Merging multiple style objects at runtime (native)useNativeMergeStyles
Static layout utilities (no theme needed)gs

Key differences: makeStyles vs makeWebStyles

makeStylesmakeWebStyles
Input property typeViewStyle / TextStyle / ImageStyle (RN)CSSProperties (React / web)
Preprocessing✅ RN → web conversions, shadow expansion❌ None — passed directly to Emotion
Validation✅ RN style validation❌ Not applied
PlatformCross-platformWeb only
OutputEmotion class name strings (same key shape as input)Emotion class name strings (same key shape as input)

版本与发布记录

@cleartrip/ct-design-style-manager 共发布 418 个版本,首次发布于 2025/10/19;过去 12 个月发布了 377 个版本。

版本发布日期距今
5.32.0latest2026/11/16今天
5.31.1-SNAPSHOT-5.32.0-SNAPSHOT-bs-height-check-161120161537.02026/11/16今天
5.31.1-SNAPSHOT-bs-height-check-151120162243.02026/11/16今天
5.31.1-SNAPSHOT-biztrip-rn-sme-snapshot-11-11-26.02026/11/115 天前
5.32.0-SNAPSHOT-native-main.22026/11/115 天前
5.31.1-SNAPSHOT-native-main.02026/11/0313 天前

其他发布通道:SNAPSHOT-styleHookTestV1 → 3.20.1-SNAPSHOT-styleHookTestV1.0,SNAPSHOT-styleHookTestV4 → 3.20.1-SNAPSHOT-styleHookTestV4.0,SNAPSHOT-styleHookTestV6 → 3.20.1-SNAPSHOT-styleHookTestV6.0,SNAPSHOT-styleHookIssue → 3.20.1-SNAPSHOT-styleHookIssue.0,SNAPSHOT-styleHookIssueV4 → 3.20.1-SNAPSHOT-styleHookIssueV4.0,SNAPSHOT-styleHookBug → 3.20.1-SNAPSHOT-styleHookBug.0。

关于 @cleartrip/ct-design-style-manager 的常见问题

@cleartrip/ct-design-style-manager 是什么?

Style hooks

如何安装 @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 和提交记录判断。