Skip to content

Commit 126f741

Browse files
gigituxmirka
andauthored
DataForm: Card bordless layout (WordPress#72514)
* Enhance Card Component: Introduce directional padding options and update size type definitions * Enhance Card Component: Introduce directional padding options and update size type definitions * add changelog * add size to footer * fix changelog * fix changelog * fix padding * clean up code * fix unit test * update types * move padding style in get-padding-by-size file * update story documentation * update documentation * remove option to make the card with border * address feedback * Refactor padding options in FormCardField component to use blockStart/blockEnd and inlineStart/inlineEnd instead of top/right/bottom/left for improved layout flexibility * Update packages/components/src/card/card/README.md Co-authored-by: Lena Morita <lena@jaguchi.com> * improve documentation * improve logic * implement none * fix build * restore changelog * update changelog * restore story * fix layout when header is not collapsible * fix story * improve card layout logic * Update paragraph styling in dataform story to remove margin for improved layout consistency --------- Co-authored-by: Lena Morita <lena@jaguchi.com>
1 parent 0d2e850 commit 126f741

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

packages/dataviews/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- DatViews list layout: remove link variant from primary actions's button. [#72920](https://github.com/WordPress/gutenberg/pull/72920)
88
- DataForm: simplify form normalization. [#72848](https://github.com/WordPress/gutenberg/pull/72848)
99
- DataViewsPicker: Add With Modal story. [#72913](https://github.com/WordPress/gutenberg/pull/72913)
10+
- DataForm: make the card layout borderless. [#72514](https://github.com/WordPress/gutenberg/pull/72514)
1011

1112
### Bug fixes
1213

packages/dataviews/src/dataform-layouts/card/index.tsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const NonCollapsibleCardHeader = ( {
3232
}: {
3333
children: React.ReactNode;
3434
} ) => (
35-
<OriginalCardHeader { ...props }>
35+
<OriginalCardHeader isBorderless { ...props }>
3636
<div
3737
style={ {
3838
height: '40px', // This is to match the chevron's __next40pxDefaultSize
@@ -70,6 +70,7 @@ export function useCardHeader( layout: NormalizedCardLayout ) {
7070
cursor: 'pointer',
7171
...props.style,
7272
} }
73+
isBorderless
7374
>
7475
<div
7576
style={ {
@@ -178,11 +179,27 @@ export default function FormCardField< Item >( {
178179
isSummaryFieldVisible( summaryField, layout.summary, isOpen )
179180
);
180181

182+
const sizeCard = {
183+
blockStart: 'medium' as const,
184+
blockEnd: 'medium' as const,
185+
inlineStart: 'medium' as const,
186+
inlineEnd: 'medium' as const,
187+
};
188+
181189
if ( !! field.children ) {
182190
const withHeader = !! field.label && layout.withHeader;
183191

192+
const sizeCardBody = {
193+
blockStart: withHeader
194+
? ( 'none' as const )
195+
: ( 'medium' as const ),
196+
blockEnd: 'medium' as const,
197+
inlineStart: 'medium' as const,
198+
inlineEnd: 'medium' as const,
199+
};
200+
184201
return (
185-
<Card className="dataforms-layouts-card__field">
202+
<Card className="dataforms-layouts-card__field" size={ sizeCard }>
186203
{ withHeader && (
187204
<CardHeader className="dataforms-layouts-card__field-header">
188205
<span className="dataforms-layouts-card__field-header-label">
@@ -207,7 +224,10 @@ export default function FormCardField< Item >( {
207224
{ ( isOpen || ! withHeader ) && (
208225
// If it doesn't have a header, keep it open.
209226
// Otherwise, the card will not be visible.
210-
<CardBody className="dataforms-layouts-card__field-control">
227+
<CardBody
228+
size={ sizeCardBody }
229+
className="dataforms-layouts-card__field-control"
230+
>
211231
{ field.description && (
212232
<div className="dataforms-layouts-card__field-description">
213233
{ field.description }
@@ -239,8 +259,15 @@ export default function FormCardField< Item >( {
239259
}
240260
const withHeader = !! fieldDefinition.label && layout.withHeader;
241261

262+
const sizeCardBody = {
263+
blockStart: withHeader ? ( 'none' as const ) : ( 'medium' as const ),
264+
blockEnd: 'medium' as const,
265+
inlineStart: 'medium' as const,
266+
inlineEnd: 'medium' as const,
267+
};
268+
242269
return (
243-
<Card className="dataforms-layouts-card__field">
270+
<Card className="dataforms-layouts-card__field" size={ sizeCard }>
244271
{ withHeader && (
245272
<CardHeader className="dataforms-layouts-card__field-header">
246273
<span className="dataforms-layouts-card__field-header-label">
@@ -262,7 +289,10 @@ export default function FormCardField< Item >( {
262289
{ ( isOpen || ! withHeader ) && (
263290
// If it doesn't have a header, keep it open.
264291
// Otherwise, the card will not be visible.
265-
<CardBody className="dataforms-layouts-card__field-control">
292+
<CardBody
293+
size={ sizeCardBody }
294+
className="dataforms-layouts-card__field-control"
295+
>
266296
<RegularLayout
267297
data={ data }
268298
field={ field }

packages/dataviews/src/stories/dataform.story.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ const LayoutCardComponent = ( {
13841384
isVisible: ( item ) => item.displayPayments,
13851385
render: ( { item } ) => {
13861386
return (
1387-
<p>
1387+
<p style={ { margin: 0 } }>
13881388
The customer has made a total of { item.totalOrders }{ ' ' }
13891389
orders, amounting to { item.totalRevenue } dollars. The
13901390
average order value is { item.averageOrderValue }{ ' ' }
@@ -1440,17 +1440,13 @@ const LayoutCardComponent = ( {
14401440

14411441
const form: Form = useMemo(
14421442
() => ( {
1443-
layout: getLayoutFromStoryArgs( {
1444-
type: 'card',
1445-
withHeader,
1446-
} ),
14471443
fields: [
14481444
{
14491445
id: 'customerCard',
14501446
layout: {
14511447
type: 'card',
14521448
summary: 'plan-summary',
1453-
isCollapsible,
1449+
withHeader,
14541450
},
14551451
label: 'Customer',
14561452
description:

0 commit comments

Comments
 (0)