Skip to content

Commit feab0fe

Browse files
committed
Fix: Footer gradient positioning
1 parent 634b674 commit feab0fe

File tree

3 files changed

+28
-1
lines changed
  • packages/components/src
  • showcase/tests/integration/components/hds/code-block

3 files changed

+28
-1
lines changed

packages/components/src/components/hds/code-block/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ export default class HdsCodeBlock extends Component<HdsCodeBlockSignature> {
201201
classes.push('line-numbers');
202202
}
203203

204+
if (this.showFooter) {
205+
classes.push('hds-code-block--has-overlay-footer');
206+
}
207+
204208
// Add a class if if the overlay footer is shown and the height is expanded
205209
if (this.showFooter && this._isExpanded) {
206210
classes.push('hds-code-block--has-overlay-footer-expanded');

packages/components/src/styles/components/code-block/index.scss

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ $hds-code-block-code-footer-height: 48px;
135135
align-items: center;
136136
justify-content: center;
137137
padding: 10px $hds-code-block-code-padding 10px $hds-code-block-code-padding;
138-
background: linear-gradient(360deg, #0d0e12 37.07%, rgba(13, 14, 18, 25%) 100%);
139138
pointer-events: none; // fix issue with scrolling when hovering over the footer
140139

141140
// re-enable pointer events for the button (or any content inside the footer)
@@ -144,10 +143,29 @@ $hds-code-block-code-footer-height: 48px;
144143
}
145144
}
146145

146+
.hds-code-block--has-overlay-footer {
147+
.hds-code-block__code::after {
148+
// gradient element
149+
position: sticky; // prevent gradient from scrolling together with content
150+
bottom: -$hds-code-block-code-padding;
151+
display: block;
152+
width: calc(100% + #{$hds-code-block-code-padding * 2});
153+
height: $hds-code-block-code-footer-height;
154+
background: linear-gradient(360deg, #0d0e12 37.07%, rgba(13, 14, 18, 25%) 100%);
155+
transform: translateX(-$hds-code-block-code-padding);
156+
content: "";
157+
pointer-events: none;
158+
}
159+
}
160+
147161
.hds-code-block--has-overlay-footer-expanded {
148162
.hds-code-block__code {
149163
// account for the footer at the bottom of the code block
150164
padding-bottom: $hds-code-block-code-footer-height;
165+
166+
&::after {
167+
content: none;
168+
}
151169
}
152170

153171
.hds-code-block__overlay-footer {
@@ -158,6 +176,7 @@ $hds-code-block-code-footer-height: 48px;
158176
// Code
159177
.hds-code-block__code {
160178
@include hds-focus-ring-basic();
179+
position: relative;
161180
display: block;
162181
margin: 0;
163182
padding: $hds-code-block-code-padding;

showcase/tests/integration/components/hds/code-block/index-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ module('Integration | Component | hds/code-block/index', function (hooks) {
257257
<Hds::CodeBlock @value="console.log('Hello world');" @maxHeight="1em" />
258258
`);
259259

260+
assert
261+
.dom('.hds-code-block')
262+
.hasClass('hds-code-block--has-overlay-footer');
263+
260264
await click('.hds-code-block__height-toggle-button');
261265

262266
assert

0 commit comments

Comments
 (0)