Skip to content

Commit d33b796

Browse files
committed
Fix: Remove footer styles affecting line highlighting
1 parent d992568 commit d33b796

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

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

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

204-
// Add a class if the overlay footer is shown
205-
if (this.showFooter) {
206-
classes.push('hds-code-block--has-overlay-footer');
207-
}
208-
209-
// Add a class if if the overlay footer is shown but the height is not expanded
210-
if (this.showFooter && !this._isExpanded) {
211-
classes.push('hds-code-block--has-overflow');
204+
// Add a class if if the overlay footer is shown and the height is expanded
205+
if (this.showFooter && this._isExpanded) {
206+
classes.push('hds-code-block--has-overlay-footer-expanded');
212207
}
213208

214209
return classes.join(' ');

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

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// DIMENSIONS
1616
$hds-code-block-line-numbers-width: 49px; // 3em ≈ 49px
1717
$hds-code-block-code-padding: 16px;
18-
$hds-code-block-code-bottom-gradient-height: 48px;
18+
$hds-code-block-code-footer-height: 48px;
1919

2020
// CODE-BLOCK PARENT/WRAPPER
2121

@@ -41,11 +41,6 @@ $hds-code-block-code-bottom-gradient-height: 48px;
4141
text-shadow: none;
4242
}
4343
}
44-
45-
code {
46-
display: block;
47-
padding: $hds-code-block-code-padding;
48-
}
4944
}
5045

5146
// VARIANTS
@@ -139,7 +134,8 @@ $hds-code-block-code-bottom-gradient-height: 48px;
139134
display: flex;
140135
align-items: center;
141136
justify-content: center;
142-
padding: 0 $hds-code-block-code-padding 10px $hds-code-block-code-padding;
137+
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%);
143139
pointer-events: none; // fix issue with scrolling when hovering over the footer
144140

145141
// re-enable pointer events for the button (or any content inside the footer)
@@ -148,36 +144,14 @@ $hds-code-block-code-bottom-gradient-height: 48px;
148144
}
149145
}
150146

151-
.hds-code-block--has-overlay-footer {
147+
.hds-code-block--has-overlay-footer-expanded {
152148
.hds-code-block__code {
153-
// gradient element
154-
&::after {
155-
position: sticky; // prevent gradient from scrolling together with content
156-
bottom: 0;
157-
display: block;
158-
height: $hds-code-block-code-bottom-gradient-height;
159-
content: "";
160-
pointer-events: none;
161-
}
149+
// account for the footer at the bottom of the code block
150+
padding-bottom: $hds-code-block-code-footer-height;
162151
}
163152

164-
// reduce the amount of space at the bottom of the code block
165-
code {
166-
padding-bottom: 0;
167-
}
168-
}
169-
170-
.hds-code-block--has-overflow {
171-
.hds-code-block__code {
172-
// gradient to add contrast for button & indicate overflow
173-
&::after {
174-
background: linear-gradient(360deg, #0d0e12 37.07%, rgba(13, 14, 18, 25%) 100%);
175-
}
176-
}
177-
178-
// make border extend to bottom of the code block
179-
&.hds-code-block.line-numbers .line-numbers-rows {
180-
padding-bottom: $hds-code-block-code-bottom-gradient-height;
153+
.hds-code-block__overlay-footer {
154+
background: none;
181155
}
182156
}
183157

@@ -186,6 +160,7 @@ $hds-code-block-code-bottom-gradient-height: 48px;
186160
@include hds-focus-ring-basic();
187161
display: block;
188162
margin: 0;
163+
padding: $hds-code-block-code-padding;
189164
overflow: auto;
190165
scrollbar-width: thin;
191166
scrollbar-color: var(--token-color-palette-neutral-400) var(--token-color-palette-neutral-500);
@@ -265,12 +240,12 @@ $hds-code-block-code-bottom-gradient-height: 48px;
265240
.hds-code-block__code {
266241
position: relative;
267242
// reserve space for line numbers
268-
padding-left: $hds-code-block-line-numbers-width;
243+
padding-left: calc(#{$hds-code-block-line-numbers-width} + #{$hds-code-block-code-padding});
269244
}
270245

271246
.hds-code-block__overlay-footer {
272247
// match horizontal padding of the code block
273-
padding-left: calc(#{$hds-code-block-line-numbers-width} + #{$hds-code-block-code-padding});
248+
margin-left: $hds-code-block-line-numbers-width;
274249
}
275250

276251
.line-numbers-rows {

showcase/app/templates/components/code-block.hbs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,35 @@ function assertObjectsEqual (actual, expected, testName) {
293293
{{! template-lint-enable no-whitespace-for-layout }}
294294
</SG.Item>
295295

296+
<SG.Item @label="maxHeight='130px, hasLineNumbers=false" @forceMinWidth={{true}}>
297+
{{! template-lint-disable no-whitespace-for-layout }}
298+
<Hds::CodeBlock
299+
@language="javascript"
300+
@maxHeight="130px"
301+
@hasLineNumbers={{false}}
302+
@value="function convertObjectToArray (obj) {
303+
let arr = Object
304+
.keys(obj) // return object's keys as an array
305+
.map(key => {return [key, obj[key] ]}) // map a function on each array item
306+
.flat()
307+
.sort()
308+
;
309+
return arr;
310+
}
311+
function assertObjectsEqual (actual, expected, testName) {
312+
let actualStr = JSON.stringify( convertObjectToArray(actual) );
313+
let expectedStr = JSON.stringify( convertObjectToArray(expected) );
314+
console.log(`ACTUAL: ${actualStr} EXPECTED: ${expectedStr}`);
315+
if (actualStr === expectedStr) {
316+
console.log('passed');
317+
} else {
318+
console.log(`FAILED [${testName}] Expected ${JSON.stringify(expected)}, but got ${JSON.stringify(actual)}`);
319+
}
320+
}"
321+
/>
322+
{{! template-lint-enable no-whitespace-for-layout }}
323+
</SG.Item>
324+
296325
<SG.Item @label="maxHeight='130px' with short content that does not overflow" @forceMinWidth={{true}}>
297326
<Hds::CodeBlock @language="javascript" @maxHeight="130px" @value="convertObjectToArray(obj);" />
298327
</SG.Item>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ module('Integration | Component | hds/code-block/index', function (hooks) {
259259

260260
await click('.hds-code-block__height-toggle-button');
261261

262+
assert
263+
.dom('.hds-code-block')
264+
.hasClass('hds-code-block--has-overlay-footer-expanded');
262265
assert
263266
.dom('.hds-code-block__code')
264267
.hasAttribute('style', 'max-height: none;');

0 commit comments

Comments
 (0)