-
Notifications
You must be signed in to change notification settings - Fork 4.6k
DataViews / DataViewsPicker: Add an optional padding prop with named values #72989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
048ab87
1d54d93
26dedaa
e7fd383
a91231d
e468883
42ee369
004dfa2
1addbfa
eb0c766
1a5bcd2
397e08a
61dfe54
338f04d
9f6ec17
860c35e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import type { | ||
| PaddingSize, | ||
| PaddingOptions, | ||
| DimensionVariant, | ||
| } from '../../types/private'; | ||
|
|
||
| /** | ||
| * Maps padding size tokens to CSS values. | ||
| * Aligned with the Card component's spacing scale (space function with 4px base): | ||
| * - x-small: space(2) = 8px | ||
| * - small: space(4) = 16px | ||
| * - medium: space(6) = 24px | ||
| * - large: space(8) = 32px | ||
| * - x-large: space(12) = 48px | ||
| */ | ||
| const paddingValuesBySize: Record< PaddingSize, string > = { | ||
| 'x-small': '8px', | ||
| small: '16px', | ||
| medium: '24px', | ||
| large: '32px', | ||
| 'x-large': '48px', | ||
| none: '0', | ||
| }; | ||
|
Comment on lines
+10
to
+26
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very happy for feedback on the naming and sizing of this, maybe |
||
|
|
||
| /** | ||
| * Gets the CSS value for a single padding size token. | ||
| * | ||
| * @param size The padding size token. | ||
| * @return The CSS value for the padding size. | ||
| */ | ||
| function getSinglePaddingValue( size: PaddingSize ): string { | ||
| return paddingValuesBySize[ size ]; | ||
| } | ||
|
|
||
| /** | ||
| * Converts padding options into CSS custom property style values. | ||
| * Returns an object with the appropriate CSS custom properties set. | ||
| * When padding is undefined, returns an empty object to allow SCSS | ||
| * defaults and container queries to apply. | ||
| * | ||
| * @param padding The padding option (single size or directional variants), or undefined to use SCSS defaults | ||
| * @return An object with CSS custom property values, or empty object to use SCSS defaults | ||
| */ | ||
| export function getPaddingBySizeStyles( | ||
| padding: PaddingOptions | undefined | ||
| ): Record< string, string > { | ||
| const styles: Record< string, string > = {}; | ||
|
|
||
| // Handle string-based sizes (single value applied to all directional variants) | ||
| if ( typeof padding === 'string' ) { | ||
| const value = getSinglePaddingValue( padding ); | ||
| styles[ '--wp-dataviews-padding-block-start' ] = value; | ||
| styles[ '--wp-dataviews-padding-block-end' ] = value; | ||
| styles[ '--wp-dataviews-padding-inline-start' ] = value; | ||
| styles[ '--wp-dataviews-padding-inline-end' ] = value; | ||
| return styles; | ||
| } | ||
|
|
||
| // If no padding specified, return empty object to use SCSS defaults | ||
| if ( ! padding ) { | ||
| return styles; | ||
| } | ||
|
|
||
| // Handle object with directional variants | ||
| const { block, blockStart, blockEnd, inline, inlineStart, inlineEnd } = | ||
| padding as DimensionVariant< PaddingSize >; | ||
|
|
||
| if ( block !== undefined ) { | ||
| const value = getSinglePaddingValue( block ); | ||
| if ( blockStart === undefined ) { | ||
| styles[ '--wp-dataviews-padding-block-start' ] = value; | ||
| } | ||
| if ( blockEnd === undefined ) { | ||
| styles[ '--wp-dataviews-padding-block-end' ] = value; | ||
| } | ||
| } | ||
|
|
||
| if ( blockStart !== undefined ) { | ||
| styles[ '--wp-dataviews-padding-block-start' ] = | ||
| getSinglePaddingValue( blockStart ); | ||
| } | ||
|
|
||
| if ( blockEnd !== undefined ) { | ||
| styles[ '--wp-dataviews-padding-block-end' ] = | ||
| getSinglePaddingValue( blockEnd ); | ||
| } | ||
|
|
||
| if ( inline !== undefined ) { | ||
| const value = getSinglePaddingValue( inline ); | ||
| if ( inlineStart === undefined ) { | ||
| styles[ '--wp-dataviews-padding-inline-start' ] = value; | ||
| } | ||
| if ( inlineEnd === undefined ) { | ||
| styles[ '--wp-dataviews-padding-inline-end' ] = value; | ||
| } | ||
| } | ||
|
|
||
| if ( inlineStart !== undefined ) { | ||
| styles[ '--wp-dataviews-padding-inline-start' ] = | ||
| getSinglePaddingValue( inlineStart ); | ||
| } | ||
|
|
||
| if ( inlineEnd !== undefined ) { | ||
| styles[ '--wp-dataviews-padding-inline-end' ] = | ||
| getSinglePaddingValue( inlineEnd ); | ||
| } | ||
|
|
||
| return styles; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,10 @@ | |
| .dataviews__view-actions, | ||
| .dataviews-filters__container { | ||
| box-sizing: border-box; | ||
| padding: $grid-unit-20 $grid-unit-60; | ||
| padding-block-start: var(--wp-dataviews-padding-block-start, #{$grid-unit-20}); | ||
| padding-block-end: $grid-unit-20; | ||
| padding-inline-start: var(--wp-dataviews-padding-inline-start, #{$grid-unit-60}); | ||
| padding-inline-end: var(--wp-dataviews-padding-inline-end, #{$grid-unit-60}); | ||
| flex-shrink: 0; | ||
| position: sticky; | ||
| left: 0; | ||
|
|
@@ -33,7 +36,9 @@ | |
|
|
||
| .dataviews-no-results, | ||
| .dataviews-loading { | ||
| padding: 0 $grid-unit-60; | ||
| padding-block: 0; | ||
| padding-inline-start: var(--wp-dataviews-padding-inline-start, #{$grid-unit-60}); | ||
| padding-inline-end: var(--wp-dataviews-padding-inline-end, #{$grid-unit-60}); | ||
| flex-grow: 1; | ||
| display: flex; | ||
| align-items: center; | ||
|
|
@@ -51,13 +56,17 @@ | |
| @container (max-width: 430px) { | ||
| .dataviews__view-actions, | ||
| .dataviews-filters__container { | ||
| padding: $grid-unit-15 $grid-unit-30; | ||
| padding-block-start: var(--wp-dataviews-padding-block-start, #{$grid-unit-15}); | ||
| padding-block-end: $grid-unit-15; | ||
| padding-inline-start: var(--wp-dataviews-padding-inline-start, #{$grid-unit-30}); | ||
| padding-inline-end: var(--wp-dataviews-padding-inline-end, #{$grid-unit-30}); | ||
| } | ||
|
|
||
| .dataviews-no-results, | ||
| .dataviews-loading { | ||
| padding-left: $grid-unit-30; | ||
| padding-right: $grid-unit-30; | ||
| padding-block: 0; | ||
| padding-inline-start: var(--wp-dataviews-padding-inline-start, #{$grid-unit-30}); | ||
| padding-inline-end: var(--wp-dataviews-padding-inline-end, #{$grid-unit-30}); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -122,7 +131,8 @@ | |
| .dataviews-view-grid, | ||
| .dataviews-loading, | ||
| .dataviews-no-results { | ||
| padding-inline: $grid-unit-30; | ||
| padding-inline-start: $grid-unit-30; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding was that the benefit of introducing an API for styling DataViews was that we'd no longer need container specific styles. Why do we still require these styles for the card? Shouldn't they be removed? |
||
| padding-inline-end: $grid-unit-30; | ||
| } | ||
|
|
||
| .dataviews-view-table tr td:first-child, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked the same question in the other place, resurfacing here as well:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--wpds-tokens come from from the Theme package and are consumed by the components in the new UI package.Eventually we'll want this variable to reference one of those tokens for the fallback instead of
grid-unit-15. E.g.:var(--wp-dataviews-padding-block-end, --wpds-dimension-padding-surface-lg)I don't have any strong feelings about how the DataView-specific variables should be named.