diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms.mdx index 8d7f2f412cb..83ccb4c8a15 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms.mdx @@ -38,8 +38,8 @@ The goal of the Forms extension is to make it easy to build forms and other data ### Additional features - [Feature fields](/uilib/extensions/forms/feature-fields) such as Email and PhoneNumber. +- [Extended features](/uilib/extensions/forms/extended-features) such as the main [Form.Handler](/uilib/extensions/forms/extended-features/Form/Handler) and [StepsLayout](/uilib/extensions/forms/extended-features/StepsLayout) for creating stepped forms. - [Layout](/uilib/extensions/forms/Layout) to apply default styles for application forms. -- [StepsLayout](/uilib/extensions/forms/advanced-blocks/StepsLayout) to create stepped forms. ### Value components @@ -75,9 +75,9 @@ Or save time and code when handling your forms: ```jsx import '@dnb/eufemia/extensions/forms/style' -import { DataContext, Field } from '@dnb/eufemia/extensions/forms' +import { Form, Field } from '@dnb/eufemia/extensions/forms' render( - - , + , ) ``` @@ -108,13 +108,13 @@ But the real strong parts about Eufemia Forms is the composability when you crea ```jsx import '@dnb/eufemia/extensions/forms/style' -import { DataContext, Field } from '@dnb/eufemia/extensions/forms' +import { Form, Field } from '@dnb/eufemia/extensions/forms' render( - + - , + , ) ``` diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Examples.tsx index f3d808d9b42..b4ae8d0ae03 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Examples.tsx @@ -3,7 +3,7 @@ import { useCallback } from 'react' import ComponentBox from '../../../../shared/tags/ComponentBox' import { Input, Slider } from '@dnb/eufemia/src' import { - DataContext, + Form, Layout, StepsLayout, Field, @@ -11,13 +11,14 @@ import { Visibility, FieldBlock, useDataValue, + DataContext, } from '@dnb/eufemia/src/extensions/forms' export const CreateBasicFieldComponent = () => { return ( { return ( { return ( { return ( { return ( { Visibility, }} > - { - + ) } -export const UsingDataContextProvider = () => { +export const UsingFormHandler = () => { return ( { Visibility, }} > - { - + - + ) } @@ -350,7 +351,7 @@ export const Validation = () => { return ( { Visibility, }} > - { - + ) } @@ -390,7 +391,7 @@ export const WithSteps = () => { return ( { Visibility, }} > - { - + - + ) } diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks.mdx deleted file mode 100644 index c2ac7e6406a..00000000000 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks.mdx +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: 'Advanced blocks' -order: 3 -breadcrumb: - - text: Forms - href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ ---- - -import ListAdvancedAPIs from './advanced-blocks/ListAdvancedAPIs' - -# Advanced blocks - -```jsx -import { StepsLayout } from '@dnb/eufemia/extensions/forms' -render( - - - Profile - - , -) -``` - -## Components - - diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton.mdx deleted file mode 100644 index c6137184a74..00000000000 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton.mdx +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: 'ArrayPushButton' -description: '`Iterate.ArrayPushButton` builds on top of the same data flow logic as field components, but the only thing it changes in the value it receives or retrieves from source data is adding a new element to the array.' -order: 2 -showTabs: true -tabs: - - title: Info - key: '/info' - - title: Demos - key: '/demos' - - title: Properties - key: '/properties' - - title: Events - key: '/events' -breadcrumb: - - text: Forms - href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ - - text: Iterate - href: /uilib/extensions/forms/advanced-blocks/Iterate/ - - text: ArrayPushButton - href: /uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/ ---- - -import Info from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/info' -import Demos from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/demos' -import Properties from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/properties' -import Events from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/events' - - - - - diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton.mdx deleted file mode 100644 index d4b9cc79c15..00000000000 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton.mdx +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: 'ArrayRemoveElementButton' -description: '`Iterate.ArrayRemoveElementButton` connects to the array of a surrounding Iterate.Array and removes the element when clicked.' -order: 3 -showTabs: true -tabs: - - title: Info - key: '/info' - - title: Demos - key: '/demos' - - title: Properties - key: '/properties' - - title: Events - key: '/events' -breadcrumb: - - text: Forms - href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ - - text: Iterate - href: /uilib/extensions/forms/advanced-blocks/Iterate/ - - text: ArrayRemoveElementButton - href: /uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/ ---- - -import Info from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/info' -import Demos from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/demos' -import Properties from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/properties' -import Events from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/events' - - - - - diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/properties.mdx deleted file mode 100644 index 47af032c2e8..00000000000 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/properties.mdx +++ /dev/null @@ -1,9 +0,0 @@ ---- -showTabs: true ---- - -## Properties - -| Property | Type | Description | -| ---------- | ------------ | ------------------------- | -| `children` | `React.Node` | _(required)_ Button text. | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/properties.mdx deleted file mode 100644 index 47af032c2e8..00000000000 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/properties.mdx +++ /dev/null @@ -1,9 +0,0 @@ ---- -showTabs: true ---- - -## Properties - -| Property | Type | Description | -| ---------- | ------------ | ------------------------- | -| `children` | `React.Node` | _(required)_ Button text. | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step/demos.mdx deleted file mode 100644 index c7bb3b3bb8e..00000000000 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step/demos.mdx +++ /dev/null @@ -1,7 +0,0 @@ ---- -showTabs: true ---- - -## Demos - -See [StepsLayout demo section](/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/demos) for examples. diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component.mdx index 060005a3bd3..f5c3f3d0b35 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component.mdx @@ -1,6 +1,6 @@ --- title: 'Create your own component' -order: 3 +order: 4 breadcrumb: - text: Forms href: /uilib/extensions/forms/ diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext.mdx index 676d88b40c2..4bd2567f3e7 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext.mdx @@ -27,6 +27,8 @@ Example of using the `DataContext.Provider`: ``` +Please use [Form.Handler](/uilib/extensions/forms/extended-features/Form/Handler) for application forms. + ## Components diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/At/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/At/Examples.tsx index 86d726ad456..636576dee98 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/At/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/At/Examples.tsx @@ -1,14 +1,15 @@ import ComponentBox from '../../../../../../../shared/tags/ComponentBox' import { - DataContext, + Form, Field, Value, + DataContext, } from '@dnb/eufemia/src/extensions/forms' export const Path = () => { return ( - - + { - + ) } export const IteratePath = () => { return ( - - + { - + ) } diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/Examples.tsx index d0adb09ca24..1176eb7b1c6 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/Examples.tsx @@ -1,6 +1,7 @@ import { JSONSchema7 } from 'json-schema' import ComponentBox from '../../../../../../../shared/tags/ComponentBox' import { + Form, DataContext, Layout, Field, @@ -78,6 +79,7 @@ export const Default = () => { return ( { - + @@ -169,6 +171,7 @@ export const ValidationWithJsonSchema = () => { return ( { - + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/events.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/events.mdx index 588d5a00f09..3321c7b7013 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/events.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/events.mdx @@ -4,9 +4,9 @@ showTabs: true ## Events -| Event | Description | -| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `onChange` | _(optional)_ Will be called when a value of any input component inside was changed by the user, with the data set (including the changed value) as argument. | -| `onPathChange` | _(optional)_ Will be called when a value of any input component inside was changed by the user, with the `path` (JSON Pointer) and new `value` as arguments. | -| `onSubmit` | _(optional)_ Will be called when the user submit the form (i.e by clicking a [SubmitButton](/uilib/extensions/forms/create-component/DataContext/SubmitButton) component inside), with the data set as argument. | -| `onSubmitRequest` | _(optional)_ Will be called when the user tries to submit, but errors stop the data from being submitted. | +| Event | Description | +| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `onChange` | _(optional)_ Will be called when a value of any input component inside was changed by the user, with the data set (including the changed value) as argument. | +| `onPathChange` | _(optional)_ Will be called when a value of any input component inside was changed by the user, with the `path` (JSON Pointer) and new `value` as arguments. | +| `onSubmit` | _(optional)_ Will be called when the user submit the form (i.e by clicking a [SubmitButton](/uilib/extensions/forms/extended-features/SubmitButton) component inside), with the data set as argument. | +| `onSubmitRequest` | _(optional)_ Will be called when the user tries to submit, but errors stop the data from being submitted. | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/info.mdx index be59774d444..0bcc3067c24 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/info.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/Provider/info.mdx @@ -5,3 +5,5 @@ showTabs: true ## Description `DataContext.Provider` is the context provider that has to wrap the features if components of Field and Value is to be used with a common source instead of distributing values and events individually. + +Please use [Form.Handler](/uilib/extensions/forms/extended-features/Form/Handler) for application forms. diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton.mdx deleted file mode 100644 index 446860012bd..00000000000 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton.mdx +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: 'SubmitButton' -description: '`DataContext.SubmitButton` connects to the `DataContext.Context` to submit the active state of the DataContext, triggering `onSubmit`.' -hideInMenu: true -showTabs: true -tabs: - - title: Info - key: '/info' - - title: Demos - key: '/demos' - - title: Properties - key: '/properties' -breadcrumb: - - text: Forms - href: /uilib/extensions/forms/ - - text: Create your component - href: /uilib/extensions/forms/create-component/ - - text: DataContext - href: /uilib/extensions/forms/create-component/DataContext/ - - text: SubmitButton - href: /uilib/extensions/forms/create-component/DataContext/SubmitButton/ ---- - -import Info from 'Docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/info' -import Demos from 'Docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/demos' - - - diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/Examples.tsx deleted file mode 100644 index a0fa301d733..00000000000 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/Examples.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import ComponentBox from '../../../../../../../shared/tags/ComponentBox' -import { DataContext } from '@dnb/eufemia/src/extensions/forms' -import { defaultContextState } from '@dnb/eufemia/src/extensions/forms/DataContext/Context' - -export const Default = () => { - return ( - - console.log('handleSubmit'), - }} - > - - - - ) -} diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/info.mdx deleted file mode 100644 index 0a5d6b26845..00000000000 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/info.mdx +++ /dev/null @@ -1,7 +0,0 @@ ---- -showTabs: true ---- - -## Description - -`DataContext.SubmitButton` connects to the [DataContext.Context](/uilib/extensions/forms/create-component/DataContext/Context/) to submit the active state of the DataContext, triggering `onSubmit`. diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/properties.mdx deleted file mode 100644 index 47af032c2e8..00000000000 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/properties.mdx +++ /dev/null @@ -1,9 +0,0 @@ ---- -showTabs: true ---- - -## Properties - -| Property | Type | Description | -| ---------- | ------------ | ------------------------- | -| `children` | `React.Node` | _(required)_ Button text. | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/Field.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/Field.mdx index f8dcac8f0f1..441ab8021d4 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/Field.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/Field.mdx @@ -10,7 +10,7 @@ breadcrumb: - text: Create your component href: /uilib/extensions/forms/create-component/ - text: Field - href: /uilib/extensions/forms/base-fields/ + href: /uilib/extensions/forms/create-component/Field/ --- import ListBaseFieldComponents from '../base-fields/ListBaseFieldComponents' diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/Value.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/Value.mdx index 90da02e4c05..4af42710165 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/Value.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/Value.mdx @@ -17,7 +17,7 @@ import ListFeatureValueComponents from './Value/ListFeatureValueComponents' # Value -Many screens summarize values from the data set statically, such as a final screen where the user can review the data they have entered before submitting it to the bank. To make displaying such data easier, a number of Value components have been created. These function similarly as field components. That is, they are data-driven, can be given `value`-props, or connected to a surrounding [DataContext.Provider](/uilib/extensions/forms/DataContext/Provider) by pointing to the relevant value they are to display with a `path`-prop. They are also available with more functional variants for given types of data. +Many screens summarize values from the data set statically, such as a final screen where the user can review the data they have entered before submitting it to the bank. To make displaying such data easier, a number of Value components have been created. These function similarly as field components. That is, they are data-driven, can be given `value`-props, or connected to a surrounding [Form.Handler](/uilib/extensions/forms/extended-features/Form/Handler) by pointing to the relevant value they are to display with a `path`-prop. They are also available with more functional variants for given types of data. ```jsx import { Value } from '@dnb/eufemia/extensions/forms' diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/demo-cases/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/demo-cases/Examples.tsx index 4530c10850a..a7c5660f5a8 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/demo-cases/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/demo-cases/Examples.tsx @@ -2,7 +2,7 @@ import ComponentBox from '../../../../../shared/tags/ComponentBox' import { GlobalStatus, Section, Code } from '@dnb/eufemia/src' import * as React from 'react' import { - DataContext, + Form, Layout, StepsLayout, Field, @@ -13,8 +13,8 @@ export const BecomeCorporateCustomer = () => { return ( { return ( <> - console.log('onSubmit', data)} @@ -170,7 +170,7 @@ export const BecomeCorporateCustomer = () => { - + @@ -178,7 +178,7 @@ export const BecomeCorporateCustomer = () => { Kvittering... - + + + + + , +) +``` + +Example using the [StepsLayout](/uilib/extensions/forms/extended-features/StepsLayout) for handling stepped layouts: + +```jsx +import { StepsLayout } from '@dnb/eufemia/extensions/forms' +render( + + + Profile + + , +) +``` + +## Components + + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form.mdx new file mode 100644 index 00000000000..d766bcaacac --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form.mdx @@ -0,0 +1,25 @@ +--- +title: 'Form' +description: '`Form` provides the main forms-helpers including data provider and event handling.' +componentType: 'advanced-api' +hideInMenu: true +showTabs: true +tabs: + - title: Info + key: '/info' + - title: Components + key: '/components' +breadcrumb: + - text: Forms + href: /uilib/extensions/forms/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ + - text: Form + href: /uilib/extensions/forms/extended-features/Form/ +--- + +import Info from 'Docs/uilib/extensions/forms/extended-features/Form/info' +import Components from 'Docs/uilib/extensions/forms/extended-features/Form/components' + + + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element.mdx new file mode 100644 index 00000000000..20363277318 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element.mdx @@ -0,0 +1,28 @@ +--- +title: 'Element' +description: '`Form.Element` is a wrapper component for the HTML form element.' +hideInMenu: true +showTabs: true +tabs: + - title: Info + key: '/info' + - title: Demos + key: '/demos' + - title: Properties + key: '/properties' +breadcrumb: + - text: Forms + href: /uilib/extensions/forms/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ + - text: Form + href: /uilib/extensions/forms/extended-features/Form/ + - text: Element + href: /uilib/extensions/forms/extended-features/Form/Element +--- + +import Info from 'Docs/uilib/extensions/forms/extended-features/Form/Element/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/Form/Element/demos' + + + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/Examples.tsx new file mode 100644 index 00000000000..80bbf103972 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/Examples.tsx @@ -0,0 +1,17 @@ +import ComponentBox from '../../../../../../../shared/tags/ComponentBox' +import { Layout, Form, Field } from '@dnb/eufemia/src/extensions/forms' + +export const DefaultElement = () => { + return ( + + console.log('onSubmit', event)}> + + + + + + + + + ) +} diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/demos.mdx new file mode 100644 index 00000000000..0d38f2d972f --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/demos.mdx @@ -0,0 +1,11 @@ +--- +showTabs: true +--- + +import * as Examples from './Examples' + +## Demos + +### Basic form element + + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/info.mdx new file mode 100644 index 00000000000..7f3412ed664 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/info.mdx @@ -0,0 +1,10 @@ +--- +showTabs: true +--- + +## Description + +`Form.Element` is a wrapper component for the HTML form element. + +- It ensures, users can press **enter key** while focusing on an input field. +- It calls `preventDefault` by default. diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/properties.mdx new file mode 100644 index 00000000000..94a17ba36f9 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Element/properties.mdx @@ -0,0 +1,11 @@ +--- +showTabs: true +--- + +## Properties + +| Property | Type | Description | +| -------------------------------------------------------------------------------------------- | ------------ | --------------------------------------------------------------------- | +| `children` | `React.Node` | _(required)_ The content of the form. | +| [Space](/uilib/components/space/properties) | Various | _(optional)_ spacing properties like `top` or `bottom` are supported. | +| [Form Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attributes) | Various | _(optional)_ all supported form element attributes. | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler.mdx new file mode 100644 index 00000000000..b481ab29adb --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler.mdx @@ -0,0 +1,30 @@ +--- +title: 'Handler' +description: '`Form.Handler` provides both the DataContext.Provider and a HTML form element.' +hideInMenu: true +showTabs: true +tabs: + - title: Info + key: '/info' + - title: Demos + key: '/demos' + - title: Properties + key: '/properties' + - title: Events + key: '/events' +breadcrumb: + - text: Forms + href: /uilib/extensions/forms/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ + - text: Form + href: /uilib/extensions/forms/extended-features/Form/ + - text: Handler + href: /uilib/extensions/forms/extended-features/Form/Handler +--- + +import Info from 'Docs/uilib/extensions/forms/extended-features/Form/Handler/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/Form/Handler/demos' + + + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/Examples.tsx new file mode 100644 index 00000000000..e48231a2dfc --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/Examples.tsx @@ -0,0 +1,20 @@ +import ComponentBox from '../../../../../../../shared/tags/ComponentBox' +import { Layout, Form, Field } from '@dnb/eufemia/src/extensions/forms' + +export const Default = () => { + return ( + + console.log('onSubmit', event)} + > + + + + + + + + + ) +} diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/demos.mdx new file mode 100644 index 00000000000..af13a4c34d1 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/demos.mdx @@ -0,0 +1,11 @@ +--- +showTabs: true +--- + +import * as Examples from './Examples' + +## Demos + +### In combination with a SubmitButton + + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/events.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/events.mdx new file mode 100644 index 00000000000..b37a5e16444 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/events.mdx @@ -0,0 +1,9 @@ +--- +showTabs: true +--- + +## Events + +| Property | Description | +| -------------------------------------------------------------------------------------------------------- | --------------------------------------- | +| All [DataContext.Provider](/uilib/extensions/forms/create-component/DataContext/Provider/events) events. | _(optional)_ events such as `onSubmit`. | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/info.mdx new file mode 100644 index 00000000000..52820c31fd8 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/info.mdx @@ -0,0 +1,24 @@ +--- +showTabs: true +--- + +## Description + +The `Form.Handler` component provides both the [Form.Element](/uilib/extensions/forms/extended-features/Form/Element) and a HTML form element. + +- It ensures, users can press **enter key** while focusing on an input field. +- It calls `preventDefault` by default. + +```jsx +import '@dnb/eufemia/extensions/forms/style' +import { Form } from '@dnb/eufemia/extensions/forms' +render( + + Your Form + , +) +``` diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/properties.mdx new file mode 100644 index 00000000000..2ff0c2ddca1 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/Handler/properties.mdx @@ -0,0 +1,12 @@ +--- +showTabs: true +--- + +## Properties + +| Property | Type | Description | +| ------------------------------------------------------------------------------------------------ | ------------ | --------------------------------------------------------------------- | +| `children` | `React.Node` | _(required)_ The content of the form. | +| [Space](/uilib/components/space/properties) | Various | _(optional)_ spacing properties like `top` or `bottom` are supported. | +| [DataContext.Provider](/uilib/extensions/forms/create-component/DataContext/Provider/properties) | Various | _(optional)_ provider properties such as `data`. | +| [Form Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attributes) | Various | _(optional)_ all supported form element attributes. | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ListComponents.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/ListComponents.tsx similarity index 91% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ListComponents.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/ListComponents.tsx index 00c62666276..de959a89703 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ListComponents.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/ListComponents.tsx @@ -12,7 +12,7 @@ export default function ListComponents() { frontmatter: { title: { ne: null }, draft: { ne: true } } internal: { contentFilePath: { - glob: "**/uilib/extensions/forms/advanced-blocks/Iterate/**/*" + glob: "**/uilib/extensions/forms/extended-features/Form/**/*" } } } diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton.mdx new file mode 100644 index 00000000000..37fd05eb3de --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton.mdx @@ -0,0 +1,28 @@ +--- +title: 'SubmitButton' +description: '`Form.SubmitButton` connects to the `Form.Handler` to submit the active state of the internal DataContext, triggering `onSubmit`.' +hideInMenu: true +showTabs: true +tabs: + - title: Info + key: '/info' + - title: Demos + key: '/demos' + - title: Properties + key: '/properties' +breadcrumb: + - text: Forms + href: /uilib/extensions/forms/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ + - text: Form + href: /uilib/extensions/forms/extended-features/Form + - text: SubmitButton + href: /uilib/extensions/forms/extended-features/Form/SubmitButton/ +--- + +import Info from 'Docs/uilib/extensions/forms/extended-features/Form/SubmitButton/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/Form/SubmitButton/demos' + + + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/Examples.tsx new file mode 100644 index 00000000000..13bc941344c --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/Examples.tsx @@ -0,0 +1,15 @@ +import ComponentBox from '../../../../../../../shared/tags/ComponentBox' +import { Form } from '@dnb/eufemia/src/extensions/forms' + +export const Default = () => { + return ( + + console.log('onSubmit', event)} + > + + + + ) +} diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/demos.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/create-component/DataContext/SubmitButton/demos.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/demos.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/info.mdx new file mode 100644 index 00000000000..ca3ce6bf01e --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/info.mdx @@ -0,0 +1,9 @@ +--- +showTabs: true +--- + +## Description + +`Form.SubmitButton` connects to the [DataContext.Provider](/uilib/extensions/forms/create-component/DataContext/Provider/) to submit the active state of the internal DataContext, triggering `onSubmit`. + +The default button type is `type="submit"`, ready to be used with the [Form.Element](/uilib/extensions/forms/extended-features/Form/Element) diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/properties.mdx new file mode 100644 index 00000000000..0965fbbe66a --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/SubmitButton/properties.mdx @@ -0,0 +1,11 @@ +--- +showTabs: true +--- + +## Properties + +| Property | Type | Description | +| --------------------------------------------- | ------------ | --------------------------------------------------------------------- | +| `children` | `React.Node` | _(required)_ Button text. | +| [Button](/uilib/components/button/properties) | Various | _(optional)_ all button properties. | +| [Space](/uilib/components/space/properties) | Various | _(optional)_ spacing properties like `top` or `bottom` are supported. | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/components.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/components.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/components.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/components.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/info.mdx new file mode 100644 index 00000000000..28b1ea01634 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Form/info.mdx @@ -0,0 +1,22 @@ +--- +showTabs: true +--- + +## Description + +`Form` provides the main forms-helpers including data provider and event handling. + +```jsx +import { Layout } from '@dnb/eufemia' +import { Form, Field } from '@dnb/eufemia/extensions/forms' +render( + + + + + + + + , +) +``` diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate.mdx similarity index 63% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate.mdx index 7393a77c125..359e3739550 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate.mdx @@ -12,14 +12,14 @@ tabs: breadcrumb: - text: Forms href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ - text: Iterate - href: /uilib/extensions/forms/advanced-blocks/Iterate/ + href: /uilib/extensions/forms/extended-features/Iterate/ --- -import Info from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/info' -import Components from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/components' +import Info from 'Docs/uilib/extensions/forms/extended-features/Iterate/info' +import Components from 'Docs/uilib/extensions/forms/extended-features/Iterate/components' diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array.mdx similarity index 54% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array.mdx index f5b6860ee82..fdf0ffc04c2 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array.mdx @@ -15,18 +15,18 @@ tabs: breadcrumb: - text: Forms href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ - text: Iterate - href: /uilib/extensions/forms/advanced-blocks/Iterate/ + href: /uilib/extensions/forms/extended-features/Iterate/ - text: Array - href: /uilib/extensions/forms/advanced-blocks/Iterate/Array/ + href: /uilib/extensions/forms/extended-features/Iterate/Array/ --- -import Info from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/info' -import Demos from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/demos' -import Properties from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/properties' -import Events from 'Docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/events' +import Info from 'Docs/uilib/extensions/forms/extended-features/Iterate/Array/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/Iterate/Array/demos' +import Properties from 'Docs/uilib/extensions/forms/extended-features/Iterate/Array/properties' +import Events from 'Docs/uilib/extensions/forms/extended-features/Iterate/Array/events' diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/Examples.tsx similarity index 95% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/Examples.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/Examples.tsx index 64c3456eae8..f0fe130d495 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/Examples.tsx @@ -4,7 +4,7 @@ import { Layout, Field, Value, - DataContext, + Form, } from '@dnb/eufemia/src/extensions/forms' import { trash as TrashIcon } from '@dnb/eufemia/src/icons' @@ -89,12 +89,12 @@ export const RenderPropsObjectElements = () => { ) } -export const ArrayFromDataContext = () => { +export const ArrayFromFormHandler = () => { return ( - { path="/avengers" pushValue={{}} /> - + ) } diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/demos.mdx similarity index 93% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/demos.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/demos.mdx index 8e86c37bac3..16fcdcd2357 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/demos.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/demos.mdx @@ -29,4 +29,4 @@ import * as Examples from './Examples' points to the root of the data source. - + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/events.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/events.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/events.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/events.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/info.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/info.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/info.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/properties.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/Array/properties.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/Array/properties.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton.mdx new file mode 100644 index 00000000000..ba9ad6c9040 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton.mdx @@ -0,0 +1,34 @@ +--- +title: 'ArrayPushButton' +description: '`Iterate.ArrayPushButton` builds on top of the same data flow logic as field components, but the only thing it changes in the value it receives or retrieves from source data is adding a new element to the array.' +order: 2 +showTabs: true +tabs: + - title: Info + key: '/info' + - title: Demos + key: '/demos' + - title: Properties + key: '/properties' + - title: Events + key: '/events' +breadcrumb: + - text: Forms + href: /uilib/extensions/forms/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ + - text: Iterate + href: /uilib/extensions/forms/extended-features/Iterate/ + - text: ArrayPushButton + href: /uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/ +--- + +import Info from 'Docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/demos' +import Properties from 'Docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/properties' +import Events from 'Docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/events' + + + + + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/Examples.tsx similarity index 81% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/Examples.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/Examples.tsx index 029c7862649..13e561f1338 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/Examples.tsx @@ -1,9 +1,5 @@ import ComponentBox from '../../../../../../../shared/tags/ComponentBox' -import { - Iterate, - Field, - DataContext, -} from '@dnb/eufemia/src/extensions/forms' +import { Iterate, Field, Form } from '@dnb/eufemia/src/extensions/forms' export const PrimitiveElements = () => { return ( @@ -20,8 +16,8 @@ export const PrimitiveElements = () => { export const ObjectElements = () => { return ( - - + { path="/" pushValue={{}} /> - + ) } diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/demos.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/demos.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/demos.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/events.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/events.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/events.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/events.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/info.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/info.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/info.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/properties.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayPushButton/properties.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayPushButton/properties.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton.mdx new file mode 100644 index 00000000000..c7658c21f06 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton.mdx @@ -0,0 +1,34 @@ +--- +title: 'ArrayRemoveElementButton' +description: '`Iterate.ArrayRemoveElementButton` connects to the array of a surrounding Iterate.Array and removes the element when clicked.' +order: 3 +showTabs: true +tabs: + - title: Info + key: '/info' + - title: Demos + key: '/demos' + - title: Properties + key: '/properties' + - title: Events + key: '/events' +breadcrumb: + - text: Forms + href: /uilib/extensions/forms/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ + - text: Iterate + href: /uilib/extensions/forms/extended-features/Iterate/ + - text: ArrayRemoveElementButton + href: /uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/ +--- + +import Info from 'Docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/demos' +import Properties from 'Docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/properties' +import Events from 'Docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/events' + + + + + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/Examples.tsx similarity index 90% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/Examples.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/Examples.tsx index 2d84c82bbc9..c793c7f4834 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/Examples.tsx @@ -3,7 +3,7 @@ import { Iterate, Layout, Field, - DataContext, + Form, } from '@dnb/eufemia/src/extensions/forms' import { trash as TrashIcon } from '@dnb/eufemia/src/icons' @@ -28,8 +28,8 @@ export const PrimitiveElements = () => { export const ObjectElements = () => { return ( - - + { - + ) } diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/demos.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/demos.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/demos.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/events.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/events.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/events.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/events.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/info.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/info.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/info.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/properties.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/ArrayRemoveElementButton/properties.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ArrayRemoveElementButton/properties.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ListComponents.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ListComponents.tsx new file mode 100644 index 00000000000..1db00ba1efa --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/ListComponents.tsx @@ -0,0 +1,40 @@ +import React from 'react' +import { useStaticQuery, graphql } from 'gatsby' +import ListSummaryFromEdges from '../../../../../../shared/parts/ListSummaryFromEdges' + +export default function ListComponents() { + const { + allMdx: { edges }, + } = useStaticQuery(graphql` + { + allMdx( + filter: { + frontmatter: { title: { ne: null }, draft: { ne: true } } + internal: { + contentFilePath: { + glob: "**/uilib/extensions/forms/extended-features/Iterate/**/*" + } + } + } + sort: [ + { frontmatter: { order: ASC } } + { frontmatter: { title: ASC } } + ] + ) { + edges { + node { + fields { + slug + } + frontmatter { + title + description + } + } + } + } + } + `) + + return +} diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/components.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/components.mdx new file mode 100644 index 00000000000..426efc1a609 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/components.mdx @@ -0,0 +1,9 @@ +--- +showTabs: true +--- + +import ListComponents from './ListComponents' + +## Components + + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/info.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Iterate/info.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Iterate/info.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/ListAdvancedAPIs.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/ListAdvancedAPIs.tsx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/ListAdvancedAPIs.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/ListAdvancedAPIs.tsx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout.mdx similarity index 72% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout.mdx index 35e7641aeab..4f26bd9f9da 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout.mdx @@ -6,21 +6,19 @@ hideInMenu: true breadcrumb: - text: Forms href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ - text: StepsLayout - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/ + href: /uilib/extensions/forms/extended-features/StepsLayout/ --- -import * as Examples from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/Examples' -import ListStepsLayoutComponents from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/ListStepsLayoutComponents' +import * as Examples from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/Examples' +import ListStepsLayoutComponents from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/ListStepsLayoutComponents' # StepsLayout `StepsLayout` is a wrapper component for showing forms with a [StepIndicator](/uilib/components/step-indicator/) for navigation between several steps. It also includes components for navigating between steps. -## APIs - ```jsx import { StepsLayout } from '@dnb/eufemia/extensions/forms' ``` diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons.mdx similarity index 50% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons.mdx index 70e27584eb8..1ba94d977ee 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons.mdx @@ -13,16 +13,16 @@ tabs: breadcrumb: - text: Forms href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ - text: StepsLayout - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/ + href: /uilib/extensions/forms/extended-features/StepsLayout/ - text: Buttons - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/ + href: /uilib/extensions/forms/extended-features/StepsLayout/Buttons/ --- -import Info from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/info' -import Demos from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/demos' +import Info from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons/demos' diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons/Examples.tsx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/Examples.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons/Examples.tsx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons/demos.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/demos.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons/demos.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons/info.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/info.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons/info.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons/properties.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Buttons/properties.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Buttons/properties.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/ListStepsLayoutComponents.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/ListStepsLayoutComponents.tsx similarity index 91% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/ListStepsLayoutComponents.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/ListStepsLayoutComponents.tsx index 96f78ece38f..5642853eec3 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/ListStepsLayoutComponents.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/ListStepsLayoutComponents.tsx @@ -12,7 +12,7 @@ export default function ListStepsLayoutComponents() { frontmatter: { title: { ne: null }, draft: { ne: true } } internal: { contentFilePath: { - glob: "**/uilib/extensions/forms/advanced-blocks/StepsLayout/**/*" + glob: "**/uilib/extensions/forms/extended-features/StepsLayout/**/*" } } } diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton.mdx similarity index 51% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton.mdx index e5c5df0a2df..e062869e0df 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton.mdx @@ -14,16 +14,16 @@ tabs: breadcrumb: - text: Forms href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ - text: StepsLayout - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/ + href: /uilib/extensions/forms/extended-features/StepsLayout/ - text: NextButton - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/ + href: /uilib/extensions/forms/extended-features/StepsLayout/NextButton/ --- -import Info from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/info' -import Demos from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/demos' +import Info from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/demos' diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/Examples.tsx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/Examples.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/Examples.tsx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/demos.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/demos.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/demos.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/info.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/NextButton/info.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/info.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/properties.mdx new file mode 100644 index 00000000000..0965fbbe66a --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/NextButton/properties.mdx @@ -0,0 +1,11 @@ +--- +showTabs: true +--- + +## Properties + +| Property | Type | Description | +| --------------------------------------------- | ------------ | --------------------------------------------------------------------- | +| `children` | `React.Node` | _(required)_ Button text. | +| [Button](/uilib/components/button/properties) | Various | _(optional)_ all button properties. | +| [Space](/uilib/components/space/properties) | Various | _(optional)_ spacing properties like `top` or `bottom` are supported. | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton.mdx similarity index 51% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton.mdx index 659077af0ef..68a3462a51e 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton.mdx @@ -14,16 +14,16 @@ tabs: breadcrumb: - text: Forms href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ - text: StepsLayout - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/ + href: /uilib/extensions/forms/extended-features/StepsLayout/ - text: PreviousButton - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/ + href: /uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/ --- -import Info from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/info' -import Demos from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/demos' +import Info from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/demos' diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/Examples.tsx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/Examples.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/Examples.tsx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/demos.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/demos.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/demos.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/info.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/PreviousButton/info.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/info.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/properties.mdx new file mode 100644 index 00000000000..0965fbbe66a --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/PreviousButton/properties.mdx @@ -0,0 +1,11 @@ +--- +showTabs: true +--- + +## Properties + +| Property | Type | Description | +| --------------------------------------------- | ------------ | --------------------------------------------------------------------- | +| `children` | `React.Node` | _(required)_ Button text. | +| [Button](/uilib/components/button/properties) | Various | _(optional)_ all button properties. | +| [Space](/uilib/components/space/properties) | Various | _(optional)_ spacing properties like `top` or `bottom` are supported. | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Step.mdx similarity index 51% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Step.mdx index 6166ce8f7eb..fbdd6af43b9 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Step.mdx @@ -14,16 +14,16 @@ tabs: breadcrumb: - text: Forms href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ - text: StepsLayout - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/ + href: /uilib/extensions/forms/extended-features/StepsLayout/ - text: Step - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/Step/ + href: /uilib/extensions/forms/extended-features/StepsLayout/Step/ --- -import Info from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step/info' -import Demos from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step/demos' +import Info from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/Step/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/Step/demos' diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Step/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Step/demos.mdx new file mode 100644 index 00000000000..c69f04e8f54 --- /dev/null +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Step/demos.mdx @@ -0,0 +1,7 @@ +--- +showTabs: true +--- + +## Demos + +See [StepsLayout demo section](/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/demos) for examples. diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Step/info.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step/info.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Step/info.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Step/properties.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/Step/properties.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/Step/properties.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout.mdx similarity index 54% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout.mdx index 5bc11526a9a..100278dd620 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout.mdx @@ -16,16 +16,16 @@ tabs: breadcrumb: - text: Forms href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ - text: StepsLayout - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/ + href: /uilib/extensions/forms/extended-features/StepsLayout/ - text: StepsLayout - href: /uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/ + href: /uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/ --- -import Info from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/info' -import Demos from 'Docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/demos' +import Info from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/info' +import Demos from 'Docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/demos' diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/Examples.tsx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/Examples.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/Examples.tsx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/demos.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/demos.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/demos.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/events.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/events.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/events.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/events.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/info.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/info.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/info.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/properties.mdx similarity index 90% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/properties.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/properties.mdx index 9dca7c91b13..6e3c99602dc 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/StepsLayout/StepsLayout/properties.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/StepsLayout/StepsLayout/properties.mdx @@ -9,4 +9,4 @@ showTabs: true | `initialActiveIndex` | `number` | _(optional)_ What step should show initially (defaults to 0 for the first one). | | `mode` | `string` | _(optional)_ How to show the steps. Inherited from [StepIndicator](/uilib/components/step-indicator/properties). | | `scrollTopOnStepChange` | `boolean` | _(optional)_ True for the UI to scroll to the top of the page when navigating between steps. | -| `children` | `React.Node` | _(required)_ Contents ([Step](/uilib/extensions/forms/advanced-blocks/StepsLayout/Step) components). | +| `children` | `React.Node` | _(required)_ Contents ([Step](/uilib/extensions/forms/extended-features/StepsLayout/Step) components). | diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility.mdx similarity index 63% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility.mdx index 8eb6e8446ea..9f887df4c36 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility.mdx @@ -12,12 +12,12 @@ tabs: breadcrumb: - text: Forms href: /uilib/extensions/forms/ - - text: Advanced blocks - href: /uilib/extensions/forms/advanced-blocks/ + - text: Extended features + href: /uilib/extensions/forms/extended-features/ - text: Visibility - href: /uilib/extensions/forms/advanced-blocks/Visibility/ + href: /uilib/extensions/forms/extended-features/Visibility/ --- -import Info from 'Docs/uilib/extensions/forms/advanced-blocks/Visibility/info' +import Info from 'Docs/uilib/extensions/forms/extended-features/Visibility/info' diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility/Examples.tsx similarity index 71% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility/Examples.tsx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility/Examples.tsx index 0dcfc5b1d88..f0c77835d00 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility/Examples.tsx @@ -1,7 +1,6 @@ import ComponentBox from '../../../../../../shared/tags/ComponentBox' import { P } from '@dnb/eufemia/src' -import { DataContext, Visibility } from '@dnb/eufemia/src/extensions/forms' -import { defaultContextState } from '@dnb/eufemia/src/extensions/forms/DataContext/Context' +import { Form, Visibility } from '@dnb/eufemia/src/extensions/forms' export const BasedOnBooleanTrue = () => { return ( @@ -33,15 +32,14 @@ export const BasedOnContext = () => { return ( - @@ -50,7 +48,7 @@ export const BasedOnContext = () => { This will not show until `notToBe` is true. - + ) } diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility/demos.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility/demos.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility/demos.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility/info.mdx similarity index 51% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility/info.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility/info.mdx index d3961bfdfe2..7a28c46f59e 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility/info.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility/info.mdx @@ -2,10 +2,10 @@ showTabs: true --- -import Demos from 'Docs/uilib/extensions/forms/advanced-blocks/Visibility/demos' +import Demos from 'Docs/uilib/extensions/forms/extended-features/Visibility/demos' ## Description -The `Visibility` component makes it possible to show or hide components on the screen based on the state of data. It can either be fed with the values directly via props, or it can read data from a surrounding [DataContext.Provider](/uilib/extensions/forms/DataContext/Provider) and show or hide components based on the data it points to. +The `Visibility` component makes it possible to show or hide components on the screen based on the state of data. It can either be fed with the values directly via props, or it can read data from a surrounding [Form.Handler](/uilib/extensions/forms/extended-features/Form/Handler) and show or hide components based on the data it points to. diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility/properties.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility/properties.mdx similarity index 100% rename from packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/advanced-blocks/Visibility/properties.mdx rename to packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/extended-features/Visibility/properties.mdx diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/general-demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/general-demos.mdx index ce270dbc984..76e865e86c3 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/general-demos.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/general-demos.mdx @@ -33,13 +33,13 @@ the need for local styles. -### Using DataContextProvider +### Using Form.Handler -Wrapping fields with a DataContextProvider component lets them read and +Wrapping fields with a Form.Handler component lets them read and write data to one common data set, and have input and output of data in one place instead of connecting to every single field component. - + ### Visibility based on data diff --git a/packages/dnb-eufemia/src/extensions/forms/DataContext/Context.ts b/packages/dnb-eufemia/src/extensions/forms/DataContext/Context.ts index 5dcd4c88274..01ac254dc9b 100644 --- a/packages/dnb-eufemia/src/extensions/forms/DataContext/Context.ts +++ b/packages/dnb-eufemia/src/extensions/forms/DataContext/Context.ts @@ -16,6 +16,7 @@ export interface ContextState { handleUnMountField: (path: string) => void setPathWithError: (path: string, hasError: boolean) => void hasErrors: () => boolean + _isInsideFormElement?: boolean } export const defaultContextState: ContextState = { @@ -29,6 +30,7 @@ export const defaultContextState: ContextState = { handleUnMountField: () => null, hasErrors: () => false, setPathWithError: () => null, + _isInsideFormElement: false, } const Context = React.createContext(defaultContextState) diff --git a/packages/dnb-eufemia/src/extensions/forms/DataContext/__tests__/Provider.test.tsx b/packages/dnb-eufemia/src/extensions/forms/DataContext/__tests__/Provider.test.tsx index 93531f10143..ce4a900e8a4 100644 --- a/packages/dnb-eufemia/src/extensions/forms/DataContext/__tests__/Provider.test.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/DataContext/__tests__/Provider.test.tsx @@ -1,7 +1,6 @@ import React from 'react' import { fireEvent, render, screen } from '@testing-library/react' -import { Field } from '../../' -import DataContext from '../' +import { Form, DataContext, Field } from '../../' import { JSONSchema7 } from 'json-schema' describe('DataContext.Provider', () => { @@ -136,7 +135,7 @@ describe('DataContext.Provider', () => { onSubmit={onSubmit} > - Submit + Submit ) @@ -157,7 +156,7 @@ describe('DataContext.Provider', () => { onSubmit={onSubmit} > - Submit + Submit ) @@ -179,7 +178,7 @@ describe('DataContext.Provider', () => { onSubmitRequest={onSubmitRequest} > - Submit + Submit ) @@ -200,7 +199,7 @@ describe('DataContext.Provider', () => { onSubmitRequest={onSubmitRequest} > - Submit + Submit ) @@ -230,7 +229,7 @@ describe('DataContext.Provider', () => { schema={TestdataSchema} > - Submit + Submit ) @@ -252,7 +251,7 @@ describe('DataContext.Provider', () => { schema={TestdataSchema} > - Submit + Submit ) @@ -278,7 +277,7 @@ describe('DataContext.Provider', () => { scrollTopOnSubmit > - Submit + Submit ) @@ -301,7 +300,7 @@ describe('DataContext.Provider', () => { scrollTopOnSubmit > - Submit + Submit ) diff --git a/packages/dnb-eufemia/src/extensions/forms/DataContext/index.ts b/packages/dnb-eufemia/src/extensions/forms/DataContext/index.ts index 363e53b0314..04fbd2cb3c6 100644 --- a/packages/dnb-eufemia/src/extensions/forms/DataContext/index.ts +++ b/packages/dnb-eufemia/src/extensions/forms/DataContext/index.ts @@ -1,12 +1,10 @@ import Context, { ContextState } from './Context' import Provider from './Provider' -import SubmitButton from './SubmitButton' import At from './At' const DataContext = { Context, Provider, - SubmitButton, At, } diff --git a/packages/dnb-eufemia/src/extensions/forms/Form/FormElement.tsx b/packages/dnb-eufemia/src/extensions/forms/Form/FormElement.tsx new file mode 100644 index 00000000000..dbed42ca8b8 --- /dev/null +++ b/packages/dnb-eufemia/src/extensions/forms/Form/FormElement.tsx @@ -0,0 +1,43 @@ +import React from 'react' +import Context from '../DataContext/Context' +import Space from '../../../components/space/Space' +import classnames from 'classnames' +import type { SpacingProps } from '../../../shared/types' + +export type Props = React.HTMLAttributes & SpacingProps + +export default function FormElement({ + children, + className = null, + onSubmit = null, + ...rest +}: Props) { + const dataContext = React.useContext(Context) + + /** + * Set to true, + * this way we prevent "handleSubmit" to be called twice when the SubmitButton is pressed. + */ + dataContext._isInsideFormElement = true + + return ( + + {children} + + ) + + function onSubmitHandler(event: React.SyntheticEvent) { + event?.preventDefault() + + dataContext?.handleSubmit?.() + + if (typeof onSubmit === 'function') { + onSubmit(event) + } + } +} diff --git a/packages/dnb-eufemia/src/extensions/forms/Form/FormHandler.tsx b/packages/dnb-eufemia/src/extensions/forms/Form/FormHandler.tsx new file mode 100644 index 00000000000..b7bbb5e53af --- /dev/null +++ b/packages/dnb-eufemia/src/extensions/forms/Form/FormHandler.tsx @@ -0,0 +1,39 @@ +import React from 'react' +import { JsonObject } from 'json-pointer' +import Provider, { Props as ProviderProps } from '../DataContext/Provider' +import FormElement from './FormElement' +import type { SpacingProps } from '../../../shared/types' + +export type Props = React.HTMLAttributes & SpacingProps + +export default function FormHandler({ + children, + data, + schema, + onChange, + onPathChange, + onSubmit, + onSubmitRequest, + scrollTopOnSubmit, + ...rest +}: ProviderProps & Props) { + const ProviderProps = { + data, + schema, + onChange, + onPathChange, + onSubmit: (data: Data) => { + if (typeof onSubmit === 'function') { + onSubmit(data) + } + }, + onSubmitRequest, + scrollTopOnSubmit, + } + + return ( + + {children} + + ) +} diff --git a/packages/dnb-eufemia/src/extensions/forms/DataContext/SubmitButton.tsx b/packages/dnb-eufemia/src/extensions/forms/Form/SubmitButton.tsx similarity index 61% rename from packages/dnb-eufemia/src/extensions/forms/DataContext/SubmitButton.tsx rename to packages/dnb-eufemia/src/extensions/forms/Form/SubmitButton.tsx index bac32763080..b8b043d9e50 100644 --- a/packages/dnb-eufemia/src/extensions/forms/DataContext/SubmitButton.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/Form/SubmitButton.tsx @@ -3,24 +3,28 @@ import classnames from 'classnames' import type { ComponentProps } from '../types' import { Button } from '../../../components' import SharedContext from '../../../shared/Context' -import Context from './Context' +import Context from '../DataContext/Context' -export type Props = ComponentProps & { - children?: string -} +export type Props = ComponentProps & + Partial> function SubmitButton(props: Props) { const sharedContext = useContext(SharedContext) const { className, children = sharedContext?.translation.Forms.contextSubmit, + ...rest } = props const dataContext = useContext(Context) return ( {children} diff --git a/packages/dnb-eufemia/src/extensions/forms/Form/__tests__/FormElement.test.tsx b/packages/dnb-eufemia/src/extensions/forms/Form/__tests__/FormElement.test.tsx new file mode 100644 index 00000000000..47141bf3480 --- /dev/null +++ b/packages/dnb-eufemia/src/extensions/forms/Form/__tests__/FormElement.test.tsx @@ -0,0 +1,148 @@ +import React from 'react' +import { fireEvent, render } from '@testing-library/react' +import { Form, DataContext, Field } from '../..' + +describe('Form.Element', () => { + it('should call "onSubmit"', () => { + const onSubmitElement = jest.fn() + + render( + + + Submit + + ) + + const inpuptElement = document.querySelector('input') + const buttonElement = document.querySelector('button') + + fireEvent.submit(inpuptElement) + + expect(onSubmitElement).toHaveBeenCalledTimes(1) + + fireEvent.click(buttonElement) + + expect(onSubmitElement).toHaveBeenCalledTimes(2) + + expect(onSubmitElement).toHaveBeenCalledWith( + expect.objectContaining({ type: 'submit', target: inpuptElement }) + ) + }) + + it('should call "onSubmit" from Provider at the same time', () => { + const onSubmit = jest.fn() + const onSubmitElement = jest.fn() + + render( + + + + Submit + + + ) + + const inpuptElement = document.querySelector('input') + const buttonElement = document.querySelector('button') + + fireEvent.submit(inpuptElement) + + expect(onSubmit).toHaveBeenCalledTimes(1) + expect(onSubmit).toHaveBeenCalledWith({ foo: 'data-context-value' }) + expect(onSubmitElement).toHaveBeenCalledTimes(1) + + fireEvent.click(buttonElement) + + expect(onSubmit).toHaveBeenCalledTimes(2) + expect(onSubmit).toHaveBeenCalledWith({ foo: 'data-context-value' }) + expect(onSubmitElement).toHaveBeenCalledTimes(2) + + expect(onSubmitElement).toHaveBeenCalledWith( + expect.objectContaining({ type: 'submit', target: inpuptElement }) + ) + }) + + it('should call preventDefault', () => { + const preventDefault = jest.fn() + const onSubmitElement = jest.fn(preventDefault) + + render( + + + Submit + + ) + + const inpuptElement = document.querySelector('input') + const buttonElement = document.querySelector('button') + + fireEvent.submit(inpuptElement) + + expect(preventDefault).toHaveBeenCalledTimes(1) + expect(onSubmitElement).toHaveBeenCalledTimes(1) + + fireEvent.click(buttonElement) + + expect(preventDefault).toHaveBeenCalledTimes(2) + expect(onSubmitElement).toHaveBeenCalledTimes(2) + }) + + it('should default to form element', () => { + render( + + Submit + + ) + + const formElement = document.querySelector('.dnb-forms__form') + + expect(formElement.tagName).toBe('FORM') + }) + + it('should set custom "className"', () => { + render( + + Submit + + ) + + const formElement = document.querySelector('form') + + expect(Array.from(formElement.classList)).toEqual([ + 'dnb-space', + 'dnb-forms__form', + 'custom-class', + ]) + }) + + it('should handle spacing prop', () => { + render( + + Submit + + ) + + const formElement = document.querySelector('form') + + expect(formElement.classList).toContain('dnb-space__top--large') + }) + + it('should forward custom HTML props', () => { + render( + + Submit + + ) + + const formElement = document.querySelector('form') + const attributes = Array.from(formElement.attributes).map( + (attr) => attr.name + ) + + expect(attributes).toEqual(['class', 'aria-label']) + expect(formElement.getAttribute('aria-label')).toBe('Aria Label') + }) +}) diff --git a/packages/dnb-eufemia/src/extensions/forms/Form/__tests__/FormHandler.test.tsx b/packages/dnb-eufemia/src/extensions/forms/Form/__tests__/FormHandler.test.tsx new file mode 100644 index 00000000000..d4a18f24563 --- /dev/null +++ b/packages/dnb-eufemia/src/extensions/forms/Form/__tests__/FormHandler.test.tsx @@ -0,0 +1,150 @@ +import React from 'react' +import { fireEvent, render } from '@testing-library/react' +import { Form, Field } from '../..' + +describe('Form.Handler', () => { + it('should call "onSubmit"', () => { + const onSubmit = jest.fn() + + render( + + + Submit + + ) + + const inpuptElement = document.querySelector('input') + const buttonElement = document.querySelector('button') + + fireEvent.submit(inpuptElement) + + expect(onSubmit).toHaveBeenCalledTimes(1) + expect(onSubmit).toHaveBeenCalledWith({ foo: 'data-context-value' }) + + fireEvent.change(inpuptElement, { target: { value: 'New Value' } }) + fireEvent.click(buttonElement) + + expect(onSubmit).toHaveBeenCalledTimes(2) + expect(onSubmit).toHaveBeenCalledWith({ foo: 'New Value' }) + }) + + it('should call "onSubmit" from Provider at the same time', () => { + const onSubmit = jest.fn() + + render( + + + Submit + + ) + + const inpuptElement = document.querySelector('input') + const buttonElement = document.querySelector('button') + + fireEvent.submit(inpuptElement) + + expect(onSubmit).toHaveBeenCalledTimes(1) + expect(onSubmit).toHaveBeenCalledWith({ foo: 'data-context-value' }) + + fireEvent.click(buttonElement) + + expect(onSubmit).toHaveBeenCalledTimes(2) + expect(onSubmit).toHaveBeenCalledWith({ foo: 'data-context-value' }) + }) + + it('should call preventDefault', () => { + const preventDefault = jest.fn() + const onSubmit = jest.fn(preventDefault) + + render( + + + Submit + + ) + + const inpuptElement = document.querySelector('input') + const buttonElement = document.querySelector('button') + + fireEvent.submit(inpuptElement) + + expect(preventDefault).toHaveBeenCalledTimes(1) + expect(onSubmit).toHaveBeenCalledTimes(1) + + fireEvent.click(buttonElement) + + expect(preventDefault).toHaveBeenCalledTimes(2) + expect(onSubmit).toHaveBeenCalledTimes(2) + }) + + it('should default to form element', () => { + render( + + Submit + + ) + + const formElement = document.querySelector('.dnb-forms__form') + + expect(formElement.tagName).toBe('FORM') + }) + + it('should set custom "className"', () => { + render( + + Submit + + ) + + const formElement = document.querySelector('form') + + expect(Array.from(formElement.classList)).toEqual([ + 'dnb-space', + 'dnb-forms__form', + 'custom-class', + ]) + }) + + it('should handle spacing prop', () => { + render( + + Submit + + ) + + const formElement = document.querySelector('form') + + expect(formElement.classList).toContain('dnb-space__top--large') + }) + + it('should forward custom HTML props', () => { + render( + + Submit + + ) + + const formElement = document.querySelector('form') + const attributes = Array.from(formElement.attributes).map( + (attr) => attr.name + ) + + expect(attributes).toEqual(['class', 'aria-label']) + expect(formElement.getAttribute('aria-label')).toBe('Aria Label') + }) +}) diff --git a/packages/dnb-eufemia/src/extensions/forms/Form/__tests__/SubmitButton.test.tsx b/packages/dnb-eufemia/src/extensions/forms/Form/__tests__/SubmitButton.test.tsx new file mode 100644 index 00000000000..372d3b6feaf --- /dev/null +++ b/packages/dnb-eufemia/src/extensions/forms/Form/__tests__/SubmitButton.test.tsx @@ -0,0 +1,104 @@ +import React from 'react' +import { fireEvent, render } from '@testing-library/react' +import { Form, Field } from '../..' + +describe('Form.SubmitButton', () => { + it('should call "onSubmit" on form element', () => { + const onSubmit = jest.fn() + + render( + + + Submit + + ) + + const buttonElement = document.querySelector('button') + + fireEvent.click(buttonElement) + + expect(onSubmit).toHaveBeenCalledTimes(1) + + fireEvent.submit(buttonElement) + + expect(onSubmit).toHaveBeenCalledTimes(2) + + expect(onSubmit).toHaveBeenCalledWith( + expect.objectContaining({ type: 'submit', target: buttonElement }) + ) + }) + + it('should call preventDefault', () => { + const preventDefault = jest.fn() + const onSubmit = jest.fn(preventDefault) + + render( + + Submit + + ) + + const buttonElement = document.querySelector('button') + + fireEvent.click(buttonElement) + + expect(preventDefault).toHaveBeenCalledTimes(1) + expect(onSubmit).toHaveBeenCalledTimes(1) + + fireEvent.submit(buttonElement) + + expect(preventDefault).toHaveBeenCalledTimes(2) + expect(onSubmit).toHaveBeenCalledTimes(2) + }) + + it('should default to button element with type of submit', () => { + render( + + Submit + + ) + + const buttonElement = document.querySelector('button') + + expect(buttonElement.tagName).toBe('BUTTON') + expect(buttonElement.type).toBe('submit') + }) + + it('should set custom "className"', () => { + render( + + + Submit + + + ) + + const buttonElement = document.querySelector('button') + + expect(Array.from(buttonElement.classList)).toEqual([ + 'dnb-button', + 'dnb-button--primary', + 'dnb-button--has-text', + 'dnb-forms__submit-button', + 'custom-class', + ]) + }) + + it('should forward custom HTML props', () => { + render( + + + Submit + + + ) + + const buttonElement = document.querySelector('button') + const attributes = Array.from(buttonElement.attributes).map( + (attr) => attr.name + ) + + expect(attributes).toEqual(['class', 'type', 'aria-label']) + expect(buttonElement.getAttribute('aria-label')).toBe('Aria Label') + }) +}) diff --git a/packages/dnb-eufemia/src/extensions/forms/Form/index.ts b/packages/dnb-eufemia/src/extensions/forms/Form/index.ts new file mode 100644 index 00000000000..a7de2695e55 --- /dev/null +++ b/packages/dnb-eufemia/src/extensions/forms/Form/index.ts @@ -0,0 +1,11 @@ +import SubmitButton from './SubmitButton' +import Element from './FormElement' +import Handler from './FormHandler' + +const FormExport = { + Handler, + Element, + SubmitButton, +} + +export default FormExport diff --git a/packages/dnb-eufemia/src/extensions/forms/index.ts b/packages/dnb-eufemia/src/extensions/forms/index.ts index 544e9d2cfea..3c42730e639 100644 --- a/packages/dnb-eufemia/src/extensions/forms/index.ts +++ b/packages/dnb-eufemia/src/extensions/forms/index.ts @@ -4,6 +4,7 @@ export { default as FieldBlock } from './FieldBlock' export { default as Field } from './Field' export { default as Iterate } from './Iterate' export { default as ValueBlock } from './ValueBlock' +export { default as Form } from './Form' export { default as Value } from './Value' export { default as Layout } from './Layout' export { default as StepsLayout, StepsContext } from './StepsLayout'
This will not show until `notToBe` is true.