Update multi step form block to use core button config generation

This commit is contained in:
Andrew Kingston 2023-12-08 14:39:47 +00:00
parent 5a8c12c91b
commit 223a315801
3 changed files with 25 additions and 6 deletions

View File

@ -33,7 +33,7 @@
} }
$: defaultButtonConfig = buildMultiStepFormBlockButtonConfig({ $: defaultButtonConfig = buildMultiStepFormBlockButtonConfig({
_id: componentInstance._id, _id: componentInstance._id,
steps: value, stepCount: value?.length,
currentStep, currentStep,
}) })

View File

@ -3,6 +3,7 @@
import Block from "components/Block.svelte" import Block from "components/Block.svelte"
import { getContext } from "svelte" import { getContext } from "svelte"
import { builderStore } from "stores" import { builderStore } from "stores"
import { Utils } from "@budibase/frontend-core"
export let componentInstance export let componentInstance
export let steps export let steps
@ -91,13 +92,19 @@
schema = (await fetchDatasourceSchema(dataSource)) || {} schema = (await fetchDatasourceSchema(dataSource)) || {}
} }
$: stepProps = steps?.map(step => { $: stepProps = steps?.map((step, idx) => {
const { title, desc, fields, buttons } = step const { title, desc, fields, buttons } = step
return { return {
fields: getDefaultFields(fields || [], schema), fields: getDefaultFields(fields || [], schema),
title, title,
desc, desc,
buttons, buttons:
buttons ||
Utils.buildMultiStepFormBlockButtonConfig({
_id: $component.id,
stepCount: steps?.length,
currentStep: idx,
}),
} }
}) })
</script> </script>
@ -118,6 +125,13 @@
<BlockComponent <BlockComponent
type="formstep" type="formstep"
props={{ step: idx + 1, _instanceName: `Step ${idx + 1}` }} props={{ step: idx + 1, _instanceName: `Step ${idx + 1}` }}
styles={{
normal: {
width: "600px",
"margin-left": "auto",
"margin-right": "auto",
},
}}
> >
<BlockComponent <BlockComponent
type="container" type="container"
@ -157,6 +171,11 @@
<BlockComponent <BlockComponent
type="buttongroup" type="buttongroup"
props={{ buttons: stepProps?.[idx]?.buttons }} props={{ buttons: stepProps?.[idx]?.buttons }}
styles={{
normal: {
"margin-top": "16px",
},
}}
/> />
</BlockComponent> </BlockComponent>
</BlockComponent> </BlockComponent>

View File

@ -242,10 +242,10 @@ export const buildFormBlockButtonConfig = props => {
} }
export const buildMultiStepFormBlockButtonConfig = props => { export const buildMultiStepFormBlockButtonConfig = props => {
const { _id, steps, currentStep } = props || {} const { _id, stepCount, currentStep } = props || {}
// Sanity check // Sanity check
if (!_id || !steps?.length) { if (!_id || !stepCount) {
return return
} }
@ -279,7 +279,7 @@ export const buildMultiStepFormBlockButtonConfig = props => {
text: "Next", text: "Next",
type: "cta", type: "cta",
size: "M", size: "M",
disabled: currentStep === steps.length - 1, disabled: currentStep === stepCount - 1,
onClick: [ onClick: [
{ {
parameters: { parameters: {