From e5c5d46dae925e8b67228716f3f48fc9556a68fd Mon Sep 17 00:00:00 2001 From: Md Afiq Iskandar Date: Thu, 10 Apr 2025 10:04:54 +0800 Subject: [PATCH] Enhance Form Builder UI with Search Functionality and Component Organization - Added a search bar to filter available components in `FormBuilderComponents.vue`. - Organized components into categories (Basic Inputs, Selection Inputs, Date and Time, Advanced, Layout) for better accessibility. - Updated styles for improved user experience and interaction feedback. - Refactored component retrieval logic to streamline rendering based on categories. --- components/FormBuilderComponents.vue | 181 ++++++++++++++++++--------- pages/form-builder/index.vue | 28 ++--- 2 files changed, 134 insertions(+), 75 deletions(-) diff --git a/components/FormBuilderComponents.vue b/components/FormBuilderComponents.vue index e78ff9a..1f96b2d 100644 --- a/components/FormBuilderComponents.vue +++ b/components/FormBuilderComponents.vue @@ -1,33 +1,114 @@ @@ -262,23 +343,10 @@ const availableComponents = [ } ]; -// Group components by category -const groupedComponents = computed(() => { - const grouped = {}; - - availableComponents.forEach(component => { - if (!grouped[component.category]) { - grouped[component.category] = { - category: component.category, - components: [] - }; - } - - grouped[component.category].components.push(component); - }); - - return Object.values(grouped); -}); +// Get components by category for rendering in sections +const getComponentsByCategory = (category) => { + return availableComponents.filter(component => component.category === category); +}; // Check if component matches search query const matchesSearch = (component) => { @@ -298,32 +366,29 @@ const onDragStart = (event, component) => { // Set the drag data event.dataTransfer.effectAllowed = 'copy'; event.dataTransfer.setData('component', JSON.stringify(component)); - - // Let browser handle the drag image naturally - // Don't call emit here to avoid double component creation }; -// Add a click handler for adding components directly +// Add a component directly via click const addComponent = (component) => { emit('add-component', component); }; \ No newline at end of file diff --git a/pages/form-builder/index.vue b/pages/form-builder/index.vue index f7913be..02be666 100644 --- a/pages/form-builder/index.vue +++ b/pages/form-builder/index.vue @@ -58,22 +58,14 @@
-

- Available Components -

+

Components

- - +
-
+
@@ -81,16 +73,18 @@

Form Canvas

- Drag components to build your form + Drag components to build your form

Configuration