跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
开发与测试

webflow-code-component:convert-component

Convert an existing React component into a Webflow Code Component. Analyzes TypeScript props, maps to Webflow prop types, generates the .webflow.tsx definition file, and identifies required modifications.

webflow · 已有 AI 审核记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add webflow/webflow-skills --skill webflow-code-component:convert-component

技能说明


name: webflow-code-component:convert-component description: Convert an existing React component into a Webflow Code Component. Analyzes TypeScript props, maps to Webflow prop types, generates the .webflow.tsx definition file, and identifies required modifications. compatibility: Node.js 18+, React 18+, TypeScript, @webflow/webflow-cli metadata: author: webflow version: "1.0"

Convert Component

Convert an existing React component into a Webflow Code Component by analyzing its structure and generating the appropriate .webflow.tsx definition file.

When to Use This Skill

Use when:

  • User has an existing React component they want to use in Webflow
  • User asks to "convert", "adapt", or "make this work with Webflow"
  • User provides a React component file and wants a Webflow definition
  • User is migrating components from another React project

Do NOT use when:

  • Creating a component from scratch (use component-scaffold)
  • User just wants to understand code components (answer directly)
  • Component is already a Webflow code component (use component-audit)

Instructions

Phase 1: Analyze Existing Component

  1. Read the React component file: Get the full source code

  2. Extract component information:

    • Component name (function/const name)
    • Props interface or type definition
    • Each prop's TypeScript type
    • Default values if defined
    • Whether component uses children
  3. Identify incompatible patterns:

    PatternIssueResolution
    React Context usageContext doesn't work across Webflow componentsRefactor to props or use nano stores
    window/document in renderSSR will failWrap in useEffect or set ssr: false
    localStorage/sessionStorage in renderSSR will failWrap in useEffect or set ssr: false
    Complex object propsCan't map to Webflow prop typesBreak into individual props
    Function props (callbacks)Not supported in WebflowRemove or internalize logic
    useContext hookWon't work across componentsUse alternative state patterns
    External CSS importsMay not work in Shadow DOMImport in .webflow.tsx instead
    CSS class references to global stylesWon't work in Shadow DOMUse component-scoped styles
    styled-componentsNeeds Shadow DOM decoratorSet up globals.ts with decorator
    Emotion (@emotion/styled)Needs Shadow DOM decoratorSet up globals.ts with decorator
  4. Detect styling approach and note required setup:

    If using styled-components:

    npm i @webflow/styled-components-utils styled-components
    

    Create/update globals.ts:

    import { styledComponentsShadowDomDecorator } from "@webflow/styled-components-utils";
    export const decorators = [styledComponentsShadowDomDecorator];
    

    If using Emotion:

    npm i @webflow/emotion-utils @emotion/cache @emotion/react
    

    Create/update globals.ts:

    import { emotionShadowDomDecorator } from "@webflow/emotion-utils";
    export const decorators = [emotionShadowDomDecorator];
    

    For both CSS-in-JS approaches, update webflow.json:

    styled-components:

    {
      "library": {
        "globals": "./src/globals.ts",
        "renderer": {
          "server": "@webflow/styled-components-utils/server"
        }
      }
    }
    

    Emotion:

    {
      "library": {
        "globals": "./src/globals.ts",
        "renderer": {
          "server": "@webflow/emotion-utils/server"
        }
      }
    }
    
  5. Flag any dependencies that might cause issues:

    • Large libraries (bundle size concern)
    • Browser-only libraries
    • Libraries that manipulate DOM directly

Phase 2: Map Props to Webflow Types

  1. Apply TypeScript → Webflow prop type mapping:

    TypeScript TypeWebflow PropNotes
    stringprops.Text()Default for short text
    string (long/HTML content)props.RichText()If prop name suggests content/body/description
    React.ReactNode / childrenprops.Slot()For nested content
    numberprops.Number()Numeric values
    booleanprops.Boolean()Toggles
    "option1" | "option2"props.Variant()String literal unions (requires options array)
    enumprops.Variant()Convert enum values to options array (required)
    { href: string; ... }props.Link()Returns { href, target?, preload? } object — may need wrapper if component expects separate href/target props
    Image-related typesprops.Image()Image src, url, etc.
    string (canvas-editable text)props.TextNode()For text editable directly on canvas; has multiline param
    boolean (show/hide)props.Visibility()Semantic show/hide toggle
    string (for HTML id)props.Id()If prop is named "id" or used for accessibility
    Complex objectsSPLITBreak into multiple simple props
    Functions/callbacksREMOVENot supported
    ArraysSPECIALMay need component redesign
  2. Handle special cases:

    Complex object props - Break them down:

    // Original
    interface Props {
      author: {
        name: string;
        avatar: string;
        bio: string;
      }
    }
    
    // Converted to flat props
    props: {
      authorName: props.Text({ name: "Author Name" }),
      authorAvatar: props.Image({ name: "Author Avatar" }),
      authorBio: props.RichText({ name: "Author Bio" })
    }
    

    Union types with more than simple strings:

    // Original - complex union
    type Size = "sm" | "md" | "lg" | { width: number; height: number };
    
    // Convert to Variant with only string options
    size: props.Variant({
      name: "Size",
      options: ["sm", "md", "lg", "custom"],
     
    
阅读完整来源 ↗