Skip to content

Commit 07cea48

Browse files
author
shleewhite
committed
small adjustments
1 parent 81fe426 commit 07cea48

File tree

4 files changed

+70
-30
lines changed

4 files changed

+70
-30
lines changed

website/app/components/doc/code-group/index.gts

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { on } from '@ember/modifier';
99
import { notEq, eq } from 'ember-truth-helpers';
1010
import { guidFor } from '@ember/object/internals';
1111
import type Owner from '@ember/owner';
12+
import { modifier } from 'ember-modifier';
1213

1314
import { HdsIcon } from '@hashicorp/design-system-components/components';
1415
import type { HdsIconSignature } from '@hashicorp/design-system-components/components/hds/icon/index';
@@ -42,8 +43,10 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
4243
@tracked copyTimer: ReturnType<typeof setTimeout> | undefined;
4344
@tracked copyIconName: HdsIconSignature['Args']['name'] = 'clipboard-copy';
4445
@tracked expandIconName: HdsIconSignature['Args']['name'] = 'unfold-open';
46+
@tracked hasScrollbar = false;
4547

4648
componentId = guidFor(this);
49+
codeSnippetWrapperElement!: HTMLDivElement;
4750

4851
constructor(owner: Owner, args: DocCodeGroupSignature['Args']) {
4952
super(owner, args);
@@ -52,6 +55,10 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
5255
}
5356
}
5457

58+
registerCodeSnippetWrapper = modifier((element: HTMLDivElement) => {
59+
this.codeSnippetWrapperElement = element;
60+
});
61+
5562
get unescapedHbsSnippet() {
5663
return unescapeCode(this.args.hbsSnippet ?? '');
5764
}
@@ -89,7 +96,7 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
8996
}
9097

9198
get toggleButtonLabel() {
92-
return this.isExpanded ? 'Collapse code' : 'Expand code';
99+
return this.isExpanded ? 'Collapse .gts snippet' : 'Expand .gts snippet';
93100
}
94101

95102
get language() {
@@ -142,13 +149,15 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
142149
handleGtsExpandClick = () => {
143150
this.isExpanded = !this.isExpanded;
144151
this.expandIconName = this.isExpanded ? 'unfold-close' : 'unfold-open';
152+
this.checkHorizontalScrollbar();
145153
};
146154

147155
handleLanguageChange = (event: Event) => {
148156
const input = event.target as HTMLInputElement;
149157
if (input.checked) {
150158
this.currentView = input.value;
151159
}
160+
this.checkHorizontalScrollbar();
152161
};
153162

154163
onSuccess = () => {
@@ -172,6 +181,20 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
172181
}, 2000);
173182
}
174183

184+
checkHorizontalScrollbar() {
185+
const codeElement = this.codeSnippetWrapperElement.querySelector(
186+
'code',
187+
) as HTMLElement;
188+
189+
console.log(codeElement);
190+
191+
if (codeElement.scrollHeight != codeElement.clientHeight) {
192+
this.hasScrollbar = true;
193+
} else {
194+
this.hasScrollbar = false;
195+
}
196+
}
197+
175198
<template>
176199
<div class="doc-code-group">
177200
<div class="doc-code-group__action-bar">
@@ -218,17 +241,24 @@ export default class DocCodeGroup extends Component<DocCodeGroupSignature> {
218241
/>
219242
</div>
220243
{{/if}}
221-
<div class="doc-code-block__code-snippet-wrapper">
244+
<div
245+
class="doc-code-block__code-snippet-wrapper"
246+
{{this.registerCodeSnippetWrapper}}
247+
>
222248
{{#if (eq this.currentView "gts")}}
223-
<button
224-
type="button"
225-
class="doc-code-group__expand-button"
226-
{{on "click" this.handleGtsExpandClick}}
227-
aria-label={{this.toggleButtonLabel}}
228-
aria-expanded={{this.isExpanded}}
229-
>
230-
<HdsIcon @name={{this.expandIconName}} />
231-
</button>
249+
<div class="doc-code-group__expand-button-container">
250+
<button
251+
type="button"
252+
class="doc-code-group__expand-button"
253+
{{on "click" this.handleGtsExpandClick}}
254+
aria-expanded={{this.isExpanded}}
255+
>
256+
<HdsIcon @name={{this.expandIconName}} />
257+
<span>
258+
{{this.toggleButtonLabel}}
259+
</span>
260+
</button>
261+
</div>
232262
{{/if}}
233263
<CodeBlock
234264
@code={{this.currentViewSnippet}}

website/app/styles/doc-components/code-group.scss

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,28 @@
3636
.doc-code-group__language-picker-option {
3737
@include doc-font-style-code();
3838

39-
color: var(--doc-color-feedback-information-100);
39+
color: var(--doc-color-gray-200);
40+
border: 1px solid transparent;
4041
border-radius: 4px;
4142
cursor: pointer;
4243
padding-block: 4px;
4344
padding-inline: 12px;
4445

45-
&:has(input:checked) {
46-
background-color: var(--doc-color-feedback-information-400);
47-
}
48-
49-
&:hover {
50-
background-color: var(--doc-color-feedback-information-400)
51-
}
46+
&:has(input:checked) {
47+
color: var(--doc-color-feedback-information-100);
48+
background-color: var(--doc-color-feedback-information-400);
49+
border-color:var(--doc-color-feedback-information-100);
50+
}
5251

53-
&:active {
54-
background-color: var(--doc-color-feedback-information-300)
55-
}
52+
&:hover {
53+
background-color: var(--doc-color-feedback-information-400)
54+
}
5655
}
5756
}
5857

5958
.doc-code-group__secondary-actions {
60-
display: flex;
61-
flex-direction: row;
59+
display: flex;
60+
flex-direction: row;
6261
flex-grow: 1;;
6362
justify-content: flex-end;
6463
}
@@ -112,15 +111,27 @@
112111
position: relative;
113112
}
114113

115-
.doc-code-group__expand-button {
114+
.doc-code-group__expand-button-container {
116115
position: absolute;
117-
top: 16px;
118-
right: 16px;
116+
bottom: 16px;
119117
z-index: 1;
120-
padding: 8px;
118+
display: flex;
119+
justify-content: center;
120+
width: 100%;
121+
}
122+
123+
.doc-code-group__expand-button {
124+
@include doc-font-style-code();
125+
126+
display: flex;
127+
flex-direction: row;
128+
gap: 8px;
129+
align-items: center;
121130
color: white;
122131
background-color: #313A5C;
123132
border: 1px solid #7080BC;
124133
border-radius: 4px;
125134
cursor: pointer;
135+
padding-inline: 8px;
136+
padding-block: 2px;
126137
}

website/config/fastboot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This is needed for ember-shiki to work in fastboot: https://ember-shiki.pages.dev/#fastboot
12
module.exports = function () {
23
return {
34
buildSandboxGlobals(defaultGlobals) {

website/lib/markdown/markdown-process-demos.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ class MarkdownReplaceDemoBlocks extends Multifilter {
9595
if (fs.existsSync(jsFilePath)) {
9696
jsCode = fs.readFileSync(jsFilePath, 'utf8');
9797
dependencies.push(jsFilePath);
98-
} else {
99-
jsCode = `// Unable to load file: ${jsFileName}, path: ${jsFilePath}`;
10098
}
10199
escapedJsCode = escapeCode(jsCode);
102100
}

0 commit comments

Comments
 (0)