-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add combined fields option to DataForms
- Loading branch information
Showing
7 changed files
with
180 additions
and
19 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
packages/dataviews/src/components/dataform-combined-edit/index.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,72 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalHStack as HStack, | ||
__experimentalVStack as VStack, | ||
__experimentalHeading as Heading, | ||
__experimentalSpacer as Spacer, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { DataFormCombinedEditProps, NormalizedField } from '../../types'; | ||
|
||
function FieldHeader( { title }: { title: string } ) { | ||
return ( | ||
<VStack | ||
className="dataforms-layouts-panel__dropdown-header" | ||
spacing={ 4 } | ||
> | ||
<HStack alignment="center"> | ||
<Heading level={ 2 } size={ 13 }> | ||
{ title } | ||
</Heading> | ||
<Spacer /> | ||
</HStack> | ||
</VStack> | ||
); | ||
} | ||
|
||
function DataFormCombinedEdit< Item >( { | ||
field, | ||
data, | ||
onChange, | ||
}: DataFormCombinedEditProps< Item > ) { | ||
const className = 'dataforms-combined-edit'; | ||
const visibleChildren = ( field.children ?? [] ) | ||
.map( ( fieldId ) => field.fields.find( ( { id } ) => id === fieldId ) ) | ||
.filter( | ||
( childField ): childField is NormalizedField< Item > => | ||
!! childField | ||
); | ||
const children = visibleChildren.map( ( child, index ) => { | ||
return ( | ||
<div className="dataforms-combined-edit__field" key={ child.id }> | ||
{ index !== 0 && <FieldHeader title={ child.label } /> } | ||
<child.Edit | ||
data={ data } | ||
field={ child } | ||
onChange={ onChange } | ||
hideLabelFromVision | ||
/> | ||
</div> | ||
); | ||
} ); | ||
|
||
if ( field.direction === 'horizontal' ) { | ||
return ( | ||
<HStack spacing={ 4 } className={ className }> | ||
{ children } | ||
</HStack> | ||
); | ||
} | ||
return ( | ||
<VStack spacing={ 4 } className={ className }> | ||
{ children } | ||
</VStack> | ||
); | ||
} | ||
|
||
export default DataFormCombinedEdit; |
6 changes: 6 additions & 0 deletions
6
packages/dataviews/src/components/dataform-combined-edit/style.scss
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,6 @@ | ||
.dataforms-combined-edit { | ||
&__field:not(:first-child) { | ||
border-top: $border-width solid $gray-200; | ||
padding-top: $grid-unit-20; | ||
} | ||
} |
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
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
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
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
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