From 90891cd568b3137558598884254dbdf2197a36ee Mon Sep 17 00:00:00 2001 From: Justineo Date: Fri, 5 Sep 2025 13:19:59 +0800 Subject: [PATCH] feat(controls): add slot props, add `control-item` slot for controls --- docs/src/guide/components/controls.md | 67 ++++++++--- examples/vite/router.ts | 4 + examples/vite/src/Controls/ControlsSlot.vue | 69 +++++++++++ packages/controls/README.md | 1 - packages/controls/package.json | 20 +-- packages/controls/src/Controls.vue | 127 +++++++++++++++----- packages/controls/src/svg.d.ts | 8 ++ packages/controls/src/types.ts | 43 +++++++ packages/controls/tsconfig.json | 11 +- 9 files changed, 282 insertions(+), 68 deletions(-) create mode 100644 examples/vite/src/Controls/ControlsSlot.vue create mode 100644 packages/controls/src/svg.d.ts diff --git a/docs/src/guide/components/controls.md b/docs/src/guide/components/controls.md index 80ecafb36..e53b37f19 100644 --- a/docs/src/guide/components/controls.md +++ b/docs/src/guide/components/controls.md @@ -35,15 +35,51 @@ import '@vue-flow/controls/dist/style.css' ``` +You can also customize the controls by using the provided slots and slot props. + +```vue + + + +``` ## [Props](/typedocs/interfaces/ControlProps) -| Name | Definition | Type | Optional | Default | -|-----------------|----------------------------------------|------------------------------------------------|----------|---------| -| showZoom | Show zoom btn | boolean | true | true | -| showFitView | Show fit-view btn | boolean | true | true | -| showInteractive | Show lock interactive btn | boolean | true | true | -| showZoom | Show zoom button | boolean | true | true | +| Name | Definition | Type | Optional | Default | +|-----------------|----------------------------------------|-------------------------------------------------------|----------|---------| +| showZoom | Show zoom btn | boolean | true | true | +| showFitView | Show fit-view btn | boolean | true | true | +| showInteractive | Show lock interactive btn | boolean | true | true | +| showZoom | Show zoom button | boolean | true | true | | fitViewParams | Params to use on fit-view button click | [FitViewParams](/typedocs/type-aliases/FitViewParams) | true | - | ## Emits @@ -59,14 +95,15 @@ import '@vue-flow/controls/dist/style.css' ### Control Buttons -| Name | Definition | -|---------------------|----------------------------| -| top | Slot above default buttons | -| control-zoom-in | Zoom-in btn | -| control-zoom-out | Zoom-out btn | -| control-fit-view | Fit-view btn | -| control-interactive | Interaction btn | -| default | Slot below default buttons | +| Name | Definition | Props | +|---------------------|----------------------------|----------------------------------------------------------------------------------------------------------------------| +| top | Slot above default buttons | [ControlsSlotProps](/typedocs/interfaces/ControlsSlotProps) | +| control-item | Each control btn | [ControlItemSlotProps](/typedocs/interfaces/ControlItemSlotProps) | +| control-zoom-in | Zoom-in btn | { disabled: boolean; zoomIn: () \=> any; icon: Component } | +| control-zoom-out | Zoom-out btn | { disabled: boolean; zoomOut: () \=> any; icon: Component } | +| control-fit-view | Fit-view btn | { fitView: () \=> any; icon: Component } | +| control-interactive | Interaction btn | { interactive: boolean; toggleInteractive: () \=> any; icon: Component; lockIcon: Component; unlockIcon: Component } | +| default | Slot below default buttons | [ControlsSlotProps](/typedocs/interfaces/ControlsSlotProps) | ### Icons @@ -77,5 +114,3 @@ import '@vue-flow/controls/dist/style.css' | icon-fit-view | Fit-view icon | | icon-lock | Interaction locked icon | | icon-unlock | Interaction unlocked icon | - - diff --git a/examples/vite/router.ts b/examples/vite/router.ts index a1f4180b3..20c680b58 100644 --- a/examples/vite/router.ts +++ b/examples/vite/router.ts @@ -138,6 +138,10 @@ export const routes: RouterOptions['routes'] = [ path: '/confirm-delete', component: () => import('./src/ConfirmDelete/ConfirmDeleteExample.vue'), }, + { + path: '/controls-slot', + component: () => import('./src/Controls/ControlsSlot.vue'), + }, ] export const router = createRouter({ diff --git a/examples/vite/src/Controls/ControlsSlot.vue b/examples/vite/src/Controls/ControlsSlot.vue new file mode 100644 index 000000000..7019ed51a --- /dev/null +++ b/examples/vite/src/Controls/ControlsSlot.vue @@ -0,0 +1,69 @@ + + + + + diff --git a/packages/controls/README.md b/packages/controls/README.md index 4cac4d97d..5b9f3041f 100644 --- a/packages/controls/README.md +++ b/packages/controls/README.md @@ -25,7 +25,6 @@ import '@vue-flow/controls/dist/style.css' import initialElements from './initial-elements' - // some nodes and edges const elements = ref(initialElements) diff --git a/packages/controls/package.json b/packages/controls/package.json index cc008dac0..b1e5b48b5 100644 --- a/packages/controls/package.json +++ b/packages/controls/package.json @@ -2,13 +2,13 @@ "name": "@vue-flow/controls", "version": "1.1.3", "private": false, - "license": "MIT", "author": "Burak Cakmakoglu<78412429+bcakmakoglu@users.noreply.github.com>", + "license": "MIT", + "homepage": "https://github.com/bcakmakoglu/vue-flow#readme", "repository": { "type": "git", "url": "git+https://github.com/bcakmakoglu/vue-flow/packages/plugins/controls" }, - "homepage": "https://github.com/bcakmakoglu/vue-flow#readme", "bugs": { "url": "https://github.com/bcakmakoglu/vue-flow/issues" }, @@ -28,11 +28,9 @@ "vueflow", "typescript" ], - "main": "./dist/vue-flow-controls.js", - "module": "./dist/vue-flow-controls.mjs", - "types": "./dist/index.d.ts", - "unpkg": "./dist/vue-flow-controls.iife.js", - "jsdelivr": "./dist/vue-flow-controls.iife.js", + "sideEffects": [ + "*.css" + ], "exports": { ".": { "types": "./dist/index.d.ts", @@ -41,13 +39,15 @@ }, "./dist/style.css": "./dist/style.css" }, + "main": "./dist/vue-flow-controls.js", + "module": "./dist/vue-flow-controls.mjs", + "unpkg": "./dist/vue-flow-controls.iife.js", + "jsdelivr": "./dist/vue-flow-controls.iife.js", + "types": "./dist/index.d.ts", "files": [ "dist", "*.d.ts" ], - "sideEffects": [ - "*.css" - ], "scripts": { "dev": "pnpm types:watch & pnpm build:watch", "build": "vite build", diff --git a/packages/controls/src/Controls.vue b/packages/controls/src/Controls.vue index 15c3b97f2..77445ebc1 100644 --- a/packages/controls/src/Controls.vue +++ b/packages/controls/src/Controls.vue @@ -1,7 +1,8 @@