@@ -20,7 +20,9 @@ export const withContextWrapper = makeDecorator({
2020 color = "light" ,
2121 context = "legacy" ,
2222 scale = "medium" ,
23- testingPreview = false ,
23+ } = { } ,
24+ parameters : {
25+ showTestingGrid = false ,
2426 } = { } ,
2527 id,
2628 viewMode,
@@ -45,7 +47,7 @@ export const withContextWrapper = makeDecorator({
4547
4648 useEffect ( ( ) => {
4749 const isDocs = viewMode === "docs" ;
48- const isTesting = testingPreview ;
50+ const isTesting = showTestingGrid ;
4951 const isRaw = Boolean ( context === "raw" ) ;
5052 const isModern = Boolean ( context === "spectrum" ) ;
5153 const isExpress = Boolean ( context === "express" ) ;
@@ -59,16 +61,18 @@ export const withContextWrapper = makeDecorator({
5961 }
6062
6163 for ( const container of fetchContainers ( id , isDocs , isTesting ) ) {
64+ // Check if the container is a testing wrapper to prevent applying colors around the testing grid
65+ const isTestingWrapper = isTesting ? container . matches ( "body:has([data-testing-preview]),[data-testing-preview]" ) : false ;
66+ // Check if the container has a static color element
67+ let hasStaticElement = container . matches ( `:has([data-html-preview])` ) ? container . matches ( `:has([data-html-preview] .${ rootClass } --staticWhite, [data-html-preview] .${ rootClass } --staticBlack)` ) : container . matches ( `:has(.${ rootClass } --staticWhite, .${ rootClass } --staticBlack)` ) ;
68+
6269 // Reset the context to the original values
6370 color = original . color ;
6471 context = original . context ;
6572 scale = original . scale ;
6673
67- // Check if the container has a static color element
68- let hasStaticElement = container . matches ( `:has([data-html-preview])` ) ? container . matches ( `:has([data-html-preview] .${ rootClass } --staticWhite, [data-html-preview] .${ rootClass } --staticBlack)` ) : container . matches ( `:has(.${ rootClass } --staticWhite, .${ rootClass } --staticBlack)` ) ;
69-
7074 let staticKey = staticColor ;
71- if ( ! staticKey && hasStaticElement ) {
75+ if ( ! isTestingWrapper && ! staticKey && hasStaticElement ) {
7276 staticKey = (
7377 container . querySelector ( `.${ rootClass } --staticWhite` ) && "white" ||
7478 container . querySelector ( `.${ rootClass } --staticBlack` ) && "black"
@@ -95,13 +99,13 @@ export const withContextWrapper = makeDecorator({
9599 }
96100
97101 // Let the static color override the color if it's set
98- if ( hasStaticElement && staticColorSettings [ staticKey ] ?. color ) {
102+ if ( ! isTestingWrapper && hasStaticElement && staticColorSettings [ staticKey ] ?. color ) {
99103 color = staticColorSettings [ staticKey ] . color ;
100104 }
101105
102106 // Force a light theme for the body wrapper in testing preview mode
103107 // because the individual containers will bring in the correct theme
104- if ( isTesting && container . matches ( "body:has([data-testing-preview]" ) ) {
108+ if ( isTestingWrapper ) {
105109 color = "light" ;
106110 }
107111
@@ -113,14 +117,17 @@ export const withContextWrapper = makeDecorator({
113117 container . classList . toggle ( `spectrum--${ s } ` , s === scale && ! isRaw ) ;
114118 }
115119
116- // Start by removing the background color from the container and then add it back if needed
117- container . style . removeProperty ( "background" ) ;
118- if ( hasStaticElement && staticKey && staticColorSettings [ staticKey ] ) {
119- container . style . background = staticColorSettings [ staticKey ] . background ;
120+ if ( ! isTestingWrapper ) {
121+ if ( hasStaticElement && staticKey && staticColorSettings [ staticKey ] ) {
122+ container . style . background = staticColorSettings [ staticKey ] . background ;
123+ }
124+ } else {
125+ // Testing background is stark white to highlight the gray-ish background color on light theme
126+ container . style . background = "Canvas" ;
120127 }
121128 }
122129
123- } , [ context , viewMode , original , staticColor , color , scale , rootClass , tokens , staticColorSettings , testingPreview ] ) ;
130+ } , [ context , viewMode , original , staticColor , color , scale , rootClass , tokens , staticColorSettings , showTestingGrid ] ) ;
124131
125132 return StoryFn ( data ) ;
126133 } ,
0 commit comments