Skip to content

Commit

Permalink
Add InitiallyOpen example
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Oct 9, 2024
1 parent 1150037 commit cf279d4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Value,
Form,
Tools,
Wizard,
} from '@dnb/eufemia/src/extensions/forms'
export { Default as AnimatedContainer } from '../AnimatedContainer/Examples'

Expand Down Expand Up @@ -368,7 +369,62 @@ export const WithVisibility = () => {
)
}

export const InitialOpen = () => {
export const InitiallyOpen = () => {
return (
<ComponentBox scope={{ Iterate, Tools }}>
<Form.Handler>
<Wizard.Container>
<Wizard.Step>
<Card stack>
<Iterate.Array path="/myList" defaultValue={[{}]}>
<Iterate.ViewContainer>
<Value.String label="Item {itemNo}" itemPath="/foo" />
</Iterate.ViewContainer>
<Iterate.EditContainer>
<Field.String
label="Item {itemNo}"
itemPath="/foo"
defaultValue="foo"
/>
</Iterate.EditContainer>
</Iterate.Array>

<Iterate.PushButton
text="Add"
path="/myList"
variant="tertiary"
pushValue={{}}
/>
</Card>

<Wizard.Buttons />
</Wizard.Step>

<Wizard.Step>
<Iterate.Array path="/myList" defaultValue={[{}]}>
<Iterate.EditContainer>
<Field.String
label="Item {itemNo}"
itemPath="/foo"
defaultValue="foo"
/>
</Iterate.EditContainer>
<Iterate.ViewContainer>
<Value.String label="Item {itemNo}" itemPath="/foo" />
</Iterate.ViewContainer>
</Iterate.Array>

<Wizard.Buttons />
</Wizard.Step>
</Wizard.Container>

<Tools.Log top />
</Form.Handler>
</ComponentBox>
)
}

export const InitialOpenWithToolbarVariant = () => {
return (
<ComponentBox scope={{ Iterate, Tools }}>
{() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ With an optional `title` and [Iterate.Toolbar](/uilib/extensions/forms/Iterate/T

### Initially open

<Examples.InitiallyOpen />

### Minium one item

This example uses the container's `toolbarVariant` property with the value `minimumOneItem`.

It hides the toolbar in the `EditContainer` when there is only one item in the array. And it hides the remove button in the `ViewContainer` when there is only one item in the array.

<Examples.InitialOpen />
<Examples.InitialOpenWithToolbarVariant />

### With DataContext and add/remove buttons

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback } from 'react'
import { Field, Form, Iterate, Tools, Value, Wizard } from '../..'
import { Card, Flex, Section } from '../../../../components'
import { Card, Flex } from '../../../../components'

export default {
title: 'Eufemia/Extensions/Forms/Iterate',
Expand Down Expand Up @@ -211,7 +211,7 @@ export const InitialOpen = () => {

<Form.SubmitButton variant="send" />

<Output />
<Tools.Log />

{count}
<button type="button" onClick={() => setCount(count + 1)}>
Expand All @@ -223,21 +223,6 @@ export const InitialOpen = () => {
)
}

const Output = () => {
const { data } = Form.useData()

return (
<Section
element="output"
backgroundColor="sand-yellow"
style={{ maxWidth: '80vw' }}
innerSpace
>
<pre>All data: {JSON.stringify(data)}</pre>
</Section>
)
}

export const WithArrayValidator = () => {
return (
<Form.Handler>
Expand Down Expand Up @@ -287,34 +272,50 @@ export function InWizard() {
<Form.Handler>
<Wizard.Container>
<Wizard.Step>
<Field.String
label="Regular"
path="/regular"
defaultValue="123"
/>
<Iterate.Array path="/items" defaultValue={[{}]}>
<Field.String
label="In Iterate"
itemPath="/x"
defaultValue="123"
<Card stack>
<Iterate.Array path="/myList" defaultValue={[{}]}>
<Iterate.ViewContainer>
<Value.String label="Item {itemNo}" itemPath="/foo" />
</Iterate.ViewContainer>
<Iterate.EditContainer>
<Field.String
label="Item {itemNo}"
itemPath="/foo"
defaultValue="foo"
/>
</Iterate.EditContainer>
</Iterate.Array>

<Iterate.PushButton
text="Add"
path="/myList"
variant="tertiary"
pushValue={{}}
/>
</Iterate.Array>
</Card>

<Wizard.Buttons />
</Wizard.Step>

<Wizard.Step>
<Iterate.Array path="/myList" defaultValue={[{}]}>
<Iterate.EditContainer>
<Field.String
label="Item {itemNo}"
itemPath="/foo"
defaultValue="foo"
/>
</Iterate.EditContainer>
<Iterate.ViewContainer>
<Value.String label="Item {itemNo}" itemPath="/foo" />
</Iterate.ViewContainer>
</Iterate.Array>

<Wizard.Buttons />
</Wizard.Step>
</Wizard.Container>

<Tools.Log />
</Form.Handler>

<Form.Handler>
<Iterate.Array path="/myList" defaultValue={[null]}>
<Field.String itemPath="/" defaultValue="bar" />
</Iterate.Array>
<Tools.Log top />
</Form.Handler>
</React.StrictMode>
)
Expand Down
4 changes: 2 additions & 2 deletions packages/dnb-eufemia/src/extensions/forms/Tools/Log.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useContext } from 'react'
import DataContext from '../DataContext/Context'
import Section, { SectionProps } from '../../../components/Section'
import Section, { SectionAllProps } from '../../../components/Section'

function Log({
placeholder,
...props
}: SectionProps & {
}: SectionAllProps & {
placeholder?: React.ReactNode
}) {
const { data } = useContext(DataContext)
Expand Down

0 comments on commit cf279d4

Please sign in to comment.