Skip to main content

component-architecture

Component design patterns including composition, render props, compound components, and design systems. Use for reusable component architecture. Use when this capability is needed.

跳到安装

来源信息

仓库
tomevault-io/skills-registry
最近来源活动
2026年4月28日 22:53
检测到的 SKILL.md 语言
英语
星标
0
分支
0

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

文件资源管理器
2 个文件

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
component-architecture
description
Component design patterns including composition, render props, compound components, and design systems. Use for reusable component architecture. Use when this capability is needed.
metadata
{"author":"ak-eyther"}
# Component Architecture Patterns ## Composition Pattern ```typescript function Card({ children }) { return <div className="card">{children}</div> } function CardHeader({ children }) { return <div className="card-header">{children}</div> } function CardBody({ children }) { return <div className="card-body">{children}</div> } // Usage <Card> <CardHeader>Title</CardHeader> <CardBody>Content</CardBody> </Card> ``` ## Compound Components ```typescript const Tabs = ({ children }) => { const [activeTab, setActiveTab] = useState(0) return ( <TabsContext.Provider value={{ activeTab, setActiveTab }}> {children} </TabsContext.Provider> ) } Tabs.List = ({ children }) => <div className="tabs-list">{children}</div> Tabs.Tab = ({ index, children }) => { const { activeTab, setActiveTab } = useTabsContext() return ( <button className={activeTab === index ? 'active' : ''} onClick={() => setActiveTab(index)} > {children} </button> ) } Tabs.Panel = ({ index, children }) => { const { activeTab } = useTabsContext() return activeTab === index ? <div>{children}</div> : null } // Usage <Tabs> <Tabs.List> <Tabs.Tab index={0}>Tab 1</Tabs.Tab> <Tabs.Tab index={1}>Tab 2</Tabs.Tab> </Tabs.List> <Tabs.Panel index={0}>Content 1</Tabs.Panel> <Tabs.Panel index={1}>Content 2</Tabs.Panel> </Tabs> ``` ## Render Props ```typescript function DataFetcher({ url, render }) { const [data, setData] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { fetch(url) .then(res => res.json()) .then(data => { setData(data) setLoading(false) }) }, [url]) return render({ data, loading }) } // Usage <DataFetcher url="/api/users" render={({ data, loading }) => loading ? <div>Loading...</div> : <UserList users={data} /> } /> ``` ## Headless Components ```typescript function useDropdown() { const [isOpen, setIsOpen] = useState(false) const toggle = () => setIsOpen(!isOpen) const close = () => setIsOpen(false) return { isOpen, toggle, close } } // Usage - completely custom UI function MyDropdown() { const { isOpen, toggle, close } = useDropdown() return ( <div> <button onClick={toggle}>Toggle</button> {isOpen && ( <div onClick={close}> Custom dropdown content </div> )} </div> ) } ``` --- > Converted and distributed by [TomeVault](https://tomevault.io/claim/ak-eyther) — claim your Tome and manage your conversions. <!-- tomevault:4.0:skill_md:2026-04-14 -->
在 GitHub 查看