Skip to content

Commit 5572a23

Browse files
authored
Revert removed shadow from Surface component (#908)
1 parent 65f2935 commit 5572a23

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

packages/core/src/components/Surface.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const Surface: React.FC<React.PropsWithChildren<Props>> = ({
4848
style={[
4949
{
5050
backgroundColor: getBackgroundColor(),
51-
elevation,
51+
...shadow(elevation),
5252
...restStyle,
5353
},
5454
]}
@@ -58,4 +58,39 @@ const Surface: React.FC<React.PropsWithChildren<Props>> = ({
5858
);
5959
};
6060

61+
const SHADOW_COLOR = "#000";
62+
const SHADOW_OPACITY = 0.24;
63+
64+
function shadow(elevation: number) {
65+
if (elevation === 0) {
66+
return {};
67+
}
68+
69+
let height, radius;
70+
switch (elevation) {
71+
case 1:
72+
height = 0.5;
73+
radius = 0.75;
74+
break;
75+
case 2:
76+
height = 0.75;
77+
radius = 1.5;
78+
break;
79+
default:
80+
height = elevation - 1;
81+
radius = elevation;
82+
}
83+
84+
return {
85+
shadowColor: SHADOW_COLOR,
86+
shadowOffset: {
87+
width: 0,
88+
height,
89+
},
90+
shadowOpacity: SHADOW_OPACITY,
91+
shadowRadius: radius,
92+
elevation,
93+
};
94+
}
95+
6196
export default withTheme(Surface);

0 commit comments

Comments
 (0)