mcpskills.net
技能MCP智能体提示词
mcpskills.net — A curated directory of AI agent Skills and MCP servers
TermsPrivacy
← 返回技能
Development

Web 制品构建器

构建交互式 Web 制品和组件。当用户需要自包含的 HTML、React 组件或交互式 Web 元素时使用。

作者:Anthropic仓库 →来源 →

构建交互式 Web 制品和自包含组件。

制品类型

HTML 制品

自包含 HTML:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Artifact Title</title>
  <style>
    /* All styles inline */
  </style>
</head>
<body>
  <!-- Content -->
  <script>
    // All JavaScript inline
  </script>
</body>
</html>

React 组件

组件结构:

function MyComponent({ prop1, prop2 }) {
  const [state, setState] = useState(initialValue);
  
  return (
    <div className="container">
      {/* Component content */}
    </div>
  );
}

构建流程

1. 需求分析

定义制品:

  • 目的与功能
  • 目标受众
  • 技术要求
  • 设计约束

2. 设计规划

组件架构:

  • 视觉层次
  • 交互模式
  • 状态管理
  • 数据流

3. 实现

HTML 制品:

<!DOCTYPE html>
<html>
<head>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    body {
      font-family: system-ui, sans-serif;
      padding: 2rem;
    }
  </style>
</head>
<body>
  <div id="app"></div>
  <script>
    const app = document.getElementById('app');
    // Interactive logic
  </script>
</body>
</html>

React 制品:

function App() {
  const [count, setCount] = useState(0);
  
  return (
    <div>
      <h1>Counter: {count}</h1>
      <button onClick={() => setCount(count + 1)}>
        Increment
      </button>
    </div>
  );
}

4. 测试与优化

跨浏览器测试:

  • Chrome/Edge
  • Firefox
  • Safari
  • 移动端浏览器

性能优化:

  • 最小化 DOM 操作
  • 高效的事件处理
  • 适当时进行懒加载

常见制品模式

交互式仪表盘

<!DOCTYPE html>
<html>
<head>
  <style>
    .dashboard {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
      gap: 1rem;
    }
    .card {
      padding: 1.5rem;
      border: 1px solid #e5e5e5;
      border-radius: 0.5rem;
    }
  </style>
</head>
<body>
  <div class="dashboard" id="dashboard"></div>
  <script>
    // Dashboard logic
  </script>
</body>
</html>

表单组件

function Form() {
  const [formData, setFormData] = useState({
    name: '',
    email: ''
  });
  
  const handleSubmit = (e) => {
    e.preventDefault();
    console.log(formData);
  };
  
  return (
    <form onSubmit={handleSubmit}>
      <input
        type="text"
        value={formData.name}
        onChange={(e) => setFormData({...formData, name: e.target.value})}
        placeholder="Name"
      />
      <input
        type="email"
        value={formData.email}
        onChange={(e) => setFormData({...formData, email: e.target.value})}
        placeholder="Email"
      />
      <button type="submit">Submit</button>
    </form>
  );
}

最佳实践

  • 保持制品自包含
  • 使用语义化 HTML
  • 确保可访问性
  • 针对性能进行优化
  • 跨浏览器测试
  • 记录使用说明
  • 在需要时提供降级方案