AgentSkillsCN

chi-recommendations

根据项目背景,推荐最合适的 Chi 实现方案。当用户询问应采用哪种 Chi 实现方式(Vue、Web Components,还是 HTML/CSS),或在启动新项目时引入 Chi,又或是需要在不同实现方案之间进行迁移时,可选用此功能。本功能提供针对各框架的具体指导,并附上代码示例。

SKILL.md
--- frontmatter
name: chi-recommendations
description: Recommend the best Chi implementation approach based on project context. Use when the user asks which Chi approach to use (Vue, Web Components, or HTML/CSS), when starting a new project with Chi, or when migrating between approaches. Provides framework-specific guidance and code examples.

Chi Implementation Recommendations

Decision Tree

Use this decision tree to recommend the best approach:

Step 1: Check Framework

FrameworkRecommended ApproachReasoning
Vue 3chi-vueFull Vue reactivity, composition API, TypeScript support
ReactCustom ElementsWorks with React; note: use ref callbacks for event listeners since React synthetic events don't fire on CEs
AngularCustom ElementsExcellent support via CUSTOM_ELEMENTS_SCHEMA in module declarations
SvelteCustom ElementsSeamless Custom Elements support
Vanilla JSCustom ElementsBest DX, no framework overhead
UnknownCustom ElementsSafe default for any framework

Step 2: Check Constraints

ConstraintOverride ToReasoning
Legacy browser support (IE11)HTML/CSSCustom Elements need polyfills
User explicitly wants CSSHTML/CSSRespect explicit preference
User wants Web ComponentsCustom ElementsRespect explicit preference
Static HTML site (no JS)HTML/CSSNo JS runtime needed
SSR without hydrationHTML/CSSCustom Elements need JS to initialize

Step 3: Determine Confidence

ScenarioConfidence
Framework detected + no conflictsHigh
Existing code matches recommendationHigh
No framework info, using defaultLow
Existing code uses different approachMedium (suggest gradual migration)

Code Examples

Vue Approach

html
<script setup>
import { ChiButton } from '@aspect/chi-vue';
</script>
<template>
  <ChiButton color="primary" size="lg" @click="handleClick">Click me</ChiButton>
</template>

Custom Elements Approach

html
<chi-button color="primary" size="lg">Click me</chi-button>
<script>
  document.querySelector('chi-button').addEventListener('chiClick', handleClick);
</script>

HTML/CSS Approach

html
<button class="chi-button -primary -lg" type="button" onclick="handleClick()">Click me</button>

Note: Requires manual event handling, ARIA attributes, and keyboard support.

Approach Detection

To detect which approach existing code uses:

PatternApproach
<Chi[A-Z] (PascalCase tags)Vue
<chi- (kebab-case custom elements)Custom Elements
class="chi- (CSS classes on native elements)HTML/CSS

Count occurrences of each pattern. The most frequent one is the existing approach.

Edge case: <chi-icon> inside a <button class="chi-button"> is mixed usage -- recommend migrating the button to <chi-button> too.

Migration Paths

HTML/CSS → Custom Elements

  1. Replace CSS base classes with Web Component tags: <button class="chi-button"><chi-button>
  2. Convert CSS modifiers to properties: -primarycolor="primary"
  3. Convert boolean modifiers to attributes: -disableddisabled
  4. Keep utility classes for spacing: class="-p--4" stays
  5. Remove manual ARIA -- Web Components handle it automatically

HTML/CSS → Vue

  1. Install @aspect/chi-vue package
  2. Import components: import { ChiButton } from '@aspect/chi-vue'
  3. Replace HTML with Vue component syntax
  4. Use v-bind for dynamic props, v-on for events

Custom Elements → Vue

  1. Replace <chi-*> tags with <Chi*> components
  2. Convert attributes to Vue props syntax
  3. Migrate events from addEventListener to v-on

Vue → Custom Elements

  1. Replace <Chi*> with <chi-*> Web Components
  2. Convert Vue props to attributes
  3. Replace v-on events with addEventListener
  4. Handle reactivity manually if needed

Priority Order

  1. chi-vue (priority 1) -- Vue 3 components for Vue projects
  2. chi-web-components (priority 2) -- Custom Elements for any framework
  3. chi-html-css (priority 3) -- CSS classes for static HTML or legacy support