Skip to content

Commit 956cb0d

Browse files
authored
Enhancements to skeleton (codesandbox#3724)
1 parent f946fd1 commit 956cb0d

File tree

2 files changed

+41
-50
lines changed

2 files changed

+41
-50
lines changed

packages/app/src/app/pages/Sandbox/Editor/Skeleton/elements.ts

+32-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
11
import styled, { css, keyframes } from 'styled-components';
2+
import Color from 'color';
23

34
const pulse = keyframes`
45
0% { background-position: 100% 50%; }
56
100% { background-position: -100% 50%; }
67
`;
78

8-
export const SkeletonTextBlock = styled.div(
9-
props => css`
9+
export const SkeletonTextBlock = styled.div(props => {
10+
const color = props.theme.colors?.sideBar.border || '#242424';
11+
const themeType = props.theme.vscodeTheme.type;
12+
13+
/**
14+
* This is fun,
15+
* We animate the background gradient to create a pulse animation
16+
*
17+
* To support all themes nicely, we can't really pick a value from the theme
18+
* So, we take the sidebar.border and then change it's luminosity
19+
* 14% for background and 16% for the pulse highlight on top
20+
* We need to set the value to 100 - value for light themes
21+
*/
22+
23+
const backgroundLuminosity = themeType === 'light' ? 86 : 14;
24+
const highlightLuminosity = themeType === 'light' ? 88 : 16;
25+
26+
const hsl = Color(color).hsl();
27+
const background = Color({ ...hsl, l: backgroundLuminosity }).hslString();
28+
const highlight = Color({ ...hsl, l: highlightLuminosity }).hslString();
29+
30+
return css`
1031
height: 16px;
1132
width: 200px;
12-
animation: ${pulse} 2s linear infinite;
33+
opacity: 0.7;
34+
animation: ${pulse} 4s linear infinite;
1335
background: linear-gradient(
1436
90deg,
15-
${props.theme.colors?.sideBar.border + '80'} 0%,
16-
${props.theme.colors?.sideBar.border + '80'} 40%,
17-
${props.theme.colors?.sideBar.border + 'd6'} 50%,
18-
${props.theme.colors?.sideBar.border + '80'} 60%,
19-
${props.theme.colors?.sideBar.border + '80'} 100%
37+
${background} 0%,
38+
${background} 20%,
39+
${highlight} 50%,
40+
${background} 80%,
41+
${background} 100%
2042
);
2143
background-size: 200% 200%;
22-
`
23-
);
44+
`;
45+
});
2446

2547
export const SkeletonWrapper = styled.div`
2648
position: absolute;

packages/app/src/app/pages/Sandbox/Editor/Skeleton/index.tsx

+9-40
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ const SkeletonExplorerContents = () => (
4343
<>
4444
<Collapsible title="Files" defaultOpen>
4545
<List>
46-
<File type="folder" />
47-
<File type="folder" />
48-
<File type="file" nested />
49-
<File type="file" nested />
50-
<File type="file" nested />
51-
<File type="file" />
46+
<File />
47+
<File />
48+
<File />
49+
<File />
50+
<File />
51+
<File />
5252
</List>
5353
</Collapsible>
5454
<Collapsible title="Dependencies" defaultOpen>
@@ -66,15 +66,12 @@ export const File = props => (
6666
<ListItem
6767
justify="space-between"
6868
align="center"
69-
css={{
70-
minHeight: '28px',
71-
paddingLeft: `calc(${props.nested ? 2 : 1}rem - 2px)`,
72-
}}
69+
css={css({ paddingLeft: 3, minHeight: 7 })}
7370
{...props}
7471
>
7572
<Stack gap={2} align="center" css={css({ color: 'sideBar.border' })}>
76-
<span style={{ opacity: 0.5 }}>{icons[props.type]}</span>{' '}
77-
<SkeletonTextBlock />
73+
<SkeletonTextBlock css={css({ width: 5 })} />
74+
<SkeletonTextBlock css={{ width: 'calc(200px - 28px)' }} />
7875
</Stack>
7976
</ListItem>
8077
);
@@ -84,31 +81,3 @@ const Dependency = () => (
8481
<SkeletonTextBlock />
8582
</ListItem>
8683
);
87-
88-
const icons = {
89-
folder: (
90-
<svg
91-
width="16"
92-
height="16"
93-
viewBox="0 0 16 16"
94-
fill="none"
95-
xmlns="http://www.w3.org/2000/svg"
96-
>
97-
<path
98-
d="M6.86667 2L8.33333 3.46667H14.2C15 3.46667 15.6667 4.13333 15.6667 4.93333V12.4C15.6667 13.2 15 13.8667 14.2 13.8667H2.46667C1.66667 14 1 13.3333 1 12.5333V3.46667C1 2.66667 1.66667 2 2.46667 2H6.86667Z"
99-
fill="currentColor"
100-
/>
101-
</svg>
102-
),
103-
file: (
104-
<svg
105-
width="12"
106-
height="12"
107-
viewBox="0 0 12 12"
108-
fill="none"
109-
xmlns="http://www.w3.org/2000/svg"
110-
>
111-
<rect width="12" height="12" rx="2" fill="currentColor" />
112-
</svg>
113-
),
114-
};

0 commit comments

Comments
 (0)