From 2c150e1053a6a9e063b1c4d9e3020ddd48e74563 Mon Sep 17 00:00:00 2001 From: Joakim Bjerknes Date: Wed, 14 Aug 2024 13:40:43 +0200 Subject: [PATCH] Update examples --- .../forms/Form/Isolation/Examples.tsx | 197 ++++++++++++------ .../extensions/forms/Form/Isolation/demos.mdx | 8 + 2 files changed, 136 insertions(+), 69 deletions(-) diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Form/Isolation/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Form/Isolation/Examples.tsx index 568b1856cb6..b8cff4527d1 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Form/Isolation/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Form/Isolation/Examples.tsx @@ -1,5 +1,5 @@ import ComponentBox from '../../../../../../shared/tags/ComponentBox' -import { Card, Flex, Section } from '@dnb/eufemia/src' +import { Card, Code, Flex, Section } from '@dnb/eufemia/src' import { Field, Form, Iterate } from '@dnb/eufemia/src/extensions/forms' import React from 'react' @@ -49,34 +49,67 @@ export const CommitHandleRef = () => { const commitHandleRef = React.useRef(null) return ( - - - Ny hovedkontaktperson - - - - - - - - - - - + <> + + + Ny hovedkontaktperson + + { + const transformedData = { + ...handlerData, + contactPersons: [ + ...handlerData.contactPersons, + { + title: isolatedData.newPerson.title, + value: + isolatedData.newPerson.title.toLowerCase(), + }, + ], + } + + return transformedData + }} + > + + + + + + + + + + + ) } const Log = () => { const { data } = Form.useData() return ( -
-
{JSON.stringify(data)}
+
+ {JSON.stringify(data || {}, null, 4)}
) } @@ -90,55 +123,81 @@ export const CommitHandleRef = () => { export const TransformCommitData = () => { return ( - - - Legg til ny hovedkontaktperson - - - - + {() => { + const MyForm = () => { + return ( + + + + Legg til ny hovedkontaktperson + + - Annen person - - - - Ny hovedkontaktperson - { - return { - ...outerData, - persons: [ - ...outerData.persons, - isolatedData.newPerson, - ], - } - }} - > - - - - + + + + Ny hovedkontaktperson + + { + const lastPersonIndex = + handlerData.people.length - 1 - - - - - + return { + ...handlerData, + people: [ + ...handlerData.people.slice( + 0, + lastPersonIndex, + ), + { + ...isolatedData.newPerson, + value: + isolatedData.newPerson.title.toLowerCase(), + }, + handlerData.people[lastPersonIndex], + ], + } + }} + > + + + + - - - + + + + + + + + + + ) + } + + return + }} ) } diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Form/Isolation/demos.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Form/Isolation/demos.mdx index 682b7e985e8..8adcd06cdb7 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Form/Isolation/demos.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Form/Isolation/demos.mdx @@ -10,3 +10,11 @@ import * as Examples from './Examples' ### Using the CommitButton + +### Using commitHandleRef + + + +### Transform data on commit + +