-
+
{{ field.label || field.name }}
@@ -90,6 +95,7 @@ import records from 'corteza-webapp-compose/src/mixins/records'
import FieldEditor from 'corteza-webapp-compose/src/components/ModuleFields/Editor'
import FieldViewer from 'corteza-webapp-compose/src/components/ModuleFields/Viewer'
import conditionalFields from 'corteza-webapp-compose/src/mixins/conditionalFields'
+import recordLayout from 'corteza-webapp-compose/src/mixins/recordLayout'
import { debounce } from 'lodash'
export default {
@@ -108,6 +114,7 @@ export default {
users,
records,
conditionalFields,
+ recordLayout,
],
props: {
@@ -137,6 +144,24 @@ export default {
})
},
+ fieldLayoutClass () {
+ const classes = {
+ default: 'd-flex flex-column px-3',
+ noWrap: 'd-flex gap-2 pl-3',
+ wrap: 'row no-gutters',
+ }
+
+ return classes[this.options.recordFieldLayoutOption]
+ },
+
+ fieldWidth () {
+ if (this.options.recordFieldLayoutOption !== 'noWrap') {
+ return {}
+ }
+
+ return { 'min-width': '20rem' }
+ },
+
errorID () {
const { recordID = NoID } = this.record || {}
return recordID === NoID ? 'parent:0' : recordID
@@ -182,6 +207,25 @@ export default {
})
},
},
+
+ processing: {
+ handler (newVal) {
+ if (this.options.recordFieldLayoutOption !== 'wrap') return
+
+ if (!newVal && this.module) {
+ this.$nextTick(() => {
+ this.initializeResizeObserver(this.$refs.fieldContainer)
+ })
+ } else if (this.resizeObserver) {
+ this.resizeObserver.unobserve(this.$refs.fieldContainer)
+ this.columnWrapClass = ''
+ }
+ },
+ },
+ },
+
+ beforeDestroy () {
+ this.destroyEvents(this.$refs.fieldContainer)
},
methods: {
@@ -210,3 +254,10 @@ export default {
},
}
+
+
diff --git a/client/web/compose/src/mixins/recordLayout.js b/client/web/compose/src/mixins/recordLayout.js
new file mode 100644
index 000000000..06d7915d5
--- /dev/null
+++ b/client/web/compose/src/mixins/recordLayout.js
@@ -0,0 +1,63 @@
+export default {
+ data () {
+ return {
+ resizeObserver: null,
+ columnWrapClass: '',
+ }
+ },
+
+ methods: {
+ initializeResizeObserver (el) {
+ this.resizeObserver = new ResizeObserver((entries) => {
+ for (let entry of entries) {
+ // Handle the resize event here
+ this.applyColumnClasses(entry.contentRect.width)
+ }
+ })
+
+ this.resizeObserver.observe(el)
+ },
+
+ applyColumnClasses (width) {
+ const breakpoints = {
+ xs: 576,
+ md: 768,
+ lg: 992,
+ xl: 1200,
+ }
+
+ const columnClasses = {
+ xs: 'col-12',
+ md: 'col-6',
+ lg: 'col-4',
+ xl: 'col-3',
+ }
+
+ let columnClass
+
+ switch (true) {
+ case width <= breakpoints.xs:
+ columnClass = columnClasses.xs
+ break
+ case width > breakpoints.xs && width <= breakpoints.md:
+ columnClass = columnClasses.md
+ break
+ case width > breakpoints.md && width <= breakpoints.lg:
+ columnClass = columnClasses.lg
+ break
+ default:
+ columnClass = columnClasses.xl
+ break
+ }
+
+ this.columnWrapClass = `field-col ${columnClass}`
+ },
+
+ destroyEvents (el) {
+ if (this.resizeObserver) {
+ this.resizeObserver.unobserve(el)
+ this.resizeObserver.disconnect()
+ }
+ },
+ },
+}
diff --git a/lib/js/src/compose/types/page-block/record.ts b/lib/js/src/compose/types/page-block/record.ts
index 51b34c8ad..0635cf29d 100644
--- a/lib/js/src/compose/types/page-block/record.ts
+++ b/lib/js/src/compose/types/page-block/record.ts
@@ -19,6 +19,7 @@ interface Options {
referenceModuleID?: string;
inlineRecordEditEnabled: boolean;
horizontalFieldLayoutEnabled: boolean;
+ recordFieldLayoutOption: string;
}
const defaults: Readonly = Object.freeze({
@@ -32,6 +33,7 @@ const defaults: Readonly = Object.freeze({
referenceModuleID: undefined,
inlineRecordEditEnabled: false,
horizontalFieldLayoutEnabled: false,
+ recordFieldLayoutOption: 'default',
})
export class PageBlockRecord extends PageBlock {
@@ -47,7 +49,7 @@ export class PageBlockRecord extends PageBlock {
applyOptions (o?: Partial): void {
if (!o) return
- Apply(this.options, o, String, 'magnifyOption', 'recordSelectorDisplayOption', 'recordSelectorAddRecordDisplayOption', 'referenceField', 'referenceModuleID')
+ Apply(this.options, o, String, 'magnifyOption', 'recordSelectorDisplayOption', 'recordSelectorAddRecordDisplayOption', 'referenceField', 'referenceModuleID', 'recordFieldLayoutOption')
Apply(this.options, o, Boolean, 'recordSelectorShowAddRecordButton', 'inlineRecordEditEnabled', 'horizontalFieldLayoutEnabled')
if (o.fields) {
diff --git a/locale/en/corteza-webapp-compose/block.yaml b/locale/en/corteza-webapp-compose/block.yaml
index 3fb4a6560..68855ab6f 100644
--- a/locale/en/corteza-webapp-compose/block.yaml
+++ b/locale/en/corteza-webapp-compose/block.yaml
@@ -278,6 +278,11 @@ record:
horizontalFormLayout: Horizontal form layout
inlineEdit:
enabled: Inline value editing enabled
+ fieldsLayoutMode:
+ label: Fields layout mode
+ default: Default
+ noWrap: No wrap
+ wrap: Wrap
preview:
blockNoRecord: Cannot render this block without a record
fieldsFromModule: Single record block, displaying fields ({{0}}) from module {{1}}