-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Forms): add EditButton, CancelButton and DoneButton to Form.Sect…
…ion containers
- Loading branch information
1 parent
3e92934
commit 6072bb4
Showing
27 changed files
with
907 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...b-design-system-portal/src/docs/uilib/extensions/forms/Form/Section/Toolbar.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
title: 'Toolbar' | ||
description: '`Form.Section.Toolbar` is a helper component to be used within an `Form.Section.ViewContainer` and `Form.Section.EditContainer`.' | ||
showTabs: true | ||
tabs: | ||
- title: Info | ||
key: '/info' | ||
- title: Demos | ||
key: '/demos' | ||
breadcrumb: | ||
- text: Forms | ||
href: /uilib/extensions/forms/Form/ | ||
- text: Section | ||
href: /uilib/extensions/forms/Form/Section/ | ||
- text: Toolbar | ||
href: /uilib/extensions/forms/Form/Section/Toolbar/ | ||
--- | ||
|
||
import Info from 'Docs/uilib/extensions/forms/Form/Section/Toolbar/info' | ||
import Demos from 'Docs/uilib/extensions/forms/Form/Section/Toolbar/demos' | ||
|
||
<Info /> | ||
<Demos /> |
28 changes: 28 additions & 0 deletions
28
...nb-design-system-portal/src/docs/uilib/extensions/forms/Form/Section/Toolbar/Examples.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import ComponentBox from '../../../../../../../shared/tags/ComponentBox' | ||
import { Button } from '@dnb/eufemia/src' | ||
import { Form } from '@dnb/eufemia/src/extensions/forms' | ||
|
||
export const ViewAndEditContainer = () => { | ||
return ( | ||
<ComponentBox> | ||
<Form.Section> | ||
<Form.Section.ViewContainer> | ||
View content | ||
<Form.Section.Toolbar> | ||
<Button variant="tertiary">Your Tool</Button> | ||
<Form.Section.ViewContainer.EditButton /> | ||
</Form.Section.Toolbar> | ||
</Form.Section.ViewContainer> | ||
|
||
<Form.Section.EditContainer> | ||
Edit content | ||
<Form.Section.Toolbar> | ||
<Button variant="tertiary">Your Tool</Button> | ||
<Form.Section.EditContainer.DoneButton /> | ||
<Form.Section.EditContainer.CancelButton /> | ||
</Form.Section.Toolbar> | ||
</Form.Section.EditContainer> | ||
</Form.Section> | ||
</ComponentBox> | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
...gn-system-portal/src/docs/uilib/extensions/forms/Form/Section/Toolbar/demos.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
showTabs: true | ||
hideInMenu: true | ||
--- | ||
|
||
import * as Examples from './Examples' | ||
|
||
## Demos | ||
|
||
### Using ViewContainer and EditContainer | ||
|
||
<Examples.ViewAndEditContainer /> |
35 changes: 35 additions & 0 deletions
35
...ign-system-portal/src/docs/uilib/extensions/forms/Form/Section/Toolbar/info.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
showTabs: true | ||
hideInMenu: true | ||
--- | ||
|
||
## Description | ||
|
||
`Form.Section.Toolbar` is a helper component to be used within the [Form.Section.ViewContainer](/uilib/extensions/forms/Form/Section/ViewContainer/) and the [Form.Section.EditContainer](/uilib/extensions/forms/Form/Section/EditContainer/). | ||
|
||
## Customize the Toolbar | ||
|
||
You can customize the toolbar by either passing a function as a child or as a JSX element: | ||
|
||
```tsx | ||
import { Form } from '@dnb/eufemia/extensions/forms' | ||
|
||
render( | ||
<Form.Section> | ||
<Form.Section.ViewContainer> | ||
View content | ||
<Form.Section.Toolbar> | ||
<Form.Section.ViewContainer.EditButton /> | ||
</Form.Section.Toolbar> | ||
</Form.Section.ViewContainer> | ||
|
||
<Form.Section.EditContainer> | ||
Edit content | ||
<Form.Section.Toolbar> | ||
<Form.Section.EditContainer.DoneButton /> | ||
<Form.Section.EditContainer.CancelButton /> | ||
</Form.Section.Toolbar> | ||
</Form.Section.EditContainer> | ||
</Form.Section>, | ||
) | ||
``` |
11 changes: 11 additions & 0 deletions
11
...stem-portal/src/docs/uilib/extensions/forms/Form/Section/Toolbar/properties.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
showTabs: true | ||
hideInMenu: true | ||
--- | ||
|
||
import PropertiesTable from 'dnb-design-system-portal/src/shared/parts/PropertiesTable' | ||
import { ToolbarProperties } from '@dnb/eufemia/src/extensions/forms/Form/Section/Toolbar/ToolbarDocs' | ||
|
||
## Properties | ||
|
||
<PropertiesTable props={ToolbarProperties} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/dnb-eufemia/src/extensions/forms/Form/Section/EditContainer/CancelButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useCallback, useContext } from 'react' | ||
import SectionContainerContext from '../containers/SectionContainerContext' | ||
import ToolbarContext from '../Toolbar/ToolbarContext' | ||
import { useTranslation } from '../../../hooks' | ||
import { Button } from '../../../../../components' | ||
import { close } from '../../../../../icons' | ||
import useContainerDataStore from './useContainerDataStore' | ||
import FieldBoundaryContext from '../../../DataContext/FieldBoundary/FieldBoundaryContext' | ||
|
||
export default function CancelButton() { | ||
const { onCancel, setShowError } = useContext(ToolbarContext) || {} | ||
const { restoreOriginalData } = useContainerDataStore() | ||
const { switchContainerMode, initialContainerMode } = | ||
useContext(SectionContainerContext) || {} | ||
const { | ||
hasVisibleError, | ||
hasSubmitError, | ||
hasError, | ||
setShowBoundaryErrors, | ||
} = useContext(FieldBoundaryContext) || {} | ||
|
||
const translation = useTranslation().SectionEditContainer | ||
|
||
const cancelHandler = useCallback(() => { | ||
if (hasSubmitError || (initialContainerMode === 'auto' && hasError)) { | ||
setShowBoundaryErrors?.(Date.now()) | ||
if (hasVisibleError) { | ||
setShowError(true) | ||
} | ||
} else { | ||
setShowError(false) | ||
setShowBoundaryErrors?.(false) | ||
restoreOriginalData() | ||
switchContainerMode?.('view') | ||
onCancel?.() | ||
} | ||
}, [ | ||
hasError, | ||
hasSubmitError, | ||
hasVisibleError, | ||
initialContainerMode, | ||
onCancel, | ||
restoreOriginalData, | ||
setShowBoundaryErrors, | ||
setShowError, | ||
switchContainerMode, | ||
]) | ||
|
||
return ( | ||
<Button | ||
variant="tertiary" | ||
icon={close} | ||
icon_position="left" | ||
on_click={cancelHandler} | ||
> | ||
{translation.cancelButton} | ||
</Button> | ||
) | ||
} |
49 changes: 49 additions & 0 deletions
49
packages/dnb-eufemia/src/extensions/forms/Form/Section/EditContainer/DoneButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React, { useCallback, useContext } from 'react' | ||
import SectionContainerContext from '../containers/SectionContainerContext' | ||
import ToolbarContext from '../Toolbar/ToolbarContext' | ||
import { useTranslation } from '../../../hooks' | ||
import { Button } from '../../../../../components' | ||
import { check } from '../../../../../icons' | ||
import FieldBoundaryContext from '../../../DataContext/FieldBoundary/FieldBoundaryContext' | ||
|
||
export default function DoneEditButton() { | ||
const { onDone, setShowError } = useContext(ToolbarContext) || {} | ||
|
||
const { switchContainerMode } = useContext(SectionContainerContext) || {} | ||
const { hasError, hasVisibleError, setShowBoundaryErrors } = | ||
useContext(FieldBoundaryContext) || {} | ||
|
||
const translation = useTranslation().SectionEditContainer | ||
|
||
const doneHandler = useCallback(() => { | ||
if (hasError) { | ||
setShowBoundaryErrors?.(Date.now()) | ||
if (hasVisibleError) { | ||
setShowError(true) | ||
} | ||
} else { | ||
setShowError(false) | ||
setShowBoundaryErrors?.(false) | ||
switchContainerMode?.('view') | ||
onDone?.() | ||
} | ||
}, [ | ||
hasError, | ||
hasVisibleError, | ||
onDone, | ||
setShowBoundaryErrors, | ||
setShowError, | ||
switchContainerMode, | ||
]) | ||
|
||
return ( | ||
<Button | ||
variant="tertiary" | ||
icon={check} | ||
icon_position="left" | ||
on_click={doneHandler} | ||
> | ||
{translation.doneButton} | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.