@alveole/theme

中文文档
2.0.0-alpha.25发布于 2026/11/05TypeScriptCommonJS近 30 天下载 4079

Shared theme tokens and utilities.

原始使用文档
文档目录13 节
  1. Installation
  2. Utilisation rapide
  3. Générer des styles
  4. Spacing
  5. Typographies
  6. Fonts
  7. fontStyle helper
  8. Radius
  9. Breakpoints & variante
  10. Couleurs
  11. Personnaliser la palette
  12. Variables CSS (web)
  13. Références

@alveole/theme

Thème partagé (tokens, typographies, helpers) pour les apps React Native / web.

Installation

npm i @alveole/theme

Peer deps requis : react, react-native, expo-font, expo-system-ui, @tamagui/core.

Utilisation rapide

import { ThemeProvider, useTheme, makeStyles } from '@alveole/theme';

export default function App() {
  return (
    <ThemeProvider>
      <Screen />
    </ThemeProvider>
  );
}

function Screen() {
  const { spacing } = useTheme();
  return <Box style={{ margin: spacing('2W') }}>Contenu</Box>;
}

Générer des styles

// Exemple.styles.tsx
import { makeStyles } from '@alveole/theme';

export const useStyles = makeStyles(({ spacing, text, color }) => ({
  container: { padding: spacing('3W') },
  title: text.Titres['H3 - MD'],
  label: { color: color.Neutre[700] },
}));
// Exemple.tsx
import { useStyles } from './Exemple.styles';

function Exemple() {
  const styles = useStyles();
  return <Box style={styles.container} />;
}

Spacing

Les clés de spacing suivent une nomenclature V (verticals, multiples de 2px) et W (horizontals, multiples de 8px) :

Clépx
0V0
0,5V2
1V4
1,5V6
1W8
3V12
2W16
3W24
4W32
5W40
6W48
8W64
12W96
15W120
const { spacing, externalPadding } = useTheme();

spacing('3W'); // 24
externalPadding(); // 16 sur mobile, 24 sur desktop

Typographies

Les styles de texte sont organisés en trois catégories :

const { text } = useTheme();

// Titres alternatifs (Geist SemiBold)
text['Titres alternatifs'].XS; // 48px
text['Titres alternatifs'].XL; // 80px

// Titres (Geist SemiBold — tailles adaptées mobile/desktop)
text.Titres['H1 - XL']; // Geist SemiBold, 40px desktop / 32px mobile
text.Titres['H3 - MD']; // 28px desktop / 24px mobile
text.Titres['H6 - XXS']; // 20px desktop / 18px mobile

// Corps de texte
text['Corps de texte'].SM.Regular; // Geist Regular, 14px
text['Corps de texte'].MD.SemiBold; // Geist SemiBold, 16px
text['Corps de texte'].LG.Medium; // Geist Medium, 18px

Fonts

Les fonts sont chargées automatiquement par ThemeProvider. Une seule famille est utilisée : Geist (titres et corps de texte).

Sur le web, les fonts sont injectées via des @font-face CSS standards (font-family: Geist; font-weight: 500). Sur native, elles utilisent le système expo-font.

const { font } = useTheme();

font['Geist-Regular']; // 'Geist-Regular' (native) ou utilisé via font-weight (web)
font['Geist-Bold'];

fontStyle helper

Pour créer des styles typés avec la bonne font selon la plateforme :

import { fontStyle } from '@alveole/theme';

const style = {
  ...fontStyle('Geist-Bold'), // { fontFamily: 'Geist', fontWeight: '600' } sur web
  fontSize: 16, // { fontFamily: 'Geist-Bold' } sur native
};

Radius

const { radius } = useTheme();

radius('sm'); // 4
radius('md'); // 6
radius('lg'); // 10
radius('full'); // 99999

Breakpoints & variante

const { variant, isVariant } = useTheme();

variant; // 'mobile' | 'tablet' | 'desktop'
isVariant('mobile'); // boolean
VarianteLargeur
mobile< 768px
tablet768px – 991px
desktop≥ 992px

Couleurs

const { color } = useTheme();

color.Neutre[700];
color.Watusi[50];
color.alpha(color.Neutre[900], 0.5); // 'rgba(55, 58, 63, 0.5)'

Personnaliser la palette

<ThemeProvider
  color={{
    Neutre: { 100: '#F7F7F7' },
    Watusi: { 50: '#FEF5F2' },
  }}
>
  <App />
</ThemeProvider>

(Recommandé) Vous pouvez définir un fichier alveole.config.js à la racine pour centraliser la surcharge :

const { Colors } = require('@alveole/theme');

/** @type {import('@alveole/theme').Palette} */
const palette = {
  primary: Colors.VertPrairie['sun-475'],

  background: {
    button: {
      primary: {
        default: Colors.VertPrairie['sun-475'],
        hover: Colors.VertPrairie['sun-475-hover'],
      },
    },
  },
};

module.exports = { palette };

// Utiliser dans le provider :
// import config from '@/alveole.config.js';
// <ThemeProvider color={config.palette}>

Variables CSS (web)

Sur le web, ThemeProvider injecte automatiquement des variables CSS pour les couleurs, l'espacement et les fonts :

/* Spacing */
var(--spacing-2W)
var(--spacing-3W)

/* Colors */
var(--color-Neutre-200)
var(--color-Watusi-50)

Références

  • Typage du thème : src/type/Theme.ts
  • Palette : src/constants/Palette.ts
  • Typographies : src/constants/Typography.ts
  • Spacing : src/constants/Spacing.ts
  • Radius : src/constants/Radius.ts
  • Fonts : src/constants/Font.ts

版本与发布记录

@alveole/theme 共发布 178 个版本,首次发布于 2026/02/07;过去 12 个月发布了 178 个版本。

版本发布日期距今
2.0.0-alpha.25latest2026/11/052 天前
2.0.0-alpha.242026/11/034 天前
2.0.0-alpha.232026/11/034 天前
2.0.0-alpha.222026/11/035 天前
2.0.0-alpha.212026/11/025 天前
2.0.0-alpha.202026/10/2811 天前

关于 @alveole/theme 的常见问题

@alveole/theme 是什么?

Shared theme tokens and utilities.

如何安装 @alveole/theme?

在项目目录运行 npm install @alveole/theme,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、expo-font(*)、react-native(*)、@tamagui/core(^3.0.0)、expo-system-ui(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@alveole/theme 支持 TypeScript 吗?

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

@alveole/theme 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@alveole/theme 可以商用吗?

@alveole/theme 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@alveole/theme 的下载量有多少?

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

@alveole/theme 还在维护吗?

最新版本 2.0.0-alpha.25 发布于 2026/11/05(2 天前);至今共发布 178 个版本,其中过去 12 个月发布了 178 个;首次发布于 2026/02/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。