core-components について
React UI 開発者向けのデザインシステム活用スキルです。レイアウト、テキスト、ボタン、入力欄、カードの基本コンポーネントと、デザイントークンによる一貫した実装を紹介します。
主な機能
- 01コア UI コンポーネントの利用
- 02間隔・色・文字のトークン適用
- 03レイアウトとフォームのパターン
- 04ボタンの種類とコンポーネント属性
活用シーン
- 01一貫した React UI の構築
- 02フォームやリストのレイアウト
- 03スタイル値の直書き回避
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ chriswiles/ claude-code-showcase --skill core-componentsインストール後、Claude Code で/core-componentsを入力して読み込まれたか確認します。
詳細
コアコンポーネント
デザインシステムの概要
プラットフォームの生のコンポーネントではなく、コアライブラリのコンポーネントを使用してください。これにより、スタイルと動作の一貫性が保たれます。
デザイントークン
値を直接ハードコードしないでください。必ずデザイントークンを使用してください。
スペーシングトークン
// CORRECT - Use tokens
<Box padding="$4" marginBottom="$2" />
// WRONG - Hard-coded values
<Box padding={16} marginBottom={8} />
| トークン | 値 |
|---|---|
$1 | 4px |
$2 | 8px |
$3 | 12px |
$4 | 16px |
$6 | 24px |
$8 | 32px |
カラートークン
// 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" />
| トークン | サイズ |
|---|---|
$xs | 12px |
$sm | 14px |
$md | 16px |
$lg | 18px |
$xl | 20px |
$2xl | 24px |
コアコンポーネント
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 対応