Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Changes

- Remove numeric multiplier option for spacing tokens from `Stack` and `Box` components. ([#73852](https://github.com/WordPress/gutenberg/pull/73852), [#74008](https://github.com/WordPress/gutenberg/pull/74008))

### New Features

- Add `Stack` component
- Add `Stack` component. ([#73928](https://github.com/WordPress/gutenberg/pull/73928))
12 changes: 5 additions & 7 deletions packages/ui/src/box/box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,20 @@ const capitalize = ( str: string ): string =>
str.charAt( 0 ).toUpperCase() + str.slice( 1 );

/**
* Converts a size value to a CSS design token property reference (with
* fallback) or a calculated value based on the base unit.
* Converts a size token name to a CSS design token property reference (with
* fallback).
*
* @param property The CSS property name.
* @param target The design system token target.
* @param value The size value, either a number (multiplier of base unit) or a string (token name).
* @param value The size token name.
* @return A CSS value string with variable references.
*/
const getSpacingValue = (
property: string,
target: string,
value: number | string
value: string
): string =>
typeof value === 'number'
? `calc(var(--wpds-dimension-base) * ${ value })`
: `var(--wpds-dimension-${ property }-${ target }-${ value }, var(--wpds-dimension-${ property }-surface-${ value }))`;
`var(--wpds-dimension-${ property }-${ target }-${ value }, var(--wpds-dimension-${ property }-surface-${ value }))`;

/**
* Generates CSS styles for properties with optionally directional values,
Expand Down
18 changes: 12 additions & 6 deletions packages/ui/src/box/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
*/
import { type ComponentProps } from '../utils/types';

type SizeToken = '2xs' | 'xs' | 'sm' | 'md' | 'lg';

type Size = number | SizeToken;
type Size = '2xs' | 'xs' | 'sm' | 'md' | 'lg';

type BackgroundColor =
| 'neutral'
Expand Down Expand Up @@ -52,6 +50,14 @@ type StrokeColor =
| 'warning'
| 'warning-strong';

type Target =
| 'surface'
| 'interactive'
| 'content'
| 'track'
| 'thumb'
| 'focus';

type DimensionVariant< T > = {
block?: T;
blockStart?: T;
Expand All @@ -65,7 +71,7 @@ export interface BoxProps extends ComponentProps< 'div' > {
/**
* The target rendering element design token grouping to use for the box.
*/
target?: string;
target?: Target;

/**
* The surface background design token for box background color.
Expand All @@ -85,12 +91,12 @@ export interface BoxProps extends ComponentProps< 'div' > {
/**
* The surface border radius design token.
*/
borderRadius?: Exclude< SizeToken, '2xs' >;
borderRadius?: Exclude< Size, '2xs' >;

/**
* The surface border width design token.
*/
borderWidth?: Exclude< SizeToken, '2xs' >;
borderWidth?: Exclude< Size, '2xs' >;

/**
* The surface border stroke color design token.
Expand Down
Loading