1
0
forked from test/crm

fix: reactive field layout

This commit is contained in:
Shariq Ansari 2025-01-02 11:21:26 +05:30
parent beedb11cd1
commit 12b93c9a74
7 changed files with 236 additions and 228 deletions

View File

@ -26,22 +26,20 @@
:class="[section.hideBorder ? 'mt-4' : 'h-px border-t my-5']" :class="[section.hideBorder ? 'mt-4' : 'h-px border-t my-5']"
/> />
<Section <Section
class="text-lg font-medium" class="flex gap-4 text-lg font-medium"
:class="{ 'px-3 sm:px-5': hasTabs }" :class="{
'px-3 sm:px-5': hasTabs,
'mt-6': section.label && !section.hideLabel,
}"
:labelClass="[
'text-lg font-medium',
{ 'px-3 sm:px-5': hasTabs },
]"
:label="section.label" :label="section.label"
:hideLabel="section.hideLabel || !section.label" :hideLabel="section.hideLabel || !section.label"
:opened="section.opened" :opened="section.opened"
:collapsible="section.collapsible" :collapsible="section.collapsible"
collapseIconPosition="right" collapseIconPosition="right"
>
<div
class="flex gap-4"
:class="[
{
'px-3 sm:px-5': hasTabs,
'mt-6': section.label && !section.hideLabel,
},
]"
> >
<div <div
class="column flex flex-col gap-4 w-full" class="column flex flex-col gap-4 w-full"
@ -55,8 +53,17 @@
> >
{{ column.label }} {{ column.label }}
</div> </div>
<div v-for="field in column.fields" :key="field.name"> <template v-for="field in column.fields" :key="field.name">
<div class="settings-field"> <div
v-if="
(field.type == 'Check' ||
(field.read_only && data[field.name]) ||
!field.read_only) &&
(!field.depends_on || field.display_via_depends_on) &&
!field.hidden
"
class="field"
>
<div <div
v-if="field.type != 'Check'" v-if="field.type != 'Check'"
class="mb-2 text-sm text-ink-gray-5" class="mb-2 text-sm text-ink-gray-5"
@ -243,8 +250,7 @@
:disabled="Boolean(field.read_only)" :disabled="Boolean(field.read_only)"
/> />
</div> </div>
</div> </template>
</div>
</div> </div>
</Section> </Section>
</div> </div>
@ -295,8 +301,7 @@ const _tabs = computed(() => {
return props.tabs.map((tab) => { return props.tabs.map((tab) => {
tab.sections = tab.sections.map((section) => { tab.sections = tab.sections.map((section) => {
section.columns = section.columns.map((column) => { section.columns = section.columns.map((column) => {
column.fields = column.fields column.fields = column.fields.map((field) => {
.map((field) => {
if (field.type == 'Link' && field.options == 'User') { if (field.type == 'Link' && field.options == 'User') {
field.type = 'User' field.type = 'User'
} }
@ -312,15 +317,6 @@ const _tabs = computed(() => {
), ),
} }
}) })
.filter((field) => {
return (
(field.type == 'Check' ||
(field.read_only && props.data[field.name]) ||
!field.read_only) &&
(!field.depends_on || field.display_via_depends_on) &&
!field.hidden
)
})
return column return column
}) })
return section return section
@ -352,7 +348,7 @@ const getPlaceholder = (field) => {
display: none; display: none;
} }
.section:has(.settings-field) { .section:has(.field) {
display: block; display: block;
} }

View File

@ -46,7 +46,7 @@
}" }"
> >
<Section <Section
class="p-2" labelClass="p-2"
:label="section.label" :label="section.label"
:opened="section.opened" :opened="section.opened"
> >

View File

@ -1,10 +1,10 @@
<template> <template>
<div> <div>
<slot name="header" v-bind="{ opened, hide, open, close, toggle }"> <slot name="header" v-bind="{ opened, hide, open, close, toggle }">
<div v-if="!hide" class="flex items-center justify-between"> <div v-if="!hide" class="column-header flex items-center justify-between">
<div <div
class="flex text-ink-gray-9 max-w-fit cursor-pointer items-center gap-2 text-base" class="flex text-ink-gray-9 max-w-fit cursor-pointer items-center gap-2 text-base"
v-bind="$attrs" :class="labelClass"
@click="collapsible && toggle()" @click="collapsible && toggle()"
> >
<FeatherIcon <FeatherIcon
@ -34,7 +34,7 @@
enter-from-class="max-h-0 overflow-hidden" enter-from-class="max-h-0 overflow-hidden"
leave-to-class="max-h-0 overflow-hidden" leave-to-class="max-h-0 overflow-hidden"
> >
<div v-show="opened"> <div class="columns" v-bind="$attrs" v-show="opened">
<slot v-bind="{ opened, open, close, toggle }" /> <slot v-bind="{ opened, open, close, toggle }" />
</div> </div>
</transition> </transition>
@ -64,6 +64,10 @@ const props = defineProps({
type: String, type: String,
default: 'left', default: 'left',
}, },
labelClass: {
type: [String, Object, Array],
default: '',
},
}) })
const hide = ref(props.hideLabel) const hide = ref(props.hideLabel)

View File

@ -127,7 +127,11 @@
class="flex flex-col p-3" class="flex flex-col p-3"
:class="{ 'border-b': i !== fieldsLayout.data.length - 1 }" :class="{ 'border-b': i !== fieldsLayout.data.length - 1 }"
> >
<Section :label="section.label" :opened="section.opened"> <Section
labelClass="px-2 font-semibold"
:label="section.label"
:opened="section.opened"
>
<template #actions> <template #actions>
<Button <Button
v-if="i == 0 && isManager()" v-if="i == 0 && isManager()"

View File

@ -125,7 +125,7 @@
:class="{ 'border-b': i !== fieldsLayout.data.length - 1 }" :class="{ 'border-b': i !== fieldsLayout.data.length - 1 }"
> >
<Section <Section
class="px-2 font-semibold" labelClass="px-2 font-semibold"
:label="section.label" :label="section.label"
:opened="section.opened" :opened="section.opened"
> >

View File

@ -178,7 +178,7 @@
:class="{ 'border-b': i !== fieldsLayout.data.length - 1 }" :class="{ 'border-b': i !== fieldsLayout.data.length - 1 }"
> >
<Section <Section
class="px-2 font-semibold" labelClass="px-2 font-semibold"
:label="section.label" :label="section.label"
:opened="section.opened" :opened="section.opened"
> >

View File

@ -112,7 +112,11 @@
class="flex flex-col p-3" class="flex flex-col p-3"
:class="{ 'border-b': i !== fieldsLayout.data.length - 1 }" :class="{ 'border-b': i !== fieldsLayout.data.length - 1 }"
> >
<Section :label="section.label" :opened="section.opened"> <Section
labelClass="px-2 font-semibold"
:label="section.label"
:opened="section.opened"
>
<template #actions> <template #actions>
<Button <Button
v-if="i == 0 && isManager()" v-if="i == 0 && isManager()"