Skip to content

Commit

Permalink
fix(addon-doc): use code actions together (#5570)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Oct 9, 2023
1 parent a759118 commit 9451225
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
9 changes: 6 additions & 3 deletions projects/addon-doc/components/code/code.style.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
margin: 0;
white-space: normal;

&:hover .t-copy,
&:focus-visible .t-copy {
&:hover .t-code-actions,
&:focus-visible .t-code-actions {
opacity: 1;
}
}
Expand All @@ -24,11 +24,14 @@
margin-top: 1rem;
}

.t-copy {
.t-code-actions {
position: absolute;
top: 0.875rem;
right: 2rem;
display: flex;
opacity: 0;
gap: 0.5rem;
flex-direction: row-reverse;
}

// highlightjs added class
Expand Down
5 changes: 4 additions & 1 deletion projects/addon-doc/components/code/code.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
class="t-code"
>
<code [lineNumbers]="true" [highlight]="content"></code>
<tui-doc-copy class="t-copy" [cdkCopyToClipboard]="content"></tui-doc-copy>
<div class="t-code-actions">
<tui-doc-copy class="t-copy" [cdkCopyToClipboard]="content"></tui-doc-copy>
<ng-content></ng-content>
</div>
</pre>
15 changes: 12 additions & 3 deletions projects/addon-doc/components/code/tests/code.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ describe(`TuiDocCodeComponent`, () => {

expect(fixture.nativeElement.querySelector(`.t-code`)?.innerHTML.trim()).toEqual(
`<code class="hljs"><span class="hljs-keyword">const</span> a = <span class="hljs-number">5</span>;</code>
<tui-doc-copy class="t-copy"></tui-doc-copy>`,
<div class="t-code-actions">
<tui-doc-copy class="t-copy"></tui-doc-copy>
\t
</div>`.replace(`\t`, ` `), // prettier problem
);
});

Expand All @@ -68,7 +71,10 @@ describe(`TuiDocCodeComponent`, () => {

expect(fixture.nativeElement.querySelector(`.t-code`)?.innerHTML.trim()).toEqual(
`<code class="hljs"><span class="hljs-keyword">const</span> a = <span class="hljs-number">10</span>;</code>
<tui-doc-copy class="t-copy"></tui-doc-copy>`,
<div class="t-code-actions">
<tui-doc-copy class="t-copy"></tui-doc-copy>
\t
</div>`.replace(`\t`, ` `), // prettier problem
);
});

Expand All @@ -82,7 +88,10 @@ describe(`TuiDocCodeComponent`, () => {

expect(fixture.nativeElement.querySelector(`.t-code`)?.innerHTML.trim()).toEqual(
`<code class="hljs"><span class="hljs-keyword">const</span> a = <span class="hljs-number">15</span>;</code>
<tui-doc-copy class="t-copy"></tui-doc-copy>`,
<div class="t-code-actions">
<tui-doc-copy class="t-copy"></tui-doc-copy>
\t
</div>`.replace(`\t`, ` `), // prettier problem
);
});

Expand Down
13 changes: 0 additions & 13 deletions projects/addon-doc/components/example/example.style.less
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,6 @@
}
}

.t-code-actions {
position: absolute;
top: 4.375rem;
right: 1rem;
display: flex;
justify-content: flex-end;
align-items: center;

& > * {
margin-left: 0.5rem;
}
}

.t-link-icon {
margin-left: 0.3rem;
vertical-align: baseline;
Expand Down
5 changes: 2 additions & 3 deletions projects/addon-doc/components/example/example.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@
#codeSection
let-code
>
<section class="t-code-actions">
<tui-doc-code [code]="code">
<ng-container *ngFor="let action of codeActions">
<ng-container *polymorpheusOutlet="action as text; context: {$implicit: code}">
{{ text }}
</ng-container>
</ng-container>
</section>
<tui-doc-code [code]="code"></tui-doc-code>
</tui-doc-code>
</ng-template>

0 comments on commit 9451225

Please sign in to comment.