frappe-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesefrappe-ui
frappe-ui
Build UIs that look and feel like Frappe products by composing frappe-ui components and styling with the library's semantic Tailwind tokens. Never hand-roll buttons, inputs, dialogs, dropdowns, etc. — pick the right component first.
通过组合frappe-ui组件并使用该库的语义化Tailwind令牌进行样式设置,构建外观和体验与Frappe产品一致的UI。切勿手动编写按钮、输入框、对话框、下拉菜单等组件——优先选择合适的组件。
Quick start
快速开始
vue
<script setup>
import { Button, Dialog, TextInput, FormControl } from 'frappe-ui'
import { ref } from 'vue'
const open = ref(false)
const name = ref('')
</script>
<template>
<div class="p-4 bg-surface-white text-ink-gray-9">
<Button variant="solid" theme="gray" @click="open = true">New Task</Button>
<Dialog v-model:open="open" title="Create Task">
<FormControl v-model="name" label="Title" required />
</Dialog>
</div>
</template>vue
<script setup>
import { Button, Dialog, TextInput, FormControl } from 'frappe-ui'
import { ref } from 'vue'
const open = ref(false)
const name = ref('')
</script>
<template>
<div class="p-4 bg-surface-white text-ink-gray-9">
<Button variant="solid" theme="gray" @click="open = true">New Task</Button>
<Dialog v-model:open="open" title="Create Task">
<FormControl v-model="name" label="Title" required />
</Dialog>
</div>
</template>Workflow
工作流程
- Pick the component, don't build one. Consult — if any entry fits, use it. Only fall back to raw HTML for layout (grids, flex containers).
COMPONENTS.md - Use semantic tokens, not raw colors. No ,
bg-gray-100,text-gray-900. Useborder-gray-300,bg-surface-*,text-ink-*. Seeborder-outline-*.TOKENS.md - Follow the two-axis color rule. Component color = (
variant) +solid | outline | subtle | ghost(theme). Never inventgray | blue | green | red | orange,intent,kind,severity.appearance - Wire two-way state with . Overlays use
v-model. Inputs usev-model:open. Comboboxes usev-model+v-model. Neverv-model:query+:value.@change - Use the labeling contract on inputs. Every input control accepts ,
label,description,error— use these instead of placeholder hacks or separaterequiredelements.<label> - Slot vocabulary is fixed. ,
#prefix,#suffix,#trigger,#empty,#header,#footer. Scoped per-item slots:#default,#item-prefix. No#item-suffix/#icon-left.#avatar-right - Icons are CSS classes. Render an icon as . For frappe-ui props that accept an icon (e.g.
<span class="lucide-<name> size-4" aria-hidden="true" />,Button.iconoptionDropdown), pass the namespaced stringicon. Never import per-icon Vue components."lucide-edit" - Imperative for one-shot UI. Use ,
dialog.confirm,dialog.alert,dialog.prompt— don't manually mounttoast.success/error/infofor confirmations.<Dialog> - API calls go through . Use the
useCallcomposable (oruseCall/useListfor higher-level shapes) for every Frappe API call. NeveruseDoc/fetchdirectly.axios+immediate: falsefor writes; default behavior auto-fetches on mount. Seesubmit(params)→ Data & resources.COMPONENTS.md
- 选择组件,而非手动构建。参考——如果有匹配的组件,就直接使用。仅在布局(网格、弹性容器)场景下才回退到原生HTML。
COMPONENTS.md - 使用语义化令牌,而非原始颜色。禁止使用、
bg-gray-100、text-gray-900这类原始颜色类,改用border-gray-300、bg-surface-*、text-ink-*。详见border-outline-*。TOKENS.md - 遵循双轴颜色规则。组件颜色由(
variant) +solid | outline | subtle | ghost(theme)决定。切勿自定义gray | blue | green | red | orange、intent、kind、severity这类属性。appearance - 使用实现双向状态绑定。弹窗组件使用
v-model,输入组件使用v-model:open,组合框使用v-model+v-model。禁止使用v-model:query+:value的组合方式。@change - 遵循输入组件的标签约定。所有输入控件都支持、
label、description、error属性——使用这些属性,而非占位符技巧或单独的required元素。<label> - 插槽命名固定。可用插槽包括、
#prefix、#suffix、#trigger、#empty、#header、#footer。针对列表项的作用域插槽:#default、#item-prefix。禁止使用#item-suffix/#icon-left这类自定义命名插槽。#avatar-right - 图标通过CSS类实现。使用渲染图标。对于frappe-ui中接受图标的属性(如
<span class="lucide-<name> size-4" aria-hidden="true" />、Button.icon选项的Dropdown),传入带命名空间的字符串icon。禁止导入单个图标的Vue组件。"lucide-edit" - 一次性UI使用命令式调用。使用、
dialog.confirm、dialog.alert、dialog.prompt——不要为了确认操作手动挂载toast.success/error/info组件。<Dialog> - API调用通过实现。所有Frappe API调用都使用
useCall组合式函数(或更高层级的useCall/useList)。禁止直接使用useDoc/fetch。写入操作使用axios+immediate: false;默认行为会在组件挂载时自动获取数据。详见submit(params)→ 数据与资源部分。COMPONENTS.md
Reference files
参考文档
- SETUP.md — scaffolding a fresh Vite + Vue 3 + frappe-ui project: version pinning, , Tailwind, PostCSS, CSS entry, plugin vs provider. Read this first when bootstrapping from scratch.
vite.config.js - COMPONENTS.md — component catalog: when to reach for each one, key props, common pitfalls.
- TOKENS.md — semantic color tokens (,
ink-*,surface-*), typography, spacing, radii.outline-* - PATTERNS.md — recipes: form pages, list pages, settings panels, empty states, confirmation flows.
- SETUP.md —— 搭建全新的Vite + Vue 3 + frappe-ui项目:版本锁定、配置、Tailwind、PostCSS、CSS入口、插件与提供者。从零开始搭建项目时请先阅读此文档。
vite.config.js - COMPONENTS.md —— 组件目录:各组件的适用场景、关键属性、常见陷阱。
- TOKENS.md —— 语义化颜色令牌(、
ink-*、surface-*)、排版、间距、圆角。outline-* - PATTERNS.md —— 实现方案:表单页面、列表页面、设置面板、空状态、确认流程。
Authoritative upstream docs
官方上游文档
When the bundled refs don't answer a specific API question, fetch the official LLM-friendly index:
- https://ui.frappe.io/llms.txt — curated index of every component doc, design-system tokens page, and data-fetching guide. Always current with the published library; follow the links inside for full details on a specific component.
Prefer the upstream over guessing — it lists every component's docs page and the canonical design-system / data-fetching pages.
llms.txt如果本地参考文档无法解答特定API问题,请查阅官方LLM友好型索引:
- https://ui.frappe.io/llms.txt —— 整理了所有组件文档、设计系统令牌页面和数据获取指南的索引。始终与已发布的库保持同步;如需了解特定组件的详细信息,请点击索引内的链接。
优先参考上游的,而非自行猜测——它列出了每个组件的文档页面以及规范的设计系统/数据获取页面。
llms.txtAnti-patterns to flag
需要规避的反模式
- Scaffolding a fresh project with and using whatever versions it gives you — current defaults (Vite 8 + Tailwind v4) are incompatible with frappe-ui 0.1.x. See SETUP.md.
npm create vite - Importing or
'frappe-ui/tailwind/preset'— these paths are not in the package's'frappe-ui/src/style.css'map. Useexportsand'frappe-ui/tailwind'.'frappe-ui/style.css' - Omitting — esbuild's prebundler will choke on the package's
optimizeDeps.exclude: ['frappe-ui']virtual imports before any Vite plugin runs.~icons/lucide/* - Forgetting because you only saw
app.use(FrappeUI)mentioned — both are required. Plugin handles app-level injections; provider mounts the imperative dialog/toast portals.<FrappeUIProvider> - Skipping for single-page prototypes —
vue-routerinjects<Button>and warns on every render without it.Symbol(router) - Hand-rolled instead of
<button class="bg-blue-500 ...">.<Button> - Raw Tailwind palette colors (,
gray-) outside the semantic tokens.blue- - /
intent="warning"/appearance="primary"props — collapse tokind="success"+variant.theme - Class-injection props (,
triggerClass). Use the component'scontentClass/data-slotattributes from CSS instead.data-state - Manually mounting just to ask "are you sure?" — use
<Dialog>.dialog.confirm - Bare on
v-modelfor visibility — use<Dialog>.v-model:open - Placeholder-as-label on /
TextInput/Select— passDatePicker.label - Raw /
fetchfor API calls — useaxios(oruseCall/useList).useDoc - /
createResource/createListResourcein new code — those are legacy v1 APIs; the v3 composables (createDocumentResource,useCall,useList) are the recommended path.useDoc
When in doubt about an API, start at https://ui.frappe.io/llms.txt and follow the link for the component or topic in question. Source lives in the GitHub repo (, plus and at the repo root).
frappe/frappe-uisrc/components/<Name>/PHILOSOPHY.mdCONTEXT.md- 使用搭建新项目并采用默认版本——当前默认版本(Vite 8 + Tailwind v4)与frappe-ui 0.1.x不兼容。详见SETUP.md。
npm create vite - 导入或
'frappe-ui/tailwind/preset'——这些路径不在包的'frappe-ui/src/style.css'映射中。请使用exports和'frappe-ui/tailwind'。'frappe-ui/style.css' - 省略——esbuild预打包器会在Vite插件运行前,因包内的
optimizeDeps.exclude: ['frappe-ui']虚拟导入而报错。~icons/lucide/* - 因只看到的说明而忘记
<FrappeUIProvider>——两者都是必需的。插件负责应用级别的注入;提供者负责挂载命令式对话框/提示框的入口。app.use(FrappeUI) - 单页原型不使用——
vue-router会注入<Button>,如果没有则会在每次渲染时发出警告。Symbol(router) - 手动编写而非使用
<button class="bg-blue-500 ...">组件。<Button> - 在语义化令牌之外使用原始Tailwind调色板颜色(、
gray-)。blue- - 使用/
intent="warning"/appearance="primary"这类属性——应简化为kind="success"+variant。theme - 使用类注入属性(、
triggerClass)。改用CSS中组件的contentClass/data-slot属性。data-state - 仅为了询问“确定吗?”而手动挂载——使用
<Dialog>即可。dialog.confirm - 在上使用裸
<Dialog>控制可见性——应使用v-model。v-model:open - 在/
TextInput/Select上用占位符代替标签——传入DatePicker属性。label - 使用原生/
fetch进行API调用——使用axios(或useCall/useList)。useDoc - 在新代码中使用/
createResource/createListResource——这些是旧版v1 API;推荐使用v3组合式函数(createDocumentResource、useCall、useList)。useDoc
如果对API有疑问,请从https://ui.frappe.io/llms.txt开始,点击对应组件或主题的链接。源代码位于`frappe/frappe-ui` GitHub仓库(,以及仓库根目录的和)。
src/components/<Name>/PHILOSOPHY.mdCONTEXT.md