Skip to content

Commit e085b37

Browse files
author
Kirill Bolotsky
authored
feat(components): added fade out overlay for expandable code blocks (#143)
Note, that this features disables previously accessible scrolling in collapsed mode.
1 parent a67b9f4 commit e085b37

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/components/shared/code/code.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ const Code = ({ children, showLineNumbers, showHeightToggler }) => {
4242

4343
let toggler = null;
4444
let containerStyles = {};
45-
// if `height` isn't equla default height,
45+
let overlayStyles = { height: 0 };
46+
// if `height` isn't equal default height,
4647
// code blocks fits the height requirements
4748
// for toggler to be shown
4849
if (height !== DEFAULT_HEIGHT) {
@@ -53,6 +54,10 @@ const Code = ({ children, showLineNumbers, showHeightToggler }) => {
5354
);
5455
containerStyles = {
5556
maxHeight: isExpanded ? height : `${MAX_HEIGHT}px`,
57+
overflowY: 'hidden',
58+
};
59+
overlayStyles = {
60+
height: isExpanded ? 0 : undefined,
5661
};
5762
}
5863

@@ -92,6 +97,7 @@ const Code = ({ children, showLineNumbers, showHeightToggler }) => {
9297
</pre>
9398
)}
9499
</Highlight>
100+
<div className={styles.overlay} style={overlayStyles} />
95101
{toggler}
96102
</WithCopyButton>
97103
);

src/components/shared/code/code.module.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
overflow-y: auto;
55
text-align: left;
66
transition: max-height 0.2s ease-in-out;
7+
position: relative;
78
@include no-scrollbars;
89
}
910

@@ -126,3 +127,13 @@
126127
}
127128
}
128129
}
130+
131+
.overlay {
132+
position: absolute;
133+
bottom: 0;
134+
left: 0;
135+
right: 0;
136+
height: 200px;
137+
transition: height 0.2s ease-in-out;
138+
background: linear-gradient(to bottom, transparent, $color-primary);
139+
}

0 commit comments

Comments
 (0)