@emotion/primitives-core

中文文档
11.13.2发布于 2024/07/29MITTypeScriptESM + CJS近 30 天下载 37.8万

Shared utilities for emotion primitives and native

原始使用文档
文档目录3 节
  1. Introduction
  2. createCss(StyleSheet)
  3. createStyled(StyleSheet)

@emotion/primitives-core

Shared utilities for emotion primitives and native

Introduction

Note: In most of the cases, you won't need this package and should use @emotion/native or @emotion/primitives.

This package contains some shared utilities which are consumed by @emotion/primitives and @emotion/native for styling and rendering components.

This package provides two functions, createCss and createStyled.

createCss(StyleSheet)

createCss accepts a platform specific StyleSheet method for creating styles, and returns a function which accepts styles via string template literal and object literal notation.

import { StyleSheet, View, Text } from 'react-native'
import { createCss } from '@emotion/primitives-core'

const css = createCss(StyleSheet)

<View style={css`background-color: red;`}><Text style={css`font-size: 40px;`}>Hello World</Text></View>

createStyled(StyleSheet)

createStyled also accepts a platform specific StyleSheet method for creating styles. It returns a function to which primitives can be assigned for example - View, Text, and it returns a styled component.

import { StyleSheet, View, Text } from 'react-native'
import { createStyled } from '@emotion/primitives-core'

const styled = createStyled(StyleSheet)

styled.Text = styled(Text)

const StyledText = styled.Text`font-size: 40px;`

<View><StyledText>Hello World</StyledText></View>

版本与发布记录

@emotion/primitives-core 共发布 50 个版本,首次发布于 2018/07/29;过去 12 个月发布了 0 个版本。

版本发布日期距今
11.13.2latest2024/07/292 年前
11.13.02024/07/202 年前
11.12.02024/07/192 年前
11.11.02023/05/063 年前
11.10.02022/07/314 年前
11.0.02020/11/126 年前

其他发布通道:next → 11.0.0-next.19,rc → 11.0.0-rc.0。

关于 @emotion/primitives-core 的常见问题

@emotion/primitives-core 是什么?

Shared utilities for emotion primitives and native

如何安装 @emotion/primitives-core?

在项目目录运行 npm install @emotion/primitives-core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.8.0)、@emotion/react(^11.0.0-rc.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@emotion/primitives-core 支持 TypeScript 吗?

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

@emotion/primitives-core 支持 ESM 还是 CommonJS?

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

@emotion/primitives-core 可以商用吗?

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

@emotion/primitives-core 的下载量有多少?

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

@emotion/primitives-core 还在维护吗?

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