mcpField
C
core-components

core-components

github.com/davila7设计与 UI33.0k249 次安装今天更新
代码仓库

关于 core-components

介绍 React 界面核心组件、设计令牌和布局模式的设计系统技能。它帮助开发者使用共享组件构建一致的页面,避免直接使用平台组件或硬编码数值。

主要功能

  1. 01使用间距、颜色和字体令牌
  2. 02通过 Box 和堆栈组件组合布局
  3. 03用核心共享组件构建界面
  4. 04为不同操作选择 Button 变体
  5. 05采用组件属性设计模式

适用场景

  1. 01构建风格一致的 React 页面
  2. 02创建表单和列表布局
  3. 03用令牌替代硬编码样式
  4. 04在不同界面模式中复用组件

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/davila7/claude-code-templates --skill core-components

安装后在 Claude Code 中输入/core-components确认已加载。

详细介绍

核心组件

设计系统概览

请使用核心库中的组件,而不是平台原生组件,以确保样式和行为一致。

设计令牌

切勿硬编码值。始终使用设计令牌。

间距令牌
// CORRECT - Use tokens
<Box padding="$4" marginBottom="$2" />

// WRONG - Hard-coded values
<Box padding={16} marginBottom={8} />
令牌值
$14px
$28px
$312px
$416px
$624px
$832px
颜色令牌
// CORRECT - Semantic tokens
<Text color="$textPrimary" />
<Box backgroundColor="$backgroundSecondary" />

// WRONG - Hard-coded colors
<Text color="#333333" />
<Box backgroundColor="rgb(245, 245, 245)" />
语义令牌用途
$textPrimary主文本
$textSecondary辅助文本
$textTertiary禁用/提示文本
$primary500品牌/强调色
$statusError错误状态
$statusSuccess成功状态
字体排版令牌
<Text fontSize="$lg" fontWeight="$semibold" />
令牌大小
$xs12px
$sm14px
$md16px
$lg18px
$xl20px
$2xl24px

核心组件

Box

支持令牌的基础布局组件:

<Box
  padding="$4"
  backgroundColor="$backgroundPrimary"
  borderRadius="$lg"
>
  {children}
</Box>
HStack / VStack

水平和垂直弹性布局:

<HStack gap="$3" alignItems="center">
  <Icon name="user" />
  <Text>Username</Text>
</HStack>

<VStack gap="$4" padding="$4">
  <Heading>Title</Heading>
  <Text>Content</Text>
</VStack>
Text

支持令牌的字体排版:

<Text
  fontSize="$lg"
  fontWeight="$semibold"
  color="$textPrimary"
>
  Hello World
</Text>
Button

带有不同变体的交互式按钮:

<Button
  onPress={handlePress}
  variant="solid"
  size="md"
  isLoading={loading}
  isDisabled={disabled}
>
  Click Me
</Button>
变体用途
solid主要操作
outline次要操作
ghost第三级/低强调操作
link行内操作
Input

带验证功能的表单输入组件:

<Input
  value={value}
  onChangeText={setValue}
  placeholder="Enter text"
  error={touched ? errors.field : undefined}
  label="Field Name"
/>
Card

内容容器:

<Card padding="$4" gap="$3">
  <CardHeader>
    <Heading size="sm">Card Title</Heading>
  </CardHeader>
  <CardBody>
    <Text>Card content</Text>
  </CardBody>
</Card>

布局模式

屏幕布局
const MyScreen = () => (
  <Screen>
    <ScreenHeader title="Page Title" />
    <ScreenContent padding="$4">
      {/* Content */}
    </ScreenContent>
  </Screen>
);
表单布局
<VStack gap="$4" padding="$4">
  <Input label="Name" {...nameProps} />
  <Input label="Email" {...emailProps} />
  <Button isLoading={loading}>Submit</Button>
</VStack>
列表项布局
<HStack
  padding="$4"
  gap="$3"
  alignItems="center"
  borderBottomWidth={1}
  borderColor="$borderLight"
>
  <Avatar source={{ uri: imageUrl }} size="md" />
  <VStack flex={1}>
    <Text fontWeight="$semibold">{title}</Text>
    <Text color="$textSecondary" fontSize="$sm">{subtitle}</Text>
  </VStack>
  <Icon name="chevron-right" color="$textTertiary" />
</HStack>

反模式

// WRONG - Hard-coded values
<View style={{ padding: 16, backgroundColor: '#fff' }}>

// CORRECT - Design tokens
<Box padding="$4" backgroundColor="$backgroundPrimary">


// WRONG - Raw platform components
import { View, Text } from 'react-native';

// CORRECT - Core components
import { Box, Text } from 'components/core';


// WRONG - Inline styles
<Text style={{ fontSize: 18, fontWeight: '600' }}>

// CORRECT - Token props
<Text fontSize="$lg" fontWeight="$semibold">

组件 Props 模式

创建组件时,请使用基于令牌的 props:

interface CardProps {
  padding?: '$2' | '$4' | '$6';
  variant?: 'elevated' | 'outlined' | 'filled';
  children: React.ReactNode;
}

const Card = ({ padding = '$4', variant = 'elevated', children }: CardProps) => (
  <Box
    padding={padding}
    backgroundColor="$backgroundPrimary"
    borderRadius="$lg"
    {...variantStyles[variant]}
  >
    {children}
  </Box>
);

与其他技能集成

  • react-ui-patterns:使用核心组件呈现 UI 状态
  • testing-patterns:在测试中模拟核心组件
  • storybook:记录组件变体

评论

支持 Markdown