@@ -5,9 +5,12 @@ import {
55 _EuiThemeShadowSize ,
66 euiShadow ,
77 euiShadowFlat ,
8+ EuiCodeBlock ,
89} from '@elastic/eui' ;
910import { type EuiShadowOptions } from '@elastic/eui-theme-common' ;
11+
1012import { ThemeValuesTable } from '../../theme_values_table' ;
13+ import { ReactNode } from 'react' ;
1114
1215const shadowTypes : _EuiThemeShadowSize [ ] = [ 'xs' , 's' , 'm' , 'l' , 'xl' ] ;
1316
@@ -22,28 +25,37 @@ export const ShadowsTable = ({
2225 const items = shadowTypes . map ( ( type ) => ( {
2326 id : type ,
2427 token : `euiShadow(euiThemeContext, '${ type } ', { direction: '${ direction } ' })` ,
25- value : euiShadow ( euiThemeContext , type , {
26- direction ,
27- } )
28- . replaceAll ( ';;' , ';' )
29- . replaceAll ( ' ;' , '' ) ,
28+ value : getFormattedCSS (
29+ euiShadow ( euiThemeContext , type , {
30+ direction ,
31+ } )
32+ ) ,
3033 } ) ) ;
3134
3235 // deprecated, remove once obsolete
3336 items . push ( {
3437 id : 'flat' ,
3538 token : `euiShadowFlat(euiThemeContext, { direction: '${ direction } ' }))` ,
36- value : euiShadowFlat ( euiThemeContext , {
37- direction ,
38- } )
39- . replaceAll ( ';;' , ';' )
40- . replaceAll ( ' ;' , '' ) ,
39+ value : getFormattedCSS (
40+ euiShadowFlat ( euiThemeContext , {
41+ direction ,
42+ } )
43+ ) ,
4144 } ) ;
4245
4346 return (
4447 < ThemeValuesTable
4548 items = { items }
4649 tokenColumnProps = { { name : 'Utility' } }
50+ valueColumnProps = { {
51+ name : 'Style output' ,
52+ align : 'left' ,
53+ render : ( value : ReactNode ) => (
54+ < small >
55+ < EuiCodeBlock language = "css" > { value } </ EuiCodeBlock >
56+ </ small >
57+ ) ,
58+ } }
4759 render = { ( item ) => (
4860 < EuiColorPickerSwatch
4961 showToolTip = { false }
@@ -61,3 +73,34 @@ export const ShadowsTable = ({
6173 />
6274 ) ;
6375} ;
76+
77+ /* CSS formatting utility */
78+ const getFormattedCSS = ( cssString : string ) => {
79+ return (
80+ cssString
81+ // Remove comments
82+ . replace ( / \/ \* [ \s \S ] * ?\* \/ / g, '' )
83+ // Clean up semicolons
84+ . replaceAll ( ';;' , ';' )
85+ . replaceAll ( ' ;' , '' )
86+ // Normalize all whitespace to single spaces
87+ . replace ( / \s + / g, ' ' )
88+ // Add line breaks after semicolons (for top-level properties)
89+ . replace ( / ; \s * (? ! [ ^ { ] * } ) / g, ';\n' )
90+ // Add line breaks before selectors like &::after
91+ . replace ( / \s * ( & [ ^ { ] * ) \s * { / g, '\n\n$1 {' )
92+ // Format inside braces: add line breaks and indent
93+ . replace ( / { ( [ ^ } ] * ) } / g, ( match , content ) => {
94+ const formatted = content
95+ . split ( ';' )
96+ . map ( ( prop : string ) => prop . trim ( ) )
97+ . filter ( ( prop : string ) => prop . length > 0 )
98+ . map ( ( prop : string ) => ` ${ prop } ;` )
99+ . join ( '\n' ) ;
100+ return `{\n${ formatted } \n}` ;
101+ } )
102+ // Clean up any leading newlines
103+ . replace ( / ^ \n + / , '' )
104+ . trim ( )
105+ ) ;
106+ } ;
0 commit comments