Skip to content

Beautiful Open-Source Form Builder

Refactor OptionSelectorInput and InputWrapper Components for Improved… (#777)

Chirag Chhatrala3847870189f6
diff --git a/client/components/forms/OptionSelectorInput.vue b/client/components/forms/OptionSelectorInput.vue
index 1ab8f2421..0b225b9c7 100644
--- a/client/components/forms/OptionSelectorInput.vue
+++ b/client/components/forms/OptionSelectorInput.vue
@@ -5,8 +5,9 @@
</template>
<div
- class="grid"
- :class="[gridClass, { 'gap-2': !seamless }]"
+ :class="[
+ seamless ? 'flex -space-x-px' : `grid ${gridClass} gap-2`
+ ]"
:style="optionStyle"
role="listbox"
:aria-multiselectable="multiple ? 'true' : 'false'"
@@ -14,60 +15,71 @@
@keydown="onKeydown"
ref="root"
>
- <button
+ <UTooltip
v-for="(option, idx) in options"
+
:key="option[optionKey]"
- class="flex flex-col items-center justify-center p-1.5 border transition-colors text-gray-500 focus:outline-none"
+ :text="option.tooltip"
+ :disabled="!option.tooltip"
:class="[
- option.class ? (typeof option.class === 'function' ? option.class(isSelected(option)) : option.class) : {},
+ 'w-full border transition-colors shadow-xs',
{
- 'border-form-color text-form-color bg-form-color/10': isSelected(option),
- 'hover:bg-gray-100 border-gray-300': !isSelected(option),
- 'opacity-50 pointer-events-none': disabled || option.disabled,
- // Seamless mode: only first and last have radius
+ // Background colors
+ 'bg-form/10': isSelected(option),
+ 'hover:bg-gray-100': !isSelected(option),
+ // Border colors
+ 'border-form': isSelected(option),
+ 'border-gray-300': !isSelected(option),
+ // Border radius for seamless mode
'rounded-lg': !seamless,
- 'rounded-l-lg': seamless && idx === 0,
- 'rounded-r-lg': seamless && idx === options.length - 1,
- // Seamless mode: overlap borders with negative margin, keep all borders
- '-ml-px': seamless && idx > 0,
- // Seamless mode: z-index hierarchy - selected > hovered/focused > default
- 'relative z-20': seamless && isSelected(option),
- 'relative z-10': seamless && !isSelected(option) && focusedIdx === idx,
- 'relative z-0': seamless && !isSelected(option) && focusedIdx !== idx,
- // Add hover z-index for seamless mode (but lower than selected)
- 'hover:z-10': seamless && !isSelected(option)
+ 'first:rounded-l-lg': seamless,
+ 'last:rounded-r-lg': seamless,
+ 'not-first:not-last:rounded-none': seamless,
+ // Z-index
+ 'relative focus-within:z-10': seamless,
+ 'relative z-10': seamless && isSelected(option),
}
]"
- :aria-selected="isSelected(option) ? 'true' : 'false'"
- :tabindex="disabled || option.disabled ? -1 : 0"
- :disabled="disabled || option.disabled"
- @click="selectOption(option)"
- @focus="focusedIdx = idx"
- @mouseenter="focusedIdx = idx"
- :title="option.tooltip || ''"
- role="option"
>
- <slot name="icon" :option="option" :selected="isSelected(option)">
- <Icon
- v-if="option.icon"
- :name="isSelected(option) && option.selectedIcon ? option.selectedIcon : option.icon"
- :class="[
- 'w-4 h-4',
- option.label ? 'mb-1' : '',
- isSelected(option) ? 'text-form-color' : 'text-inherit',
- option.iconClass ? (typeof option.iconClass === 'function' ? option.iconClass(isSelected(option)) : option.iconClass) : {}
- ]"
- />
- </slot>
- <span
- v-if="option.label || !option.icon"
- class="text-xs"
- :class="{
- 'text-form-color': isSelected(option),
- 'text-inherit': !isSelected(option),
- }"
- >{{ isSelected(option) ? option.selectedLabel ?? option.label : option.label }}</span>
- </button>
+ <button
+ class="flex flex-col items-center justify-center p-1.5 transition-colors text-gray-500 focus:outline-none w-full h-full"
+ :class="[
+ option.class ? (typeof option.class === 'function' ? option.class(isSelected(option)) : option.class) : {},
+ {
+ 'text-form-color': isSelected(option),
+ 'opacity-50 pointer-events-none': disabled || option.disabled,
+ }
+ ]"
+ :aria-selected="isSelected(option) ? 'true' : 'false'"
+ :tabindex="disabled || option.disabled ? -1 : 0"
+ :disabled="disabled || option.disabled"
+ @click="selectOption(option)"
+ @focus="focusedIdx = idx"
+ @mouseenter="focusedIdx = idx"
+ role="option"
+ >
+ <slot name="icon" :option="option" :selected="isSelected(option)">
+ <Icon
+ v-if="option.icon"
+ :name="isSelected(option) && option.selectedIcon ? option.selectedIcon : option.icon"
+ :class="[
+ 'w-4 h-4',
+ option.label ? 'mb-1' : '',
+ isSelected(option) ? 'text-form-color' : 'text-inherit',
+ option.iconClass ? (typeof option.iconClass === 'function' ? option.iconClass(isSelected(option)) : option.iconClass) : {}
+ ]"
+ />
+ </slot>
+ <span
+ v-if="option.label || !option.icon"
+ class="text-xs"
+ :class="{
+ 'text-form-color': isSelected(option),
+ 'text-inherit': !isSelected(option),
+ }"
+ >{{ isSelected(option) ? option.selectedLabel ?? option.label : option.label }}</span>
+ </button>
+ </UTooltip>
</div>
<template #help>
diff --git a/client/components/forms/components/InputWrapper.vue b/client/components/forms/components/InputWrapper.vue
index 45f29311e..a39ce27e4 100644
--- a/client/components/forms/components/InputWrapper.vue
+++ b/client/components/forms/components/InputWrapper.vue
@@ -4,6 +4,7 @@
:style="inputStyle"
>
<slot name="label">
+ <VTransition name="fadeHeight">
<InputLabel
v-if="label && !hideFieldName"
:label="label"
@@ -12,7 +13,9 @@
:native-for="id ? id : name"
:uppercase-labels="uppercaseLabels"
/>
+ </VTransition>
</slot>
+ <VTransition name="fadeHeight">
<slot
v-if="helpPosition === 'above_input'"
name="help"
@@ -26,8 +29,10 @@
</template>
</InputHelp>
</slot>
+ </VTransition>
<slot />
+ <VTransition name="fadeHeightDown">
<slot
v-if="helpPosition === 'below_input'"
name="help"
@@ -49,36 +54,37 @@
:field-name="label"
/>
</slot>
+ </VTransition>
</div>
</template>
<script setup>
-import InputLabel from "./InputLabel.vue"
-import InputHelp from "./InputHelp.vue"
+import InputLabel from './InputLabel.vue'
+import InputHelp from './InputHelp.vue'
import {twMerge} from "tailwind-merge"
-import CachedDefaultTheme from "~/lib/forms/themes/CachedDefaultTheme.js"
+import CachedDefaultTheme from '~/lib/forms/themes/CachedDefaultTheme.js'
defineProps({
- id: {type: String, required: false},
- name: {type: String, required: false},
- label: {type: String, required: false},
- form: {type: Object, required: false},
+ id: { type: String, required: false },
+ name: { type: String, required: false },
+ label: { type: String, required: false },
+ form: { type: Object, required: false },
theme: {
- type: Object, default: () => {
- const theme = inject("theme", null)
- if (theme) {
- return theme.value
+ type: Object, default: () => {
+ const theme = inject('theme', null)
+ if (theme) {
+ return theme.value
+ }
+ return CachedDefaultTheme.getInstance()
}
- return CachedDefaultTheme.getInstance()
- }
- },
- wrapperClass: {type: String, required: false},
- inputStyle: {type: Object, required: false},
- help: {type: String, required: false},
- helpPosition: {type: String, default: "below_input"},
- uppercaseLabels: {type: Boolean, default: true},
- hideFieldName: {type: Boolean, default: true},
- required: {type: Boolean, default: false},
- hasValidation: {type: Boolean, default: true},
+ },
+ wrapperClass: { type: String, required: false },
+ inputStyle: { type: Object, required: false },
+ help: { type: String, required: false },
+ helpPosition: { type: String, default: 'below_input' },
+ uppercaseLabels: { type: Boolean, default: true },
+ hideFieldName: { type: Boolean, default: true },
+ required: { type: Boolean, default: false },
+ hasValidation: { type: Boolean, default: true },
})
</script>
diff --git a/client/components/global/ErrorBoundary.vue b/client/components/global/ErrorBoundary.vue
index f1f105ef2..3f893a809 100644
--- a/client/components/global/ErrorBoundary.vue
+++ b/client/components/global/ErrorBoundary.vue
@@ -16,6 +16,7 @@
}
onErrorCaptured(err => {
error.value = err
+ console.error(err)
emit('on-error', err)
return false
})
diff --git a/client/components/global/transitions/VTransition.vue b/client/components/global/transitions/VTransition.vue
index ff778d2ed..a7b1969b2 100644
--- a/client/components/global/transitions/VTransition.vue
+++ b/client/components/global/transitions/VTransition.vue
@@ -24,15 +24,26 @@
</transition>
<transition
v-else-if="name === 'fadeHeight'"
- enter-active-class="transition-all duration-500 ease-in-out overflow-hidden"
+ enter-active-class="transition-all duration-400 ease-in-out overflow-hidden"
enter-from-class="opacity-0 -translate-y-2 max-h-0"
enter-to-class="opacity-100 translate-y-0 max-h-screen"
- leave-active-class="transition-all duration-300 ease-in-out overflow-hidden"
+ leave-active-class="transition-all duration-400 ease-in-out overflow-hidden"
leave-from-class="opacity-100 translate-y-0 max-h-screen"
leave-to-class="opacity-0 -translate-y-2 max-h-0"
>
<slot />
</transition>
+ <transition
+ v-else-if="name === 'fadeHeightDown'"
+ enter-active-class="transition-all duration-400 ease-in-out overflow-hidden"
+ enter-from-class="opacity-0 translate-y-2 max-h-0"
+ enter-to-class="opacity-100 translate-y-0 max-h-screen"
+ leave-active-class="transition-all duration-400 ease-in-out overflow-hidden"
+ leave-from-class="opacity-100 translate-y-0 max-h-screen"
+ leave-to-class="opacity-0 translate-y-2 max-h-0"
+ >
+ <slot />
+ </transition>
</template>
<script setup>
diff --git a/client/components/open/forms/OpenCompleteForm.vue b/client/components/open/forms/OpenCompleteForm.vue
index 511166274..881837898 100644
--- a/client/components/open/forms/OpenCompleteForm.vue
+++ b/client/components/open/forms/OpenCompleteForm.vue
@@ -3,7 +3,7 @@
v-if="form"
class="open-complete-form"
:dir="form?.layout_rtl ? 'rtl' : 'ltr'"
- :style="{ '--font-family': form.font_family, 'direction': form?.layout_rtl ? 'rtl' : 'ltr', '--form-color': form.color }"
+ :style="{ '--font-family': form.font_family, 'direction': form?.layout_rtl ? 'rtl' : 'ltr', '--form-color': form.color, '--form': form.color }"
>
<ClientOnly>
<Teleport to="head">
diff --git a/client/components/open/forms/components/form-components/FormCustomization.vue b/client/components/open/forms/components/form-components/FormCustomization.vue
index bd5e8fb84..5ff44070e 100644
--- a/client/components/open/forms/components/form-components/FormCustomization.vue
+++ b/client/components/open/forms/components/form-components/FormCustomization.vue
@@ -101,42 +101,37 @@
icon="heroicons:rectangle-stack-16-solid"
title="Layout & Sizing"
/>
- <div class="flex space-x-4 justify-stretch">
- <div class="flex-grow">
- <OptionSelectorInput
- seamless
- label="Input Size"
- v-model="form.size"
- :form="form"
- name="size"
- :options="[
- { name: 'sm', label:'S'},
- { name: 'md', label:'M' },
- { name: 'lg', label:'L' },
- ]"
- :multiple="false"
- :columns="3"
- class="mb-4"
- />
- </div>
-
- <div class="flex-grow">
- <OptionSelectorInput
- label="Input Roundness"
- v-model="form.border_radius"
- seamless
- :form="form"
- name="border_radius"
- :options="[
- { name: 'none', icon: 'i-tabler-border-corner-square' },
- { name: 'small', icon: 'i-tabler-border-corner-rounded' },
- { name: 'full', icon: 'i-tabler-border-corner-pill' },
- ]"
- :multiple="false"
- :columns="3"
- class="mb-4"
- />
- </div>
+ <div class="grid grid-cols-2 gap-4">
+ <OptionSelectorInput
+ seamless
+ label="Input Size"
+ v-model="form.size"
+ :form="form"
+ name="size"
+ :options="[
+ { name: 'sm', label:'S'},
+ { name: 'md', label:'M' },
+ { name: 'lg', label:'L' },
+ ]"
+ :multiple="false"
+ :columns="3"
+ class="mb-4"
+ />
+ <OptionSelectorInput
+ label="Input Roundness"
+ v-model="form.border_radius"
+ seamless
+ :form="form"
+ name="border_radius"
+ :options="[
+ { name: 'none', icon: 'i-tabler-border-corner-square' },
+ { name: 'small', icon: 'i-tabler-border-corner-rounded' },
+ { name: 'full', icon: 'i-tabler-border-corner-pill' },
+ ]"
+ :multiple="false"
+ :columns="3"
+ class="mb-4"
+ />
</div>
<OptionSelectorInput
diff --git a/client/components/open/forms/fields/components/BlockOptions.vue b/client/components/open/forms/fields/components/BlockOptions.vue
index be442e3c8..c25968327 100644
--- a/client/components/open/forms/fields/components/BlockOptions.vue
+++ b/client/components/open/forms/fields/components/BlockOptions.vue
@@ -19,36 +19,42 @@
:can-be-hidden="true"
:can-be-required="false"
/>
-
- <div class="grid grid-cols-2 gap-2 mt-2">
- <select-input
+
+ <OptionSelectorInput
+ v-model="field.width"
name="width"
- class="flex-grow"
+ class="grow"
+ :form="field"
+ label="Block Width"
+ seamless
:options="[
- { name: 'Full', value: 'full' },
- { name: '1/2', value: '1/2' },
- { name: '1/3', value: '1/3' },
- { name: '2/3', value: '2/3' },
- { name: '1/4', value: '1/4' },
- { name: '3/4', value: '3/4' },
+ { name: 'full', label: 'Full' },
+ { name: '1/2', label: '1/2' },
+ { name: '1/3', label: '1/3' },
+ { name: '2/3', label: '2/3' },
+ { name: '1/4', label: '1/4' },
+ { name: '3/4', label: '3/4' },
]"
- :form="field"
- label="Width"
+ :multiple="false"
+ :columns="6"
/>
- <select-input
+ <OptionSelectorInput
v-if="['nf-text', 'nf-image'].includes(field.type)"
+ v-model="field.align"
name="align"
- class="flex-grow"
+ class="w-2/3"
+ :form="field"
+ label="Text Alignment"
+ seamless
:options="[
- { name: 'Left', value: 'left' },
- { name: 'Center', value: 'center' },
- { name: 'Right', value: 'right' },
- { name: 'Justify', value: 'justify' },
+ { name: 'left', icon: 'i-heroicons-bars-3-bottom-left', tooltip: 'Align left' },
+ { name: 'center', icon: 'i-heroicons-bars-3', tooltip: 'Align center' },
+ { name: 'right', icon: 'i-heroicons-bars-3-bottom-right', tooltip: 'Align right' },
+ { name: 'justify', icon: 'i-heroicons-bars-4', tooltip: 'Justify text' },
]"
- :form="field"
- label="Alignment"
+ :multiple="false"
+ :columns="4"
/>
- </div>
</div>
<div
diff --git a/client/components/open/forms/fields/components/FieldOptions.vue b/client/components/open/forms/fields/components/FieldOptions.vue
index 91087a7a7..508369c41 100644
--- a/client/components/open/forms/fields/components/FieldOptions.vue
+++ b/client/components/open/forms/fields/components/FieldOptions.vue
@@ -515,29 +515,33 @@
name="placeholder"
class="mt-3"
:form="field"
- label="Empty Input Text (Placeholder)"
+ label="Empty Input Text - Placeholder"
/>
<text-input
v-else-if="hasPlaceholder"
name="placeholder"
class="mt-3"
:form="field"
- label="Empty Input Text (Placeholder)"
+ label="Empty Input Text - Placeholder"
/>
- <select-input
+ <OptionSelectorInput
+ v-model="field.width"
name="width"
- class="mt-3"
+ class="mt-4"
+ :form="field"
+ label="Block Width"
+ seamless
:options="[
- { name: 'Full', value: 'full' },
- { name: '1/2 (half width)', value: '1/2' },
- { name: '1/3 (a third of the width)', value: '1/3' },
- { name: '2/3 (two thirds of the width)', value: '2/3' },
- { name: '1/4 (a quarter of the width)', value: '1/4' },
- { name: '3/4 (three quarters of the width)', value: '3/4' },
+ { name: 'full', label: 'Full' },
+ { name: '1/2', label: '1/2' },
+ { name: '1/3', label: '1/3' },
+ { name: '2/3', label: '2/3' },
+ { name: '1/4', label: '1/4' },
+ { name: '3/4', label: '3/4' },
]"
- :form="field"
- label="Field Width"
+ :multiple="false"
+ :columns="6"
/>
<!-- Help -->
@@ -546,7 +550,7 @@
class="mt-3"
:form="field"
:editor-toolbar="editorToolbarCustom"
- label="Field Help"
+ label="Help Text"
:editor-options="{
formats: [
'bold',
@@ -558,18 +562,22 @@
'list'
]
}"
- help="Your field help will be shown below/above the field, just like this text."
+ help="Displayed below/above the field, like this text"
:help-position="field.help_position"
/>
- <select-input
+ <OptionSelectorInput
+ v-model="field.help_position"
name="help_position"
- class="mt-3"
+ class="mt-4 w-2/3"
+ :form="field"
+ label="Help Text Position"
+ seamless
:options="[
- { name: 'Below input', value: 'below_input' },
- { name: 'Above input', value: 'above_input' },
+ { name: 'below_input', label: 'Below input'},
+ { name: 'above_input', label: 'Above input'},
]"
- :form="field"
- label="Field Help Position"
+ :multiple="false"
+ :columns="2"
@update:model-value="onFieldHelpPositionChange"
/>
@@ -581,6 +589,7 @@
:form="field"
label="Max character limit"
:required="false"
+ class="mt-3"
@update:model-value="onFieldMaxCharLimitChange"
/>
<toggle-switch-input
diff --git a/client/tailwind.config.js b/client/tailwind.config.js
index 711a94fbb..ee5d89dd4 100644
--- a/client/tailwind.config.js
+++ b/client/tailwind.config.js
@@ -79,6 +79,7 @@ module.exports = {
border: 'rgba(15, 15, 15, 0.1)',
borderDark: 'rgba(255, 255, 255, 0.1)'
},
+ 'form': 'rgb(from var(--form-color, var(--bg-form-color)) r g b / <alpha-value>)',
'form-color': 'rgb(from var(--form-color, var(--bg-form-color)) r g b / <alpha-value>)'
},
transitionProperty: {