|
1 | 1 | import styled, { css, keyframes } from 'styled-components';
|
| 2 | +import Color from 'color'; |
2 | 3 |
|
3 | 4 | const pulse = keyframes`
|
4 | 5 | 0% { background-position: 100% 50%; }
|
5 | 6 | 100% { background-position: -100% 50%; }
|
6 | 7 | `;
|
7 | 8 |
|
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` |
10 | 31 | height: 16px;
|
11 | 32 | width: 200px;
|
12 |
| - animation: ${pulse} 2s linear infinite; |
| 33 | + opacity: 0.7; |
| 34 | + animation: ${pulse} 4s linear infinite; |
13 | 35 | background: linear-gradient(
|
14 | 36 | 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% |
20 | 42 | );
|
21 | 43 | background-size: 200% 200%;
|
22 |
| - ` |
23 |
| -); |
| 44 | + `; |
| 45 | +}); |
24 | 46 |
|
25 | 47 | export const SkeletonWrapper = styled.div`
|
26 | 48 | position: absolute;
|
|
0 commit comments