Skip to content

Commit

Permalink
Add Wizard example
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Dec 5, 2024
1 parent ed3afe2 commit a0972f2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ComponentBox from '../../../../../../shared/tags/ComponentBox'
import { Field, Form } from '@dnb/eufemia/src/extensions/forms'
import { createRequest } from '../SubmitIndicator/Examples'
import { Field, Form, Wizard } from '@dnb/eufemia/src/extensions/forms'
import { Button } from '@dnb/eufemia/src'

const request = createRequest()
Expand Down Expand Up @@ -72,3 +72,49 @@ export const SuccessMessage = () => {
</ComponentBox>
)
}

export const WithAWizard = () => {
const request = createRequest()
return (
<ComponentBox scope={{ request }}>
{() => {
// myFormId can be anything, as long as it's a unique instance
const myFormId = () => null

return (
<Form.Handler
id={myFormId}
onSubmit={async () => {
await request(1000)
Form.Status.setStatus(myFormId, 'success')
}}
>
<Form.Status>
<Wizard.Container
onStepChange={async () => {
await request(1000)
}}
>
<Wizard.Step title="Step 1">
<Form.Card>
<Field.String
path="/someInfo"
label="Some information"
/>
</Form.Card>
<Wizard.NextButton />
</Wizard.Step>
<Wizard.Step title="Step 2">
<Form.Card>
<Field.String path="/more" label="More information" />
</Form.Card>
<Form.SubmitButton variant="send" />
</Wizard.Step>
</Wizard.Container>
</Form.Status>
</Form.Handler>
)
}}
</ComponentBox>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ import * as Examples from './Examples'
### Success message

<Examples.SuccessMessage />

### With a Wizard

<Examples.WithAWizard />
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,22 @@ export function BothStatuses() {
)
}

export function InWizard() {
export function WithAWizard() {
return (
<Form.Handler
id="test"
onSubmit={(data) => {
console.log('data', data)
onSubmit={async (data) => {
await new Promise((r) => setTimeout(r, 1000))
Form.Status.setStatus('test', 'success')
console.log('data', data)
}}
>
<Form.Status>
<Wizard.Container>
<Wizard.Container
onStepChange={async () => {
await new Promise((r) => setTimeout(r, 1000))
}}
>
<Wizard.Step title="Step 1">
<Field.String path="/someInfo" label="Some information" />
<Wizard.NextButton />
Expand Down

0 comments on commit a0972f2

Please sign in to comment.