Skip to content

Commit

Permalink
feat(Forms): Extension (beta) for simplified implementation of web fo…
Browse files Browse the repository at this point in the history
…rms through tailored functionality for layout and data handling (#2420)

## Summary

This is an extension to the base components of Eufemia for data input,
display and layout surrounding data input/display.

## Details

For more information about the architecture and idea behind how these
components are structured, I would recommend reading the documentation
for the extension that is added to the portal in the PR. Both in the
base extension page (`/uilib/extensions/deposit/`), the provided demos
there, as well as the base pages of each group of components (like
`/uilib/extensions/deposit/DataInput/`) and each component page. For
more detailed questions or discussions, please contact me on Slack.

<img width="2015" alt="Screenshot 2023-06-01 at 14 24 28"
src="https://github.com/dnbexperience/eufemia/assets/2526740/b7ce2b07-db7e-4479-9088-93f77a4c0dba">

## Test plan

<!-- Demonstrate the code is solid. Example: The exact commands you ran
and their output, screenshots / videos if the pull request changes UI.
-->

---------

Co-authored-by: Henrik Haugberg <[email protected]>
Co-authored-by: Tobias Høegh <[email protected]>
Co-authored-by: -l <[email protected]>
  • Loading branch information
4 people authored Aug 17, 2023
1 parent d8cfb1c commit 74700c0
Show file tree
Hide file tree
Showing 437 changed files with 15,589 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/dnb-design-system-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@babel/node": "7.22.5",
"@emotion/cache": "11.11.0",
"@playwright/test": "1.35.1",
"@types/json-schema": "7.0.12",
"@types/react": "18.2.13",
"@types/react-dom": "18.2.6",
"@typescript-eslint/parser": "5.60.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: 'Forms'
description: 'Reusable components for data input, data display and surrounding layout for simplified user interface creation in React, built on top of base Eufemia components.'
showTabs: true
status: 'beta'
order: 2
tabs:
- title: Info
key: /uilib/extensions/forms/info
- title: Demos
key: /uilib/extensions/forms/demos
- title: Case demo 1
key: /uilib/extensions/forms/casedemo1
---

import Info from 'Docs/uilib/extensions/forms/info'
import Demos from 'Docs/uilib/extensions/forms/demos'

<Info />
<Demos />
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: 'DataContext'
order: 0
showTabs: true
tabs:
- title: Info
key: '/info'
- title: Components
key: '/components'
---

import Info from 'Docs/uilib/extensions/forms/DataContext/info'
import Components from 'Docs/uilib/extensions/forms/DataContext/components'

<Info />
<Components />
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: 'At'
description: '`DataContext.At` makes it possible to dig into a data set to set a pointer as the root for sub components, as well as iterate array-data'
showTabs: true
tabs:
- title: Info
key: '/info'
- title: Demos
key: '/demos'
- title: Properties
key: '/properties'
---

import Info from 'Docs/uilib/extensions/forms/DataContext/At/info'
import Demos from 'Docs/uilib/extensions/forms/DataContext/At/demos'
import Properties from 'Docs/uilib/extensions/forms/DataContext/At/properties'

<Info />
<Demos />
<Properties />
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import ComponentBox from '../../../../../../shared/tags/ComponentBox'
import {
DataContext,
Field,
Value,
} from '@dnb/eufemia/src/extensions/forms'

export const Path = () => {
return (
<ComponentBox scope={{ DataContext, Field }}>
<DataContext.Provider
data={{
foo: {
one: 1,
two: 2,
},
bar: 'Bar',
}}
>
<DataContext.At path="/foo">
<Field.Number path="/one" label="One" />
<Field.Number path="/two" label="Two" />
</DataContext.At>
</DataContext.Provider>
</ComponentBox>
)
}

export const IteratePath = () => {
return (
<ComponentBox scope={{ DataContext, Field, Value }}>
<DataContext.Provider
data={{
list: [
{
title: 'Object 1',
},
{
title: 'Object 2',
},
],
bar: 'Bar',
}}
onChange={(data) => console.log('onChange', data)}
onPathChange={(path, value) =>
console.log('onPathChange', path, value)
}
>
<DataContext.At path="/list" iterate>
<Value.String path="/title" label="Title" />
<Field.String path="/title" label="Title" />
</DataContext.At>
</DataContext.Provider>
</ComponentBox>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
showTabs: true
---

import * as Examples from './Examples'

## Demos

### At path

<Examples.Path />

### Iterate path

<Examples.IteratePath />
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
showTabs: true
---

## Description

`DataContext.At` makes it possible to dig into a data set to set a pointer as the root for sub components, as well as iterate array-data.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
showTabs: true
---

## Properties

| Property | Type | Description |
| ---------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `children` | `React.Node` | _(optional)_ Features with given path as root for the DataContext. |
| `path` | `string` | _(optional)_ JSON Pointer path to where in the outer DataContext source to point at. |
| `iterate` | `boolean` | _(optional)_ True to iterate elements at given path based on the source data, including the index in the outer path, instead of just rendering children once. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: 'Context'
description: 'The context object used in `DataContext.Provider`.'
showTabs: false
---

# DataContext.Context

## Description

The main context for [DataContext.Provider](/uilib/extensions/forms/DataContext/Provider) which the [Field](/uilib/extensions/forms/Field/) and [Value](/uilib/extensions/forms/Value/) components connect to (optional) for sources and callbacks when it is present. It can be used for creating custom components in similar ways.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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, nin: "Fragments" }
draft: { ne: true }
}
internal: {
contentFilePath: {
glob: "**/uilib/extensions/forms/DataContext/**/*"
}
}
}
sort: [
{ frontmatter: { order: ASC } }
{ frontmatter: { title: ASC } }
]
) {
edges {
node {
fields {
slug
}
frontmatter {
title
description
}
}
}
}
}
`)

return <ListSummaryFromEdges edges={edges} />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: 'Provider'
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.'
showTabs: true
tabs:
- title: Info
key: '/info'
- title: Demos
key: '/demos'
- title: Properties
key: '/properties'
- title: Events
key: '/events'
---

import Info from 'Docs/uilib/extensions/forms/DataContext/Provider/info'
import Demos from 'Docs/uilib/extensions/forms/DataContext/Provider/demos'
import Properties from 'Docs/uilib/extensions/forms/DataContext/Provider/properties'
import Events from 'Docs/uilib/extensions/forms/DataContext/Provider/events'

<Info />
<Demos />
<Properties />
<Events />
Loading

1 comment on commit 74700c0

@vercel
Copy link

@vercel vercel bot commented on 74700c0 Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.