Skip to content
Open
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
5 changes: 5 additions & 0 deletions packages/ui/src/box/box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const Box = forwardRef< HTMLDivElement, BoxProps >( function Box(
borderRadius,
borderWidth,
borderColor,
elevation,
render = DEFAULT_RENDER,
...props
},
Expand Down Expand Up @@ -108,6 +109,10 @@ export const Box = forwardRef< HTMLDivElement, BoxProps >( function Box(
style.borderColor = `var(--wpds-color-stroke-${ target }-${ borderColor }, var(--wpds-color-stroke-surface-${ borderColor }))`;
}

if ( elevation ) {
style.boxShadow = `var(--wpds-elevation-${ elevation })`;
}

const element = useRender( {
render,
ref,
Expand Down
39 changes: 39 additions & 0 deletions packages/ui/src/box/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,42 @@ export const DirectionalPadding: Story = {
},
},
};

export const WithElevation: Story = {
render: () => (
<div style={ { display: 'flex', gap: '24px', flexWrap: 'wrap' } }>
<Box
backgroundColor="neutral"
padding="md"
borderRadius="md"
elevation="x-small"
>
Elevation: x-small
</Box>
<Box
backgroundColor="neutral"
padding="md"
borderRadius="md"
elevation="small"
>
Elevation: small
</Box>
<Box
backgroundColor="neutral"
padding="md"
borderRadius="md"
elevation="medium"
>
Elevation: medium
</Box>
<Box
backgroundColor="neutral"
padding="md"
borderRadius="md"
elevation="large"
>
Elevation: large
</Box>
</div>
),
};
30 changes: 30 additions & 0 deletions packages/ui/src/box/test/box.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,34 @@ describe( 'Box', () => {
width: '10px',
} );
} );

it( 'applies elevation style', () => {
render( <Box elevation="small">Content</Box> );

const box = screen.getByText( 'Content' );

expect( box ).toHaveStyle( {
'box-shadow': 'var(--wpds-elevation-small)',
} );
} );

it( 'applies different elevation levels', () => {
const { rerender } = render( <Box elevation="x-small">Content</Box> );
let box = screen.getByText( 'Content' );
expect( box ).toHaveStyle( {
'box-shadow': 'var(--wpds-elevation-x-small)',
} );

rerender( <Box elevation="medium">Content</Box> );
box = screen.getByText( 'Content' );
expect( box ).toHaveStyle( {
'box-shadow': 'var(--wpds-elevation-medium)',
} );

rerender( <Box elevation="large">Content</Box> );
box = screen.getByText( 'Content' );
expect( box ).toHaveStyle( {
'box-shadow': 'var(--wpds-elevation-large)',
} );
} );
} );
7 changes: 7 additions & 0 deletions packages/ui/src/box/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from '@wordpress/theme';
import { type ComponentProps } from '../utils/types';

type ElevationSize = 'x-small' | 'small' | 'medium' | 'large';

type DimensionVariant< T > = {
block?: T;
blockStart?: T;
Expand Down Expand Up @@ -54,6 +56,11 @@ export interface BoxProps extends ComponentProps< 'div' > {
*/
borderColor?: SurfaceStrokeColor;

/**
* The elevation design token for box shadow.
*/
elevation?: ElevationSize;

/**
* The content to be rendered inside the component.
*/
Expand Down
Loading