Skip to content

Commit 8983965

Browse files
authored
[Docs] Unify shadow documentation (#9117)
1 parent badbb1f commit 8983965

File tree

4 files changed

+62
-82
lines changed

4 files changed

+62
-82
lines changed

packages/website/docs/getting-started/theming/tokens/shadows/index.mdx

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/website/docs/getting-started/theming/tokens/shadows/shadows_table.tsx

Lines changed: 0 additions & 48 deletions
This file was deleted.

packages/website/docs/getting-started/theming/utilities/shadows/index.mdx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ sidebar_position: 10
66

77
EUI provides 5 shadow sizes (`xs`, `s`, `m`, `l`, `xl`) that can be applied in two directions: `down` (default) and `up`.
88

9-
The provided EUI shadow utilities handle the following additional style adjustments:
9+
The provided EUI shadow utilities use the underlying theme shadow tokens and automatically add required adjustments
10+
for dark mode and high contrast mode that ensure expected visibility.
11+
12+
:::warning Never use the underlying shadow tokens separately
13+
Always use the shadow utilities to ensure proper styling.
14+
:::
15+
16+
These shadow utilities handle the following additional style adjustments:
1017

1118
- adds a light, 4-sided `border` style in Dark mode to increase elevated item visibility
1219
- replaces the `box-shadow` in High Contrast mode with `border` to ensure visibility in high contrast themes
@@ -23,7 +30,7 @@ import { EuiSpacer } from '@elastic/eui';
2330

2431
const styles = css`
2532
${euiShadow(euiThemeContext, 's')};
26-
${euiShadow(euiThemeContext, 's', { direction: 'up' })};
33+
${euiShadow(euiThemeContext, 's', { direction: 'down' })};
2734
`;
2835
```
2936
</Example.Snippet>

packages/website/docs/getting-started/theming/utilities/shadows/shadows_table.tsx

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import {
55
_EuiThemeShadowSize,
66
euiShadow,
77
euiShadowFlat,
8+
EuiCodeBlock,
89
} from '@elastic/eui';
910
import { type EuiShadowOptions } from '@elastic/eui-theme-common';
11+
1012
import { ThemeValuesTable } from '../../theme_values_table';
13+
import { ReactNode } from 'react';
1114

1215
const 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

Comments
 (0)