### Start the development server Source: https://github.com/frappe/frappe-ui/blob/main/docs/content/docs/getting-started.md Installs dependencies and launches the Vite development server. ```sh cd frontend yarn yarn dev ``` -------------------------------- ### Quick Start Example Source: https://github.com/frappe/frappe-ui/blob/main/skills/frappe-ui/SKILL.md Demonstrates basic usage of frappe-ui components like Button, Dialog, and FormControl with Vue 3's Composition API. Use this to scaffold new pages, forms, or dialogs. ```vue ``` -------------------------------- ### Install Frappe UI Source: https://github.com/frappe/frappe-ui/blob/main/readme.md Install Frappe UI using npm or yarn. ```sh npm install frappe-ui # or yarn add frappe-ui ``` -------------------------------- ### Autocomplete Component Setup Source: https://github.com/frappe/frappe-ui/blob/main/src/components/Autocomplete/Autocomplete.api.md This snippet shows the basic setup for the Autocomplete component, importing necessary table components for displaying props, slots, and emits. ```vue ``` -------------------------------- ### Default Tooltip Example Source: https://github.com/frappe/frappe-ui/blob/main/src/components/Tooltip/Tooltip.md Demonstrates the basic usage of the Tooltip component. ```javascript import { Tooltip } from "frappe-ui"; export default function App() { return ( ); } ``` -------------------------------- ### Install Dependencies for Frappe UI Source: https://github.com/frappe/frappe-ui/blob/main/skills/frappe-ui/SETUP.md Installs specific versions of Vite, Tailwind CSS, and other necessary packages compatible with frappe-ui 0.1.x. This command replaces the default installations from `npm create vite@latest`. ```bash npm uninstall tailwindcss @tailwindcss/vite vite @vitejs/plugin-vue npm install -D \ tailwindcss@^3.4 postcss autoprefixer \ vite@^5 @vitejs/plugin-vue@^5 \ vue-router@^4 \ unplugin-auto-import unplugin-vue-components unplugin-icons \ lucide-static @iconify/json npm install frappe-ui@beta ``` -------------------------------- ### Divider Examples Source: https://github.com/frappe/frappe-ui/blob/main/src/components/Divider/Divider.md Demonstrates basic usage of the Divider component for visual separation. ```html ``` -------------------------------- ### Creating and Fetching a Resource Source: https://github.com/frappe/frappe-ui/blob/main/docs/content/docs/data-fetching/resource.md This example demonstrates how to create a resource to fetch a list of 'ToDo' items from the Frappe backend and manually trigger the fetch operation. ```APIDOC ## Creating and Fetching a Resource ### Description This example shows how to initialize a resource to fetch a list of 'ToDo' items from the Frappe backend. It includes setting the URL, parameters, and then explicitly calling the `fetch` method to initiate the data retrieval. ### Method `createResource(options)` ### Parameters - **options** (object) - **url** (string) - Required - The endpoint URL to fetch data from. - **params** (object) - Optional - Parameters to send with the request. - **doctype** (string) - Required - The doctype to query. - **filters** (object) - Optional - Filters to apply to the query. - **allocated_to** (string) - Example filter. ### Request Example ```javascript import { createResource } from 'frappe-ui' let todos = createResource({ url: '/api/method/frappe.client.get_list', params: { doctype: 'ToDo', filters: { allocated_to: 'faris@example.com', }, }, }) todos.fetch() ``` ### Response - **todos.data**: Will contain the fetched list of ToDos. - **todos.loading**: Will be true during the fetch operation. - **todos.error**: Will contain any errors encountered. ``` -------------------------------- ### Basic Data Fetching Example Source: https://github.com/frappe/frappe-ui/blob/main/docs/content/docs/data-fetching/resource.md Demonstrates traditional manual handling of async data fetching, including loading and error states. ```js let data, loading, error try { data = await fetch('https://jsonplaceholder.typicode.com/posts/1') } catch (e) { error = e } // rest of your code ``` -------------------------------- ### App Setup with FrappeUIProvider Source: https://github.com/frappe/frappe-ui/blob/main/spec/dialog.md Wrap your application with FrappeUIProvider to enable the imperative dialog API. This component also hosts the toast viewport. ```vue ``` -------------------------------- ### Import Lucide Icons in Script Setup Source: https://github.com/frappe/frappe-ui/blob/main/vite/README.md Import Lucide icons explicitly for use within ` ``` -------------------------------- ### Configuring Frappe Request Fetcher Source: https://github.com/frappe/frappe-ui/blob/main/docs/content/docs/data-fetching/resource.md This example shows how to configure Frappe UI to use `frappeRequest` for resources, which automatically handles Frappe's response format for data and errors. ```APIDOC ## Configuring Frappe Request Fetcher ### Description By default, resources use a generic `request` function. This example demonstrates how to configure `frappe-ui` to use `frappeRequest` instead. This specialized fetcher understands Frappe's standard response structure, automatically extracting data from the `message` key and errors from the `exc` key, and simplifies the URL by removing the `/api/method` prefix. ### Method `setConfig(key, value)` ### Parameters - **key** (string): The configuration key, set to `'resourceFetcher'`. - **value** (function): The fetcher function to use, typically `frappeRequest`. ### Usage Example **main.js** ```javascript import { setConfig, frappeRequest } from 'frappe-ui' setConfig('resourceFetcher', frappeRequest) ``` **Component Usage After Configuration** When `resourceFetcher` is set to `frappeRequest`, the resource initialization simplifies: ```vue ``` ### Response Handling with `frappeRequest` - **Data Extraction**: The `data` property of the resource will be populated from the `message` field of the Frappe response. - **Error Extraction**: The `error` property of the resource will be populated from the `exc` field of the Frappe response. ``` -------------------------------- ### Consumer Text Editor Implementation Source: https://github.com/frappe/frappe-ui/blob/main/v1-release/research/11-texteditor-usage-audit.md Example of how a consumer would use the headless primitives to build a text editor. All dependencies and configurations are explicitly imported and passed. ```vue ``` -------------------------------- ### Rating Component Labeling Example Source: https://github.com/frappe/frappe-ui/blob/main/src/components/Rating/Rating.md Demonstrates how to associate labels with the Rating component for improved accessibility and user experience. ```vue ``` -------------------------------- ### Importing Toast API and Provider Source: https://github.com/frappe/frappe-ui/blob/main/v1-release/11-toast-spec.md Import the imperative `toast` API and the `ToastProvider` component from `frappe-ui`. The `FrappeUIProvider` is also available for a one-stop setup. ```typescript // Imperative API — sonner's `toast`, re-exported as-is. import { toast } from 'frappe-ui' // Viewport — our styled wrapper around sonner's ``, with the // frappe-ui defaults baked in. Raw `` is intentionally *not* // re-exported; consumers either mount `` or // `` directly. import { ToastProvider } from 'frappe-ui' // One-stop provider — mounts with our defaults next to . import { FrappeUIProvider } from 'frappe-ui' // Vestigial back-compat export. Not documented; not promoted. // Kept so that any code still importing `{ Toast }` keeps compiling. import { Toast } from 'frappe-ui' ``` -------------------------------- ### Install Frappe UI Claude Code Skill Source: https://github.com/frappe/frappe-ui/blob/main/readme.md Add the Frappe UI agent skill using Vercel's skills CLI for AI coding agents. ```sh npx skills add https://github.com/frappe/frappe-ui/tree/main/skills/frappe-ui ``` -------------------------------- ### Dropdown Migration Example: Old to New Source: https://github.com/frappe/frappe-ui/blob/main/v1-release/08b-dropdown-spec.md Illustrates the migration from an older Dropdown template structure to the new recommended structure, focusing on how item rendering and conditional display of elements like checkmarks are handled. ```vue ``` ```vue ``` -------------------------------- ### Example: Grouped Options Data Structure Source: https://github.com/frappe/frappe-ui/blob/main/spec/multiselect.md Demonstrates the data structure for using grouped options in the MultiSelect component. Options are organized under 'group' keys. ```typescript const options = [ { group: 'Active', options: [ { label: 'Alpha', value: 'alpha' }, { label: 'Beta', value: 'beta' }, ], }, { group: 'Archived', options: [{ label: 'Gamma', value: 'gamma' }], }, ] ``` -------------------------------- ### List Resource Initialization and Properties Source: https://github.com/frappe/frappe-ui/blob/main/docs/content/docs/data-fetching/list-resource.md Initialize a list resource and access its core properties for data and state management. Use this to get the fetched data, original response, or trigger a reload and pagination. ```javascript let todos = createListResource({...}) todos.data // data returned from request todos.originalData // response data before being transformed todos.reload() // reload the existing list todos.next() // fetch the next page todos.hasNextPage // whether there is next page to fetch ``` -------------------------------- ### Initialize frappe-ui Source: https://github.com/frappe/frappe-ui/blob/main/docs/content/docs/getting-started.md Sets up a Vue project with frappe-ui inside the frontend directory. ```sh cd apps/todo # this will setup a vue project with frappe-ui set up # inside the frontend directory npx degit netchampfaris/frappe-ui-starter frontend ``` -------------------------------- ### Legacy Input Component Usage Examples Source: https://github.com/frappe/frappe-ui/blob/main/v1-release/research/09-input-components-usage-audit.md Examples of how the legacy Input.vue component is used with different types. These are candidates for migration to FormControl. ```vue ``` ```vue ``` ```vue ``` ```vue ``` -------------------------------- ### Create a new Frappe app Source: https://github.com/frappe/frappe-ui/blob/main/docs/content/docs/getting-started.md Initializes a new Frappe application using the bench CLI. ```sh bench new-app todo ``` -------------------------------- ### Vue App Entry Point with Frappe UI Plugin Source: https://github.com/frappe/frappe-ui/blob/main/skills/frappe-ui/SETUP.md Sets up the Vue application, registers the router, imports global styles, and uses the FrappeUI plugin. ```javascript import { createApp } from 'vue' import { FrappeUI } from 'frappe-ui' import { router } from './router' import './style.css' import App from './App.vue' const app = createApp(App) app.use(router) // required — frappe-ui's ``` ```vue ``` -------------------------------- ### Old Select Component Customization Source: https://github.com/frappe/frappe-ui/blob/main/v1-release/08c-select-spec.md Example of customizing the Select component using the #option slot in older versions. ```vue ``` -------------------------------- ### Fetch and display data with createResource Source: https://github.com/frappe/frappe-ui/blob/main/docs/content/docs/introduction.md Demonstrates using createResource to fetch a list of ToDo items and rendering them with Frappe UI components. ```vue ``` -------------------------------- ### Rating Component States Example Source: https://github.com/frappe/frappe-ui/blob/main/src/components/Rating/Rating.md Illustrates different visual states of the Rating component, such as valid, invalid, and disabled. ```vue ``` -------------------------------- ### MultiSelect Example Source: https://github.com/frappe/frappe-ui/blob/main/src/components/MultiSelect/MultiSelect.md A basic MultiSelect component with a button trigger, search input, option list, and default footer. ```vue ``` -------------------------------- ### Configuring Frappe Request Fetcher Source: https://github.com/frappe/frappe-ui/blob/main/docs/content/docs/data-fetching/resource.md Demonstrates how to configure Frappe UI to use `frappeRequest` for resource fetching, which simplifies handling Frappe backend responses. ```javascript import { setConfig, frappeRequest } from 'frappe-ui' setConfig('resourceFetcher', frappeRequest) ``` -------------------------------- ### Basic App Shell Structure Source: https://github.com/frappe/frappe-ui/blob/main/skills/frappe-ui/PATTERNS.md Sets up the fundamental application shell using FrappeUIProvider, a Sidebar, and a main content area with routing. Ensures imperative UI components like dialogs and toasts function correctly. ```vue ``` -------------------------------- ### New Select Component Customization Source: https://github.com/frappe/frappe-ui/blob/main/v1-release/08c-select-spec.md Example of customizing the Select component using #item-prefix and #item-label slots in newer versions. ```vue ``` -------------------------------- ### Create a Custom Quote Button Source: https://github.com/frappe/frappe-ui/blob/main/spec/editor.md Example of creating a custom menu item for toggling blockquotes, including icon and action. ```typescript const QuoteButton: CommandMenuItem = { icon: LucideQuote, label: 'Quote', action: (e) => e.chain().focus().toggleBlockquote().run(), isActive: (e) => e.isActive('blockquote'), } ``` -------------------------------- ### Required Indicator Rendering Example Source: https://github.com/frappe/frappe-ui/blob/main/spec/inputs.md Illustrates the canonical implementation for rendering a required indicator using FormLabel's pattern. ```html ``` -------------------------------- ### Configure Frappe UI Build Settings Source: https://github.com/frappe/frappe-ui/blob/main/vite/README.md Defines the build output paths and asset serving URLs for the Frappe environment. ```javascript frappeui({ buildConfig: { outDir: '../app_name/public/frontend', baseUrl: '/assets/app_name/frontend/', indexHtmlPath: '../app_name/www/app_name.html', emptyOutDir: true, sourcemap: true, }, }) ``` -------------------------------- ### Resource Options Configuration Source: https://github.com/frappe/frappe-ui/blob/main/docs/content/docs/data-fetching/resource.md Illustrates various configuration options for `createResource`, including URL formats, HTTP methods, parameters, debouncing, initial data, automatic fetching, caching strategies, and event hooks. ```js let post = createResource({ // partial rest api routes url: '/api/posts/1' // or full urls url: 'https://jsonplaceholder.typicode.com/posts/1', // http method: GET, POST, PUT, DELETE method: 'GET', // parameters params: { id: 1 }, // generate params from function makeParams() { return { id: 1 } }, // debounce request every 500ms debounce: 500, // initial data initialData: [] // make the first request automatically auto: true, // cache key to cache the resource // can be a string cache: 'post', // or an array that can be serialized cache: ['post', '1'], // you can also pass reactive variable here cache: ['post', postId] // events // before making the request beforeSubmit(params) { }, // validate parameters before making request validate(params) { if (!params.id) { // return a string message to throw an error return 'id is required' } }, // error can occur from failed request and validate function onError(error) { }, // on successful response onSuccess(data) { }, // transform data before setting it transform(data) { for (let d of data) { d.open = false } return data }, }) ``` -------------------------------- ### Icon Customization Examples (Vue) Source: https://github.com/frappe/frappe-ui/blob/main/PHILOSOPHY.md Illustrates correct and incorrect ways to customize icons in Vue components. Demonstrates string-based icon names, component fallbacks, and the use of generic slots versus component-specific props. ```Vue